python

How do I use Trac wiki formatting in a Django/Python web application?

I have a Python web application (Django, specifically). I'm reading in some data from a Trac database (where the descriptions use wiki formatting) and displaying it as HTML. I considered the markdown module, but realised that Trac wiki formatting and markdown are really quite different. Is there a module for Django, or a Python package t...

Read the first line of batch file from the same batch file?

I have a batch file that tries to run the program specified in its first line. Similar to Unix's shebang: C:\> more foo.bat #!C:\Python27\python.exe %PYTHON% foo-script.py C:\> What I want to know is: is there a way to automatically set %PYTHON% to C:\Python27\python.exe which is specified in the first line of the script following the...

psp (python server pages) code under mod_wsgi?

Is there some way to run .psp (python server pages) code under apache + mod_wsgi? While we are moving towards newer wsgi based frameworks we still have some legacy code written in psp which runs under mod_python. We'd like to be able to run it on the same server that hosts other wsgi based python code. In short - is there a way to supp...

Find all decorated functions in a module

Is it possible to find out if a function is decorated at runtime? For example could I find all functions in a module that are decorated by "example"? @example def test1(): print "test1" ...

I'm using Hadoop for data processing with python, what file format should be used?

I'm using Hadoop for data processing with python, what file format should be used? I have project with a substantial amount of text pages. Each text file has some header information that I need to preserve during the processing; however, I don't want the headers to interfere with the clustering algorithms. I'm using python on Hadoop (...

How can I access the current URI in python's mako templating system?

I'd like to submit the form to the current URI, like this: <form action="${CURRENT_URI}" method="post"> <input type="text" name="email" /> </form> from within a mako template. But I am not sure what variable holds the current uri information. Thanks. ...

what is {% trans "This is the title." %} used for,i can't understand the api.

i know the {% trans %} is for translation, and how can i translate {% trans "This is the title." %} to chinese. thanks D:\zjm_code\register2>python D:\Python25\Lib\site-packages\django\bin\django-adm in.py compilemessages processing file django.po in D:\zjm_code\register2\locale\cn\LC_MESSAGES msgfmt: iconv failure ...

assigning points to bins

What is a good way to bin numerical values into a certain range? For example, suppose I have a list of values and I want to bin them into N bins by their range. Right now, I do something like this: from scipy import * num_bins = 3 # number of bins to use values = # some array of integers... min_val = min(values) - 1 max_val = max(value...

my pythonpath has 'register2',why i can't import it

import sys print sys.path ['D:\\zjm_code\\register2', 'C:\\WINDOWS\\system32\\python25.zip', 'D:\\Python25\\DLLs', 'D:\\Python25\\lib', 'D:\\Python25\\lib\\plat-win', 'D:\\Python25\\lib\\lib-tk', 'D:\\Python25', 'D:\\Python25\\lib\\site-packages'] and #from django.core.management import setup_environ from register2 import settings #...

Why can't I use 'django-admin.py makemessages -l cn'

print : D:\zjm_code\register2>python D:\Python25\Lib\site-packages\django\bin\django-adm in.py makemessages -l cn Error: This script should be run from the Django SVN tree or your project or app tree. If you did indeed run it from the SVN checkout or your project or applica tion, maybe you are just missing the conf/locale (in the djang...

best way to add file way to my pythpath.which can be saved.

import sys print sys.path sys.path+=['D:\\zjm_code'] print sys.path it can't be save,how does do it, thanks ...

Python C interoperability

I wish to wrap an existing C (pure C that is. No C++) library into Python so that I can call it from Python scripts. Which approach among the various available (C Api, SWIG etc.) would be the most suitable? ...

Nested Choices in a python program

I have a script that I wrote in python for testing out the sorting algorithms that I've implemented. The main part of the program asks the user to select on of the sort algorithms from a list. And then whether they would like to sort from a file of numbers or select a list of random numbers. I have it setup (i think) so that typing a num...

Is it safe to use sys.platform=='win32' check on 64-bit Python?

The usual check to differentiate between running Python-application on Windows and on other OSes (Linux typically) is to use conditional: if sys.platform == 'win32': ... But I wonder is it safe to use today when 64-bit Python is more widely used in last years? Does 32 really means 32-bit, or basically it refers to Win32 API? If t...

How to know the encoding of a file in Python?

Hello Does anybody know how to get the encoding of a file in Python. I know that you can use the codecs module to open a file with a specific encoding but you have to know it in advance. import codecs f = codecs.open("file.txt", "r", "utf-8") Is there a way to detect automatically which encoding is used for a file? Thanks in advance...

sqlite python insert with where condition

from this post http://stackoverflow.com/questions/2130641/sqlite-python-insert I learned inserting into tables but now I need to use where something like cursor.execute("insert into table1(id) values (?) where ip=? and address=?",(id,),(ip,),(addr,)); ...

Using Django, why would REMOTE_ADDR return 127.0.0.1 on a web server?

When getting the IP with request.META['REMOTE_ADDR'] code. This works fine on the local system but when hosted on a web server the ip got is 127.0.0.1 - How can this be resolved? ...

Python: multiple calls to __init__() on the same instance

The __init__() function gets called when object is created. Is it ok to call an object __init__() function again, after its been created? instance = cls(p1=1, p2=2) # some code instance.__init__(p1=123, p2=234) # some more code instance.__init__(p1=23, p2=24) why would anyone wanna call __init__() on an object that is already created?...

Have a Python CGI call a Perl CGI, passing original info (to limit searching private Mailman archives to logged-in users)

I need to have a Python CGI script do some stuff (a little bit of security checking), and then end up calling a Perl CGI script, passing anything it received (e.g., POST info) onto the Perl script. For background, my reason for doing this is that I'm trying to integrate Swish searching with Mailman list archives. Swish searching uses s...

Is this a memory leak ( a program in python with sqlalchemy/sqlite)

I have the following code runs over a large set of data (2M). It eats up all my 4G mem before finishing. for sample in session.query(CodeSample).yield_per(100): for proj in projects: if sample.filename.startswith(proj.abs_source): sample.filename = "some other path" ...