python

How to substitute into a regular expression group in Python

>>> s = 'foo: "apples", bar: "oranges"' >>> pattern = 'foo: "(.*)"' I want to be able to substitute into the group like this: >>> re.sub(pattern, 'pears', s, group=1) 'foo: "pears", bar: "oranges"' Is there a nice way to do this? ...

Manipulating binary data in Python

I am opening up a binary file like so: file = open("test/test.x", 'rb') and reading in lines to a list. Each line looks a little like: '\xbe\x00\xc8d\xf8d\x08\xe4.\x07~\x03\x9e\x07\xbe\x03\xde\x07\xfe\n' I am having a hard time manipulating this data. If I try and print each line, python freezes, and emits beeping noises (I think ...

python streaming TCP server with RPC

I have written a little streaming mp3 server in python. So far all it does is accept a ServerSocket connection, and begin streaming all mp3 data in its queue to the request using socket.send(). I have implemented this to chunk in stream icy metadata, so the name of the playing song shows up in the client. I would like to add playlist ...

Django adminsite customize search_fields query

Howdy! In the django admin you can set the search_fields for the ModelAdmin to be able to search over the properties given there. My model class has a property that is not a real model property, means it is not within the database table. The property relates to another database table that is not tied to the current model through relatio...

numpy array assignment problem

Hi All: I have a strange problem in Python 2.6.5 with Numpy. I assign a numpy array, then equate a new variable to it. When I perform any operation to the new array, the original's values also change. Why is that? Please see the example below. Kindly enlighten me, as I'm fairly new to Python, and programming in general. -Sujan >>>...

Python - Open default mail client using mailto, with multiple recipients

Hi, I'm attempting to write a Python function to send an email to a list of users, using the default installed mail client. I want to open the email client, and give the user the opportunity to edit the list of users or the email body. I did some searching, and according to here: http://www.sightspecific.com/~mosh/WWW_FAQ/multrec.html...

how to set Content-Type automatically when i download the data that i uploaded.

this is my code : import os from google.appengine.ext import webapp from google.appengine.ext.webapp import template from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext import db #from login import htmlPrefix,get_current_user class MyModel(db.Model): blob = db.BlobProperty() class BaseRequestHandler...

Django Template Inheritance -- Missing Images?

Howdy, I have got the following file heirarchy: project   other stuff   templates       images           images for site       app1           templates for app1       registration           login template       base.html (base for entire site)       style.css (for base.html) In the login template, I am extending 'base.html.' 'base.htm...

Traditional SQL vs MongoDB/CouchDB for simple python app

Say I got an traditional SQL structure like so: create table tags (id PRIMARY KEY int, tag varchar(100)); create table files (id PRIMARY KEY int, filename varchar(500)); create table tagged_files (tag_id int, file_id int); I add some tags: insert into table tags (tag) values ('places'); insert into table tags (tag) values ('locations...

Adding contextual information to your logging output in Python 2.5

I am using Python 2.5. The Python logging module allows adding contextual information to your logging output. Is something similar possible in Python 2.5? ...

Django-modpython deploying project

Hi All, I am deploying a Django project on apache server with mod_python in linux. I have created a directory structure like: /var/www/html/django/demoInstall where demoInstall is my project. In the httpd.conf I have put the following code. <Location "/django/demoInstall"> SetHandler python-program PythonHandler django.core.han...

Python - appending a file?

Hi I wish to add a column of data to a file. The file currently has three tab delimited columns. abbd 1234 0.987 affr 2345 0.465 I have a list of length 8,800 comprising floats. li = [-1.0099876, 34.87659] I wish to add this list as a fourth column to the file. abbd 1234 0.987 -1.0099876 Note - my file is ...

Are there any libraries that support MTOM encryption in Python

Hello, I am using Python Suds to connect to a webservice and I am wanting to use MTOM encrpytion to send an XML message. I have looked around the web and seen libraries for PHP etc. but not for Python. Can anyone recommend a good MTOM library to use preferably for use with SUDS. Thanks for any suggestions. ...

SQLAlchemy: select over multiple tables

Hi, I wanted to optimize my database query: link_list = select( columns=[link_table.c.rating, link_table.c.url, link_table.c.donations_in], whereclause=and_( not_(link_table.c.id.in_( select( columns=[request_table.c.recipient], whereclause=request_table.c.donator==donator.id ...

buzz-python-client's consumer_secret

Hi I using buzz-python-client. In the example: client.build_oauth_consumer('your-app.appspot.com', 'consumer_secret') Where can I get a consumer_secret? ...

Massage with BeatifulSoup or clean with Regex

Could someone tell me whats a better way to clean up bad HTML so BeautifulSoup can handle it - should one use the massage methods of BeautifulSoup or clean it up using regular expressions? Thanks. ...

Python MySQL wrong architecture error

I've been at this for some time and read many sites on the subject. suspect I have junk lying about causing this problem. But where? This is the error when I import MySQLdb in python: >>> import MySQLdb /Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg/_mysql.py:3: UserWarning: Module _mysql wa...

How to write "Hello World" RESTful API using Python and then consume it

Hi, I am totally new to Python. Can anybody guide me how to write and then consume a simple "Hello World" RESTful API in Python. Thanks in advance. Zubair ...

How can I iterate over only the first variable of a tuple

In python, when you have a list of tuples, you can iterate over them. For example when you have 3d points then: for x,y,z in points: pass # do something with x y or z What if you only want to use the first variable, or the first and the third. Is there any skipping symbol in python? ...

Python: Dennis Nedry - Security

Has anyone seen Jurrassic Park where Dennis Nedry has protected the system with an animation that says 'You didn't say the magic word' where after the system goes down. Is it possible to do something similar ikn Python ? To describe it less humoristic: A response screen which waits for a condition fulfilled by the user. And encrypts ...