I am looking for some general advice about the mp3 format before I start a small project to make sure I am not on a wild-goose chase. My understanding of the internals of the mp3 format is minimal. Ideally, I am looking for a library that would abstract those details away. I would prefer to use Python (but could be
Validating with an XML schema in Python
I have an XML file and an XML schema in another file and I’d like to validate that my XML file adheres to the schema. How do I do this in Python? I’d prefer something using the standard library, but I can install a third-party package if necessary. Answer I am assuming you mean using XSD files. Surprisingly there aren’t
Create a zip file from a generator in Python?
I’ve got a large amount of data (a couple gigs) I need to write to a zip file in Python. I can’t load it all into memory at once to pass to the .writestr method of ZipFile, and I really don’t want to feed it all out to disk using temporary files and then read it back. Is there a
Convert a string to preexisting variable names
How do I convert a string to the variable name in Python? For example, if the program contains a object named self.post that contains a variable named, I want to do something like: Answer As referenced in Stack Overflow question Inplace substitution from ConfigParser, you’re looking for eval():
unpacking an array of arguments in php
Python provides the “*” operator for unpacking a list of tuples and giving them to a function as arguments, like so: This is equivalent to: Does anyone know if there is a way to achieve this in PHP? Some googling for variations of “PHP Unpack” hasn’t immediately turned up anything.. perhaps it’s called something different in PHP? Answer You can
Size of an open file object
Is there a way to find the size of a file object that is currently open? Specifically, I am working with the tarfile module to create tarfiles, but I don’t want my tarfile to exceed a certain size. As far as I know, tarfile objects are file-like objects, so I imagine a generic solution would work. Answer Adding ChrisJY’s idea
How do I determine all of my IP addresses when I have multiple NICs?
I have multiple Network Interface Cards on my computer, each with its own IP address. When I use gethostbyname(gethostname()) from Python’s (built-in) socket module, it will only return one of them. How do I get the others? Answer Use the netifaces module. Because networking is complex, using netifaces can be a little tricky, but here’s how to do what you
How do I find the location of Python module sources?
How do I learn where the source file for a given Python module is installed? Is the method different on Windows than on Linux? I’m trying to look for the source of the datetime module in particular, but I’m interested in a more general answer as well. Answer For a pure python module you can find the source by looking
Python re.findall with groupdicts
I kind of wish that there were a version of re.findall that returned groupdicts instead of just groups. Am I missing some simple way to accomplish the same result? Does anybody know of a reason that this function doesn’t exist? Answer You could use the finditer() function. This will give you a sequence of match objects, so you can get
Finding invocations of a certain function in a c++ file using python
I need to find all occurrences of a function call in a C++ file using python, and extract the arguments for each call. I’m playing with the pygccxml package, and extracting the arguments given a string with the function call is extremely easy: What I couldn’t find is a way of getting the calls parsing a file: Is there a