python

Python regex: Turn "ThisFileName.txt" into "This File Name.txt"

I'm trying to add a space before every capital letter, except the first one. Here's what I have so far, and the output I'm getting: >>> tex = "ThisFileName.txt" >>> re.sub('[A-Z].', ' ', tex) ' his ile ame.txt' I want: 'This File Name.txt' (It'd be nice if I could also get rid of .txt, but I can do that in a separate operation.) ...

Is there a Vim equivalent to the Linux/Unix "fold" command?

I realize there's a way in Vim to hide/fold lines, but what I'm looking for is a way to select a block of text and have Vim wrap lines at or near column 80. Mostly I want to use this on comments in situations where I'm adding some text to an existing comment that pushes it over 80 characters. It would also be nice if it could insert ...

What is Erlang's secret to scalability?

Erlang is getting a reputation for being untouchable at handling a large volume of messages and requests. I haven't had time to download and try to get inside Mr. Erlang's understanding of switching theory... so I'm wondering if someone can teach me (or point to a good instructional site.) Say as a thought-experiment I wanted to port ...

Mixed language source directory layout

We are running a large project with several different languages: Java, Python, PHP, SQL and Perl. Until now people have been working in their own private repositories, but now we want to merge the entire project in a single repository. The question now is: how should the directory structure look? Should we have separate directories for...

How do I ensure that only one of a certain category of job runs at once in Hudson?

I use Hudson to automate the testing of a very large important product. I want to have my testing-hosts able to run as many concurrent builds as they will theoretically support with the exception of excel-tests which must only run one per machine at any time. Any number of non-excel tests can run concurrently, however at most one excel t...

Is plotting an image on a map with matplotlib possible?

Using basemap it's easy to plot a set of coordinates, like so: x, y = m(lons, lats) m.plot(x, y, 'go') but would it be possible to use an image instead of the green circle ('go')? I didn't find a direct way of doing this from the documentation. So, let's clarify this a bit: I'm using a map generated with basemap as a background a...

Control 2 separate Excel instances by COM independently... can it be done?

I've got a legacy application which is implemented in a number of Excel workbooks. It's not something that I have the authority to re-implement, however another application that I do maintain does need to be able to call functions in the Excel workbook. It's been given a python interface using the Win32Com library. Other processes can ...

return eats exception

I found the following behavior at least weird: def errors(): try: ErrorErrorError finally: return 10 print errors() # prints: 10 # It should raise: NameError: name 'ErrorErrorError' is not defined The exception disappears when you use return inside a finally clause. Is that a bug? Is that documented anywhere? ...

How do I write output in same place on the console?

I am new to python and am writing some scripts to automate downloading files from FTP servers, etc. I want to show the progress of the download, but I want it to stay in the same position, such as: output: Downloading File FooFile.txt [47%] I'm trying to avoid something like this: Downloading File FooFile.txt [47%] Down...

HOWTO: Write Python API wrapper?

I'd like to write a python library to wrap a REST-style API offered by a particular Web service. Does anyone know of any good learning resources for such work, preferably aimed at intermediate Python programmers? I'd like a good article on the subject, but I'd settle for nice, clear code examples. CLARIFICATION: What I'm looking to do ...

BinaryFields in Django Models

I have a twenty byte hex hash that I would like to store in a django model. If I use a text field, it's interpreted as unicode and it comes back garbled. Currently I'm encoding it and decoding it, which really clutters up the code, because I have to be able to filter by it. def get_changeset(self): return bin(self._changeset) de...

String formatting in Python

I want to do something like String.Format ("[{0}, {1}, {2}]", 1, 2, 3) which returns: [1, 2, 3] How do I do this in Python? ...

Execute a string as a command in python

I am developing my stuff in python. In this process I encountered a situation where I have a string called "import django". And I want to validate this string. Which means, I want to check whether the module mentioned('django' in this case) is in the python-path. How can I do it? ...

What is the best way to remove accents in a python unicode string?

I have a unicode string in python, and I would like to remove all the accents (diacritics). I found on the Web an elegant way to do this in Java: convert the unicode string to its long normalized form (with a separate character for letters and diacritics) remove all the characters whose unicode type is "diacritic". Do I need to inst...

How to clear python interpreter console?

Like most Python developers, I typically keep a console window open with the Python interpreter running to test commands, dir() stuff, help() stuff, etc. Like any console, after a while the visible backlog of past commands and prints gets to be cluttered, and sometimes confusing when re-running the same command several times. I'm wonde...

Getting the length of an array in Python

In python is this the only way to get the number of elements: arr.__len__() If so, why the strange syntax? ...

How to work with unsaved many-to-many relations in django?

I have a couple of models in django which are connected many-to-many. I want to create instances of these models in memory, present them to the user (via custom method-calls inside the view-templates) and if the user is satisfied, save them to the database. However, if I try to do anything on the model-instances (call rendering methods,...

List/Arrays - Check Dates

I'm trying to make a program that checks an array to make sure there are four folders with partially same names. So For a date like 0103 (jan 3rd), there should be 0103-1, 0103-2, 0103-3, and 0103-4. Other folders are like 0107-1, 0107-2, 0107-3, 0107-4. How do I go about doing this? I thought about using glob.glob (python) and wildcar...

Getting OperationalError: FATAL: sorry, too many clients already using psycopg2

I am getting the error OperationalError: FATAL: sorry, too many clients already when using psycopg2. I am calling the close method on my connection instance after I am done with it. I am not sure what could be causing this, it is my first experience with python and postgresql, but I have a few years experience with php, asp.net, mysql, a...

Lazy Method for Reading Big File in Python?

I have a very big file 4GB and when I try to read it my computer hangs. So I want to read it piece by piece and after processing each piece store the processed piece into another file and read next piece. Is there any method to yield these pieces ? I would love to have a lazy method. ...