python

Setting the width of a wxPython TextCtrl in number of characters

I have a TextCtrl in my wxPython program and I'd like to set its width to exactly 3 characters. However, the only way to set its size manually accepts only numbers of pixels. Is there any way to specify characters instead of pixels? ...

TimedRotatingFileHandler Changing File Name?

I am trying to implement the python logging handler called TimedRotatingFileHandler. When it rolls over to midnight it appends the current day in the form: "YYYY-MM-DD". LOGGING_MSG_FORMAT = '%(name)-14s > [%(levelname)s] [%(asctime)s] : %(message)s' LOGGING_DATE_FORMAT = '%Y-%m-%d %H:%M:%S' logging.basicConfig( level=logging.DEB...

Tool to convert python indentation from spaces to tabs?

I have a some .py files that use spaces for indentation, and I'd like to convert them to tabs. I could easily hack together something using regexes, but I can think of several edge cases where this approach could fail. Is there a tool that does this by parsing the file and determining the indentation level the same way the python inter...

python ImportError No module named

Hello, I am very new at python and I am getting this error: Traceback (most recent call last): File "mountain.py", line 28, in ? from toolkit.interface import interface ImportError: No module named toolkit.interface Python is installed in a local directory: My directorie tree is like this: (local directory)/site-packages/toolk...

Python: Nicest way to pad zeroes to string

What is the nicest/shortest way to pad a string with zeroes to the left, so the string length has a specific length? ...

How do you unzip very large files in python?

Using python 2.4 and the built-in ZipFile library, I cannot read very large zip files (greater than 1 or 2 GB) because it wants to store the entire contents of the uncompressed file in memory. Is there another way to do this (either with a third-party library or some other hack), or must I "shell out" and unzip it that way (which isn't ...

Writing a compiler for a DSL in python

I am writing a game in python and have decided to create a DSL for the map data files. I know I could write my own parser with regex, but I am wondering if there are existing python tools which can do this more easily, like re2c which is used in the PHP engine. Some extra info: Yes, I do need a DSL, and even if I didn't I still want t...

Problems raising a ValidationError on a Django Form

I'm trying to validate that a submitted URL doesn't already exist in the database. The relevant parts of the Form class look like this: from django.contrib.sites.models import Site class SignUpForm(forms.Form): # ... Other fields ... url = forms.URLField(label='URL for new site, eg: example.com') def clean_url(self): ...

End-line characters from lines read from text file, using Python

When reading lines from a text file using python, the end-line character often needs to be truncated before processing the text, as in the following example: f = open("myFile.txt", "r") for line in f: line = line[:-1] # do something with line Is there an elegant way or idiom for retrieving text lines without th...

How do I strptime from a pattern like this?

Hi, I need to use a datetime.strptime on the text which looks like follows. "Some Random text of undetermined length Jan 28, 1986" how do i do this? ...

Proxy objects in IronPython

I'm trying to make a proxy object in IronPython, which should dynamically present underlying structure. The proxy itself shouldn't have any functions and properties, I'm trying to catch all the calls in the runtime. Catching the function calls is easy, I just need to define getattr() function for my object, and check does appropriate fun...

IronPython For Unit Testing over C#

We know that Python provides a lot of productivity over any compiled languages. We have programming in C# & need to write the unit test cases in C# itself. If we see the amount of code we write for unit test is approximately ten times more than the original code. Is it ideal choice to write unit test cases in IronPython instead of C#?...

Is rewriting a PHP app into Python a productive step?

I have some old apps written in PHP that I'm thinking of converting to Python - both are websites that started as simple static html, then progressed to PHP and now include blogs with admin areas, rss etc. I'm thinking of rewriting them in Python to improve maintainability as well as to take advantage of my increase in experience to writ...

Suppressing Output of Paramiko SSHClient Class

When I call the connect function of the Paramiko SSHClient class it outputs some log data about establishing the connection, which I would like to suppress. Is there a way to do this either through Paramiko itself, or python in general? Thanks in advance ...

Will Python 3.0's backwards-incompatibility affect adoption?

I visited Slashdot this morning to find out that Python 3.0 has been released. I know C# and Perl, but have wanted to learn Python for some time, especially after I saw its ease of use to create useful tools, not to mention its use in game scripting. My question is, how does the intentionally backwards-incompatible release of Python ...

Automatically generating test cases

I'm writing a script a script to test a third party XML interface, using the python unittest module. First of all, is this a reasonable use of unittest, using an API we wrote, but actually testing the interface it's connecting to? Secondly, I have a huge list of fields I want to test. The code to test each field is identical. I want to...

What features of Python 3.0 will change your everyday coding?

Py3k just came out and has gobs of neat new stuff! I'm curious, what are SO pythonistas most excited about? What features are going to affect the way you write code on a daily basis, or have you been looking forward to? ...

How can I reboot a Windows XP64 Machine in a Python Script?

How can I reboot a Windows XP64 Machine in a Python Script? This machine does not have the "shutdown" or "restart" executables available. ...

Can I install python 3.x and 2.x on the same computer?

I'm running windows and the shell/os automatically runs python based on the registry settings when you run a program on the command line. Will this break if I install a 2.x and 3.x version of python on the same machine? I want to play with 3.0 while still be able to run 2.x scripts on the same machine... ...

Python Decorators run before function it is decorating is called?

As an example, def get_booking(f=None): print "Calling get_booking Decorator" def wrapper(request, **kwargs): booking = _get_booking_from_session(request) if booking == None: # we don't have a booking in our session. return HttpRedirect('/') else: return f(request=reque...