python

Change the width of form elements created with ModelForm in Django

How can i change the width of a textarea form element if i used ModelForm to create it? Here is my product class: class ProductForm(ModelForm): long_desc = forms.CharField(widget=forms.Textarea) short_desc = forms.CharField(widget=forms.Textarea) class Meta: model = Product And the template code... {% for f in fo...

Is there an easy way to request a URL in python and NOT follow redirects?

Looking at the source of urllib2 it looks like the easiest way to do it would be to subclass HTTPRedirectHandler and then use build_opener to override the default HTTPRedirectHandler, but this seems like a lot of (relatively complicated) work to do what seems like it should be pretty simple. ...

Report generation

I am writing a web app using TurboGears, and in that app the users must be able to generate different reports. The data the reports need is stored in a database (MySQL). The reports must be returned either as a easily printable html document, or a pdf file. I have previously used jasper and iReport for creating the documents, but if I c...

Re-ordering entries in a model using drag-and-drop

Say I have a blogging app in Django. How can i re-order the posts using a draggable table in the default admin? It would be best if i didn't have to add any extra fields to the model, but if i really have to i can. ...

Dirty fields in django

In my app i need to save changed values (old and new) when model gets saved. Any examples or working code? I need this for premoderation of content. For example, if user changes something in model, then administrator can see all changes in separate table and then decide to apply them or not. ...

How do I end a Python Tkinter program?

How do I end a Python Tkinter program? Let's say I have this code: from Tkinter import * def quit(): ??? root = Tk() Button(root, text="Quit", command=quit).pack() root.mainloop() How should I define the quit() routine? ...

How do I handle the window close event (user clicking the 'X' button) in a Python Tkinter program?

How do I handle the window close event (user clicking the 'X' button) in a Python Tkinter program? ...

What is a "callable" in Python ?

Now that it's clear what a metaclass is, there is an associated concept that I use all the time without knowing what it really means. I suppose everybody made once a mistake with parenthesis, resulting in an "object is not callable" exception. What's more, using __init__ and __new__ lead to wonder what this bloody __call__ can be used...

What did you use to teach yourself python?

I'm an avid programmer, and I like to learn new languages... I normally teach them myself. Python isn't a "MUST Learn" for me, but, as I work with Ubuntu, and a lot of their own code is now Python based, it'd be useful for me to learn, so that I can work with their code. I already know the basics of programming (and the advanced) and m ...

How do I find out the size of a canvas item in Python/Tkinter?

I want to create some text in a canvas: myText = self.canvas.create_text(5, 5, anchor=NW, text="TEST") Now how do I find the width and height of myText? ...

Is there any way to do HTTP PUT in python

I need to upload some data to a server using HTTP PUT in python. From my brief reading of the urllib2 docs, it only does HTTP POST. Is there any way to do an HTTP PUT in python? ...

Using Python's ftplib to get a directory listing, portably

You can use ftplib for full FTP support in Python. However the preferred way of getting a directory listing is: # File: ftplib-example-1.py import ftplib ftp = ftplib.FTP("www.python.org") ftp.login("anonymous", "ftplib-example-1") data = [] ftp.dir(data.append) ftp.quit() for line in data: print "-", line Which yields: $ p...

python.array versus numpy.array

If you are creating a 1d array in Python is there any benefit to using the NumPy package? ...

How do I overlap widgets with the pack geometry manager in Python/Tkinter?

I want to put a canvas with an image in my window, but then I want to pack() widgets over top of it so the canvas acts as a background. Is it possible to have two states for the pack() manager, one for one set of widgets and another for another set? ...

What are some good web resources for learning Object-Oriented Programming?

I've started programming more in OO style than ever (Python). Any good web resources I could read? I need help constructing and modelling objects, relations, interfaces etc. . Not only dry theory (I've read that), but something easy to grasp (examples would be nice), do you know any site or a good book? ...

Does anyone know of a widget for a desktop toolkit(GTK, Qt, WX) for displaying a map of US states?

I'm specifically looking for one that lets me display a map of US states with each one as it's own "object" in the sense that I can control the color, on click, and on mouseover of each one individually. GTK is my personal preference, but at this point I'd settle for just about anything. The application itself will be written in Python...

List all words in a dictionary that start with <user input>

How would a go about making a program where the user enters a string, and the program generates a list of words beginning with that string? Ex: User: "abd" Program:abdicate, abdomen, abduct... Thanks! Edit: I'm using python, but I assume that this is a fairly language-independent problem. ...

How do I use genshi.builder to programmatically build an HTML document?

I recently discovered the genshi.builder module. It reminds me of Divmod Nevow's Stan module. How would one use genshi.builder.tag to build an HTML document with a particular doctype? Or is this even a good thing to do? If not, what is the right way? ...

py2exe - generate single executable file

I thought I heard that py2exe was able to do this, but I never figured it out. Has anyone successfully done this? Can I see your setup.py file, and what command line options you used? Basically I'm thinking of it giving me a single executable file that does something like unzips itself to maybe /temp and runs. ...

How would one log into a phpBB3 forum through a Python script using urllib, urllib2 and ClientCookie?

(ClientCookie is a module for (automatic) cookie-handling: http://wwwsearch.sourceforge.net/ClientCookie) # I encode the data I'll be sending: data = urllib.urlencode({'username': 'mandark', 'password': 'deedee'}) # And I send it and read the page: page = ClientCookie.urlopen('http://www.forum.com/ucp.php?mode=login', data) output = pa...