python

When to create a new app (with startapp) in Django?

I've googled around for this, but I still have trouble relating to what Django defines as "apps". Should I create a new app for each piece of functionality in a site, even though it uses models from the main project? Do you guys have good rule of thumb of when to split off a new app, and when to keep functionality together with the "...

How can I access App Engine through a Corporate proxy?

I have corporate proxy that supports https but not HTTP CONNECT (even after authentication). It just gives 403 Forbidden in response anything but HTTP or HTTPS URLS. It uses HTTP authenication, not NTLM. It is well documented the urllib2 does not work with https thru a proxy. App Engine trys to connect to a https URL using urllib2 to upd...

Best Python supported server/client protocol?

I'm looking for a good server/client protocol supported in Python for making data requests/file transfers between one server and many clients. Security is also an issue - so secure login would be a plus. I've been looking into XML-RPC, but it looks to be a pretty old (and possibly unused these days?) protocol. Thanks for your help in ...

leaving a time delay in python

is there any way to leave a time delay between the execution of two lines of code? ...

Sending mail from Python using SMTP

I'm using the following method to send mail from Python using SMTP. Is it the right method to use or are there gotchas I'm missing ? from smtplib import SMTP import datetime debuglevel = 0 smtp = SMTP() smtp.set_debuglevel(debuglevel) smtp.connect('YOUR.MAIL.SERVER', 26) smtp.login('USERNAME@DOMAIN', 'PASSWORD') from_addr = "John Doe...

What is the best WYSIWYG GUI editor for Python?

What is the best WYSIWYG GUI editor for Python? I'm looking for something like Visual Studio form designer. The specific GUI toolkit doesn't matter. And I'm not looking for a code editor/IDE. ...

How to setup VIM properly for editing Python files - *.py

I've troubles setting VIM (7.1.xxx) for editing python files. Identing seems broken (optimal 4 spaces). I've followed some tutorials I found via google. Still no effect :/ Please help. ...

Caching compiled regex objects in Python?

Each time a python file is imported that contains a large quantity of static regular expressions, cpu cycles are spent compiling the strings into their representative state machines in memory. a = re.compile("a.*b") b = re.compile("c.*d") ... Question: Is it possible to store these regular expressions in a cache on disk in a pre-compi...

How to add method using metaclass

How do I add an instance method to a class using a metaclass (yes I do need to use a metaclass)? The following kind of works, but the func_name will still be "foo": def bar(self): print "bar" class MetaFoo(type): __new__(cls, name, bases, dict): dict["foobar"] = bar return type(name, bases, dict) class Foo(obje...

Decorating a parent class method

Not sure if what I want to accomplish is even possible, but I'd like to make a child class have a method of the parent class be a 'classmethod' even though the method in the parent class is not. Essentiall I'm trying to accomplish the following: class foo(Object): def meth1(self,val): self.value=val class bar(foo): met...

How do I create a new signal in pygtk

I've created a python object, but I want to send signals on it. I made it inherit from gobject.GObject, but there doesn't seem to be any way to create a new signal on my object. ...

mod_python/MySQL error on INSERT with a lot of data: "OperationalError: (2006, 'MySQL server has gone away')"

When doing an INSERT with a lot of data, ie~ `INSERT INTO table (mediumtext_field) VALUES ('...lots of text here: about 2MB worth...')', MySQL returns "OperationalError: (2006, 'MySQL server has gone away')" This is happening within a minute of starting the script, so it is not a timeout issue. Also, mediumtext_field should be able to h...

why might my pyglet vertex lists and batches be very slow on Windows?

I'm writing opengl code in python using the library pyglet. When I draw to the screen using pyglet.graphics.vertex_list or pyglet.graphics.batch objects, they are very slow (~0.1 fps) compared to plain old pyglet.graphics.draw() or just glVertex() calls, which are about 40fps for the same geometry. In Linux the vertex_list is about the s...

Serving dynamically generated ZIP archives in Django

How to serve users a dynamically generated ZIP archive in Django? I'm making a site, where users can choose any combination of available books and download them as ZIP archive. I'm worried that generating such archives for each request would slow my server down to a crawl. I have also heard that Django doesn't currently have a good solu...

How to import module from file name

How can I load a python module given its full path? Note that the file can be anywhere in the filesystem, as it is a configuration option. ...

What's a good resource for starting to write a programming language, that's not context free?

I'm looking to write a programming language for fun, however most of the resource I have seen are for writing a context free language, however I wish to write a language that, like python, uses indentation, which to my understanding means it can't be context free. ...

Why do you need explicitly have the "self" argument into a Python method?

When defining a method on a class in Python, it looks something like this: class MyClass(object): def __init__(self, x, y): self.x = x self.y = y But in some other languages, such as C#, you have a reference to the object that the method is bound to with the "this" keyword without declaring it as an argument in the...

Change command Method for Tkinter Button in Python

I create a new Button object but did not specify the command option upon creation. Is there a way in Tkinter to change the command (onclick) function after the object has been created? ...

How do I copy a file to a remote server in python using scp or ssh?

I have a text file on my local machine that is generated by a python script run daily in cron. I would like to add a bit of code to have that file sent securely to my server over ssh. Help. ...

Send file using POST from a Python script

Is there a way to send a file using POST from a Python script? ...