python

git server side hooks

I am running into a problem when running the follow python script on the server looking for commit information for the push making sure it follows a particular syntax, I am unable to get input from the user which is why the username and password are hard coded. I am now also unable to get the list of commit message that occurred before t...

How do I delete an object in a django relation (While keeping all related objects)?

I have the following model: One name (Char) Many one (ForeignKey,blank=True,null=True) title (Char) I want to delete a One instance and all related objects should loose their relation to the One instance. At the moment my code looks like this: one=One.objects.get(<some criterion>) more=Many.objects.filter(one=one) for m ...

Select element within a list/tuple

Hey bit of a beginners question here, I have connected to an imap server using the imaplib and fetched a email, it returns the following: [('1 (BODY[HEADER.FIELDS (SUBJECT)] {62}', "Subject: Gmail is different. Here's what you need to know.\r\n\r\n"), ')'] My question is how do I select just the subject element ("Subject: Gmail is..."...

Having Problems with importing xlwt?

I am using Eclipse with the PyDev plugin. I am using xlwt which is for writing to an excel sheet. I have the xlwt library in my src file. I have another python file called gene_sorter.py where i try to import xlwt. using import xlwt I keep gettting back this error: File "C:\Documents and Settings\Ben Fossen\Pythonworkspace\MTBgenes\...

Can't pickle loggers??

Working on a project that requires that I am able to pickle the container object at any point, since we expect it to fail on external conditions quite frequently and be able to statefully pick up where we left off. I'm using the python logging library quite extensively, and all of my classes start by setting up a logger like: class foo...

Finding a function's parameters in Python

I want to be able to ask a class's __init__ method what it's parameters are. The straightforward approach is the following: cls.__init__.__func__.__code__.co_varnames[:code.co_argcount] However, that won't work if the class has any decorators. It will give the parameter list for the function returned by the decorator. I want to get...

3D line segment box intersection

Looking for code to detect an intersection between a 3D segment (not a line/ray) and a 3D box (not necessarily a cube, but always axis-aligned). The boxes are voxels so they have regular spacing. Already have the code to find a segment/plane intersection. Ideally, I'd like to find an efficient solution to adapt this for a rectangle, rep...

get screen size in python

I was wondering if there was a way to get the screen size from a python script. Similar Questions: Getting monitor size in python This question tells you how to get it through pygame. Is there a way to do it with just python? I need the scripts to run on several Unix-based operating system. ...

python: print values from a dictionary

generic_drugs_mapping={'MORPHINE':[86], 'OXYCODONE':[87], 'OXYMORPHONE':[99], 'METHADONE':[82], 'BUPRENORPHINE':[28], 'HYDROMORPHONE':[54], 'CODEINE':[37], 'HYDROCODONE'...

Why is my Django installation delivering an empty HTTP response?

Final Update: There was a stray LoadModule python_module modules/mod_python.so that conflicted with mod_wsgi. Removing that LoadModule made everything work again. I am setting up a production server with Django and following along with the Django tutorial, yet receiving a blank page (or, as Chrome likes to report, Error 324 (net::ERR_...

python: comparing values string/integer

i will be comparing two values like this:\ value1>value2 i know that value2 is always an integer, but sometimes value1 is None or a string, how do force the comparison ONLY if value1 is numerical? value1 is a decimal ...

Python: upload images

Can python upload images onto the internet and provide a URL for it? For example is it possible for python to upload an image onto photobucket or any other uploading image service and then retreive the URL for it? ...

python: is there an isError function?

is there a function that will return true if some_function returns an error? ...

Should I use ImageMath or ImageChops?

The PIL handbook says ImageMath (containing a function to evaluate expressions) is new in version 1.1.6. Is it now obsolete? It seems like ImageChops has similar functions to perform arithmetic operators on images. ...

How can I vectorize a function in numpy with multiple arguments?

Hello! I am trying to do a fit to a given function using Scipy. Scipy.optimize.leastsq needs a vectorized function as one of the input parameters. This all works fine, but now I have a more complicated function which is not vectorized automatically by Scipy/Numpy. def f1(a, parameters): b, c = parameters result = scipy.integr...

python: accessing a list using a dictionary

i read a csv into a variable called b now i am going through every row in it like this: for row in b: this dictionary gives me the positions of where these drugs are in the row: generic_drugs_mapping={'MORPHINE':[86], 'OXYCODONE':[87], 'OXYMORPHONE':[99], 'MET...

Append a value to a list and move all values over

if i start off with : a=[1,2,4] and i want the result to be a=[1,3,2,4] how do i do this append? ...

Approximate session data from apache access.log - python

How might one use the ip and timestamp from Apache's access log to approximate a "session" for a given visitor? A session would include all consecutive requests within a given period, say 60secs. I have a class to parse the log file, and follow an IP address through it (the log is in timestamp order, thankfully). The class creates a t...

How do I add a new column of data to a csv file.

I am reading a csv file into a variable data like this: def get_file(start_file): #opens original file, reads it to array with open(start_file,'rb') as f: data=list(csv.reader(f)) data is the entire csv file. How do I add an extra column to this data? ...

What are the benefits (and drawbacks) of a weakly typed language?

I'm a big fan of PHP and it's obviously a very weakly-typed language. I realize some of the benefits include the general independence of changing variable types on the fly and such. What I'm wondering about are the drawbacks. What can you get out of a strongly-typed language like C that you otherwise can't get from a weakly-typed one li...