python

Python sendto() not working on 3.1 (works on 2.6)

Hi! For some reason, the following seems to work perfectly on my ubuntu machine running python 2.6 and returns an error on my windows xp box running python 3.1 from socket import socket, AF_INET, SOCK_DGRAM data = 'UDP Test Data' port = 12345 hostname = '192.168.0.1' udp = socket(AF_INET,SOCK_DGRAM) udp.sendto(data, (hostname, port)) ...

Python class method - Is there a way to make the calls shorter?

I am playing around with Python, and I've created a class in a different package from the one calling it. In this class, I've added a class method which is being called from my main function. Again, they are in separate packages. The line to call the class method is much longer than I thought it would be from the examples I've seen in...

PySide vs. PyQt ?

Has anyone tried the new Python Qt binding - PySide yet? I wonder about its matureness and compatibility with PyQt. What are your experiences on this matter? I know it has only been released this week, but it's such great news for Python development of Qt-based GUIs - there's a lot of interest in this thing. ...

Why there is a difference in "import" vs. "import *" ?

"""module a.py""" test = "I am test" _test = "I am _test" __test = "I am __test" ============= ~ $ python Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from a import * >>> test 'I am test' >>> _test Tr...

How do I write a single-file Django application?

I want to write a very small Django application in a single file, requiring all the appropriate modules and stuff, and then be able to run that as a normal Python script, like this: $ python myapp.py You can assume I won't render HTML, so I don't need templates (I'll return JSON or some other auto-generated string). ...

How useful would be a Smalltalk source code browser for other programming languages?

I'm working on an IDE for python, ruby and php. Never having used Smallltalk myself (even it was very popular when I was at university) I wonder if the classic Smalltalk Browser which displays only one method is really an improvment or to classical file editing or not. I myself like to have the overview of as much as possible in a cla...

--home or --prefix in python package install ?

When you build and install a python package, you have two choices: --home and --prefix. I never really got the difference between the two (I always use --home) but if I understood correctly one is deprecated and the other is "the way to go"™. Am I wrong ? ...

Is there an easy way to use a python tempfile in a shelve (and make sure it cleans itself up)?

Basically, I want an infinite size (more accurately, hard-drive rather than memory bound) dict in a python program I'm writing. It seems like the tempfile and shelve modules are naturally suited for this, however, I can't see how to use them together in a safe manner. I want the tempfile to be deleted when the shelve is GCed (or at guara...

Unescape/unquote binary strings in (extended) url encoding in python

Hi, for analysis I'd have to unescape URL-encoded binary strings (non-printable characters most likely). The strings sadly come in the extended URL-encoding form, e.g. "%u616f". I want to store them in a file that then contains the raw binary values, eg. 0x61 0x6f here. How do I get this into binary data in python? (urllib.unquote onl...

How to set initial size for a dictionary in Python?

I'm putting around 4 millions different keys into a python dictionary. Creating this dictionary takes about 15 minutes and consumes about 4GB memory on my machine. After dictionary is fully created, queering the dictionary is fast. I suspect that dictionary creation is so resource consuming as the dictionary is very often rehashed (as i...

How can I call the svn.client.svn_client_list2 with python SVN API SWIG bindings?

The question How do I call svn_client_list2 C API function from python via SVN API SWIG bindings? Problem description I can find that function from the svn.client module, but calling it is the problem, because the callback function it uses is a typedef svn_client_list_func_t and I don't know how to use that typedef in python. Althou...

How do I get a list of versioned files from a working copy path via python SVN SWIG API?

The need I want a list of versioned files from a path which is a working copy of SVN repository using the python SVN SWIG API. Below is the approach I've taken, but if it's wrong just point me in the right direction. An approach It seems that you'd do this via C API with svn_client_list2 function. So calling that via python SVN API S...

Problem using MySQLdb: Symbol not found: _mysql_affected_rows

A colleague got this error message when trying to use MySQLdb from Django: [...] ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/roy/.python-eggs/MySQL_python-1.2.3c1-py2.5-macosx-10.5-i386.egg-tmp/_mysql.so, 2): Symbol not found: _my...

How to check if python is installed in windows from java?

How can I check from inside a java program if python is installed in windows? Python does not add its path to the system Path and no assumption is to be made about the probable path of installation(i.e it can be installed anywhere). ...

Handling international dates in python

I have a date that is either formatted in German for e.g, 2. Okt. 2009 and also perhaps as 2. Oct. 2009 How do I parse this into an ISO datetime (or python datetime)? Solved by using this snippet: for l in locale.locale_alias: worked = False try: locale.setlocale(locale.LC_TIME, l) worked = True exce...

Beginner at testing Python code, need help!

I don't do tests, but I'd like to start. I have some questions : Is it ok to use the unittest module for that? From what I understand, the unittest module will run any method starting with test. if I have a separate directory for the tests ( consider a directory named tests ), how would I import the code I'm testing? Do I need to use t...

Error while importing SQLObject on Windows

Hi. I am getting following error while importing SQLObject on Window. Does anyone knows what is this error about and how to solve it? ============================== from sqlobject import * File "c:\python26\lib\site-packages\sqlobject-0.10.4-py2.6.egg\sqlobject\__init__.py", line 5, in <module> from main import * File "c:\p...

upload file with Python Mechanize

When I run the following script: from mechanize import Browser br = Browser() br.open(url) br.select_form(name="edit_form") br['file'] = 'file.txt' br.submit() I get: ValueError: value attribute is readonly And I still get the same error when I add: br.form.set_all_readonly(False) So, how can I use Python Mechanize to interact wit...

Apache/Django freezing after a few requests.

I'm running Django through mod_wsgi and Apache (2.2.8) on Ubuntu 8.04. I've been running Django on this setup for about 6 months without any problems. Yesterday, I moved my database (postgres 8.3) to its own server, and my Django site started refusing to load (the browser spinner would just keep spinning). It works for about 10 mintue...

HTTPResponse - Return organised data (table?)

My Webservice is currently returning a HTTPResponse which contains thousands of data from a mySQL database (via a Objects.filter). It's currently just displating them in a very boring way! I'm looking to organised this data in some way. What would be ideal is two things: The possibility of having a table and maybe having some kind of s...