python

How can I ask for root password but perform the action at a later time?

I have a python script that I would like to add a "Shutdown when done" feature to. I know I can use gksudo (when the user clicks on "shutdown when done") to ask the user for root privileges but how can I use those privileges at a later time (when the script is actually finished). I have thought about chmod u+s on the shutdown command s...

launching vs2008 build from python

The first batch file launches a command prompt, i need the second command to be in the ccontext of the first. how can I do this in python? As is, it launches the batch, and blocks until the batch (with its command prompt context) terminates, and then executes devenv without the necessary context. os.system(r'%comspec% /k ""C:\Program ...

Access Ruby objects with Python via XML-RPC?

Hello I am trying to export a Ruby framework via XML-RPC. However I am having some problems when trying to call a method from a class not directly added as a handler to the XML-RPC server. Please see my example below: I have a test Ruby XML-RPC server as follows: require "xmlrpc/server" class ExampleBar def bar() return "hello ...

Google AppEngine: How to fetch more than 1000?

First: I'm a beginner in python. How can I fetch more than 1000 record from data store and put all in one single list to pass to django? ...

setting the gzip timestamp from Python

I'm interested in compressing data using Python's gzip module. It happens that I want the compressed output to be deterministic, because that's often a really convenient property for things to have in general -- if some non-gzip-aware process is going to be looking for changes in the output, say, or if the output is going to be cryptogr...

using jython and open office 2.4 to convert docs to pdf

Hi guys I completed a python script using pyuno which successfully converted a document/ xls / rtf etc to a pdf. Then I needed to update a mssql database, due to open office currently supporting python 2.3, it's ancientness, lacks support for decent database libs. So I have resorted to using Jython, this way im not burdened down by runn...

Python - one variable equals another variable when it shouldn't

Here is my sample code. It is meant to be an iterative procedure for gauss seidel (matrix solver). Essentially when the error is small enough it breaks out of the while loop. i=1 while (i>0): x_past = x_present j=0 while(j<3): value=0 k=0 while(k<3): if(k!=j): if(i==1): ...

Why the Global Interpreter Lock?

What is exactly the function of Python's Global Interpreter Lock? Do other languages that are compiled to bytecode employ a similar mechanism? ...

HTTP Request Timeout

In Python 2.6, a new "timeout" parameter was added to the httplib.HTTPConnection class: http://docs.python.org/library/httplib.html#httplib.HTTPConnection However, this is only a timeout for the connection to a server. I am looking to set a timeout value for the request, not the connection. This doesn't seem to be supported by httplib...

How do I process a string such as this using regular expressions?

How can I create a regex for a string such as this: <SERVER> <SERVERKEY> <COMMAND> <FOLDERPATH> <RETENTION> <TRANSFERMODE> <OUTPUTPATH> <LOGTO> <OPTIONAL-MAXSIZE> <OPTIONAL-OFFSET> Most of these fields are just simple words, but some of them can be paths, such as FOLDERPATH, OUTPUTPATH, these paths can also be paths with a filename an...

Django Forms, Display Error on ModelMultipleChoiceField

I'm having an issue getting validation error messages to display for a particular field in a Django form, where the field in question is a ModelMultipleChoiceField. In the clean(self) method for the Form, I try to add the error message to the field like so: msg = 'error' self._errors['field_name'] = ErrorList([msg]) raise forms.Validat...

Best way to strip punctuation from a string in Python

It seems like there should be a simpler way than: import string s = "string. With. Punctuation?" # Sample string out = s.translate(string.maketrans("",""), string.punctuation) Is there? ...

Setting up a Python web development environment on OSX

I'm running Leopard and wanted to know what the easy way to setup a web development environment to use Python, MySQL, Apache on my machine which would allow me to develop on my Mac and then easily move it to a host in the future. EDIT: I've been trying to get mod_wsgi installed and configured to work with Django and have a headache now....

Python: Check if uploaded file is jpg

How can I check if a file uploaded by a user is a real jpg file in Python (Google App Engine)? This is how far I got by now: Script receives image via HTML Form Post and is processed by the following code ... incomming_image = self.request.get("img") image = db.Blob(incomming_image) ... I found mimetypes.guess_type, but it does not ...

Using Python's smtplib with Tor

I'm conducting experiments regarding e-mail spam. One of these experiments require sending mail thru Tor. Since I'm using Python and smtplib for my experiments, I'm looking for a way to use the Tor proxy (or other method) to perform that mail sending. Ideas how this can be done? ...

How do I treat an ASCII string as unicode and unescape the escaped characters in it in python?

For example, if I have a unicode string, I can encode it as an ASCII string like so: >>> u'\u003cfoo/\u003e'.encode('ascii') '<foo/>' However, I have e.g. this ASCII string: '\u003foo\u003e' ... that I want to turn into the same ASCII string as in my first example above: '<foo/>' ...

scripting fruityloops or propellerheads reason from VB or Python?

I have both Fruityloops and Propellerheads Reason software synths on my Windows PC. Any way I can get at and script these from either Visual Basic or Python? Or at least send Midi messages to the synths from code? Update : attempts to use something like a "midi-mapper" (thanks for link MusiGenesis) don't seem to work. I don't think Rea...

How to create a picture with animated aspects programmatically

Background I have been asked by a client to create a picture of the world which has animated arrows/rays that come from one part of the world to another. The rays will be randomized, will represent a transaction, will fade out after they happen and will increase in frequency as time goes on. The rays will start in one country's bou...

How to add an automatic filter to a relation with SQLAlchemy?

I'm using SQLAlchemy 0.5rc, and I'd like to add an automatic filter to a relation, so that every time it tries to fetch records for that relation, it ignores the "remote" ones if they're flagged as "logically_deleted" (a boolean field of the child table) For example, if an object "parent" has a "children" relation that has 3 records, bu...

Python distutils and replacing strings in code

I often find a need to put paths in my code in order to find data or in some cases tool-specific modules. I've so far always used autotools because of this--it's just so easy to call sed to replace a few strings at build time. However, I'd like to find a more Pythonic way of doing this, i.e. use distutils or some other blessed way of b...