python

Is Using eval In Python A Bad Practice?

I am using the following class to easily store data of my songs. class Song: """The class to store the details of each song""" attsToStore=('Name', 'Artist', 'Album', 'Genre', 'Location') def __init__(self): for att in self.attsToStore: exec 'self.%s=None'%(att.lower()) in locals() def setDetail(self,...

What does Python's builtin __build_class__ do?

In Python 3.1, there is a new builtin function I don't know in the builtins module: __build_class__(...) __build_class__(func, name, *bases, metaclass=None, **kwds) -> class Internal helper function used by the class statement. What does this function do? Why must it be in builtins if it's internal? What is the difference to ...

how can I save a form with ModelMultipleChoiceField ?

I have a model Calendar and in a form I want to be able to create multiple instances of it. Here are my models: class Event(models.Model): user = models.ForeignKey(User) class Group(models.Model): name = models.CharField(_('Name'), max_length=80) events = models.ManyToManyField(Event, through='Calendar') class Calendar(mo...

Simple way to simulate a slow network in python.

Scenario. I have a client with two network connections to a server. One connection uses a mobile phone, and the other is using a wlan connection. The way that I have solved this is by having the server listen at two ports. But, the mobile connection should be slower than the wlan connection. The data that is sent, is usually just a lin...

Javascript + python url-en/decoding problem

Hi there im kinda stucked with the url encoding between python and javascript, i hope you can help me out :S Javascript: encodeURIComponent('lôl'); -> "l%C3%B4l" Python: import urllib test = container.REQUEST.form.get('test') print test print urllib.unquote(test) -> "lÃŽl" -> "lÃŽl" Javascript encodes "lôl" twice however python do...

How to make some Django settings accessible by staff?

In Django, settings are stored in a file, settings.py. This file is part of the code, and goes into the repository. It is only the developers who deal with this file. The admin deals with the models, the data in the database. This is the data that the non-development staff edits, and the site visitors see rendered in templates. The thin...

python regex escape characters

Hi. We have: >>> str 'exit\r\ndrwxr-xr-x 2 root root 0 Jan 1 2000 \x1b[1;34mbin\x1b[0m\r\ndrwxr-xr-x 3 root root 0 Jan 1 2000 \x1b[1;34mlib\x1b[0m\r\ndrwxr-xr-x 10 root root 0 Jan 1 1970 \x1b[1;34mlocal\x1b[0m\r\ndrwxr-xr-x 2 root root 0 Jan 1 2000 \x1b[1...

Confirmation of Successful HTTP Download in Python

Is there a easy and reliable way to confirm that a web download completed successfully to download using Python or WGET [for large files]? I want to make sure the file downloaded in its entirety before performing another action. ...

Can I use the xmodem protocol with PySerial?

Hi, I have a working connection with my serial device via PySerial, but I also want to transfer files via the xmodem protocol as part of my program. Which would be the most platform-neutral way to do this? Worst case, I could close() my serial.Serial object in Python and use subprocess to call upon /usr/bin/sb, but that seems inelegan...

[Python] Pmw Group Widget "Tab Focusing" Order

The Python Pmw Group widget has an issue with tab ordering. Running the following code will illustrate the issue: import Pmw import Tkinter #Create a window to house the Group widgets window = Tkinter.Tk() #Run the Pmw activation function for the new Tkinter window Pmw.initialise(window) #Loop to create the widgets #Just for fun, le...

Python check windows server version

I need to log the current windows version in my python application for reporting purposes, but the built in functions I've found so far cant tell the difference between Windows client and server versions: os.sys.getwindowsversion() (6, 0, 6002, 2, 'Service Pack 2') platform.release() 'Vista' platform.win32_ver() ('Vista', '6.0.6002', 'S...

Does a File Object Automatically Close when its Reference Count Hits Zero?

I was under the impression that file objects are immediately closed when their reference counts hit 0, hence the line: foo = open('foo').read() would get you the file's contents and immediately close the file. However, after reading the answer to http://stackoverflow.com/questions/1832528/is-close-necessary-when-using-iterator-on-a-py...

Serving simple image with App Engine django patch?

How the heck do i serve a simple img without all that MediaGenerator nonsense, in Django on App Engine? I am using app engine patch. I got layout like this: django_app_engine_project_folder my_app Where should my folder for my media be? In my_app? Or do I put everything in the top media folder? I want to do something like this in...

split a comma separated list with links in with beautifulsoup

I've got a comma separated list in a table cell in an HTML document, but some of items in the list are linked: <table> <tr> <td>Names</td> <td>Fred, John, Barry, <a href="http://www.example.com/"&gt;Roger&lt;/a&gt;, James</td> </tr> </table> I've been using beautiful soup to parse the html, and I can get to the table, but ...

How do ldexp and frexp work in python?

The python frexp and ldexp functions splits floats into mantissa and exponent. Do anybody know if this process exposes the actual float structure, or if it requires python to do expensive logarithmic calls? ...

Python after Ruby on Rails

I have been working with Ruby on Rails for over a year now and have been offered some development work with Python. I would like know if development with Python is as enjoyable as Ruby in terms of the clarity and ease of use. And how well is Python suited for Web development. I've heard of Pylons being a direct port of the Rails framewor...

Python, PowerShell, or Other?

What are the advantages of Python, PowerShell, and other scripting environments? We would like to standardize our scripting and are currently using bat and cmd files as the standard. I think Python would be a better option than these, but am also researching PowerShell and other scripting tools. The scripts would be used to trigger pr...

error: can't start new thread

Hello my friends. I have a site that runs with follow configuration: Django + mod-wsgi + apache In one of user's request, I send another HTTP request to another service, and solve this by httplib library of python. But sometimes this service don't get answer too long, and timeout for httplib doesn't work. So I creating thread, in th...

pygst - glimagesink callback

I'm trying to use 'glimagesink' element with python. The element (which is GObject inside) has client-draw-callback property which should (in C++ at least) contain a function (bool func(uint t, uint w, uint h)) pointer. I've tried element.set_property('client-draw-callback', myfunc), and creating function pointer with ctypes, but every t...

How do I uninstall Python 2.5?

I recently upgraded to Mac OS 10.6 and didn't realise that it shipped with Python 2.6. I installed Python 2.5.4 and now it is the default Python installation. Can I uninstall Python 2.5.4 and keep 2.6? ...