python

What is the correct method of handling events in PyQt 4?

I have seen examples like this: self.connect(self.ui.add_button, QtCore.SIGNAL('clicked()'),self.printer) And examples like this: self.ui.add_button.clicked.connect(self.printer) I'm just starting to learn Qt; which one should I focus on? ...

Py2exe: Embed static files in library.zip or exe file itself and transparently access them at runtime

Is there a way to have py2exe embed static files (and/or subdirectories of static files) in a library.zip and/or the exe file itself (with zipfile=None) and then transparently access these embedded static files from code at runtime? Thank you, Malcolm ...

Is there any Python syntax highlighter for Visual Studio 2010?

When I used Visual Studio 2008 I could install IronPython + IronPython Integrated IDE + Visual Studio Shell Integrated Mode and then my Visual Studio would parse .py files and highlight its syntax. I tried the same with Visual Studio 2010 beta 2 with no success. Where is the catch? Should I wait a bit longer for new releases or there is...

In python, is there a setdefault() equivalent for getting object attributes?

Python's setdefault allows you to get a value from a dictionary, but if the key doesn't exist, then you assign the based on parameter default. You then fetch whatever is at the key in the dictionary. Without manipulating an object's __dict__Is there a similar function for objects? e.g. I have an object foo which may or may not have a...

Py2exe: Are manifest files and w9xpopen.exe required when compiling a web server without GUI interface?

I'm using Py2exe to compile a CherryPy (3.1) server using Python 2.6 (32-bit) on Windows 7 Pro (64-bit). This server will run without a GUI. Questions: Do I need to be concerned about adding a manifest file for this application if it runs without a GUI? Do I need to include w9xpopen.exe with my exe? So far, my limited testing has i...

Install libxml2 and associated python bindings - Windows

Hello, I am attempting to install libxml2 so that I can setup the python bindings and eventually use lxml. However I am unable to work out here on earth I am supposed to be unzipping the files. I haven't been able to google successfully. Do I need Cygwin/MinGW for the installation to be successful? At the moment I have the files from...

How can I sort by the id of a ManyToManyField in Django?

I've got a ManyToManyField in a user object and it's used to map the users that user is following. I'm trying to show a subset list of who they have most recently followed. Is there a trick in .order_by() that will allow me to sort by the id of the ManyToManyField? The data is there, right? # (people the user is following) following = m...

Is IronPython usable as a replacement for CPython?

Has IronPython gotten to a point where you can just drop it in as a replacement for CPython? To clarify: I mean can IronPython run applications originally written for CPython (no .NET involved, of course) ...

Keyword Matching in Pyparsing: non-greedy slurping of tokens

Pythonistas: Suppose you want to parse the following string using Pyparsing: 'ABC_123_SPEED_X 123' were ABC_123 is an identifier; SPEED_X is a parameter, and 123 is a value. I thought of the following BNF using Pyparsing: Identifier = Word( alphanums + '_' ) Parameter = Keyword('SPEED_X') or Keyword('SPEED_Y') or Keyword('SPEED_Z') ...

Starting Python script without explicitly having X11 open

I had Python v2.3 on my system. When I wanted to run a Tkinter script I could just use python myscript.py I recently upgraded to Python 2.5 and now I need to have X11 running and the "DISPLAY" environment variable set before I can run any of my scripts. This is bad for me, because I can't distribute any scripts without explicitly stat...

Literals in django template language?

If I want some text to appear literally in a Django template, e.g. {{Image.jpg|title}} and I want that text to be output (not interpretated) in the HTML, how do I do so? ...

Python QPushButton setIcon: put icon on button

Hello Everybody, I want to put an in ICON into a push button.. the code should work like that: self.printButton = QtGui.QPushButton(self.tab_name) self.printButton.setIcon(QtGui.QPixmap('printer.tif')) self.printButton.setGeometry(QtCore.QRect(1030, 500, 161, 61)) But instead, it gives the error message: TypeError: a...

python time(milli seconds) calculation

How to calculate milliseconds,from the code below. a = datetime.datetime.now() b = datetime.datetime.now() c = b - a >>> c >>> c.days 0 >>> c.seconds 4 >>> c.microseconds Thanks.......... ...

Crop a PNG image to its minimum size

How to cut off the blank border area of a PNG image and shrink it to its minimum size using Python? ...

Django date filter to output "am" or "A.M."

The Django date template filter takes the format character "a" for "a.m." and "A" for "AM". How do you get lower case without periods or upper case with the periods? You can use lower and upper filters, but they will mess with month and day of the week formatting. ...

turbogears request/user object in templates and request context

Hi all, I am currently making the switch from Django to Turbogears 2.1 and am running into some problems that I could not find the answers to in the Turbogears docs. If tg developers read this, let me tell you that one of the best features Django has over TG is its documentation! 1) How do I access the request (user?) object within a m...

split svnversion output in bash

I have this function, works fine, but I would like to rewrite it in bash. the problem is, I have too little knowledge of what's available in bash. #!/usr/bin/python def parse_svnversion(value): """split the output of svnversion into its three components given a string that looks like the output of the command svnversion, ...

Django template and Python dictionary data structure question

I am trying to present a dictionary from my view.py at the HTML template such as: test = { 'works': True, 'this fails':False } and in the template: This works without a problem: {{ test.works }} But a dictionary key that is having an empty space between words such as 'this fails' doesn't work: {{ test.this fails }} I get this e...

multiple requests in a single connection?

Hello Friends, Is it possible to put multiple requests without breaking the connection using python httplib?. Like, can I upload a big file to the server in parts but in a single socket connection. I looked for answers. But nothing seemed so clear and definite. Any examples/related links will be helpfull. Thanks. ...

How to connect an application with Facebook?

The topic may be a bit ambiguous. I am writing a Python application. I want to upload it on Facebook as a Facebook application (NOT Facebook Connect). But I am having the hardest time figuring out how to implement the features of my application with Facebook. My application currently uses a MySQL database. Now I want a user of Facebook...