python

How to install django-haystack using buildout

I'm trying to convert a current Django project in development to use zc.buildout So far, I've got all the bits figured except for Haystack figured out. The Haystack source is available on GitHub, but I don't want to force users to install git. A suitable alternative seems to be to fetch a tarball from here That tarball contains a set...

Buildout recipe for a hierarchy of parts.

Is there a Python buildout recipe which would allow the following: [buildout] parts = group-of-parts [group-of-parts] recipe = what.can.i.use.for.this parts = part-1 part-2 [part-1] ... [part-2] ... In other words, I want a recipe which takes a 'parts' attribute much like 'buildout' section does so I can manually manage a hierarchy...

Preventing variable substitutions from occurring with buildout.

Is there a simple way of escaping the magic characters used for variable substitution in a buildout configuration, such that the string is left alone. In other words, where I say: [part] attribute = ${variable} I don't actually want it to expand ${variable} but leave it as the literal value. In practice the specific problem I am enco...

increment int object

Is there a way in python to increment int object in place, int doesn't seem to implement __iadd__ so += 1 actually returns a new object >>> n=1 >>> id(n) 9788024 >>> n+=1 >>> id(n) 9788012 What I want is n to remain pointing to same object. Purpose: I have class derived from int and I want to implement C type '++n' operator for that ...

Using python scripts in subversion hooks on windows

My main goal is to get this up and running. My hook gets called when I do the commit with Tortoise SVN, but it always exits when I get to this line: Python "%~dp0trac-post-commit-hook.py" -p "%TRAC_ENV%" -r "%REV%" || EXIT 5 If I try and replace the call to the python script with any simple Python script it still doesn't work so I'm as...

connecting Python 2.6.1 with MySQLdb

Hi All I am using Python 2.6.1 and I want to connect to MySQLdb, I installed mySQL in my system, and I am trying to connect MySQL-python-1.2.2.win32-py2.6 from http://www.codegood.com/archives/4 site but its not working while running my application its saying that No module named MySQLdb please any one provide me the proper setu...

How do I receive SNMP traps on OS X?

I need to receive and parse some SNMP traps (messages) and I would appreciate any advice on getting the code I have working on my OS X machine. I have been given some Java code that runs on Windows with net-snmp. I'd like to either get the Java code running on my development machine or whip up some Python code to do the same. I was able...

Efficent way to insert thousands of records into a table (SQLite, Python, Django)

I have to insert 8000+ records into a SQLite database using Django's ORM. This operation needs to be run as a cronjob about once per minute. At the moment I'm using a for loop to iterate through all the items and then insert them one by one. Example: for item in items: entry = Entry(a1=item.a1, a2=item.a2) entry.save() What is...

Allowing user to configure cron

I have this bash script on the server that runs every hour, via cron. I was perfectly happy, but now the user wants to be able to configure the frequency through the web interface. I don't feel comfortable manipulating the cron configuration programmatically, but I'm not sure if the other options are any better. The way I see it, I can...

Inserting a python datetime.datetime object into mysql

I have a date column in a mysql table. I want to insert a datetime.datetime() object into this column. What should i be using in the execute statement? I have tried: now = datetime.datetime(2009,5,5) cursor.execute("INSERT INTO table (name, id, datecolumn) VALUES (%s, %s , %s)",("name", 4,now)) I am getting an error as: "TypeError: n...

how do I use the json google translate api?

I am trying to use google translate from python with utf-8 text. How do I call the json api? They have a document for embedding it in html but I can't find a proper API or wsdl anywhere. Thanks Raphael ...

When should I use varargs in designing a Python API?

Is there a good rule of thumb as to when you should prefer varargs function signatures in your API over passing an iterable to a function? ("varargs" being short for "variadic" or "variable-number-of-arguments"; i.e. *args) For example, os.path.join has a vararg signature: os.path.join(first_component, *rest) -> str Whereas min allow...

is it required to give path after installation MySQL db for Python 2.6

I am using Python 2.6.1, MySQL4.0 in Windows platform and I have successfully installed MySQLdb. Do we need to set any path for my python code and MySQLdb to successful run my application? Without any setting paths (in my code I am importing MySQLdb) I am getting No module named MySQLdb error is coming and I am not able to move further....

What does python *intern* do, and when should it be used?

I came across this question about memory management of dictionaries, which mentions the intern function. What exactly does it do, and when would it be used? To give an example: If I have a set called seen, that contains tuples in the form (string1,string2), which I use to check for duplicates, would storing (intern(string1),intern(stri...

What is the correct way to document a **kwargs parameter?

I'm using sphinx and the autodoc plugin to generate API documentation for my Python modules. Whilst I can see how to nicely document specific parameters, I cannot find an example of how to document a **kwargs parameter. Does anyone have a good example of a clear way to document these? ...

python ctype for using libc.so.6 Linux and libc.dylib Mac Os X

I've been reading about ctype and the usage of dynamic libs. I'm now able to use libs in Windows using "windll.kernel32" Linux using "libc.so.6" Under Windows I'm able to open other progs using createProcessA(..long_param_list..) Now I want to do the same for Linux and Mac OS X but I'm stocked at the point where I have to find out ...

Using python scipy.weave inline with ctype variables?

I am trying to pass a ctype variable to inline c code using scipy.weave.inline. One would think this would be simple. Documentation is good when doing it with normal python object types, however, they have a lot more features than I need, and It makes more sense to me to use ctypes when working with C. I am unsure, however, where my erro...

Recommended Python cryptographic module?

I've been exploring what cryptographic modules are available to Python, and I've found 3: ezPyCrypt, yawPyCrypt and KeyCzar (which actually supports a few languages, but Python is included amongst them). The first two rely on the PyCrypto module. Are there choices I am missing? Is there a clear front-runner for ease and features or does...

Get first non-empty string from a list in python

In Python I have a list of strings, some of which may be the empty string. What's the best way to get the first non-empty string? ...

Django Template Error : Template u'base.html' cannot be extended

I get this error when I run a django app (dpaste) Template error In template c:\python\projects\mycms\dpaste\templates\dpaste\base.html, error at line 1 Template u'base.html' cannot be extended, because it doesn't exist 1 {% extends "base.html" %} But the "base.html" do exist in the template directory and it has this one line in ...