python

How to delete specific tags

Hi. I have the following XML file: <book> <bookname child="test"> <text> Works </text> <text> Doesn't work </text> </bookname> </book> This is just a one block, there are more than one <bookname> tags. I need to iterate through the whole document and remove specific <text> tags. How do I do that? My approach is to create an El...

What is the magic method

What is the magic method? Please give brief definition of magic method? ...

Problem with Web Service call on complexType data element using SOAPY in Python

I am trying to use SOAPy to access a temperature conversion Web service, for example to do a FahrenheitToCelcius temperature conversion. The WSDL file of the webservice defines the input message of the FahrenheitToCelcius operation as:- <input message="tns:FahrenheitToCelciusSoapRequest"/> with the FahrenheitToCelciusSoapRequest messa...

Django template doesn't render a Variable's method

Hello ! I am obviously victim of some dark magic... Here is a template that I render : context = Context({'my_cube': c}) template = Template( '{% load cube_templatetags %}' '{{ my_cube|inspect }} {{ my_cube.measure }}' ) Here is the implementation of the inspect filter : def inspect_object(obj): return obj.measure() He...

Where can I get Twisted ? Official site seems hacked

Hello, the official site of Twisted is down (parked by advertisment). I just bought a book about Twisted Network Programming Essentials. Chapter 1 is getting Twisted and setting it up. But with the site down, I don't find where to download Twisted and get extra docs about it. Could somebody point me to a mirror ? ...

Python: problem processing a string

I have a string as follows: names = "name:fred, name:wilma, name:barney, name2:gauss, name2:riemann" let's say the string names has name and name2 attributes. How do I write a function, is_name_attribute(), that checks if a value is a name attribute? That is is_name_attribute('fred') should return True, whereas is_name_attribute('gau...

UnicodeEncodeError: 'ascii' codec can't encode character when trying a HTTP POST in Python

Hi there, I'm trying to do a HTTP POST with a unicode string (u'\xe4\xf6\xfc') as a paremter in Python, but I receive the following error: UnicodeEncodeError: 'ascii' codec can't encode character This is to the code used to make the HTTP POST (with httplib2) http = httplib2.Http() userInfo = [('Name', u'\xe4\xf6\xfc')] data = ur...

Django Template Ternary Operator

Hi, I was wondering if there was a ternary operator (condition ? true-value : false-value) that could be used in a Django template. I see there is a python one (true-value if condition else false-value) but I'm unsure how to use that inside a Django template to display the html given by one of the values. Any ideas? ...

Do a search-and-replace across all files in a folder through python?

I'd like to learn to use python as a command line scripting replacement. I spent some time with python in the past but it's been a while. This seems to be within the scope of it. I have several files in a folder that I want to do a search-and-replace on, within all of them. I'd like to do it with a python script. For example, sear...

Eclipse and WX compatibility issue

Hi, I decided to give PyDev and Eclipse a try. I have compatible version of Python (2.6.5) and wx, but when I try to run a program with PyDev/Eclipse I get the following error: import wx File "/var/tmp/wxWidgets/wxWidgets-13~231/2.6/DSTROOT/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unico...

Python: Get name of shoutcast/internet radio station from url

I've been trying to get the name/title of internet radio stations based on the url in python, but with no luck so far. It seems that internet radio stations use another protocol than HTTP, but please correct me if I'm wrong. For example: http://89.238.146.142:7030 Has the title: "Ibiza Global Radio" How can i store this title in a var...

Extracting projects to their own repository in svn using svndumpfilter2 (python assertion error)

I'm attempting to migrate a project out of one repository into its own repository to more easily handle authentication/authorization via ldap. However, in attempting the svnadmin dump | svndumpfilter --include ... I get the standard error that some files in the included path were moved or copied from somewhere NOT in the included path, ...

Why type(classInstance) is returning 'instance'?

Hi! I have a method that accepts a parameter that can be of several types, and has to do one thing or other depending on the type, but if I check the type of said parameter, I don't get the 'real' type, I always get <type 'instance'>, and that is messing up with my comparisons. I have something like: from classes import Class1 from c...

How to save user's daily progress?

Hello, I'm building an app where I'm trying to store the user's progress on a game. I want to be able to store the score of a player on a daily basis, and then retrieve the day's score when I look for the date. I wanted to store a dictionary in the database, with keys being the dates when the user played and the values being the score,...

How do I get the client IP of a Tornado request?

I have a RequestHandler object for incoming post()s. How can I find the IP of the client making the request? I've browsed most of RequestHandler's methods and properties and seem to have missed something. ...

write sorted results to file

I have a simple function that sorts a dictionary: data = inputfile.readlines() lineData = sorted(data, key=len, reverse=True)[:3] Printing the output: print sorted(data, key=len, reverse=True)[:3] generates the expected result, however writing to file: outputfile.writelines sorted(data, key=len, reverse=True)[:3] generates nothi...

Django import problem with models.py and multiple ManyToManyFields()

I am working on creating a simple contest submission system using django. This is my first real django project. Basically each user can view a list of problems, submit a file, and view a results page. Each problem can be associated with multiple contests, and different contests can use the same problem. Because of this, both problem and...

Is it possible to make Nose only run tests which are sub-classes of TestCase or TestSuite (like unittest.main())

My test framework is currently based on a test-runner utility which itself is derived from the Eclipse pydev python test-runner. I'm switching to use Nose, which has many of the features of my custom test-runner but seems to be better quality code. My test suite includes a number of abstract test-classes which previously never ran. The ...

FTP and python question

Can someone help me. Why it is not working import ftplib import os def readList(request): machine=[] login=[] password=[] for line in open("netrc"): #read netrc file old=line.strip() line=line.strip().split() if old.startswith("machine"): machine.append(line[-1]) ...

Python performance: Try-except or not in?

In one of my classes I have a number of methods that all draw values from the same dictionaries. However, if one of the methods tries to access a value that isn't there, it has to call another method to make the value associated with that key. I currently have this implemented as follows, where findCrackDepth(tonnage) assigns a value to...