python

Django inheritance: how to have one method for all subclasses?

I have a model BaseModel and several subclasses of it ChildModelA(BaseModel), ChildModelB(BaseModel), ... using multi-table inheritance. In future I plan to have dozens of subclass models. All subclasses have some implementation of method do_something() How can I call do_somthing from a BaseModel instance? Almost identica...

Python TCP stack implementation

Is there a python library which implements a standalone TCP stack? I can't use the usual python socket library because I'm receiving a stream of packets over a socket (they are being tunneled to me over this socket). When I receive a TCP SYN packet addressed to a particular port, I'd like to accept the connection (send a syn-ack) and t...

How do I make these relative imports work in Python 3?

I have a directory structure that looks like this: project/ __init__.py foo/ __init.py__ first.py second.py third.py plum.py In project/foo/__init__.py I import classes from first.py, second.py and third.py and put them in __all__. There's a class in first.py nam...

How to perform a "Group By" query in Django 1.1?

I have seen a lot of talk about 1.1's aggregation, but I am not sure how to use it to perform a simple group by. I am trying to use Django's sitemap framework to create a sitemap.xml file that Google can crawl to find all the pages of my site. Currently I am passing it all the objects, as in Model.objects.all() - however all that really...

Installing python-mysql with wamp's mysql

Hello, (I'm not sure if this should be asked here or SU.. but seeing this question on SO, I am asking it here...) I have wamp (mysql-5.1.33) server setup on my vista machine, and I am trying to install python-mysql 1.2.3c1 to use the mysql version provided by wamp. At first, when I ran python setup.py install, I got an error saying it...

How to draw a bitmap real quick in python using Tk only?

Here is a problem. I want to visualize a specific vector field as a bitmap. It's ok with the representation itself, so I allready have some matrix of RGB lists like [255,255,115], but I have no good idea of how to draw it on screen. So far I make thousands of colored 1px rectangles, but this works too slow. I'm sure there is a better way...

How check if a task is already in python Queue?

Hello. I'm writing a simple crawler in Python using the threading and Queue modules. I fetch a page, check links and put them into a queue, when a certain thread has finished processing page, it grabs the next one from the queue. I'm using an array for the pages I've already visited to filter the links I add to the queue, but if there ar...

How to wrap a CLI program in Python (keeping the interactivity)?

Hello everybody, I'd like to write a wrapper for an interactive CLI Program (the Asterisk CLI). Basically, I need to keep the interaction with the CLI (including tab-completion) but I want to filter the output of Asterisk, in order to show only lines matching a given pattern. I tried a select() based approach, using popen.popen4 and pu...

Noob-Ready Cython Tutorials

I know a bunch of scripting languages, (python, ruby, lua, php) but I don't know any compiled languages like C/C++ , I wanted to try and speed up some python code using cython, which is essentially a python -> C compiler, aimed at creating C extensions for python. Basically you code in a stricter version of python which compiles into C -...

phpDocumentor goes to PHP, as X goes to Python (Django)

What is the X? Thanks ...

Dynamic URL with CherryPY MethodDispatcher

I need to configure a RESTful style URL that support the following URL scheme: /parent/ /parent/1 /parent/1/children /parent/1/chidren/1 I want to use the MethodDispatcher so that each of the above can have GET/POST/PUT/DELETE functions. I have it working for the first and second, but can't figure out how to configure the dispat...

Longest string in numpy object_ array

I'm using a numpy object_ array to store variable length strings, e.g. a = np.array(['hello','world','!'],dtype=np.object_) Is there an easy way to find the length of the longest string in the array without looping over all elements? ...

asyncore not running handle_read

I'm trying to just make a simple asyncore example where one socket is the sender and one is the receiver. For some reason, the handle_read() on the receiver is never called so I never get the 'test' data. Anyone know why? This is my first shot at asyncore, so it's probably something extremely simple. import asyncore, socket, pdb, random...

Using/Creating Python objects with Jython

HI, lets say I have a Java interface B, something like this. B.java : public interface B { String FooBar(String s); } and I want to use it with a Python class D witch inherits B, like this. D.py : class D(B): def FooBar(s) return s + 'e' So now how do I get an instance of D in java? I'm sorry im asking such a n00b que...

Selenium IDE - can't select "table" tab

Can someone tell me why I can't select the "table" tab? Here is a pic: ...

Long, slow operation in Django view causes timeout. Any way for Python to speak AJAX instead?

I've been programming Python a while, but DJango and web programming in general is new to me. I have a very long operation performed in a Python view. Since the local() function in my view takes so long to return, there's an HTTP timeout. Fair enough, I understand that part. What's the best way to give an HTTPresponse back to my users ...

Best practice for the Python-then-profile-then-C design pattern?

Hi all. A popular software development pattern seems to be: Thrash out the logic and algorithms in Python. Profile to find out where the slow bits are. Replace those with C. Ship code that is the best trade-off between high-level and speedy. I say popular simply because I've seen people talk about it as being a great idea. But are t...

edit text file using Python

I need to update a text file whenever my IP address changes, and then run a few commands from the shell afterwards. Create variable LASTKNOWN = "212.171.135.53" This is the ip address we have while writing this script. Get the current IP address. It will change on a daily basis. Create variable CURRENT for the new IP. Compare (as stri...

pycurl installation on Windows

I am not able to install pycurl on Windows on Python2.6. Getting following error: C:\Documents and Settings\vijayendra\Desktop\Downloads\pycurl-7.19.0>python setup.py install --curl-dir="C:\Documents and Settings\vijayendra\Desktop\Downloads\ curl-7.19.5-win32-ssl\curl-7.19.5" Using curl directory: C:\Documents and Settings\vijayendra\D...

String matching in python with re

I have a file in this structure: 009/foo/bar/hi23123/foo/bar231123/foo/bar/yo232131 What i need is to find the exact match of a string; e.g. only /foo/bar among /foo/bar/hi and /foo/bar/yo One solution came up in my mind is like to check for ending "/" for the input string. Because if there is ending "/" in the possible results, that...