python

How to upgrade the version of Python used by Apache?

On a Red hat box, I upgraded Python from 2.3 to 2.6.4 and changed the symlink to python so when I type in python the 2.6.4 interpreter comes up. However my .py file works from the command-line, but not in the browser. It seemed like a sys.path issue so I opened the file in a browser and printed out sys.path. Surprisingly, my sys.path i...

Does 'p' have a special meaning in Django?

Why are p and p8 different in the following code? The beginning of a view function (in file views.py in a Django app named "proteinSearch" with a model named "Protein" that has a field named "description"): def searchForProteins2(request, searchStr): p8 = Protein.objects.filter( description__icontains=searchStr) #Why doesn't t...

getting the absolute path of a file object

I am using file = tkFileDialog.askopenfile(parent=root,mode='rb',filetypes=[('Subrip Subtitle File','*.srt')],title='Choose a subtitle file') to get a file object specified by the user. Is there any way I can get the absolute path of this file from the File object? ...

pyExcelerator has problems reading some files

I've got a problem using pyExcelerator when reading some xls-files. There're some python scripts i wrote, that use this library to parse XLS-files and populate database with info. The templates for the files these scripts parse may vary and i sometimes reconfigure the script to handle them. With the one of the templates i ran into pro...

What is the best way to get a stacktrace when using multiprocessing?

I'm wondering about the best way to get a stacktrace when there is an exception inside a function executed via the multiprocessing module. Here's an example: import multiprocessing def square(x): raise Exception("Crash.") return x**2 if __name__ == '__main__': pool = multiprocessing.Pool(processes=4) results = pool.map...

Is there any scripting SVG editor?

I would like to edit SVG files using some scripting language (preferably Python). In particular, I would like to merge two SVG files, add some annotations, and arrange them in a larger image. Is there any software available for such purposes? Thanks, Bartosz ...

Python stacktrace help

hello, I have this stack trace error when I try view some data in my Python website, could some one clue me up as to what the problem is I am so lost Environment: Request Method: GET Request URL: http://mywesbite.genericdomain.co.uk/admin/shop/passwordresetrequest/4/ Django Version: 1.1.1 Python Version: 2.5.2 Installed Applicati...

how (in maya) can i get the 3D position of the mouse?

hello... i have created a dragger context in maya using the following code, pos holds my 2D coordinates of mouse cursor, i want to convert it into 3D coordinate to be the source of the ray i want to launch,, i want it either through python scripting or through the python api,, import maya.cmds as mc mc.draggerContext( 'testContext', ...

How to transfer a file between two FTP servers?

Hey guys, I have two ftp servers with fxp enabled on both, I'm just wondering how I would transfer a file between the two servers in Python? I was told curl wouldnt do it, but maybe ftplib will do. so, the file (file.txt) is in '/personal/' FTP1 and I want to transfer that to FTP2 also to the same place, '/personal/' Any ideas on how ...

How to unpickle from C code

I have a python code computing a matrix, and I would like to use this matrix (or array, or list) from C code. I wanted to pickle the matrix from the python code, and unpickle it from c code, but I could not find documentation or example on how to do this. I found something about marshalling data, but nothing about unpickling from C. Edi...

httplib2 not found

sh-3.2# python -V Python 2.6.4 sh-3.2# python -c "import httplib2" Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named httplib2 errr.. how to fix this? ...

How do I transfer data in .csv file into my sqlite database in django?

This is my models.py from django.db import models class School(models.Model): school = models.CharField(max_length=300) def __unicode__(self): return self.school class Lawyer(models.Model): firm_url = models.URLField('Bio', max_length=200) firm_name = models.CharField('Firm', max_length=100) first = mode...

Creating an Python/py2app application that simply opens a terminal on launch?

I've written a nice Python application that is basically an HTTP proxy for SMS modems, and I'd like to make it a double-clickable application on Macs. So far I've been including a .commmand file which is double-clickable, which basically consists of cd `dirname $0` (sleep 8;open http://127.0.0.1:8080/)&amp; mac/slingshotsms.app/Contents...

Excel and Django

I have an excel spreadsheet with calculations I would like to use in a Django web application. I do not need to present the spreadsheet as it appears in excel. I only want to use the formulae embedded in it. What is the best way to do this? ...

Big List Of Portability in Python

I thought it would be a good idea to compile a list of things to watch out for when making a Python app portable. There are a lot of subtle 'gotchas' in portability that are only discovered through experience and thorough testing; there needs to be some sort of list addressing the more common ones. Please post one gotcha (with its fix) ...

Pinging first available host in network subnets

I've written a small script in Python that pings all subnets of my school's wireless network and prints out the IP addresses and hostnames of computers that are connected to each subnet of the network. My current setup is that I'm relying on creating threads to handle each of the ping requests. from threading import Thread import subpr...

How to parse through script tag using python and beautifulsoup

Hi, I am trying to extract attributes of frame tag which is inside document.write function on a page like this: <script language="javascript"> . . . document.write('<frame name="nav" src="/nav/index_nav.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" border = "no" noresize>'); if (anchor != "") { document.write(...

Contents of PyString in Qt Creator debugger?

I've got a PyString* object that I would like to see the contents of. Is there any way to see the text of the PyString using Qt Creator's debugger? PyObject *import_str = PyString_InternFromString("__import__"); If it makes a difference, Qt Creator is a front end to GDB. ...

Using Python, how do I to read/write data in memory like I would with a file?

I'm used to C++, and I build my data handling classes/functions to handle stream objects instead of files. I'd like to know how I might modify the following code, so that it can handle a stream of binary data in memory, rather than a file handle. def get_count(self): curr = self.file.tell() self.file.seek(0, 0) count, = stru...

Learn Java from Python background

I have been programming in Python for a while now, and I'd like to learn a more "hireable" language like Java or the C/C++/C# family. I'm acquainted with (though not necessarily good at) all of them. I'm leaning towards Java because it runs just about everywhere, and I'd like to start developing for the Android. Coming from a dynamic l...