python

Clutter does not update screen outside of breakpoints

Hi, I have some code: l1 = clutter.Label() l1.set_position(100,100) for i in range(0,10): l1.set_text(str(i)) time.sleep(1) That is designed to show a count from 1 to 10 seconds on the screen in clutter, but I'm getting a strange error. When I run the script normally the screen runs as it should do, but there is no text displayed u...

Python decorator to ensure that kwargs are correct

I have done a decorator that I used to ensure that the keyword arguments passed to a constructor are the correct/expected ones. The code is the following: from functools import wraps def keyargs_check(keywords): """ This decorator ensures that the keys passed in kwargs are the onces that are specified in the passed tuple. When applied...

How to make easy_install execute custom commands in setup.py?

I want my setup.py to do some custom actions besides just installing the Python package (like installing an init.d script, creating directories and files, etc.) I know I can customize the distutils/setuptools classes to do my own actions. The problem I am having is that everything works when I cd to the package directory and do "python s...

Python CGI FieldStorage Too Slow

Hi Everyone, I have recently been learning python and have run into a problem when uploading files larger than 1-2mb with cgi. I am building a file uploader with a progress bar that updates with ajax. Everything is working great for smaller files and for larger files once it gets past the line: form = cgi.FieldStorage() I think ...

What are good names for user defined exceptions?

This question covers a broad range of programming languages; however, I am specifically working with Python in this case. I would like to create some user defined exceptions, but I'm not sure how fine-grained they should be. For example, if I have the following class: class Race(object): def __init__(self, start_time, end_time): ...

How to encapsulate python modules?

Is it possible to encapsulate python modules 'mechanize' and 'BeautifulSoup' into a single .py file? My problem is the following: I have a python script that requires mechanize and BeautifulSoup. I am calling it from a php page. The webhost server supports python, but doesn't have the modules installed. That's why I would like to do thi...

Help with Python in the web

I've been using Werkzeug to make WSGI compliant applications. I'm trying to modify the code in the front page. Its basic idea is that you go to the /hello URL and you get a "Hello World!" message. You go to /hello/ and you get "hello !". For example, /hello/jeff yields "Hello Jeff!". Anyway, what I'm trying to do is putting a form in th...

Embed a spreadsheet/table in a PyGTK application?

Hi, In my application, we want to present the user with a typical spreadsheet/table (OO.O/Excel-style), and then pull out the values and do something with them internally. Is there a preexisting widget for PyGTK that does this? The PyGTK FAQ mentions GtkGrid, but the link is dead and I can't find a tarball anywhere. ...

How do I partition datetime intervals which overlap (Org Mode clocked time)?

I have related tasks from two Org files/subtrees where some of the clocked time overlaps. These are a manual worklog and a generated git commit log, see below. One subtree's CLOCK: entries needs to be adjusted to remove overlapping time. The other subtree is considered complete, and it's CLOCK: entries should not be adjusted. EDIT: Thi...

Format floats with standard json module

I am using the standard json module in python 2.6 to serialize a list of floats. However, I'm getting results like this: >>> import json >>> json.dumps([23.67, 23.97, 23.87]) '[23.670000000000002, 23.969999999999999, 23.870000000000001]' I want the floats to be formated with only two decimal digits. The output should look like this: ...

How to send a file via HTTP, the good way, using Python?

If a would-be-HTTP-server written in Python2.6 has local access to a file, what would be the most correct way for that server to return the file to a client, on request? Let's say this is the current situation: header('Content-Type', file.mimetype) header('Content-Length', file.size) # file size in bytes header('Content-MD5', file.hash...

Installed Python to portable python

I have installed python from .msi installer in windows and installed a lot of other modules. i would like to have all these available on a portable thumbdrive, but i don't want to redownload all the extramodules. Is there a way i can convert my C:\python26* to a portable python installation? ...

How do I see the results of my class on a file?

I found this class to take a space delimited file and if there are multiple spaces, they will be treated as a single separator. How do I see the effects of this on a file? class FH: def __init__(self, fh): self.fh = fh def close(self): self.fh.close() def seek(self, arg): self.fh.seek(arg) de...

Symlinks on windows?

Does anyone know of a way to make/read symbolic links across versions of win32 from Python? Ideally there should be a minimum amount of platform specific code, as I need my app to be cross platform. ...

Error trying to pass (large) image over socket in python ..

I am trying to pass an image over python socket for smaller images it works fine but for larger images it gives error as socket.error: [Errno 10040] A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itse...

Django ORM, filtering objects by type with model inheritence.

So I have two models... Parent and Child. Child extends Parent. When I do Parent.objects.all(), I get both the Parents and the Children. I only want Parents Is there a Parent.objects.filter() argument I can use to only get the Parent objects instead of the objects that extend parent? ...

IDLE and Python have different path in Mac OS X

I am running Mac OS X 10.5.8. I have installed Python 2.6 from the site. It's in my application directory. I have edited my .bash_profile to have: # Setting PATH for MacPython 2.6 # The orginal version is saved in .bash_profile.pysave PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}" export PATH export PATH=/usr/lo...

Decorators should not have side effects?

Editing because the initial code was confusing. I would assume these two things to be same, #I would use either of these #Option 1 def bar(*args): pass foo = deco(bar) #Option2 @deco def foo(*args): pass However if the decorators deco has side effects, this is not guaranteed. In partcicular, this was my ecpectation form a de...

How to integrate JQGrid with Django/Python

Anybody out there who have tried to use JQGrid a Jquery plugin with django? Please share your knowledge/code samples Gath ...

Python SOCK_STREAM over internet ...

I have a simple programs for socket client and server its not working over internet # Echo server program import socket import ImageGrab HOST = '' # Symbolic name meaning all available interfaces PORT = 3000 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, ...