python

A dictionary with values that are dictionaries: trying to sum across those keys in python

Data structure is a dictionary, each value is another dictionary, like: >>> from lib import schedule >>> schedule = schedule.Schedule() >>> game = schedule.games[0] >>> game.home <lib.schedule.Team instance at 0x9d97c6c> >>> game.home.lineup {'guerv001': {'HR': 392, '1B': 1297}, 'kendh001': {'HR': 12, '1B': 201}, 'andeg001': {'HR': 272,...

How do I make a simple DNS server listening two ports simultaneously in python

Hi, I'm trying to build a DNS server in python. It must listen two ports (8007 - client, 8008 - admin). The client only send an URL and receives the respective IP. The admin has permissions to change the DNS table (add, remove,.. doesn't matter to this right now). So my question is: how do I implement the server listening continuously ...

Python functions can be given new attributes from outside the scope?

I didn't know you could do this: def tom(): print "tom's locals: ", locals() def dick(z): print "z.__name__ = ", z.__name__ z.guest = "Harry" print "z.guest = ", z.guest print "dick's locals: ", locals() tom() #>>> tom's locals: {} #print tom.guest #AttributeError: 'function' object has no attribut...

Can this breadth-first search be made faster?

I have a data set which is a large unweighted cyclic graph The cycles occur in loops of about 5-6 paths. It consists of about 8000 nodes and each node has from 1-6 (usually about 4-5) connections. I'm doing single pair shortest path calculations and have implemented the following code to do a breadth-first search. from Queue import Queu...

Python optparse Values Instance

How can I take the opt result of opt, args = parser.parse_args() and place it in a dict? Python calls opt a "Values Instance" and I can't find any way to turn a Values Instance into a list or dict. One can't copy items from opt in this way, for i in opt: myDict[i] = opt[i] instead, its a clumsy, myDict[parm1] = opt.parm1 myDic...

appcfg.py upload_data is failing with expected <directory> even though I've got it

I am having trouble getting the bulk uploader to work. I have been following the tutorial here:http://code.google.com/appengine/docs/ python/tools/uploadingdata.html. When I enter the following command (from Windows, using PowerShell) appcfg.py upload_data --config_file=src/friend_loader.py --filename=frienddata.csv --kind=Friend ./sr...

What approach(es) have you used for lightweight Python unit-tests on App Engine?

I'm about to embark on some large Python-based App Engine projects, and I think I should check with Stack Overflow's "wisdom of crowds" before committing to a unit-testing strategy. I have an existing unit-testing framework (based on unittest with custom runners and extensions) that I want to use, so anything "heavy-weight"/"intrusive" ...

Qt Python radiobutton: activate event

Hi Everybody, I am developing a project for one customer, where the design has a radio button with exclusive options. Here is a piece of the code that runs and show two nice radio buttons: self.performGroupBox = QtGui.QGroupBox(self.centralwidget) self.performGroupBox.setGeometry(QtCore.QRect(50, 20, 181, 121)) self.perfo...

How to use PyUsb 0.4 for windows

Possible Duplicate: Where can I find useful documentation for pyusb (Python USB library)? i using PyUsb 0.4 on windows, but i can't find any tutorial ,anyone hav some link/resource ...

python multiprocessing db access is very slow.

Hi I have GUI that will interact with a postgres database, using psycopg2. I have db connection in a multiprocessing process, and send SQL via a multiprocessing queue, and receive via another queue. The problem is that the speed is very very slow. A simple select * from a small table (30 rows) can be 1/10th of a second, or can take o...

DOM related question and problem

Hello, these day im making python script related with DOM. problem is these day many website structure is very complicate . what is best method to check DOM structure and path.. i mean...following is some example. what is best method to check can extract such like following info quickly? before i was spent much time to extract such...

Get Intervals Between Two Times

A User will specify a time interval of n secs/mins/hours and then two times (start / stop). I need to be able to take this interval, and then step through the start and stop times, in order to get a list of these times. Then after this, I will perform a database look up via a table.objects.filter, in order to retrieve the data correspon...

log pysvn update

How could I, if possible, get information on what files have been added, removed, updated etc when running svn update in pysvn? I want to write this information to a log file. ...

How can I run a Makefile in setup.py?

I need to compile ICU using it's own build mechanism. Therefore the question: How can I run a Makefile from setup.py? Obviously, I only want it to run during the build process, not while installing. ...

[Python] 'import feedparser' works via SSH, but fails when in browser

I installed feedparser via SSH, using $ python setup.py install --home=~/httpdocs/python-libraries/feedparser-4.1/ I did that because I don't seem to have permission to properly run 'python setup.py install' I am running the following python code in 'test.py'. print "Content-type: text/html\n\n" try: import feedparser except: ...

How do I get stdout from tcl into a python string variable when using tkinter?

Hi I have the following python code... import Tkinter root = Tkinter.Tk() root.tk.eval('puts {printed by tcl}') It prints "printed by tcl" to the screen. How can I capture what the tcl interpreter prints to the screen into a python string. This is a simplified example of what I am doing. I have an automation system written in pyt...

Converting RE code from PHP to Python

I have done a simple program in PHP, now need to convert this into Python: $string="Google 1600 Amphitheatre Parkway Mountain View, CA 94043 phone"; preg_match_all('/[0-9]+.{10,25}[^0-9]*[0-9]{5,6}+\s/',$string,$matches); print_r($matches); ...

Problem with db.get in Google App Engine

When I run the following code: query = datastore.Food_Item.all() results = query.fetch(1) foodA = results[0] foodB = db.get(foodA.key()) I would expect foodA and foodB to be the same type. However, I see that the foodA is of type "model.datastore.Food_Item" and foodB is of type "datastore.Food_Item". Why are they diffe...

Understanding Generators in Python?

Reading the Python cookbook at the minute and currently looking at generators. I'm finding it hard to get my head round. As I come from a Java background, is there a Java equivelant? The book was speaking about 'Producer / Consumer', however when I hear that I think of threading. Can anyone explain what a generator is and why you would...

Gracefully convert .rar to .zip using Python

I'm currently making system call to "unrar and zip" commands. It interrupts and requires me to enter password while encounter password propected archives. Is it possible to let it run and return a "unsuccessful" value to main program on any error or password prompt? Can we natively use rarfile and zipfile library to do the job without ...