python

Testing for cookie existence in Django

Simple stuff here... if I try to reference a cookie in Django via request.COOKIE["key"] if the cookie doesn't exist that will throw a key error. For Django's GET and POST, since they are QueryDict objects, I can just do if "foo" in request.GET which is wonderfully sophisticated... what's the closest thing to this for cookies tha...

Parameterized queries with psycopg2 / Python DB-API and PostgreSQL

What's the best way to make psycopg2 pass parameterized queries to PostgreSQL? I don't want to write my own escpaing mechanisms or adapters and the psycopg2 source code and examples are difficult to read in a web browser. If I need to switch to something like PyGreSQL or another python pg adapter, that's fine with me. I just want simple...

Can SAP work with Python?

Let's focus on using SAP as the database engine and just doing different queries. Can I do it in Python? ...

Django models - pass additional information to manager

Hello. I'm trying to implement row-based security checks for Django models. The idea is that when I access model manager I specify some additional info which is used in database queries so that only allowed instances are fetched from database. For example, we can have two models: Users and, say, Items. Each Item belongs to some User an...

Are python modules first class citizens?

I mean, can I create them dynamically? ...

django registration module

i started to learn django using the official documentation tutorial and in turn created this registration form. i have the whole app setup but am stuck at how to process the data. i mean the documentation is a little tough to understand. if i can get some help, it would be great. this is how the models are setup: class user (models.Mo...

How do i make Pydev + jython to startup faster when running a script?

Hi, i'm working with pydev + jython.great ide , but quite slow when i try to run a jython program. this is probably something due to libraries load time. What can i do to speed it up ? Thanks , yaniv ...

What language could I use for fast execution of this database summarization task?

So I wrote a Python program to handle a little data processing task. Here's a very brief specification in a made-up language of the computation I want: parse "%s %lf %s" aa bb cc | group_by aa | quickselect --key=bb 0:5 | \ flatten | format "%s %lf %s" aa bb cc That is, for each line, parse out a word, a floating-point number, an...

How does this work?

So I'm trying to comprehend the source file for csv2rec in matplotlib.mlab. It is used to take a csv file and parse the data into certain formats. So it may take a string '234' and convert it to int. or take a date string and make it into python datetimes. def get_converters(reader): converters = None for i, row in enumera...

python: how to get all members of an array except for ones that match a condition

I'm trying to create an array of all .asm files I need to build except for one that is causing me trouble right now. Here's what I have, based on the Scons "Handling Common Cases" page: projfiles['buildasm'] = ['#build/'+os.path.splitext(x)[0]+'.asm' for x in projfiles['a']]; (this maps paths of the form 'foo.a' to '#build/foo.asm'...

python win32 extensions documentation

I'm new to both python and the python win32 extensions available at http://python.net/crew/skippy/win32/ but I can't find any documentation online or in the installation directories concerning what exactly the win32 extensions provide. Where is this information? ...

Python CreateFile Cannot Find PhysicalMemory

I am trying to access the Physical Memory of a Windows 2000 system (trying to do this without a memory dumping tool). My understanding is that I need to do this using the CreateFile function to create a handle. I have used an older version of win32dd to help me through this. Other documentation on the web points me to using either "\D...

Cross-platform help viewer with search functionality

I am looking for a help viewer like Windows CHM that basically provides support for adding content in HTML format define Table of Contents decent search It should work on Windows, Mac and Linux. Bonus points for also having support for generating a "plain HTML/javascript" version that can be viewed in any browser (albeit without sea...

How to contribute improvements to packages hosted on Cheeseshop ( pypi ) ?

I've been using zc.buildout more and more and I'm encountering problems with some recipes that I have solutions to. These packages generally fall into several categories: Package with no obvious links to a project site Package with links to free hosted service like github or google code Setup #2 is better then #1, but not much bett...

How do you turn an unquoted Python function/lambda into AST? 2.6

This seems like it should be easy, but I can't find the answer anywhere - nor able to derive one myself. How do you turn an unquoted python function/lambda into an AST? Here is what I'd like to be able to do. import ast class Walker(ast.NodeVisitor): pass # ... # note, this doesnt work as ast.parse wants a string tree = ast...

What networking libraries/frameworks exist for Python?

I was wondering what good networking libraries/frameworks there are for Python. Please provide a link to the standard API documentation for the library, and perhaps a link to a decent tutorial to get started with it. A comment or two about its advantages/disadvantages would be nice as well. ...

Python canvas suggestions

I'm looking for a very simple canvas for python. What I really need is the ability to draw lines and circles, move them around / get rid of them, and scroll the canvas (so, I'm ideally drawing on an infinite canvas, and just scrolling it around). Ideally, the code would look like: c = Canvas() l1 = c.line((x0, y0), (x1, y1)) l2 = c.line...

why can't I import the 'math' library when embedding python in c?

I'm using the example in python's 2.6 docs to begin a foray into embedding some python in C. The example C-code does not allow me to execute the following 1 line script: import math Using line: ./tmp.exe tmp foo bar it complains Traceback (most recent call last): File "/home/rbroger1/scripts/tmp.py", line 1, in <module> i...

Probability exercise returning different result that expected

As an exercise I'm writing a program to calculate the odds of rolling 5 die with the same number. The idea is to get the result via simulation as opposed to simple math though. My program is this: # rollFive.py from random import * def main(): n = input("Please enter the number of sims to run: ") hits = simNRolls(n) hits...

Why am I receiving a low level socket error when using the Fabric python library?

When I run the command: fab -H localhost host_type I receive the following error: [localhost] Executing task 'host_type' [localhost] run: uname -s Fatal error: Low level socket error connecting to host localhost: Connection refused Aborting. Any thoughts as to why? Thanks. Fabfile.py from fabric.api import run def host_type(): ...