python

Learning to write reusable libraries

We need to write simple scripts to manipulate the configuration of our load balancers (ie, drain nodes from pools, enabled or disable traffic rules). The load balancers have a SOAP API (defined through a bunch of WSDL files) which is very comprehensive but using it is quite low-level with a lot of manual error checking and list manipulat...

String manipulation in Python docstrings

I've been trying to do the following: #[...] def __history_dependent_simulate(self, node, iterations=1, *args, **kwargs): """ For history-dependent simulations only: """ + self.simulate.__doc___ What I tried to accomplish here is to have the same documentation for this p...

Verifying peer in SSL using python

Hi, I was trying to find out how I can go about verifying a self-signed certificate by a server in python. I could not find much data in google. I also want to make sure that the server url Thanks in advance for any insights. ...

Is it normal that running python under valgrind shows many errors with memory?

I've tried to debug memory crash in my Python C extension and tried to run script under valgrind. I found there is too much "noise" in the valgrind output, even if I've ran simple command as: valgrind python -c "" Valgrind output full of repeated info like this: ==12317== Invalid read of size 4 ==12317== at 0x409CF59: PyObject_Fre...

How do you host your own egg repository?

Say you're on a team that's maintaining a lot of internal python libraries(eggs), and for whatever reason uploading them to pypi is not an option. How could you host the libraries(eggs) so that easy_install can still work for the members of your team? Basically it would be cool if this worked.... (someproj)uberdev@hackmo:~$ easy_instal...

Provisioning mercurial server

I'm in need of a software (not a service) that has a web API to both create as well as interact with mercurial repositories. In my mind's eye I imagine the API might look like: POST /repos name=foo Creates a repository at /repos/foo, which then works as per hgwebdir.cgi. Does such software exist? If not, any recommendations about...

NumPy and memmap: [Errno 24] Too many open files...

I am working with large matrixes, so I am using NumPy's memmap. However, I am getting an error as apparently the file descriptors used by memmap are not being closed. import numpy import tempfile counter = 0 while True: temp_fd, temporary_filename = tempfile.mkstemp(suffix='.memmap') map = numpy.memmap(temporary_filename, dtype...

Python SQLAlchemy/Elixer Question

I am trying to define a SQLAlchemy/Elixer model that can describe the following relationship. I have an SSP table, which has multiple Foreign Keys to the POC table. I've defined the ManyToOne relationships correctly within the SSP object (allowing me to SSP.get(1).action.first_name correctly). What I would also like to add is the other s...

How to check which version of Numpy I'm using?

How can I check which version of Numpy I'm using? I'm using Mac OS X 10.6.1 Snow Leopard. ...

How to update Numpy on Mac OS X Snow Leopard?

How can I update Numpy into the newest one? Should I download .dmg file from here: http://sourceforge.net/projects/numpy/files/ This .dmg is only for 10.5? I installed numpy using these instructions: http://www.scipy.org/Installing_SciPy/Mac_OS_X My current Numpy is 1.2.1. I'm running on Mac OS X 10.6.1 Snow Leopard. Thanks! ...

Python: Running command line application to the script. Sending parameters in files

I want to try to use a command line script with my python application. The task is the following, my database stores some initial data for the script and I need to execute a command line application in a following way: $ application -parameter1 -file1 Here file1 is a file which contains my initial data, and parameter1 is an unrelated ...

How does Python's triple-quote string work?

How should this function be changed to return "123456"? def f(): s = """123 456""" return s UPDATE: Everyone, the question is about understanding how to not have \t or whatever when having a multiline comment, not how to use the re module. ...

Getting proper code completion for Python on Vim?

I've gotten omnicompletion with Pysmell to work before, but I can't seem to do it again. I tried following some steps online, but most, if not all, of them are to vague and assume too much that you know what you are doing to some extent. Can someone post a full, step-by-step tutorial on how to get code completion working properly, for...

Compile pyme for Python 2.6

Hi, Has anyone been able to compile pyme (http://sourceforge.net/projects/pyme/) I installed mingw32 and I can compile other modules like pycrypto without issues, but pyme is proving to be a real pain in the you know what :-) ...

Suggested second-step textbook for self-educating programmer?

I'm currently giving myself a self-taught crash course in computer science, half for fun and half for continuing education. I'm just about finished with John Zelle's Python Programming: An Introduction To Computer Science (http://amzn.com/1887902996), and now I'm looking for a second book to pick up for when I do finish this one. Just ...

Python Fixed Length Packet

I am trying to build a fixed length packet in python for an ATSC PSIP generator. This is probably very simple but so far I can't seem to get it to work. I am trying to build a packet with fields similar to the following: table_id = 0xCB syntax = 0b1 reserved = 0b11 table_ext = 0xFF the end goal would be the following in binary '110...

Basic Comet in Python using just std lib

I'm developing a web interface for an already existing desktop application. I've been looking for a way to allow the server to push content to the browser and ended up reaching Comet. Navigating through the internet, and most of the questions here, I got answers like twisted, orbited, tornado and most of them even point to java applicat...

Is it possible to reduce an image's depth using PIL?

Is it possible to reduce the depth of an image using PIL? Say like going to 4bpp from a regular 8bpp. ...

What is a good size (in bytes) for a log file?

I am using the python logging modules RotatingFileHandler, and you can set the maximum size of each log file. What is a good maximum size for a log file? Please give your answer in bytes. ...

How do you know when two objects can communicate?

class GuiMaker(Frame): #more code def __init__(self, parent=None): Frame.__init__(self, parent) self.pack(expand=YES, fill=BOTH) # make frame stretchable self.start() # for subclass: set menu/toolBar self.makeMenuBar() # done here: build menu-...