python

Programmatically detect system-proxy settings on Windows XP with Python

I develop a critical application used by a multi-national company. Users in offices all around the globe need to be able to install this application. The application is actually a plugin to Excel and we have an automatic installer based on Setuptools' easy_install that ensures that all a project's dependancies are automatically installe...

Python unittest: how to run only part of a test file ?

Hi, I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class. Since they take time and furthermore are not likely to break, I'd want to be able to choose whether this subset of tests does or doesn't run (the best way woul...

Using SimpleXMLTreeBuilder in elementtree

I have been developing an application with django and elementtree and while deploying it to the production server i have found out it is running python 2.4. I have been able to bundle elementtree but now i am getting the error: "No module named expat; use SimpleXMLTreeBuilder instead" Unfortunately i cannot upgrade python so im stuck ...

Skip steps on a django FormWizard

I have an application where there is a FormWizard with 5 steps, one of them should only appear when some conditions are satisfied. The form is for a payment wizard on a on-line cart, one of the steps should only show when there are promotions available for piking one, but when there are no promotions i want to skip that step instead of ...

Django way to do conditional formatting

What is the correct way to do conditional formatting in Django? I have a model that contains a date field, and I would like to display a list of records, but colour the rows depending on the value of that date field. For example, records that match today's date I want to be yellow, records that is before today I want green and ones afte...

Is there a python module compatible with Google Apps Engine's new "Tasks"

I'm writing a Python application, that I want to later migrate to GAE. The new "Task Queues" API fulfills a requirement of my app, and I want to simulate it locally until I have the time to migrate the whole thing to GAE. Does anyone know of a compatible module I can run locally? ...

Problem using os.system() with sed command

Hi, I'm writing a small method to replace some text in a file. The only argument I need is the new text, as it is always the same file and text to be replaced. I'm having a problem using the os.system() call, when I try to use the argument of the method If I use a string like below, everything runs ok: stringId = "GRRRRRRRRR" cmd="se...

Open-Source Forum with API

Does anyone have suggestions for a PHP, Python, or J2EE-based web forum that has a good API for programmatically creating users and forum topics? Thanks In Advance -J ...

using profiles in iPython and Django

I've got a Django product I'm using iPython to interact with. I'm trying to have modules automatically loaded when I start a shell: python manage.py shell I've copied .ipython/ipythonrc to the root directory of the project and added to the file: import_some module_name model1 model2 However, when I start the shell, these names are...

Python + CGI script cannot access environment variables

I'm coding a webservice on python that uses an Oracle database. I have cx_Oracle installed and working but I'm having some problems when I run my python code as CGI using Apache. For example the following code works perfectly at the command line: #!/usr/bin/python import os import cx_Oracle import defs as df os.putenv('ORACLE_HOME...

How to create "virtual root" with Python's ElementTree?

I am trying to use Python's ElementTree to generate an XHTML file. However, the ElementTree.Element() just lets me create a single tag (e.g., HTML). I need to create some sort of a virtual root or whatever it is called so that I can put the various , DOCTYPES, etc. How do I do that? Thanks ...

Equivalent for inject() in Python?

In Ruby, I'm used to using Enumerable#inject for going through a list or other structure and coming back with some conclusion about it. For example, [1,3,5,7].inject(true) {|allOdd, n| allOdd && n % 2 == 1} to determine if every element in the array is odd. What would be the appropriate way to accomplish the same thing in Python? ...

How To: View MFC Doc File in Python

I want to use Python to access MFC document files generically? Can CArchive be used to query a file and view the structure, or does Python, in opening the document, need to know more about the document structure in order to view the contents? ...

Writing a website in Python

I'm pretty proficient in PHP, but want to try something new. I'm also know a bit of Python, enough to do the basics of the basics, but haven't used in a web design type situation. I've just written this, which works: #!/usr/bin/python def main(): print "Content-type: text/html" print print "<html><head>" print "<title...

Pylons: address already in use when trying to serve

I'm running pylons and I did this: paster server development.ini It's running on :5000 But when I try to run the command again: paster serve development.ini I get this message: socket.error: [Errno 98] Address already in use Any ideas? ...

Deploying Pylons with Nginx reverse proxy?

Is there a tutorial on how to deploy Pylons with Nginx? I've been able to start nginx and then serve pylons to :8080 with paster serve development.ini However, I can't seem to do other stuff as pylons locks me into that serve mode. If I try to CTRL+Z out of pylons serving to do other stuff on my server, pylons goes down. There must b...

call javascript from python

I want to execute this script (view source) that uses Google Translate AJAX API from python, and be able to pass arguments and get the answer back. I don't care about the HTML. I understand I need to embed a Javascript interpreter of some sort. Does this mean I need to have a browser instance and manipulate it? What is the cleanest w...

Detect URLs in a string and wrap with "<a href..." tag

Hi, I am looking to write something that seems like it should be easy enough, but for whatever reason I'm having a tough time getting my head around it. I am looking to write a python function that, when passed a string, will pass that string back with HTML encoding around URLs. unencoded_string = "This is a link - http://google.com" ...

Why does list comprehension using a zip object results in an empty list?

f = lambda x : 2*x g = lambda x : x ** 2 h = lambda x : x ** x funcTriple = ( f, g, h ) myZip = ( zip ( funcTriple, (1, 3, 5) ) ) k = lambda pair : pair[0](pair[1]) # Why do Output # 1 (2, 9, 3125) and Output # 2 ( [ ] ) differ? print ("\n\nOutput # 1: for pair in myZip: k(pair) ...") for pair in myZip : print ( k(pair) ) print (...

Form Initialization with ToscaWidgets

Question: How do I prefill a CheckBoxTable from ToscaWidgets with values. Background: I've looked everywhere and I can't seem to figure out how to initialize a particular form field with ToscaWidgets. Most form fields seem to respond just fine to initialization, like if I create a form with a single TextField in it when I render the ...