python

python qt raise syntax error

I have a top level widget that is producing a syntax error in python. raise() on line 15. This is using the python Qt bindings. I know that raise is a python reserved word. I am looking for how to call the Qt "raise()" function with the python bindings. #!/usr/bin/python # simple.py import sys from PyQt4 import QtGui app = QtGui...

Use raw SQL to create tables in SQLAlchemy, after which use ORM

Hello everybody Is it possible to use raw SQL rather than the TABLE construct for creating tables in SQL Alchemy? I would still like to use the rest of SQLAlchemy though, such as the object mapper and session module. I'm just not fond of the SQLAlchemy syntax used to create tables (I've spent too long mired in SAS and SQL to learn ano...

upload file via python script

Hello, I want to upload a file from my computer to a filehoster like hotfile.com via a python script. Because Hotfile is only offering a webbased-upload service (no ftp) I need python first to login with my username and password and after that to upload the file. When the Filetransfer is over, I need the Download and Delete-link (which i...

Compare attributes of a Django Queryset in a template using the `in` Operator

I'm trying to use the in operator to determine if a template variable on the current page is also a foreign key in another model. The model is like so: class WishlistItem(models.Model): user = models.ForeignKey(User, related_name='wishlist_items') issue = models.ForeignKey(Issue) On the "Issue" page template, I'm trying to d...

A programming strategy to bypass the os thread limit?

The scenario: We have a python script that checks thousands of proxys simultaneously. The program uses threads, 1 per proxy, to speed the process. When it reaches the 1007 thread, the script crashes because of the thread limit. My solution is: A global variable that gets incremented when a thread spawns and decrements when a thread finis...

How to reset Python interpreter to a 'safe' state?

I have a C++ app that embeds the Python interpreter. There are points in the code where the interpreter may get interrupted and I need to make sure the interpreter is in a 'safe' state to execute new code. I would just call Py_Finalize and re-initialize everything except I have a bunch of PyObject * references that I need to stay valid. ...

SocketServer client side socket error during third send() on winXP

Hello, I'm struggling with following error: "socket.error: [10053] 'Software caused connection abort'" Traceback (most recent call last): ... self.send(json.dumps([0x02, subItems])+"\n") ... sent = self.handler.send(data) socket.error: [Errno 10053] I established server properely, I can connect to it, send "hell...

python hebrew input\filesytem format

import os import pprint import subprocess def Convert (dir): curDir = dir pathToBonk = "C:\\Program Files\\BonkEnc\\becmd.exe" #Where the becmd.exe file lives problemFiles = [] #A list of files that failed conversion # for item in os.listdir(curDir): if item.upper().endswith('.M4A'): fullPath = os...

Possible to send variables to the index page in CherryPy?

For instance I want to visit http://localhost:8080/?var=val or similar with POST, but I get a 500 server error: 500 Internal Server Error The server encountered an unexpected condition which prevented it from fulfilling the request. Traceback (most recent call last): File "c:\python26\lib\site-packages\cherrypy\_cprequest.py"...

translate this block of C physics code to python

Hi all, I have only learnt python for for few months and totally a newb in C, I got a C code from the web, and I am dying to study it. But i only understand python language, so would someone can help to translate the following code to python would be great. Thanks in advance! for(i=0; i<n; i++) { /* Foreach particle "i" ... */ ax=0.0;...

How can I force cherrypy to accept a variable number of GET parameters?

for instance, say I have my cherrypy index module set up like this >>> import cherrypy >>> class test: def index(self, var = None): if var: print var else: print "nothing" index.exposed = True >>> cherrypy.quickstart(test()) If I send more than one GET parameter ...

if my condition false how to do a statement one time only in python

hi all, is there any way to make this logic: I need to make a statement one time only if the condition is false as below: while 1: statement1 statement2 if condition: --condition is true here statement3 else --condition is false here statement3 --I n...

Where is os.environ initialized?

Using this code, many keys are output, but I expected no output: import os for i in os.environ: print i This is the code from os.py: try: environ except NameError: environ = {} Where does os.environ get its values from? Where is it initialized? ...

PNG optimisation tools

A while back I used a PNG optimisation service called (I think) "smush it". You fed it a weblink and it returned a zip of all the PNG images with their filesizes nicely, well, smushed... I want to implement a similar optimisation feature as part of my website's image upload process; does anyone know of a pre-existing library (PHP or Pyt...

Learning Python and using dictionaries

I'm working through exercises in Building Skills in Python, which to my knowledge don't have any published solutions. In any case, I'm attempting to have a dictionary count the number of occurrences of a certain number in the original list, before duplicates are removed. For some reason, despite a number of variations on the theme belo...

Expanding tuples into arguments

Is there a way to expand a Python tuple into a function - as actual parameters? For example, here expand() does the magic: tuple = (1, "foo", "bar") def myfun(number, str1, str2): return (number * 2, str1 + str2, str2 + str1) myfun(expand(tuple)) # (2, "foobar", "barfoo") I know one could define myfun as "myfun((a, b, c))", but...

How do I trust the order of a Python dictionary?

I'm trying to make a dictionary in Python that I can sort through but it seems to change order when I add new things. Is there a way around this? ...

Drag and drop ordering of formset with extra entries

I have been looking for a way to allow the user to easily change the order of entries in a formset. I found a StackOverflow question that addresses this subject, with the accepted answer referencing a Django Snippet that uses a JQuery tool to allow drag 'n drop of the entries. This is nifty and cool, but I have a problem with 'extra' e...

how change int to binary. on python 2.5

print 077777#how can i get binary thanks i use python2.5 ...

Map list onto dictionary

Is there a way to map a list onto a dictionary? What I want to do is give it a function that will return the name of a key, and the value will be the original value. For example; somefunction(lambda a: a[0], ["hello", "world"]) => {"h":"hello", "w":"world"} (This isn't a specific example that I want to do, I want a generic function li...