python

pysqlite user types in select statement

Using pysqlite how can a user-defined-type be used as a value in a comparison, e. g: “... WHERE columnName > userType”? For example, I've defined a bool type with the requisite registration, converter, etc. Pysqlite/Sqlite responds as expected for INSERT and SELECT operations (bool 'True' stored as an integer 1 and returned as True). B...

django admin inlining foreign key issue

Ok, I'm sure I'm missing something stupidly simple, since nobody else seems to be asking the same question. Either way, the problem's annoying me, so I'll suck up my pride and just ask it. I'm mainly just playing around right now with creating a simple Training/Testing application. For starters, I need to be able to create a quiz type ap...

Problems title-casing a string in Python

I have a name as a string, in this example "markus johansson". I'm trying to code a program that makes 'm' and 'j' uppercase: name = "markus johansson" for i in range(1, len(name)): if name[0] == 'm': name[0] = "M" if name[i] == " ": count = name[i] + 1 if count == 'j': name[count] = 'J' I'm pre...

Charts in django Web Applications

I want to Embed a chart in a Web Application developed using django. I have come across Google charts API, ReportLab, PyChart, MatPlotLib and ChartDirector I want to do it in the server side rather than send the AJAX request to Google chart APIs, as I also want to embed the chart into the PDF. Which is the best option to use, and what...

Boolean 'and' in Python

In C# we can do this: int i = 5; int ii = 10; if(i == 5 && ii == 10) { Console.WriteLine("i is 5, and ii is 10"); } Console.ReadKey(true); I tested this in Python: i = 5 ii = 10 if i == 5 & ii == 10: print "i is 5 and ii is 10"; But this does...

Yahoo Pipes, simplejson and slashes

Im trying to use http://www.javarants.com/2008/04/13/using-google-app-engine-to-extend-yahoo-pipes/ as inspiration, but I'm having some troubles with the output. Its obvious when testing with the console and the App Engine "django util simplejson": /cygdrive/c/Program Files/Google/google_appengine/lib/django $ python Python 2.5.2 (r252...

Catching Python exceptions using 'expect' method?

import sys try: file = open("words.txt") expect(IOError): if file: print "%s" % file else: print "Cant the %s file" % "words.txt" this gives me an a error - File "main.py", line 4 expect(IOError): SyntaxError: invaild syntax What im going wrong/ how do you fix this ...

Is there something like CherryPy or Cerise in the Java world?

CherryPy and Cerise are two small frameworks that implement nothing but the barebones of a web-framework and I love their simplicity: in fact I reckon that if Classic ASP was implemented that way (and didn't pretty much require VBScript) I could have settled for it and lived happily ever after. But now I'm living at the borders of the J...

How to know if an object has an attribute in Python

Is there a way in Python to determine if an object has some attribute? For example: >>> a = SomeClass() >>> a.someProperty = value >>> a.property Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: SomeClass instance has no attribute 'property' How can you tell if a has the attribute property befo...

What is a good strategy for constructing a directed graph for a game map (in Python)?

I'm developing a procedurally-generated game world in Python. The structure of the world will be similar to the MUD/MUSH paradigm of rooms and exits arranged as a directed graph (rooms are nodes, exits are edges). (Note that this is not necessarily an acyclic graph, though I'm willing to consider acyclic solutions.) To the world genera...

Django Model Inheritance. Hiding or removing fields.

I want to inherit a model class from some 3rd party code. I won't be using some of the fields but want my client to be able to edit the model in Admin. Is the best bet to hide them from Admin or can I actually prevent them being created in the first place? Additionally - what can I do if one of the unwanted fields is required? My first ...

Can compiled bytecode files (.pyc) get generated in different directory?

When python compiles modules to bytecode, it produces .pyc files from your .py files. My question is, is it possible to have these .pyc files written to a different directory than where the module resides? For example, I have a large directory of modules. Rather than having it littered with .pyc files, I would like to keep my source c...

Can you give a Django app a verbose name for use throughout the admin?

In the same way that you can give fields and models verbose names that appear in the Django admin, can you give an app a custom name? ...

Problem using super(python 2.5.2)

I'm writing a plugin system for my program and I can't get past one thing: class ThingLoader(object): ''' Loader class ''' def loadPlugins(self): ''' Get all the plugins from plugins folder ''' from diones.thingpad.plugin.IntrospectionHelper import loadClasses classList=loadClasses('./plugin...

Code samples for Django + SWFUpload?

Does anyone have any simple code samples for Django + SWFUpload? I have it working perfectly in my PHP application but Django is giving me headaches. ...

Best Python templating library to facilitate code generation.

It's been awhile since I've done something like this and it seems that everyone and their grandmother has created a templating library for python, from Mako, Cheetah, Genshi, etc... Instead of me spending the next day (or year) reading about them all, any suggestions for templating engines that I should look into in more detail? Thanks...

Python one-liner to print every file in the current directory

How can I make the following one liner print every file through Python? python -c "import sys;print '>>',sys.argv[1:]" | dir *.* Specifically would like to know how to pipe into a python -c. DOS or Cygwin responses accepted. ...

Why do I get wrong results for hmac in Python but not Perl?

I'm trying to compute hmac using sha-512. The Perl code: use Digest::SHA qw(hmac_sha512_hex); $key = "\x0b"x20; $data = "Hi There"; $hash = hmac_sha512_hex($data, $key); print "$hash\n"; and gives the correct hash of 87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cde daa833b7d6b8a702038b274eaea3f4e4be9d914eeb6...

Python: Sort a dictionary by value

I have a dictionary of values read from 2 fields in a database: a string field and a numeric field. The string field is unique so that is the key of the dictionary. I can sort on the keys, but how can I sort based on the values? Note: I have read this post 72899 and probably could change my code to have a list of dictionaries but since...

How does Vista Recycle bin work?

I am trying to write a python module to move files to the 'Recycle Bin' on both Mac and PC. Is there a way, only from the commandline (and yes, I mean using absloutly no C#/C++/etc) to move a file into the Recycle Bin, and have it appear as a file trashed by drag and drop (or deleted via SHFileOperation, etc). ...