python

Sqlite3 "chained" query

I need to create a configuration file from a data file that looks as follows: MAN1_TIME '01-JAN-2010 00:00:00.0000 UTC' MAN1_RX 123.45 MAN1_RY 123.45 MAN1_RZ 123.45 MAN1_NEXT 'MAN2' MAN2_TIME '01-MAR-2010 00:00:00.0000 UTC' MAN2_RX 123.45 [...] MAN2_NEXT 'MANX' [...] MANX_TIME [...] This file describes different "legs" of a trajectory...

What does "result.status_code == 200" in Python mean?

In this little piece of code, what is the fourth line all about? from google.appengine.api import urlfetch url = "http://www.google.com/" result = urlfetch.fetch(url) if result.status_code == 200: doSomethingWithResult(result.content) ...

How to send EOF to Python sys.stdin from commandline? CTRL-D doesn't work.

I am writing to my Python process from the commandline on unix. I want to send EOF (or somehow flush the stdin buffer, so Python can read my input.) If I hit CTRL-C, I get a KeyboardError. If I hit CTRL-D, the program just stops. How do I flush the stdin buffer? ...

What are the various popularity metrics and sites for programming languages such as Ruby, Python, Java, etc?

What are the various sites that offer metrics that compare Ruby, Python, Perl, Smalltalk etc. What are their respective metrics? Do any of them control or account for the time that Rails was introduced, and/or the adoption rates for various languages? Will someone please help me close this question? Clearly it was not a successful vent...

How do derived class constructors work in python?

I have the following base class: class NeuralNetworkBase: def __init__(self, numberOfInputs, numberOfHiddenNeurons, numberOfOutputs): self.inputLayer = numpy.zeros(shape = (numberOfInputs)) self.hiddenLayer = numpy.zeros(shape = (numberOfHiddenNeurons)) self.outputLayer = numpy.zeros(shape = (numberOfOutputs)...

Why program functionally in Python?

At work we used to program our Python in a pretty standard OO way. Lately, a couple guys got on the functional bandwagon. And their code now contains lots more lambdas, maps and reduces. I understand that functional languages are good for concurrency but does programming Python functionally really help with concurrency? I am just try...

Simple DB query on Google App Engine taking a lot of CPU time.

I'm fairly new to Google App Engine and Python, but I did just release my first real-world site with it. But now I'm getting problems with one path that is using significantly more CPU (and API CPU) time than the other paths. I've narrowed it down to a single datastore fetch that's causing the problem: Carvings.all().fetch(1000) Under t...

Make Tkinter jump to the front.

How do I get a Tkinter application to jump to the front. Currently the window appears behind all my other windows and doesn't get focus. Is there some method I should be calling? ...

Pausing a process in Windows...

I'm making a nice little Python GUI frontend for ffmpeg on Windows (one that is specifically designed to convert videos to an iPhone-friendly format and automatically import it to iTunes and tag it), and I want it to work so that you can pause the process and resume it if you want. Since I start ffmpeg as a separate process, the obvious...

Web.py on shared hosting

Hi, I just built a small app with the very cool and minimalistic web.py. I am using a cheap shared hosting package (at WebFaction) and have installed web.py via virtualenv. I cannot use the system python since I need additional packages which I'm not allowed to install into the system python. So now I start my app with /home/me/my...

sending http request to apache through a python script

All, How do we send a http request through a python script.which will login and in turn call another link? Thanks. ...

Why import urlfetch from Google App Engines?

Here in Google App Engines I got this code that would help fetch an HTML code of any web page by its URL: from google.appengine.api import urlfetch url = "http://www.google.com/" result = urlfetch.fetch(url) if result.status_code == 200: doSomethingWithResult(result.content) I don't understand one thing here (among many other things, ...

Basic Python Numbers!

Why does 0.1 + 0.1 + 0.1 - 0.3 evaluates to 5.5511151231257827e-17 in Python? ...

Cross-Platform Python Notification Library

I'm making a python script that should run in the background and notify a user of changes, and I'd quite like it to work cross-platform. Main problem is, I don't have access to a mac at all, so coding specifically for it could be very difficult. wxPython seems like massive overkill for simple popups, so is there anything with a lighter f...

return variable outputs in Python function?

Hi, I have a function that returns a list. When I know the number of elements in the list I can do something like: x,y,z=foo() however, the number of elements in the list can vary. I would like to do something like x,y*=foo() where x would contain the first element in the returned list and y* would contain the remainder of however...

PYTHONPATH vs. sys.path

Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory. We have a Python project with a typical directory structure: Project setup.py package __init__.py lib.py script.py In script.py, we need...

Color a Button after subprocess has finished

I have a Tk python program that creates a list of python files in the current directory and generates a button for each of them. When you click a button the corresponding python program is launched via subprocess in a new gnome-terminal. I'd like to switch the button's color to red after the subprocess has finished executing on the new t...

Shaders with pygtkglext

Do someone know how to get glsl shaders work in gtk-opengl window? With glut all glCreateProgram etc. functions works, but when I tried to put the same gl code into pygtkglext window, its complaining about NullReference: OpenGL.error.NullFunctionError: Attempt to call an undefined function glCreateProgram, check for bool(glCreateProgram...

How to override ord behaivour in Python for str childs?

I have this class: class STR(str): def __int__(self): return 42 If i use it in the promt like this: >>> a=STR('8') >>> ord(a) 56 >>> int(a) 42 >>> chr(a) '*' that's the behaivour. I'd like to ord(a) be 42. How can I do it? Which method should I override in the str class? Is all this documented anywhere? Thanks! ...

Python random and int to string question

Hi, I am using this line of code to generate a random list of integers: random.sample(range(2000), 100) With this code i know i wont have double value's with my result. Is their maybe a faster way to achieve the same results? Now i actually have to convert these int to string. Whats the fastest way to do this? Thanks ...