Python3 – reload() can not be called on __import__ object?

The reload built-in function has been moved to importlib module in Python 3.4: In [18]: from importlib import reload In [19]: reload? Reload the module and return it. The module must have been successfully imported before. As pointed out by @JPaget in comments reload() function has been moved from imp to importlib module in Python … Read more

Random word generator- Python

Reading a local word list If you’re doing this repeatedly, I would download it locally and pull from the local file. *nix users can use /usr/share/dict/words. Example: word_file = “/usr/share/dict/words” WORDS = open(word_file).read().splitlines() Pulling from a remote dictionary If you want to pull from a remote dictionary, here are a couple of ways. The requests … Read more

Why is dictionary ordering non-deterministic?

Update: In Python 3.6, dict has a new implementation which preserves insertion order. From Python 3.7, this order-preserving behaviour is guaranteed: the insertion-order preservation nature of dict objects has been declared to be an official part of the Python language spec. This is the result of a security fix from 2012, which was enabled by … Read more

Is there official guide for Python 3.x release lifecycle?

Yes, you could look at the table in the Pythons Developer Guide for most releases. Specifically Python 3.3 will have security fixes until 2017-09-29. Additionally, appropriate PEPs exist (google-able or from the devguide table) for each branch where a lifespan section specifies these. For 3.3 in PEP 398: 3.3 will receive bugfix updates approximately every … Read more

Writing to CSV with Python adds blank lines [duplicate]

The way you use the csv module changed in Python 3 in several respects (docs), at least with respect to how you need to open the file. Anyway, something like import csv with open(‘test.csv’, ‘w’, newline=””) as fp: a = csv.writer(fp, delimiter=”,”) data = [[‘Me’, ‘You’], [‘293’, ‘219’], [’54’, ’13’]] a.writerows(data) should work.

Return in generator together with yield

This is a new feature in Python 3.3. Much like return in a generator has long been equivalent to raise StopIteration(), return <something> in a generator is now equivalent to raise StopIteration(<something>). For that reason, the exception you’re seeing should be printed as StopIteration: 3, and the value is accessible through the attribute value on … Read more