python

Python Django MySQLdb setup problem:: setup.py dosen't build due to incorrect location of mysql

I'm trying to install MySQLdb for python. but when I run the setup, this is the error I get. well I know why its giving all the missing file statements, but dont know where to change the bold marked location from. Please help gaurav-toshniwals-macbook-7:MySQL-python-1.2.3c1 gauravtoshniwal$ python setup.py build running build running ...

Finding the nth number of primes

I can not figure out why this won't work. Please help me from math import sqrt pN = 0 numPrimes = 0 num = 1 def checkPrime(x): '''Check\'s whether a number is a prime or not''' prime = True if(x==2): prime = True elif(x%2==0): prime=False else: root=int(sqrt(x)) for i in range(3,root,2): ...

Python Pickle: what can cause stack index out of range error?

I'm getting this error: File "C:\Python26\lib\pickle.py", line 1374, in loads return Unpickler(file).load() File "C:\Python26\lib\pickle.py", line 858, in load dispatch[key](self) File "C:\Python26\lib\pickle.py", line 1075, in load_obj k = self.marker() File "C:\Python26\lib\pickle.py", line 874, in marker while...

Disable logging during manage.py test?

I utilize the standard python logging module. When I call python manage.py test I'd like to disable logging before all the tests are ran. Is there a signal or some other kind of hook I could use to call logging.disable? Or is there some other way to disable logging when python manage.py test is ran? ...

Writing to a file in Python inserts null bytes

I'm writing a todo list program. It keeps a file with a thing to do per line, and lets the user add or delete items. The problem is that for some reason, I end up with a lot of zero bytes at the start of the file, even though the item is correctly deleted. I'll show you a couple of screenshots to make sure I'm making myself clear. This ...

Python "draw() must be called with Label instance as first argument (got _WindowMetaclass instance instead)"

This is a class I made using Python with pyglet to display a window. class Window(pyglet.window.Window): def __init__(self): super(Window, self).__init__() pyglet.text.Label("Prototype") windowText = text.Label.draw(Window, "Hello World", font_name = "Times New Roman", ...

Numpy array, how to select indices satisfying multiple conditions?

Suppose I have a numpy array x = [5, 2, 3, 1, 4, 5], y = ['f', 'o', 'o', 'b', 'a', 'r']. I want to select the elements in y corresponding to elements in x that are greater than 1 and less than 5. I tried x = array([5, 2, 3, 1, 4, 5]) y = array(['f','o','o','b','a','r']) output = y[x > 1 & x < 5] # desired output is ['o','o','a'] but ...

Is it possible to read path in JPEG image with python?

If you Save as > jpg in Adobe Photoshop a path (selection) is stored in the file. Is it possible to read that path in python, for example to create a composition with PIL? EDIT Imagemagick seems to help, example ...

"TypeError: draw() takes exactly 1 non-keyword argument (3 given)"

I wrote this code to open a window with Pyglet in Python... import pyglet from pyglet import window class Window(pyglet.window.Window): def __init__(self): super(Window, self).__init__() myLabel = pyglet.text.Label("Prototype") windowText = myLabel.draw(Window, "Hello World", font_n...

Disable comments/ratings with YouTube Python API?

Hi, does anyone know if it's possible to disable YouTube ratings/comments using the Python API? I know you can do it using the 'yt:accessControl' tag in the XML request but I have no idea how to build a request manually. Any help would be appreciated :) ...

Where is the Google App Engine SDK path on OSX?

I need to know for creating a Pydev Google App Engine Project in Eclipse. ...

is there any way to enforce the 30 seconds limit on local appengine dev server?

Hey, i was wondering if there is a way to enforce the 30 seconds limit that is being enforced online at the appengine production servers to the local dev server? its impossible to test if i reach the limit before going production. maybe some django middlware? ...

why does text from socket server erase previously written text?

This is strange enough I'm not sure how to search for an answer. I have a program in Python that communicates via TCP/IP sockets to a telnet-based server. If I telnet in manually and type commands like this: SET MDI G0 X0 Y0 the server will spit back a line like this: SET MDI ACK Pretty standard stuff. Here's the weird part. If...

urllib2.URLError: <urlopen error (10054, 'Connection reset by peer')> on gae.

i can't Deploy data on gae , so i use this "appcfg.py rollback myapp/" but ,it is not useful this time ,and the error is : Application: zjmzjm1126; version: small-forum. Server: appengine.google.com. Scanning files on local disk. Scanned 500 files. Scanned 1000 files. Initiating update. 2010-06-13 09:54:35,155 ERROR appcfg.py:1568 An ...

how to detect an escape sequence in a string

Given a string named line whose raw version has this value: \rRAWSTRING how can I detect if it has the escape character \r? What I've tried is: if repr(line).startswith('\r'): blah... but it doesn't catch it. I also tried find, such as: if repr(line).find('\r') != -1: blah doesn't work either. What am I missing? thx!...

Look for match in a nested list in Python

Hello everybody, I have two nested lists of different sizes: A = [[1, 7, 3, 5], [5, 5, 14, 10]] B = [[1, 17, 3, 5], [1487, 34, 14, 74], [1487, 34, 3, 87], [141, 25, 14, 10]] I'd like to gather all nested lists from list B if A[2:4] == B[2:4] and put it into list L: L = [[1, 17, 3, 5], [141, 25, 14, 10]] Additionally if the match ...

uWSGI with Cherokee: first steps

Has anyone tried using uWSGI with Cherokee? Can you share your experiences and what documents you relied upon the most? I am trying to get started from the documentation on both (uWSGI and Cherokee) websites. Nothing works yet. I am using Ubuntu 10.04. Edit: To clarify, Cherokee has been working fine. I am getting the error message: ...

Installing psycopg2 (postgresql) in virtualenv on windows

I installed psycopg2 in virtualenv using easy_install psycopg2. I did not see any errors and looks like installation went fine.. there is an egg file created in the site-packages dir for psycopg2.. but when I run import psycopg2 in the interpreter, I am getting following error.. any clue? How can I fix it.. any other way to install psyc...

How come string.maketrans does not work in Python 3.1?

I'm a Python newbie. How come this doesn't work in Python 3.1? from string import maketrans # Required to call maketrans function. intab = "aeiou" outtab = "12345" trantab = maketrans(intab, outtab) str = "this is string example....wow!!!"; print str.translate(trantab); When I executed the above code, I get the following instead:...

Serve external template in Django

Hey, I want to do something like return render_to_response("http://docs.google.com/View?id=bla", args) and serve an external page with django arguments. Django doesn't like this (it looks for templates in very particular places). What's the easiest way make this work? Right now I'm thinking to use urllib to save the page to somewh...