python

Authenticated HTTP POST with XML payload using Python urllib2

I'm trying to send a POST message with a purely XML payload (I think) using urllib2 in IronPython. However, everytime I send it, it returns Error code 400 (Bad Request). I'm actually trying to mimick a Boxee remove queue item call for which the actual data packets looks like this (from WireShark): POST /action/add HTTP/1.1 User-Agent:...

Django 'resolve' : get the url name instead of the view_function

Hi ! My problem is simple, I have an url, I would like to resolve it, but get the url name instead of the view function associated with it ... For example... this is urlconf : urlpatterns = patterns('', ... url('^/books/$', book_list, name="overview_books"), ... ) And this is what I would like : >>> resolve('/books/') 'overview_...

[Python] Use 2 sound cards

I need to play a sound with sound card "A", while recording another sound using sound card "B". I know how to play or record a sound (using PyAudio), but I don't know how to choose which sound card to use for it. I have the impression that PyAudio doesn't allow choosing the sound card, but I might be wrong (I'm a beginner at Python). ...

Why the id(string) does not return the address of string

import ctypes a = 'abc' b = ctypes.string_at(id(a), 3) c = ctypes.string_at(id(a) + 20, 3) I expect the result of b to be 'abc', but it is not; and the result of c is 'abc'. I don't know why. Anyone can explain me? ...

Can ( s is "" ) and ( s == "" ) ever give different results in Python 2.6.2?

As any Python programmer knows, you should use == instead of is to compare two strings for equality. However, are there actually any cases where ( s is "" ) and ( s == "" ) will give different results in Python 2.6.2? I recently came across code that used ( s is "" ) in code review, and while pointing out that this was incorrect I wante...

how to display a numpy array with pyglet?

I have a label matrix with dimension (100*100), stored as a numpy array, and I would like to display the matrix with pyglet. My original idea is to use this matrix to form a new pyglet image using function pyglet.image.ImageData(). It requres a buffer of the imagedata as an input, however I have no idea how to get a right formated buffe...

Unable to upload file using django

I'm unable to upload a file using django. When I hit submit button I get "This webpage is not available. The webpage at http://127.0.0.1:8000/results might be temporarily down or it may have moved permanently to a new web address." error in chrome. For the file upload HTTP query the corresponding webserver's log entry is: [02/Jul/2010 ...

[Django + Twisted + PyQy] Having PyQt app controlling all. How use reactor?

Hi all. I've a django application, served via Twisted, which also serves ohter services (three sockets, mainly). I need to have it working under windows, and I decide to write a PyQt4 application which acts quite like Apache Service Monitor for windows. I was not able to connect twisted reactor to pyqt application reactor, so any hint...

Google application engine, maximum number of static files?

Hi All, I am developing an application in google application engine which would have a user profiles kind of feature. I was going through the Google App's online tutorial where I found that the maximum number of static files (app files and static files) should not exceed 3000. I am afraid whether the user's would be able to upload their...

module for pcap stream in python

i am trying to filter some headers off my pcap stream using python. is there a particular module to do this. help with any or suggestion would be well appreciated ...

import statement mess in python

I want to have a number of files imported in a general python file and then include that file when I need the imported modules in the current module. This of course will lead to errors and re-imports if using the from x import y, however when using the "normal" import statement I end up with long instruction statements, for example: x =...

Ruby string strip defined characters

in Python, we can e.g. "[foo ]".strip(" []") # -> "foo" how do we do this in Ruby? string strip method is stripping only whitespace .. UPDATE stripping is not deleting! : ) "[ foo boo ]".strip(" []") # -> "foo boo" ...

Py-appscript: How can I make message with Mail.app

I'm trying to create mail with py-appscript (AppleScript interface for python). I tried following code, from appscript import * mail = app('Mail') msg = mail.make(new=k.outgoing_message, with_properties={'visible':True, 'content':"hello", 'subject':"appsc...

Python images display

How can I create a python script that runs through the images (1.jpeg-n.jpeg) in a directory on a mac and displays them in a browser OR via another python program? Do I import a file to python and than display in browser? Do I extract the file names 1,2,3,4,5 and add that to a list, which I give to another function that calls a browser ...

Python project architecture

I'm a java developer new to python. In java, you can access all classes in the same directory without having to import them. I am trying to achieve the same behavior in python. Is this possible? I've tried various solutions, for example by importing everything in a file which I import everywhere. That works, but I have to type myClass ...

How to use OR using Django's model filter system?

It seems that Django's object model filter method automatically uses the AND SQL keyword. For example: >>> Publisher.objects.filter(name__contains="press", country__contains="U.S.A" will automatically translate into something like: SELECT ... FROM publisher WHERE name LIKE '%press%' AND country LIKE '%U.S.A.%' However, I was won...

python regex: match a string with only one instance of a character

Suppose there are two strings: $1 off delicious ham. $1 off delicious $5 ham. In Python, can I have a regex that matches when there is only one $ in the string? I.e., I want the RE to match on the first phrase, but not on the second. I tried something like: re.search(r"\$[0-9]+.*!(\$)","$1 off delicious $5 ham.") ..saying "Match ...

Python: How to make object attribute refer call a method

I'd like for an attribute call like object.x to return the results of some method, say object.other.other_method(). How can I do this? Edit: I asked a bit soon: it looks like I can do this with object.__dict__['x']=object.other.other_method() Is this an OK way to do this? ...

Scraping a table using BeautifulSoup

Dear Python Experts, I have a question which i suspect is fairly straight forward. I have the following type of page from which I want to collect the information in the last table (if you scroll all the way down it is the one in the box labelled "Procedure"): http://www.europarl.europa.eu/sides/getDoc.do?type=REPORT&mode=XML&re...

Storing XML/HTML files inside a SQLite database - Possible?

Hi, Is it possible to directly store a XML/HTML file inside a SQLite database? I'm writing a program in python which is supposed to parse XML/HTML files and store the values inside the database. However, the fields inside the XML/HTML files may vary and I thought it would be easier to simply store the entire XML/HTML file inside the da...