python

Python: execfile from other file's working directory?

I have some code that loads a default configuration file and then allows users to supply their own Python files as additional supplemental configuration or overrides of the defaults: # foo.py def load(cfg_path=None): # load default configuration exec(default_config) # load user-specific configuration if cfg_path: ...

Why should I use WSGI ?

Been using mod_python for a while, I read more and more articles about how good WSGI is, without really understanding why. So why should I switch to it? What are the benefits? Is it hard, and is the learning curve worth it? ...

Help with dictionaries

I'm trying to remove duplicate items in a list through a dictionary: def RemoveDuplicates(list): d = dict() for i in xrange(0, len(list)): dict[list[i]] = 1 <------- error here return d.keys() But it is raising me the following error: TypeError: 'type' object does not support item assignment What is the ...

Django, how to generate an admin panel without models?

Hi, I'm building a rather large project, that basically consists of this: Server 1: Ice based services. Glacier2 for session handling. Firewall allowing access to Glacier2. Server 2: Web interface (read, public) for Ice services via Glacier2. Admin interface for Ice services via Glacier 2. The point I'm concerned with is the...

How to deal with "None" DB values in Django queries

Hello, I have the following filter query which is doing an SQL OR statement: results = Stores.objects.filter(Q(title__icontains=prefs.address1) | Q(title__icontains=prefs.address2)) This works fine but if the prefs.address1 and prefs.address2 values (which come from another model) are blank in mySQL, Django complains with the followi...

Intersection between bezier curve and a line segment

I am writing a game in Python (with pygame) that requires me to generate random but nice-looking "sea" for each new game. After a long search I settled on an algorithm that involves Bezier curves as defined in padlib.py. I now need to figure out when the curves generated by padlib intersect a line segment. The brute force method would b...

A puzzle concerning Q objects and Foreign Keys

I've got a model like this: class Thing(models.Model): property1 = models.IntegerField() property2 = models.IntegerField() property3 = models.IntegerField() class Subthing(models.Model): subproperty = models.IntegerField() thing = modelsForeignkey(Thing) main = models.BooleanField() I've got a function that is...

How does python webdriver work?

Hi, I want to add some features to webdriver, but since I don't know Java at all, I want to understand the way it works first. So as I get it, there is a firefox plugin (javascript) and there is java code that starts firefox with that extension installed, then this java code listens to a local port and when it gets some command, java sig...

Running a process in pythonw with Popen without a console

I have a program with a GUI that runs an external program through a Popen call: p = subprocess.Popen("<commands>" , stdout=subprocess.PIPE , stderr=subprocess.PIPE , cwd=os.getcwd()) p.communicate() But a console pops up, regardless of what I do (I've also tried passing it NUL for the file handle). Is there any way to do that without ...

rsync --delete --files-from=list / dest/ does not delete unwanted files

Hi, as you can see in the title i try to sync a folder with a list of files. I hoped that this command would delete all files in dest/ that are not on the list, but it didn't. So i searched a little bit and know now, that rsync can't do this. But i need it, so do you know any way to do it? PS: The list is created by a python script, ...

How to search a HTML page for an item in a given list

I have a list of schools schools = ['Harvard Law School', 'Stanford Law School', 'Yale Law School', 'Columbia Law School', 'NYU School of Law', 'University of Chicago Law School'] and bios of lawyers that contain one of these schools: html = "page that contains one of these schools" like this "<strong><em>Education</em></strong><...

python and securing pyc files on disk

I set django's settings.py file to chmod 600 to keep felonious folks from spying my database connection info, but on import python compiles this file and writes out settings.pyc as mode 644. It doesn't take much sleuthing for the bad guys to get the info they need from this compiled version. I fear my blog entries are in grave danger. B...

Convert Python to Haskell / Lambda calculus

What is the Python code in Haskell and Lambda calculus? def f1(): x = 77 def f2(): print x f2 f1 My attempt in lambda calculus \x. 77 (\x.x) ...

Django, displaying a view in an another view?

I would like to know if I can display a view inside another view with django. This is what I tried to do: def displayRow(request, row_id): row = Event.objects.get(pk=row_id) return render_to_response('row.html', {'row': row}) def listEventsSummary(request): listEventsSummary = Event.objects.all().order_by('-id')[:20] r...

Global disk resource becomes unavailable

Hi all, If I've got a global disk resource (mount point on an isilon file server) that multiple servers use to access a lock file. What is a good way to handle the situation if that global disk becomes unavailable and the servers can't access the global lock file? Thanks, Doug ...

Simple way to convert a string to a dictionary

What is the simplest way to convert a string of keyword=values to a dictionary, for example the following string: name="John Smith", age=34, height=173.2, location="US", avatar=":,=)" to the following python dictionary: {'name':'John Smith', 'age':34, 'height':173.2, 'location':'US', 'avatar':':,=)'} The 'avatar' key is just to sho...

MySQL driver issues with INFORMATION_SCHEMA?

I'm trying out the Concurrence framework for Stackless Python. It includes a MySQL driver and when running some code that previously ran fine with MySQLdb it fails. What I am doing: Connecting to the MySQL database using dbapi with username/password/port/database. Executing SELECT * FROM INFORMATION_SCHEMA.COLUMNS This fails with me...

Allow only one concurrent login per user in django app

is it possible to allow only one concurrent login per user in django application? if yes, how do you approach? ...

New transport and reader type in Twisted

I'm trying to add a new transport to Twisted, which will read data from a stream - either a file in a tail -f way, or from a pipe, but I have some problems with Twisted architecture. I've got the transport itself (implements ITransport) ready - it handles all file opening. I've got streaming functions/deferreds ready. How do I put it to...

Python: How to shutdown a threaded HTTP server with persistent connections (how to kill readline() from another thread)?

I'm using python2.6 with HTTPServer and the ThreadingMixIn, which will handle each request in a separate thread. I'm also using HTTP1.1 persistent connections ('Connection: keep-alive'), so neither the server or client will close a connection after a request. Here's roughly what the request handler looks like request, client_address =...