Best way to return multiple values from a function? [closed]

Named tuples were added in 2.6 for this purpose. Also see os.stat for a similar builtin example. In recent versions of Python 3 (3.6+, I think), the new typing library got the NamedTuple class to make named tuples easier to create and more powerful. Inheriting from typing.NamedTuple lets you use docstrings, default values, and type annotations. Example (From the docs):

Pip freeze vs. pip list

When you are using a virtualenv, you can specify a requirements.txt file to install all the dependencies. A typical usage: The packages need to be in a specific format for pip to understand, which is That is the “requirements format”. Here, django==1.4.2 implies install django version 1.4.2 (even though the latest is 1.6.x). If you … Read more

Converting string into datetime

datetime.strptime is the main routine for parsing strings into datetimes. It can handle all sorts of formats, with the format determined by a format string you give it: The resulting datetime object is timezone-naive. Links: Python documentation for strptime: Python 2, Python 3 Python documentation for strptime/strftime format strings: Python 2, Python 3 strftime.org is … Read more