python

How do I design and implement a programming language?

This question is related to This question on Aardvark This question on here The past couple of years I've been thinking about things I like and don't like about languages I use. I always wanted to write my own language, but never did so. I also own both the Lego RCX and NXT, but most of the time I never actually make my robots do an...

Regex matching items following a header in HTML

What should be a fairly simple regex extraction is confounding me. Couldn't find a similar question on SO, so happy to be pointed to one if it exists. Given the following HTML: <h1 class="title">Title One</h1><p><a href="#">40.5</a><a href="#">31.3</a></p> <h1 class="title alternate">Title Two</h1><p><a href="#">12.1</a><a href="#">8...

A python class that acts like dict

I want to write a custom class that behaves like dict - so, I am inheriting from dict. My question though is that do I need to create a private dict member in my init() method?. I dont see the point of this, since I already have the dict behaviour if I simply inherit from dict. Can anyone point out why most of the inheritance snippets ...

Send commands between two computers over the internet

I wish to control my computer (and usb devices attached to the computer) at home with any computer that is connected to the internet. The computer at home must have a program installed that receives commands from any other computer that is connected to the internet. I thought it would be best if I do this with a web interface as it would...

[Python] Splitting results from chardet output to collect encoding type.

Hi All, I am testing chardet in one of my scripts. I wanted to identify the encoding type of a result variable and chardet seems to do fine here. So this is what I am doing: myvar1 <-- gets its value from other functions myvar2 = chardet.detect(myvar1) <-- to detect the encoding type of myvar1 Now when I do a print myvar2,...

Viewing the code of a Python function

Let's say I'm working in the Python shell and I'm given a function f. How can I access the string containing its source code? (From the shell, not by manually opening the code file.) I want this to work even for lambda functions defined inside other functions. ...

Python - Neaten this append/extend conditional

Hey, I have a method which I will accept either a single object or a list of objects. I want to add whatever is passed to another list. Currently, my method looks like this: def appendOrExtend(self, item): if type(item).__name__ == "list": self.list.extend(item) else: self.list.append(item) It seems to me that there shoul...

Problems with VLC and instant messaging.

I've have asked these questions before with no proper answer. I hope I'll get some response here. I'm developing an instant messenger in python and I'd like to handle video/audio streaming with VLC. Tha basic idea right now is that in each IM client I'm running one VLC instance that acts as a server that streams to all the users I want...

Serialize django model with foreign key models.

How to serialize dajngo model in json format if i want include foreign key models fields. If i have: class Model1(models.Model): name=models.CharField() child=models.ForeignKey(Model2) class Mode2(models.Model): field1=models.CharField() field2=models.IntegerField() I wanna include everything in js...

Does master/worker scale?

I have a master/worker model implemented with separate python processes. The master process holds job/result lists which are protected by mutexes. Many workers run on many machines (about 200 worker processes). I have noticed that on each machine the workers tend to do 0-20% more or less work than other worker processes and that the mac...

python class inherits object

Is there any reason for a class declaration to inherit object? I just found some code that does this and I can't find a good reason why. class MyClass(object): # class code follows... The code is using swig for binding some C code to Python, if that's relevant. ...

Compression with best ratio in Python?

Which compression method in Python has the best compression ratio? Is the commonly used zlib.compress() the best or are there some better options? I need to get the best compression ratio possible. I am compresing strings and sending them over UDP. A typical string I compress has about 1,700,000 bytes. ...

Create a new variable as named from input in Python?

This is something that I've been questioning for some time. How would I create a variable at runtime as named by the value of another variable. So, for example, the code would ask the user to input a string. A variable would then be created named after that string with a default value of "default". Is this even possible? ...

Use PYTHONSTARTUP to interactively test a python file in the interpreter

I want to establish a standard script file that is imported into python at startup using the PYTHONSTARTUP environment variable. Additionally, I want to be able to conveniently reload the same script file after modifying it in an external editor, to test its behavior after the modification. I created a ~/.pythonrc.py file and set it as P...

Can I include sub-config files in my mercurial .hgrc?

I want to keep my main .hgrc in revision control, because I have a fair amount of customization it in, but I want to have different author names depending on which machine I'm using (work, home, &c.). The way I'd do this in a bash script is to source a host-local bash script that is ignored by Mercurial, but I'm not sure how to do this ...

my python client for magento is not installing.

I downloaded the python client for magento from Here But When I am downloading is using python setup.py install then it shows following error. How can i rectify this error? error: File "setup.py", line 31, in <module> import magento File "/home/sam/Downloads/magento-0.1.1/magento/__init__.py", line 21, in <module> from api...

Recursive problem

Hey guys, I have a problem when I import classes from one to another. I have those classes in different modules: crm.py from CRMContactInformation import CRMContactInformation class CRM(rdb.Model): """Set up crm table in the database""" rdb.metadata(metadata) rdb.tablename("crms") id = Column("id", In...

Running a PIL based Python program as a web application

I have created a Python Program that converts strings into images at run time , using PIL's Image Draw module. I want to run this program interfaced with a simple web form that should display a text field to input the string and on pressing a button , it should display the string converted as an image. Would be a great deal of help if...

How to use Python's "easy_install" on Windows ... it's not so easy!

After installing Python 2.7 on Windows XP, then manually setting the %PATH% to python.exe (why won't the python installer do this?), then installing setuptools 0.6c11 (why doesn't the python installer do this?), then manually setting the %PATH% to easy_install.exe (why doesn't the installer do this?), I finally tried to install a python ...

Python web crawling and storing to mysql

Hi, Looking for few days for some simple solution for this, but I think that in this moment I am still on the beginning :) I need good web crawler written in Python to store complete page into mysql database. Small system that I am experimenting uses now PHP Sphider to crawl and store into database. I need something that works almost ex...