python

Apache vs Twisted

I know Twisted is a framework that allows you to do asynchronous non-blocking i/o but I still do not understand how that is different from what Apache server does. If anyone could explain the need for twisted, I would appreciate it.. ...

Equivalent of Backticks in Python

What is the equivalent of the backticks found in Ruby and Perl in Python? That is, in Ruby I can do this: foo = `cat /tmp/baz` What does the equivalent statement look like in Python? I've tried os.system("cat /tmp/baz") but that puts the result to standard out and returns to me the error code of that operation. ...

Python - Windows Shutdown Events

When using win32api.setConsoleCtrlHandler(), I'm able to receive shutdown/logoff/etc events from Windows, and cleanly shut down my app. However, this only works when running the app under python.exe (i.e., it has a console window), but not under pythonw.exe (no console window). Is there an equivalent way in Windows to receive these eve...

Twisted - listen to multiple ports for multiple processes with one reactor

Hi, i need to run multiple instances of my server app each on it's own port. It's not a problem if i start these with os.system or subprocess.Popen, but i'd like to have some process communication with multiprocessing. I'd like to somehow dynamically set up listening to different port from different processes. Just calling reactor.lis...

Locking in sqlalchemy

I'm confused about how to concurrently modify a table from several different processes. I've tried using Query.with_lockmode(), but it doesn't seem to be doing what I expect it to do, which would be to prevent two processes from simultaneously querying the same rows. Here's what I've tried: import time from sqlalchemy.orm import session...

How do I stop getting ImportError: Could not import settings 'mofin.settings' when using django with wsgi?

I can't get wsgi to import my settings file for my project 'mofin'. The list of errors from the apache error log are as follows mod_wsgi (pid=4001): Exception occurred within WSGI script '/var/www/wsgi-scripts/django.wsgi'. Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 2...

Having problem with IronPython to instantiate a class in IronPython Console.

I'm trying to learn IronPython. I created an extremely simple class like this one: class Test: def testMethod(self): print "test" Next I'm trying to use it in IronPython Console: >>> import Test >>> t = Test() After the second line I get following error: TypeError: Scope is not callable What I'm doing wrong? ...

Help with basic Python function

I have a function to connect to a database. This code works: def connect(): return MySQLdb.connect("example.com", "username", "password", "database") But this doesn't: def connect(): host = "example.com" user = "username" pass = "password" base = "database" return MySQLdb.connect(host, user, pass, base) Why ...

How to get '\x01' to 1

I am getting this: _format_ = "7c7sc" print struct.unpack(self._format_, data) gives ('\x7f', 'E', 'L', 'F', '\x01', '\x01', '\x01', '\x00\x00\x00\x00\x00\x00\x00', '\x00') I want to take '\x01' and get 1 from it, i.e., convert to ``int. Any ideas? Thanks ...

What difference it makes when I set python thread as a Deamon

What difference it makes when I set python thread as a Deamon, using thread.setDaemon(True) ? ...

Python CGI returning an http status code, such as 403?

Hi, How can my python cgi return a specific http status code, such as 403 or 418? I tried the obvious (print "Status:403 Forbidden") but it doesn't work. ...

Python: what's the pythonic way to perform this loop?

What is the pythonic way to perform this loop. I'm trying to pick a random key that will return a subtree and not the root. Hence: 'parent == None' cannot be true. Nor can 'isRoot==True' be true. thekey = random.choice(tree.thedict.keys()) while (tree.thedict[thekey].parent == None)or(tree.thedict[thekey].isRoot == True): thekey...

Reading XML using Python minidom and iterating over each node

I have an XML structure that looks like the following, but on a much larger scale: <root> <conference name='1'> <author>Bob</author> <author>Nigel</author> </conference> <conference name='2'> <author>Alice</author> <author>Mary</author> </conference> </root> For this, I used the following code: dom = parse(filepath) conference=dom.ge...

Custom QStyledItemDelegate: adding bold items

So here's the story: I have a QListview that uses a QSqlQueryModel to fill it up. Because some items should display in bold based on the value of a hidden column of the model, I decided to make my own custom delegate. I'm using PyQT 4.5.4 and thus inheriting from QStyledItemDelegate is the way to go according to the docs. I got it worki...

Twisted(asynch server) vs Django(or any other framework)

I need help understanding what the advantage of using an asynch framework is. Suppose I want to develop a simple chat web app. Why cant I write python code in the Django framework that does long polling where I dont send a response back the server until someone enters a new msg. What does Twisted provide that gives it an advantage for re...

Python decorate a class to change parent object type

Suppose you have two classes X & Y. You want to decorate those classes by adding attributes to the class to produce new classes X1 and Y1. For example: class X1(X): new_attribute = 'something' class Y1(Y): new_attribute = 'something' *new_attribute* will always be the same for both X1 and Y1. X & Y are not related in any meaning...

Modifying a GUI started with Glade

I am just starting to learn Glade with pyGTK. Since Glade makes XML files instead of actual python code, is there a good way to start a project with Glade and then hand code more or tweak it? Are there times or reasons it would be preferrable to hand code all of it instead of starting with glade? ...

Python Triple Quote / Multi-line indentation

I have a python editor where the user is entering a script or code, which is then put into a main method behind the scenes, while also having every line indented. The problem is that if a user has a multi line string, the indentation made to the whole script affects the string, by inserting a tab in every space. A problem script would be...

IronPython libraries for scientific plots

What are good python libraries which IronPython supports (current version wise) for drawing scientific plots on Win ? By "scientific plots" I mean simple x-y plots, x-y-z surface plots and x-y-z shaded plots. ...

Django extends template

Hi to all , i have simple django/python app and i got 1 page - create.html. So i want to extend this page to use index.html. Everything work (no errors) and when the page is loaded all data from create.html and all text from index.html present but no formating is available - images and css that must be loaded from index.html is not load...