python

Wildcard for PyGTK States

How do I combine: button.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("Green")) button.modify_bg(gtk.STATE_ACTIVE, gtk.gdk.color_parse("Green")) button.modify_bg(gtk.STATE_SELECTED, gtk.gdk.color_parse("Green")) etc. Into a one-liner wildcard covering all of the possible states (See Doc) ...

how % applies to this method in Python?

From my studying of python, I've found two uses for %. It can be used as what's called a modulo, meaning it will divide the value to the left of it and the value to the right of it and spit back the remainder. The other use is a string formatter. So I can do something like 'Hi there %s' % name, where name is a list of names. Also, if y...

Ñ not displayed in google app engine website

I'm using google app engine to build a website and I'm having problems with special characters. I think I've reduced the problem to this two code samples: request = urlfetch.fetch( url=self.WWW_INFO, payload=urllib.urlencode(inputs), method=urlfetch.POST, headers={'Content-Type': 'application/x-www-form-urlencode...

HTML tag replacement using regex and python

I have a Python script that will look at an HTML file that has the following format: <DOC> <HTML> ... </HTML> </DOC> <DOC> <HTML> ... </HTML> </DOC> How do I remove all HTML tags (replace the tags with '') with the exception of the opening and closing DOC tags using regex in Python? Also, if I want to retain the alt-text of an tag, w...

How to build a mini-network of small programs feeding each other data?

I'm trying to simulate a real-time network where nodes are consumers and producers of different rates. How would I quickly implement a sample of this with Python? I was imagining that I'd write a simple program for each node, but I'm not sure how to connect them to each other. ...

How do I Access File Properties on Windows Vista with Python?

The question is as simple as in the title, how do I access windows file properties like date-modifed, and more specifically tags, with Python? For a program I'm doing, I need to get lists of all the tags on various files in a particular folder, and I'm not sure on how to do this. I have the win32 module, but I don't see what I need. Tha...

how are these two variables unpacked?

Through tutorials I had learned that you can define two variables in the same statement, e.g.: In [15]: a, b = 'hello', 'hi!' In [16]: a Out[16]: 'hello' In [17]: b Out[17]: 'hi!' well how does that apply to here? fh, opened = cbook.to_filehandle(fname, 'w', return_opened = True) I prodded further: In [18]: fh Out[18]: <open fil...

Do any sites using MVC frameworks ( php, python ) post their full source through a VC browser?

I recall Django had its source online awhile ago, I'm just looking to study how a fully functional site operates - I don't mind looking at any type of Python/PHP based MVC framework such as Pylons, Django, Zend, or Kohana. ...

there's PyQuery....is there one for Ruby ?

you guys know Pyquery i was wondering if theres one for Ruby ...

Putting in extra restrictions when filtering on foreignkey in django-admin

When getting members based on Unit, I only want to get the ones who are actually in that unit as of now. I've got a model looking like this: class Member(models.Model): name = models.CharField(max_length=256) unit = models.ManyToManyField(Unit, through='Membership') class Membership(models.Model): member = models.ForeignKe...

How to pack a tkinter widget underneath an existing widget that has been packed to the left side?

Hi all, I'm attempting to write a basic Tkinter GUI that has a Text widget at the top, then a Button widget left aligned under it, then another Text widget underneath the button. The problem I'm having is, after packing the Button widget to the left, when I then go to pack the second Text widget, it puts it next to the button on the ri...

Resize image twice in Django using PIL

I have a function in which I'm trying to resize a photo twice from request.FILES['image']. I'm using the image.thumbnail() with the Parser as well. This works fine when I create one thumbnail, but in my view if I repeat the exact same thing again, it fails in the parser via IOError cannot parse image. I'm very confused. I've created Stri...

Using mechanize to visit a site that requires SSL

I need to visit a site (https://*) that requires me to install two certificates in Firefox before I can visit it successfully. One I can export as a .p12 file (Client Certificate), and one is a .crt file (CA Certificate). If I try accessing this site without these certificates, I get a "failed handshake error". How do I visit this site ...

Return a list of dictionaries that match the corresponding list of values in python

For example, this is my list of dictionaries: [{'name': 'John', 'color': 'red' }, {'name': 'Bob', 'color': 'green'}, {'name': 'Tom', 'color': 'blue' }] Based on the list ['blue', 'red', 'green'] I want to return the following: [{'name': 'Tom', 'color': 'blue' }, {'name': 'John', 'color': 'red' }, {'name': 'Bob', 'color': '...

Python: Behaviour of increment and decrement operators

I am a newbie to Python. I notice that a pre-increment/decrement operator can be applied on a variable (like ++count). It compiles, but it does not actually change the value of the variable! What is the behavior of the pre-increment/decrement operators (++/--) in Python? Why does Python deviate from the behavior of these operators seen ...

Get django-paypal working with pycrypto?

I would like to use the button encryption in django-paypal, but it requires M2Crypto which will not build on webfaction servers. Tech support at Webfaction told me that pycrypto is already installed on the system, but I am too dumb to translate from M2Crypto to pycrypto. Can anyone tell me how to convert the following to work with pycr...

an auth method over HTTP(s) and/or REST with libraries for Python and/or C++

Because I don't exactly know how any auth method works I want to write my own. So, what I want to do is the following. A client sends over HTTPs username+password(or SHA1(username+password)) the server gets the username+password and generates a big random number and stores it in a table called TOKENS(in some database) along with his IP...

Python PIL cannot locate my "libjpeg" ...simple installation issue

I cannot use PIL because it cannot find my libjpeg! First, I installed PIL default. And when I ran the selftest.py, it gave me: IOError: decoder jpeg not available 1 items had failures: 1 of 57 in selftest.testimage Test Failed 1 failures. *** 1 tests of 57 failed. Then, I followed instructions online to change PIL's s...

pyinotify.ThreadedNotifier, process_* not called

Hi I have a problem with pyinotify: the methods process_*() of the ProcessEvent are not called The code import sys, time, syslog from pyinotify import WatchManager, Notifier, ThreadedNotifier, ProcessEvent, EventsCodes from daemon import Daemon class PTmp(ProcessEvent): def process_IN_CREATE(self, event): syslog.syslog("cre...

Parsing commandline output progression containing carriage returns in real time with python

I am able to transform carriage returns into new lines. The problem however is to get it running in nearly 'real time'. It will be quite stupid looking if progres bar only values are 0 and 100 :-) This code returns output at once: import subprocess p = subprocess.Popen(['mplayer', '/home/user/sample.mkv'], stdout=subprocess.PIPE).comm...