Skip to content

How can I make a deepcopy of a function in Python?

I would like to make a deepcopy of a function in Python. The copy module is not helpful, according to the documentation, which says: This module does not copy types like module, method, stack trace, stack frame, file, socket, window, array, or any similar types. It does “copy” functions and classes (shallow a…

Regular expression to find any number in a string

What’s the notation for any number in re? Like if I’m searching a string for any number, positive or negative. I’ve been using d+ but that can’t find 0 or -1 Answer Searching for positive, negative, and/or decimals, you could use [+-]?d+(?:.d+)? This isn’t very smart about leadin…

How to create a new database using SQLAlchemy?

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…

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 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…