python

Python - is there a "don't care" symbol for tuple assignments?

Given a string "VAR=value" I want to split it (only) at the first '=' sign (< value > may contain more '=' signs), something like this: var, sep, value = "VAR=value".partition('=') Is there a way to NOT declare a variable 'sep'? Like this (just made up the syntax): var, -, value = "VAR=value".partition('=') Just for completeness, I...

How to make scipy.interpolate give a an extrapolated result beyond the input range?

I'm trying to port a program which uses a hand-rolled interpolator (developed by a mathematician colleage) over to use the interpolators provided by scipy. I'd like to use or wrap the scipy interpolator so that it has as close as possible behavior to the old interpolator. A key difference between the two functions is that in our origina...

Python - 2 Questions: Editing a variable in a function and changing the order of if else statements internally/during runtime

First of all, I should explain what I'm trying to do first. I'm creating a dungeon crawler-like game, and I'm trying to program the movement of computer characters/monsters in the map. The map is basically a Cartesian coordinate grid. The locations of characters are represented by tuples of the x and y values, (x,y). The game works by t...

Incremental PCA

Hi, Lately, I've been looking into an implementation of an incremental PCA algorithm in python - I couldn't find something that would meet my needs so I did some reading and implemented an algorithm I found in some paper. Here is the module's code - the relevant paper on which it is based is mentioned in the module's documentation. I w...

Python key word arguments

I have several layers of function calls, passing around a common dictionary of key word arguments: def func1(**qwargs): func2(**qwargs) func3(**qwargs) I would like to supply some default arguments in some of the subsequent function calls, something like this: def func1(**qwargs): func2(arg = qwargs.get("arg", default), *...

Python, how to tell if screen is running.

Hello, I am very new to programming and am trying to run a python code to see if the screen program is running and if it is then to not run the rest of the code. This is what I have and it's not working. #!/usr/bin/python import os var1 = os.system ('screen -r > /root/screenlog/screen.log') fd = open("/root/screenlog/screen.log") cont...

Passing variables in python when using from a import *

How can I make this print "baz" when I run b.py? a.py def foo(): global bar print bar b.py from a import * bar = "baz" foo() ...

Check if command had some trouble in Python?

I have this command h = urllib.urlopen("http://google.com/") How can I check if it retrieves me some error, internet down or something I don't expect? For example, something like if error print 'ERROR' Thank you ...

How to connect to foreign DB2 database using Python (Ubuntu)

sudo easy_install ibm_db-1.0.1-py2.5-linux-i686.egg only works after sudo apt-get install python-dev. Some troubles to find that out in the first place ... Downloaded from IBM site v9.5fp5_linuxia32_dsdriver.tar.gz and pointing IBM_DB_DIR and IBM_DB_LIB to the clidriver(/lib) dir -- is this needed/correct one? -- libdb2.so(.1) is in th...

Library like minim for python?

Minim seems like a nice library for building music visualisers and other stuff in java or processing. Is there a nice audio library like this in python ? ...

Efficient way to build a MySQL update query in Python

I have a class variable called attributes which lists the instance variables I want to update in a database: attributes = ['id', 'first_name', 'last_name', 'name', 'name_url', 'email', 'password', 'password_salt', 'picture_id'] Each of the class attributes are updated upon instantiation. I would like to loop through eac...

Django custom template tag with 'parser.compile_filter(tokens[2])' doesn't work

I tried to implement the solution proposed by T. Stone on my question "how-do-i-pass-a-lot-of-parameters-to-views-in-django" ([link text][1]). I can't manage to get any result. It's difficult to find information about the compile_filter(), but as far as I understand cls(queryset=parser.compile_filter(tokens[2]), template=template) should...

Adding string to end of URL

To practise some more bits of python I've been having a go at the challenges on pythonchallenge.com In brief, this challenge as a first step requires one to load an html page from a url with a number at the end. The page contains a single line of text which has in it a number. That number is used to replace the existing one in the url, ...

PyDev and Django: PyDev breaking Django shell?

I've set up a new project, and populated it with simple models. (Essentially I'm following the tut.) When I run python manage.py shell on the command line, it works fine: >python manage.py shell Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for mo...

Python - converting wide-char strings from a binary file to Python unicode strings...

It's been a long day and I'm a bit stumped. I'm reading a binary file that contains lots of wide-char strings and I want to dump these out as Python unicode strings. (To unpack the non-string data I'm using the struct module, but I don't how to do the same with the strings.) For example, reading the word "Series": myfile = open("test...

PyDev and Django: how to restart dev server?

I'm new to Django. I think I'm making a simple mistake. I launched the dev server with Pydev: RClick on project >> Django >> Custom command >> runserver The server came up, and everything was great. But now I'm trying to stop it, and can't figure out how. I stopped the process in the PyDev console, and closed Eclipse, but web pa...

Importing modules on portable python

Hi, I am running PortablePython_1.1_py2.6.1 on a USB stick. My code relies on some modules that are not preinstalled. Does anyone know whether it is possible to add new modules to a portable python installation? Simply copying in folders into site-lib does not seem to work. ...

wrap py2exe in its own executable

Hi, Is it possible to generate a .exe of py2exe's functionality, such that I can create python .exe files without running python? Seems like circular logic that is unlikely to work, but would be handy otherwise. ...

Joining different models in Django

Let's say I have this data model: class Workflow(models.Model): ... class Command(models.Model): workflow = models.ForeignKey(Workflow) ... class Job(models.Model): command = models.ForeignKey(Command) ... Suppose somewhere I want to loop through all the Workflow objects, and for each workflow I want to loop through its Co...

How do I overwrite a file currently being read by Python

Hi guys, I am not too sure the best way to word this, but what I want to do, is read a pdf file, make various modifications, and save the modified pdf over the original file. As of now, I am able to save the modified pdf to a separate file, but I am looking to replace the original, not create a new file. Here is my current code: from...