python

How to make socket.listen(1) work for some time and then continue rest of code???

I'm making server that make a tcp socket and work over port range, with each port it will listen on that port for some time, then continue the rest of the code. like this:: import socket sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sck.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) msg ='' ports = [x for x in xrange...

how to use cherrpy built in data storage

Ok I have been reading the cherrypy documents for sometime and have not found a simple example yet. Let say I have a simple hello world site, how do I store data? Lets say I want to store a = 1, and b =2 to a dictionary using cherrypy. The config files are confusing as hell. Anyone have very simple example of storing values from a si...

Problem with for-loop in python

This code is supposed to be able to sort the items in self.array based upon the order of the characters in self.order. The method sort runs properly until the third iteration, unil for some reason the for loop seems to repeat indefinitely. What is going on here? Edit: I'm making my own sort function because it is a bonus part of a pytho...

PyQt4 Custom Widgets

Are there any good PyQt4 custom widgets like at Qt-Apps.org? I would like to start making PyQt custom widgets but online resources that I find don't seem to be clear For example, Trolltech's and Zetcode's don't seem to be related in any way at all. Thanks for any input :) ...

Python sock.listen(...)

All the examples I've seen of sock.listen(5) in the python documentation suggest I should set the max backlog number to be 5. This is causing a problem for my app since I'm expecting some very high volume (many concurrent connections). I set it to 200 and haven't seen any problems on my system, but was wondering how high I can set it bef...

Go to a specific line in python?

i want to go to line 34 in a .txt file and read it how would you do that? In python? ...

How to control a subthread process in python?

Code first: '''this is main structure of my program''' from twisted.web import http from twisted.protocols import basic import threading threadstop = False #thread trigger,to be done class MyThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.start() def run(self): whi...

Dynamically expanding Django forms

I would like to create a form where a user can enter an arbitrary # of items in separate textboxes. The user could add (and potentially remove) fields as needed. Something like this: I found the following different solutions: http://www.eggdrop.ch/blog/2007/02/15/django-dynamicforms/ http://dewful.com/?p=100 These methods both appea...

Is there an alternative to gobject.timeout_add() in Python?

Hi there, I'm using gobject.timeout_add() to display a timer in my project (dojotools). I was wondering if there is any other way to achieve the same results, but without the gobject dependency. The requirement is just calling a method repeatedly, in a certain time interval. ...

SQLAlchemy custom query column

I have a declarative table defined like this: class Transaction(Base): __tablename__ = "transactions" id = Column(Integer, primary_key=True) account_id = Column(Integer) transfer_account_id = Column(Integer) amount = Column(Numeric(12, 2)) ... The query should be: SELECT id, (CASE WHEN transfer_account_id=1 T...

How do I add my own custom attributes to existing built-in Python types? Like a string?

I want to do something like this... def helloWorld(): print "Hello world!" string.helloWorld = helloWorld "foo".helloWorld() Which would print out "Hello world!" ...

Generating two thumbnails from the same image in Django

Hello, this seems like quite an easy problem but I can't figure out what is going on here. Basically, what I'd like to do is create two different thumbnails from one image on a Django model. What ends up happening is that it seems to be looping and recreating the same image (while appending an underscore to it each time) until it throws ...

Python 2 dict_items.sort() in Python 3

I'm porting some code from Python 2 to 3. This is valid code in Python 2 syntax: def print_sorted_dictionary(dictionary): items=dictionary.items() items.sort() In Python 3, the dict_items have no method 'sort' - how can I make a workaround for this in Python 3? ...

Distribute pre-compiled python extension module with distutils

Quick one today: I'm learning the in's and out's of Pythons distutils library, and I would like to include a python extension module (.pyd) with my package. I know of course that the recommended way is to have distutils compile the extension at the time the package is created, but this is a fairly complex extension spanning many source f...

Can a CLSID be different for the same program installed on two different machines?

I am using comtypes to generate wrappers for a certain com library. I am having certain issues with a few things, that are not being generated properly. I can get around this by doing the missing work, manually. However can i depend on the fact that CLSID's will not change? Lets say: I install a program with the com library Foo 1.0, no...

Unpacking tuples/arrays/lists as indices for Numpy Arrays

I would love to be able to do >>> A = numpy.array(((1,2),(3,4))) >>> idx = (0,0) >>> A[*idx] and get 1 however this is not valid syntax. Is there a way of doing this without explicitly writing out >>> A[idx[0], idx[1]] ? EDIT: Thanks for the replies. In my program I was indexing with a Numpy array rather than a tuple and gettin...

Python beginner having trouble running code

For some reason this code will not seem to run in the interpreter. When I hit F5 nothing happens, not even the debugger seems to recognize it. I assume it has something to do with the class, as when removed the interpreter seems to recognize the rest of the code. Please tell me what I am doing wrong. Edit: I have restarted the interprete...

How does Python differentiate between the different data types?

Sorry if this is quite noobish to you, but I'm just starting out to learn Python after learning C++ & Java, and I am wondering how in the world I could just declare variables like id = 0 and name = 'John' without any int's or string's in front! I figured out that perhaps it's because there are no ''s in a number, but how would Python fig...

How to get the list of price offers on an item from Amazon with python-amazon-product-api item_lookup function?

I am trying to write a function to get a list of offers (their prices) for an item based on the ASIN: def price_offers(asin): from amazonproduct import API, ResultPaginator, AWSError from config import AWS_KEY, SECRET_KEY api = API(AWS_KEY, SECRET_KEY, 'de') str_asin = str(asin) node = api.item_lookup(id=str_asin, Re...

Django migrations--is it possible to use South in the middle of the project?

I already started a project, and the models are all synced and everything. ...