I have a python script I want to distribute to Windows, where people might not have python installed. So I use py2exe. The problem is in the script I run other python scripts by using subprocess, which requires python interpreter as the program to execute. As I don’t have python interpreter installed on…
Tag: python
How to convert an iterable to a stream?
If I’ve got an iterable containing strings, is there a simple way to turn it into a stream? I want to do something like this: Answer Here’s my streaming iterator an experimental branch of urllib3 supporting streaming chunked request via iterables: Source with context: https://github.com/shazow/url…
What is the Python way to walk a directory tree?
I feel that assigning files, and folders and doing the += [item] part is a bit hackish. Any suggestions? I’m using Python 3.2 Answer Take a look at the os.walk function which returns the path along with the directories and files it contains. That should considerably shorten your solution.
Python Django Templates and testing if a variable is null or empty string
I am pretty new to django, but have many years experience coding in the java world, so I feel ridiculous asking this question – I am sure the answer is obvious and I am just missing it. I can’t seem to find the right way to query this in google or something… I have searched through the djang…
How can I convert a string with dot and comma into a float in Python
How can I convert a string like 123,456.908 to float 123456.908 in Python? For ints, see How to convert a string to a number if it has commas in it as thousands separators?, although the techniques are essentially the same. Answer Just remove the , with replace():
Convert SVG to PNG in Python
How do I convert an svg to png, in Python? I am storing the svg in an instance of StringIO. Should I use the pyCairo library? How do I write that code? Answer The answer is “pyrsvg” – a Python binding for librsvg. There is an Ubuntu python-rsvg package providing it. Searching Google for its …
How to stitch several PDF pages into one big canvas-like PDF?
I have a 32-page PDF of my family tree. Instead of having the family tree all on one really big PDF page (which is what I want), it is formatted so a group of 8 individual US letter-sized pages are supposed to be stitched across the width; 4 rows of this completes the tree. The margins of each page are
Installing multiple versions of a package with pip
In my application I would like to use: packageA, which requires packageX==1.3 packageB, which requires packageX==1.4 packageX==1.5 How can I install multiple versions of packageX with pip to handle this situation? Answer pip won’t help you with this. You can tell it to install a specific version, but it…
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…