Using SQLAlchemy, an Engine object is created like this: Accessing engine fails if the database specified in the argument to create_engine (in this case, mydb) does not exist. Is it possible to tell SQLAlchemy to create a new database if the specified database doesn’t exist? Answer On postgres, three da…
Tag: python
Dictionary keys match on list; get key/value pair
In python… I have a list of elements ‘my_list’, and a dictionary ‘my_dict’ where some keys match in ‘my_list’. I would like to search the dictionary and retrieve key/value pairs for the keys matching the ‘my_list’ elements. I tried this… But it doesn…
Terminal text becomes invisible after terminating subprocess
After terminating an ffmpeg subprocess, the terminal gets messed up – typed characters are invisible! The input still works in that commands can be executed, but keyboard input is not echoed to the terminal. Issuing shell command reset puts everything back to normal (or !reset from within ipython), so a…
How to have Calendar thing in Django date field
I have this Datetime field in Django But I want the Calendar to pop up. In docs, they say to write this Now I have a few problems: Where to declare this class and how to use it I don’t have pretty.css , animation.css , how can get it Do I need to do programming for it?? Answer The files
How to get a list of all the Python standard library modules?
I want something like sys.builtin_module_names except for the standard library. Other things that didn’t work: sys.modules – only shows modules that have already been loaded sys.prefix – a path that would include non-standard library modules and doesn’t seem to work inside a virtualenv…
How to add the current query string to an URL in a Django template?
When I load a page, there is a link “sameLink” that I want to append to it the query string of its containing page. I have following URL: How can I do that? Answer To capture the QUERY_PARAMS that were part of the request, you reference the dict that contains those parameters (request.GET) and url…
How to convert an H:MM:SS time string to seconds in Python?
Basically I have the inverse of this problem: Python Time Seconds to h:m:s I have a string in the format H:MM:SS (always 2 digits for minutes and seconds), and I need the integer number of seconds that it represents. How can I do this in python? For example: “1:23:45” would produce an output of 50…
HTTP requests and JSON parsing in Python [duplicate]
This question already has answers here: How can I parse (read) and use JSON? (5 answers) What are the differences between the urllib, urllib2, urllib3 and requests module? (11 answers) Closed last month. I want to dynamically query Google Maps through the Google Directions API. As an example, this request cal…
Using @functools.lru_cache with dictionary arguments
I have a method that takes (among others) a dictionary as an argument. The method is parsing strings and the dictionary provides replacements for some substrings, so it doesn’t have to be mutable. This function is called quite often, and on redundant elements so I figured that caching it would improve i…
python win32 COM closing excel workbook
I open several different workbooks (excel xlsx format) in COM, and mess with them. As the program progresses I wish to close one specific workbook but keep the rest open. How do I close ONE workbook? (instead of the entire excel application) Answer The the Workbook COM object has a Close() method. Basically, …