python

foreignkey problem

Hey, Imagine you have this model: class Category(models.Model): node_id = models.IntegerField(primary_key = True) type_id = models.IntegerField(max_length = 20) parent_id = models.IntegerField(max_length = 20) sort_order = models.IntegerField(max_length = 20) name = models.CharField(max_length = 45) ...

[Python] How can I speed up unpickling large objects if I have plenty of RAM?

It's taking me up to an hour to read a 1-gigabyte NetworkX graph data structure using cPickle (its 1-GB when stored on disk as a binary pickle file). Note that the file quickly loads into memory. In other words, if I run: import cPickle as pickle f = open("bigNetworkXGraph.pickle","rb") binary_data = f.read() # This part doesn't take...

Openssl_seal in Python

Hi, to connect a server i've found that using PHP i've to use openssl_seal. That's ok, but i want to use Python. But i'm not able to convert "Openssl_seal" in an equivalent function. can you help me? this is what Openssl_seal do: Description int openssl_seal ( string $data , string &$sealed_data , array &$env_keys , ...

Parse metadata from http live stream

Hi, I'd like to extract the info string from an internet radio streamed over HTTP. By info string I mean the short note about the currently played song, band name etc. Preferably I'd like to do it in python. So far I've tried opening a socket but from there I got a bunch of binary data that I could not parse... thanks for any hints ...

Customizing Django form widgets? - Django

Hi folks, I'm having a little problem here! I have discovered the following as being the globally accepted method for customizing Django admin field. from django import forms from django.utils.safestring import mark_safe class AdminImageWidget(forms.FileInput): """ A ImageField Widget for admin that shows a thumbnail. "...

Template strings python 2.5 error

#!/usr/bin/python from string import Template s = Template('$x, go home $x') s.substitute(x='lee') print s error i get is <string.Template object at 0x81abdcc> desired results i am looking for is : lee, go home lee ...

giving garbage value while trying to store a md5 hash in a file in python

m=md5.new() a=10111011 >>> m.update(str(a)) >>> k=m.digest() >>> k '\xec\x9d1\x89e\x08\xa1\xc2Y\xf6\xbf6\xfe\xe4\xe2M' >>> f.write(str(k)) >>> f.flush() the file f is filled with garbage value which i cant use to read again for further use of the hash . Why does it give the garbage value when on the python terminal it gives proper out...

When deploying python, what web server options do we have? is the process inefficient at all?

I think in the past python scripts would run off CGI, which would create a new thread for each process. I am a newbie so I'm not really sure, what options do we have? Is the web server pipeline that python works under any more/less effecient than say php? ...

Including global package into a virtualenv that has been created with --no-site-packages

I'd usually prefer to create virtualenvs with --no-site-packages option for more isolation, and also because default python global packages includes quite a lot of packages, and usually most of them are not needed. However I'd still want to keep a few select packages in global, like PIL or psycopg2. Is there a good way to include them in...

SQLAlchemy Relationship Filter?

can i do: table.relationship.filter( column = value ) to get a subset of rows for relationships? and the same for order_by? ...

Getting Started with Python: Attribute Error

I am new to python and just downloaded it today. I am using it to work on a web spider, so to test it out and make sure everything was working, I downloaded a sample code. Unfortunately, it does not work and gives me the error: "AttributeError: 'MyShell' object has no attribute 'loaded' " I am not sure if the code its self has an erro...

Eclipse and python: library will import in interprer, but not in IDE

I'm running Windows 7, Python 2.6.4 and the latest version of Eclipse. I downloaded the boto library (http://code.google.com/p/boto/) and ran python setup.py install, which created boto-1.9b-py2.6.egg in C:\Python26\Lib\site-packages. Importing a class - say, by doing 'from boto.sqs.connection import SQSConnection' - works fine from th...

Generating content diffs using SequenceMatcher (Python)

I want to generate a diff between to revisions of text (more specifically, Markdown-formatted articles) in Python. I want to format this diff in a manner similar to what Github does. I've looked at difflib and have found that it does what I want. However, the Differ class is too high-level; I would have to parse the diff lines to gener...

Lua parser in python

Hi, I'm looking into using Lua in a web project. I can't seem to find any way of directly parsing in pure python and running Lua code in Python. Does anyone know how to do this? Joe ...

google app engine python download file

I am trying to figure out a way where I can create a tab-delimited file containing data from user-defined fields and allow the user to download that file on google app engine. The sandbox environment that the app runs in does not allow the application to write to disk. Is there another way where I can create a downloadable file? ...

Iterating over key and value of defaultdict dictionaries

The following works as expected: d = [(1,2), (3,4)] for k,v in d: print "%s - %s" % (str(k), str(v)) But this fails: d = collections.defaultdict(int) d[1] = 2 d[3] = 4 for k,v in d: print "%s - %s" % (str(k), str(v)) With: Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is no...

Creating Python C module from Fortran sources on Ubuntu 10.04 LTS

In a project I work on we use a Python C module compiled from Fortran with f2py. I've had no issues building it on Windows 7 32bit (using mingw32) and on the servers it's built on 32bit Linux. But I've recently installed Ubuntu 10.04 LTS 64bit on my laptop that I use for development, and when I build it I get a lot of warnings (even thou...

Windows equivalent to this Makefile

The advantage of writing a Makefile is that "make" is generally assumed to be present on the various Unices (Linux and Mac primarily). Now I have the following Makefile: PYTHON := python all: e installdeps e: virtualenv --distribute --python=${PYTHON} e installdeps: e/bin/python setup.py develop e/bin/pip ins...

Dynamic Class Creation in SQLAlchemy

We have a need to create SQLAlchemy classes to access multiple external data sources that will increase in number over time. We use the declarative base for our core ORM models and I know we can manually specify new ORM classes using the autoload=True to auto generate the mapping. The problem is that we need to be able generate them dy...

Iterating through String word at a time in Python

I have a string buffer of a huge text file. I have to search a given words/phrases in the string buffer. Whats the efficient way to do it ? I tried using re module matches. But As i have a huge text corpus that i have to search through. This is taking large amount of time. Given a Dictionary of words and Phrases. I iterate through th...