How do I compile my Python 3 app to an .exe? [closed]

cx_Freeze does this but creates a folder with lots of dependencies. py2exe now does this and, with the –bundle-files 0 option, creates just one EXE, which is probably the best solution to your question. UPDATE: After encountering third-party modules that py2exe had trouble “finding”, I’ve moved to pyinstaller as kotlet schabowy suggests below. Both have … Read more

Printing subscript in python

If all you care about are digits, you can use the str.maketrans() and str.translate() methods: example_string = “A0B1C2D3E4F5G6H7I8J9” SUB = str.maketrans(“0123456789”, “₀₁₂₃₄₅₆₇₈₉”) SUP = str.maketrans(“0123456789”, “⁰¹²³⁴⁵⁶⁷⁸⁹”) print(example_string.translate(SUP)) print(example_string.translate(SUB)) Which will output: A⁰B¹C²D³E⁴F⁵G⁶H⁷I⁸J⁹ A₀B₁C₂D₃E₄F₅G₆H₇I₈J₉ Note that this won’t work in Python 2 – see Python 2 maketrans() function doesn’t work with Unicode for an explanation of … Read more

Getting certificate chain with Python 3.3 SSL module

Thanks to the contributing answer by Aleksi, I found a bug/feature request that already requested this very thing: http://bugs.python.org/issue18233. Though the changes haven’t been finalized, yet, they do have a patch that makes this available: This is the test code which I’ve stolen from some forgotten source and reassembled: import socket from ssl import wrap_socket, … Read more

Return in generator together with yield

This is a new feature in Python 3.3 (as a comment notes, it doesn’t even work in 3.2). 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, … Read more

‘str’ object has no attribute ‘decode’ in Python3

One encodes strings, and one decodes bytes. You should read bytes from the file and decode them: for lines in open(‘file’,’rb’): decodedLine = lines.decode(‘ISO-8859-1’) line = decodedLine.split(‘\t’) Luckily open has an encoding argument which makes this easy: for decodedLine in open(‘file’, ‘r’, encoding=’ISO-8859-1′): line = decodedLine.split(‘\t’)