python

Remote system event Notification Library

Hi I am looking for some sort of library that will allow: - multiple remote applications to register with the system on which events it is interested in - When this event occurs, the system will sent out notification to these remote applications regarding this event - Objects, or hash tables information should be able to be exchanged as ...

How do you modify sys.path in Google App Engine (Python)?

I've tried adding the following line to my handler script (main.py), but it doesn't seem to work: sys.path.append('subdir') subdir lives in the my root directory (i.e. the one containing app.yaml). This doesn't seem to work, because when I try to import modules that live in subdir, my app explodes. ...

GoogleAppEngine web proxy

Does anyone know of a simple open source proxy capable of running on google app engine or where to start in making one? (preferably in python, I'm trying to bypass a site blocking system) ...

what's the meaning of %r in python

what's the meaning of %r in the following statement? print '%r' % (1) I think I've heard of %s, %d, and %f but never heard of this. ...

ALTER TABLE Sqlite: how to check if a column exists before alter the table?

Hello everyone! I need to execute in python a SQL query that adds a new column, in sqlite3. The problem is that sometimes it already exists. So previous to executing the query I need to check if the column already exists. If it does, then I won't execute the query. Is there a way in sqlite to do that? Or do I have to make it throug...

Running Python With STDIN From Bash

I have a bash code (Mybash1.sh) where the result I need to pass to another bash code (Mybash2.sh) that contain Python Here are the codes. Mybash1.sh #! /bin/bash # Mybash1.sh cut -f1,3 input_file.txt | sort | ./Mybash2.sh Mybash2.sh is this: #! /bin/bash #Mybash2.sh python mycode.py foo.txt <("$@") > output.txt # do something for...

Implicitly invoking parent class initializer

class A(object): def __init__(self, a, b, c): #super(A, self).__init__() super(self.__class__, self).__init__() class B(A): def __init__(self, b, c): print super(B, self) print super(self.__class__, self) #super(B, self).__init__(1, b, c) super(self.__class__, self).__init__(1, b,...

Reading from the serial port from C++ or Python on windows

Hi all, I need to read the serial port from windows, using either Python or C++. What API/Library should I use? Can you direct me to a tutorial? Thanks! ...

Universal construct for STDIN and Fileinput in Python Code

I want my code to be able to accept input from a file AND stdin. What's the construct to do it? I mean a unifying construct that implies file1 = sys.stdin and file1 = fileinput.input(sys.argv[1]) ...

llvm-py questions

1) Is it possible to use llvm-py on Windows without Visual Studio 2008? Maybe I can compile files on another computer and use on my? 2) Is llvm-py mature enough in your opinion? If not, what are the problems? ...

python parsing url after string

I want to extract a string from a url (link). That string is in a <h3></h3> tag. link = http://www.test.com/page.html Content of link: <h3>Text here</h3> What would be an elegant way to first get the content/sourcecode of page.html and then exctract the link? Thanks! ...

Problem running Virtualenv on Mac OS X

I'm using virtualenv-1.4.5 on Mac OS X 10.6.2 (Xcode is installed) and Python 2.6. Here's what I get when I attempt to run a virtualenv... Mac-Pro:pylonsdev paul$ virtualenv --no-site-packages -v trythis Creating trythis/lib/python2.6 Symlinking Python bootstrap modules Symlinking trythis/lib/python2.6/_abcoll.pyc Symlinking trythi...

Access module masked by variable name

How do I access a module named x that I masked with a variable named x? ...

Python DBAPI time out for connections?

I was attempting to test for connection failure, and unfortunately it's not failing if the ip address of the host is fire walled. This is the code: def get_connection(self, conn_data): rtu, hst, prt, usr, pwd, db = conn_data try: self.conn = pgdb.connect(host=hst+":"+prt, user=usr, password=pwd, database=db) ...

Ugly combination of generator expression with for loop

The following appears in my Python 2.6 code: for src, dst in ([s,d] for s in universe for d in universe if s != d): Can I do much better? What I particularly don't like is that I'm in effect specifying the same pair twice, once for the for loop and again for the generator expression. I'm uncertain whether I'd prefer: for src, dst in ...

Group a string into 3s in a loop (python)

I have a nine character string and need to perform operations on groups of three characters in a loop. How would i achieve this in python? ...

Python: Control timeout length

I have code similar to the following running in a script: try: s = ftplib.FTP('xxx.xxx.xxx.xxx','username','password') except: print ('Could not contact FTP serer') sys.exit() IF the FTP site is inaccessible, the script almost seems to 'hang' ... It is taking about 75 seconds on average before sys.exit() appears to be ca...

python socket related question.

Hello,All im totally new to socket programming in python. i was read some tutorial and manual, but i didn't found what i want to make python related socket script in manual or tutorial. i want to make socket script which can send some info to server and also receive some info from server. For example, i want to send my login informatio...

python ImportError: No module named primes

hey all, im really new to python, im trying to import a third party module called primes.py, i have placed this module C:\Python26\Lib ( the location where i installed python) i then have another file which is trying to import this module, this file is located at C:\Python26 in my python file i have the following two lines import prime...

At what point does importing become the correct solution?

This weekend I was working on a project and I needed to use a binomial distribution to test the probability of an event (the probability that x of y characters would be alphanumeric given random bytes). My first solution was to write the test myself since it is rather simple. def factorial(n): if n == 0: return 1 else: ...