python

How to print context content in the template?

How can I print or iterate over all the variables available in the context from the template code? I know about {% debug %} but it contains too much information. I'd just like to print variable names available in the current context. Is there a way to do this without writing custom tag? ...

"download link " fails in IE

Hi, all. I was trying to implement a "download link" and put it beside one of my report table so that users can download a csv file and open it with applications like Excel. The records are generated dynamically based on the query made by users. So somewhere in my controller there's something like: response.headers['Content-Type'] = ...

Python string splitting

If I have a string 'x=10', how can I extract the 10 as an integer using one line of code? ...

is there a way to append the etag at the end of the static resources in django.

Hi: In rails, if I import a css file or javascript file, the url will be like this <script type="text/javascript" src="some.js?<ETag here>"></script> if I upgrade the some.js the etag will be changed, so my browser can cache the static resource smartly and update the cache when necessary. Is there a way to do it in django? ...

Problem allocating heap space over 4 GB when calling java "from Python"

I am using using os.system call from python to run jar file. The jar file requires large heap space and thus i am allocating 4 Gb heap space using Xmx. When i execute the command "java -Xms4096m -Xmx4096m -jar camXnet.jar net.txt" from command line it executes properly, however when i call it from a python program via os.system, it wor...

PyQt, widget do not shown

Hi I've this hort program in Python ad Qt4 #!/usr/bin/python # -*- coding: utf-8 -*- import sys from PyQt4 import QtGui from PyQt4 import QtCore color = QtGui.QColor(99, 0, 0) class colorButton(QtGui.QWidget): def __init__(self, args): QtGui.QWidget.__init__(self,args) self.setGeometry(150, 22, 50, 50) se...

Does Django need an IDE?

My company is evaluating the possibility of developing a specialized IDE for Django. So we would like to ask Django users: Do you feel the need for a specialized IDE for Django? Would you be willing to pay for it, or would you only consider free a open-source product? What Django-specific features are you missing currently in your ...

Retrieve module object from stack frame

Given a frame object, I need to get the corresponding module object. In other words, implement callers_module so this works: import sys from some_other_module import callers_module assert sys.modules[__name__] is callers_module() (That would be equivalent because I can generate a stack trace in the function for this test case. The i...

Class or Metaclass Design for Astrodynamics Engine

Gurus out there: The differential equations for modeling spacecraft motion can be described in terms of a collection of acceleration terms: d2r/dt2 = a0 + a1 + a2 + ... + an Normally a0 is the point mass acceleration due to a body (a0 = -mu * r/r^3); the "higher order" terms can be due to other planets, solar radiation pressure, thr...

Is it a good idea to use undocumented public code from the Python standard library?

For instance, in multiprocessing.managers there is a function called MakeProxyType. This function isn't in the multiprocessing documentation at all, but its name doesn't begin with an underscore either. Disregarding the subject of whether or not it's actually useful to use MakeProxyType, would it be ok to use this function in my code? ...

How to create dynamical scoped variables in Python?

Hello, I am translating some code from lisp to Python. In lisp, you can have a let construct with the variables introduced declared as special and thus having dynamic scope. (See http://en.wikipedia.org/wiki/Dynamic_scope#Dynamic_scoping) How can I do likewise in Python? It seems the language does not support this directly, if true,...

Launch script on any network connection

On linux (ubuntu), is it possible to execute a script upon any incoming network connection? During long periods inactivity on my home server, I plan on stopping the software raid, parking the data disks and restarting the raid array upon encountering an incoming network connection. I've been researching this problem and haven't come a...

Using Python csv module on updating file

I am using python's csv module to extract data from a csv that is constantly being updated by an external tool. I have run into a problem where when I reach the end of the file I get a StopIteration error, however, I would like the script to continue to loop waiting for more lines to be added by the external tool. What I came up with s...

Should I use Lex or a home-brewed solution to parse a formula?

I'm in the process of writing a small, rule-based 'math' engine. I realize this is unclear, so I'll provide a small example. Let's say you have some variable a, that holds an integer. You also have some functions you can apply to the number, i.e. sqr - square the number flp - flip the bits of the number dec - decrement the number inc ...

How do I update attachment content with the google sites python API?

I'm trying to write a script that will automatically update some attachments on a website created and managed through Google Sites. This should be possible as Google released the Sites API in September and the Python GData API claims to support sites. However, the closest method I can find is called client.update, which allows me to up...

Cannot understand how to get data from checklistbox in wxpython

I am trying to get either the strings checked or the integers from a check list. I cannot seem to get it anywhere. In the code below, you'll see a bunch of un-commented code, those are just different ways I've tried. I thought I would leave them in case any one's suggestions have to do with it. I am very new to GUI-programming and wx. Th...

Javascript lexer / tokenizer (in Python?)

Does anyone know of a Javascript lexical analyzer or tokenizer (preferably in Python?) Basically, given an arbitrary Javascript file, I want to grab the tokens. e.g. foo = 1 becomes something like: variable name : "foo" whitespace operator : equals whitespace integer : 1 ...

How to load modules dynamically on package import?

Given the following example layout: test/ test.py formats/ __init__.py format_a.py format_b.py What I try to archive is, that whenever I import formats, the __init__.py looks for all available modules in the formats subdir, loads them and makes them available (right now simply through a variable, supported_formats). If...

How to Use Mathematic Equations as Filters in SQLAlchemy

I'm using the SQLAlchemy ORM to construct the MySQL queries in my application, and am perfectly able to add basic filters to the query, like so: query = meta.Session.query(User).filter(User.user_id==1) Which gives me something basically equivalent to this: SELECT * FROM users WHERE user_id = 1 My question is how I would integrate s...

Converting PDF to images automatically

So the state I'm in released a bunch of data in PDF form, but to make matters worse, most (all?) of the PDFs appear to be letters typed in Office, printed/fax, and then scanned (our government at its best eh?). At first I thought I was crazy, but then I started seeing numerous pdfs that are 'tilted', like someone didn't get them on the s...