python

Is there a better way to iterate over tuples in a (django) template in google-app-engine

Basically, what I'm trying to do is to render os.environ in a template in google app engine. I believe the technology is (or is adapted from) the Django template engine version 0.96 (but correct me if I'm wrong). I found this question suggesting that you could do: {{ for key, value in environ}} But when I try that, I get an error say...

How to wrap a <myClass*, myClass*> C++ dictionary using SWIG for Python and .NET

Hi, I'm wrapping C++ code into Python and .NET code by using SWIG 2.0.0. I'm able to wrap a (myClass*, std::string) by introducing the following sentence in the "interface.i" file: %template(Dictionary_myClass_String) std::map<myClass*, std::string>; But I'm getting several errors if i try this: %template(Dictionary_myClass_myClass)...

pyodbc and mySQL

I am unable to connect to mySQl db using pyodbc. Here is a snippet of my script: import pyodbc import csv cnxn = pyodbc.connect("DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE=mydb; UID=root; PASSWORD=thatwouldbetelling;") crsr = cnxn.cursor() with open('C:\\skunkworks\\archive\\data\\myfile.csv','r') as myfile: rows...

Structuring Django Many-to-Many Relation

In writing an application for my school's yearbook committee, I've hit a bit of a dead end with modeling a specific relation. Currently I have a photo class class Photo(models.Model): photo = models.ImageField(upload_to="user_photos/") name = models.CharField(blank=True, max_length=50) rating = models.IntegerField(default=1000) wi...

For user-based and certificate-based authentication, do I want to use urllib, urllib2, or curl?

A few months ago, I hastily put together a Python program that hit my company's web services API. It worked in three different modes: 1) HTTP with no authentication 2) HTTP with user-name and password authentication 3) HTTPS with client certificate authentication I got 1) to work with urllib, but ran into problems with 2) and 3). Ins...

How do you wrap the view of a 3rd-party Django app

How do you wrap the view of a 3rd-party app (let's call the view to wrap "view2wrap" and the app "3rd_party_app") so you can do some custom things before the app does its thing? I've set urls.py to capture the correct url: url( r'^foo/bar/$', view_wrapper, name='my_wrapper'), I've created my custom view: from 3rd_party_app.views...

Python ogg vorbis encoder on Windows

I want to use Python to convert a wav file to ogg vorbis format, so it can be streamed to a browser for playback. I've been able to use PyMedia 1.3.7.3 to encode to mp3 format, but when I set the output stream type to 'ogg', I get the error: oggvorbis_encode_init: init_encoder failed and the script dies. Perhaps I don't have the right ...

Dictionary based switch-like statement with actions

Hi, I'm relatively new to Python and would like to know if I'm reinventing a wheel or do things in a non-pythonic way - read wrong. I'm rewriting some parser originally written in Lua. There is one function which accepts a field name from imported table and its value, does some actions on value and stores it in target dictionary under ...

Consequences of changing __type__

I'm attempting to create what a believe (in my ignorance) is known as a class factory. Essentially, I've got a parent class that I'd like to take an __init__ argument and become one of several child classes. I found an example of this recommended on StackOverflow here, and it looks like this: class Vehicle(object): def __init__(self, ...

Python: How do I redirect this output?

I'm calling rtmpdump via subprocess and trying to redirect its output to a file. The problem is that I simply can't redirect it. I tried first setting up the sys.stdout to the opened file. This works for, say, ls, but not for rtmpdump. I also tried setting the sys.stderr just to make sure and it also didn't work. I tried then using a "...

dynamic load better choice than joinedload?

Hello, I'd like to know what the best choice is. This is what I do in my system: I'm using grok server and python on the server side; and javascript on the client side. I store all the user data in a session object and this data gets called twice, one to render the HTML on the server side and another to send the data to the client side...

C# bindings for MEEP (Photonic Simulation Package)

Does anyone know of a way to call MIT's Meep simulation package from C# (probably Mono, god help me). We're stuck with the #$@%#$^ CTL front-end, which is a productivity killer. Some other apps that we're integrating into our sim pipeline are in C# (.NET). I've seen a Python interface to Meep (light years ahead of CTL), but I'd like to...

python on xp: errno 13 permission denied - limits to number of files in folder?

Hi, I'm running Python 2.6.2 on XP. I have a large number of text files (100k+) spread across several folders that I would like to consolidate in a single folder on an external drive. I've tried using shutil.copy() and shutil.copytree() and distutils.file_util.copy_file() to copy files from source to destination. None of these methods ...

How to add xml header to dom object

I'm using Python's xml.dom.minidom but I think the question is valid for any DOM parser. My original file has a line like this at the beginning: <?xml version="1.0" encoding="utf-8" standalone="yes"?> This doesn't seem to be part of the dom, so when I do something like dom.toxml() the resulting string have not line at the beginning....

Set a variable equal to result if result exists

This seems very verbose, particularly with long function names, is there a better way to do this in Python? if someRandomFunction(): variable = someRandomFunction() Edit: For more context variable is not already defined, and it will be a new node on a tree. I only want to create this node if someRandomFunction() returns a value. A...

Slicing a result list by time value

I got a result list and want to keep the elements that are newer than timeline and older than bookmark. Is there a more convenient method than iterating the whole list and removing the elements if they match the conditition? Can you introduce me to how specically how? The way I fetch data and then sort it results = A.all().search(self.r...

Check facebook object type

Hi there. In my app, I have a form where user should submit a facebook page URL. How to check that it's correct? Presently, I'm just checking that it begins with 'http://www.facebook.com' How can I check that it is a page (where you can become a fan) and not a profile, event or whatever? I'm using the python api and appengine. Thanks!...

rename files with python - regex

hello, I am wanting to rename 1k files using python. they are all in the format somejunkDATE.doc basically, I would like to delete all the junk, and only leave the date. I am unsure how to match this for all files in a directory. thanks ...

Python Class Decorator

I am trying to decorate an actual class, using this code: def my_decorator(cls): def wrap(*args, **kw): return object.__new__(cls) return wrap @my_decorator class TestClass(object): def __init__(self): print "__init__ should run if object.__new__ correctly returns an instance of cls" test = TestClass() # s...

How to intercept the Redirect URL in python

Hi, I am following this link to create a test desktop app using python. http://developers.facebook.com/docs/authentication/desktop I used webbrowser module to invoke the login web page. When user Successfully logs into facebook it redirects to the Dumy facebook success page. Now I am not able to intercept this Redirect URL of Dummy su...