python

python syntax error on print

I'm new to python and am currently lost as to why print is giving a syntax here. Hoping someone might be able to point me in the right direction. Thanks Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print "hello World" Fi...

Unit testing for D-Bus and HAL?

How does one test a method that does some interactions with the local D-Bus (accessing a HAL object)? Results of tests will differ depending on the system that the test is run on, so I don't know how to provide the method reliable input. I'm working in Python, by the way. ...

Is there a way to list all the available drive letters in python?

More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system? (My google-fu seems to have let me down on this one.) Related: Enumerating all available drive letters in Windows (C++ / Win32) ...

Should my python web app use unicode for all strings?

I see some frameworks like Django using unicode all over the place so it seems like it might be a good idea. On the other hand, it seems like a big pain to have all these extra 'u's floating around everywhere. What will be a problem if I don't do this? Are there any issues that will come up if I do do this? I'm using Pylons right no...

PyODBC and Microsoft Access: Inconsistent results from simple query

I am using pyodbc, via Microsoft Jet, to access the data in a Microsoft Access 2003 database from a Python program. The Microsoft Access database comes from a third-party; I am only reading the data. I have generally been having success in extracting the data I need, but I recently noticed some discrepancies. I have boiled it down to ...

How do you validate a URL with a regular expression in Python?

I'm building a Google App Engine app, and I have a class to represent an RSS Feed. I have a method called setUrl which is part of the feed class. It accepts a url as an input. I'm trying to use the re python module to validate off of the RFC 3986 Reg-ex (http://www.ietf.org/rfc/rfc3986.txt) Below is a snipped which should work, right?...

Python interpreter with Linux Screen

I was working with Python with a Linux terminal screen. When I typed: help(somefunction) It printed the appropriate output, but then my screen was stuck, and at the bottom of the terminal was "(end)". How do I get unstuck? Thanks in advance. ...

How do I constrain the SCons Command builder to run only if its dependencies have changed?

I am using the Command builder in scons to specify that a particular script needs to be invoked to produce a particular file. I would like to only run the script if it has been modified since the file was previously generated. The default behaviour of the Command builder seems to be to always run the script. How can I change this? Th...

Python double pointer

I'm trying to get the values from a pointer to a float array, but it returns as c_void_p in python The C code double v; const void *data; pa_stream_peek(s, &data, &length); v = ((const float*) data)[length / sizeof(float) -1]; Python so far import ctypes null_ptr = ctypes.c_void_p() pa_stream_peek(stream, null_ptr, ctypes.c_ulon...

file handling in python

Hi, Thanks in advance. I have written a program which works for small files. But that doesn't work for files of 1 GB. Please tell me is there is any way to handle big file. Here is the code. fh=open('reg.fa','r') c=fh.readlines() fh.close() s='' for i in range(0,(len(c))): s=s+c[i] lines=s.split('\n') for line in s: ...

Python - Save the context

Hi to all, I need to save the context of the program before exiting ... I've put all the needed stuff to an object that I've previously created a I tried many times to picke it, but no way !! I continuously have errors like : PicklingError: Can't pickle 'SRE_Match' object: <_sre.SRE_Match object at 0x2a969cd9c0> OSError: [Errno 1] Oper...

List a dictionary

In a list appending is possible. But how I achieve appending in dictionary? Symbols from __ctype_tab.o: Name Value Class Type Size Line Section __ctype |00000000| D | OBJECT|00000004| |.data __ctype_tab |00000000| r | OBJECT|00000101| |.ro...

Debugging swig extensions for Python

Is there any other way to debug swig extensions except for doing gdb python stuff.py ? I have wrapped the legacy library libkdtree++ and followed all the swig related memory managemant points (borrowed ref vs. own ref, etc.). But still, I am not sure whether my binding is not eating up memory. It would be helpful to be able to ju...

Is Python2.6 stable enough for production use?

Or should I just stick with Python2.5 for a bit longer? ...

Using Python multiprocessing while importing a module via file path

I'm writing a program which imports a module using a file path, with the function imp.load_source(module_name,module_path). It seems to cause a problem when I try to pass objects from this module into a Process. An example: import multiprocessing import imp class MyProcess(multiprocessing.Process): def __init__(self,thing): ...

Django: custom constructor for form class, trouble with accessing data from request.POST.

Hello. I have written custom constructor for a form, the whole form class looks like this: class UploadForm(forms.Form): file = forms.FileField(label = "Plik") def __init__(self, coto, naglowek, *args, **kwargs): super(UploadForm, self).__init__(*args, **kwargs) self.coto = coto self.naglowek = naglowek...

What is the proper procedure for offering a patch to the Python documentation?

I'm about to dive into the source code for the cgi.py module again because the MiniFieldStorage class is mentioned in the documentation, but not actually documented. It occurred to me that I have done this so many times that maybe I could write documentation for it. If I did, how should I submit it? ...

str.format() -> how to left-justify

>>> print 'there are {0:10} students and {1:10} teachers'.format(scnt, tcnt) there are 100 students and 20 teachers What would be the code so that the output became: there are 100 students and 20 teachers Thanks. ...

Mosso Python Module

Hello, Has anybody had success installing the Mosso (cloudfiles) python module? I'm trying to install it and getting the following error. python-cloudfiles-1.3.1]# python setup.py install running install running build running build_py running install_lib byte-compiling /usr/lib/python2.3/site-packages/cloudfiles/container.py to contai...

Python's PIL crop problem: color of cropped image screwed

Hi, I have a probably very basic problem with PIL's crop function: The cropped image's colors are totally screwed. Here's the code: >>> from PIL import Image >>> img = Image.open('football.jpg') >>> img <PIL.JpegImagePlugin.JpegImageFile instance at 0x00 >>> img.format 'JPEG' >>> img.mode 'RGB' >>> box = (120,190,400,415) >>> area = img...