python

Can Django be used for web services?

My friend said, "Pylons is so much better for web services." My other friend said, "You can modify Django in a way to do exactly whatever you like." In Django, what is necessary to be modified (urls.py? models classes? settings?) in order to do "web services" with APIs and REST and versioning, etc etc.? ...

Python new-style classes and __subclasses__ function

Can somebody explain to me why this works (in Python 2.5) : class Foo(object): pass class Bar(Foo): pass print(Foo.__subclasses__()) but this doesn't : class Foo(): pass class Bar(Foo): pass print(Foo.__subclasses__()) The latter returns "AttributeError: class Foo has no attribute '__subclasses__'" but i'm not s...

Parameters for find function

Hello, I'm using beautiful soup (in Python). I have such hidden input object: <input type="hidden" name="form_build_id" id="form-531f740522f8c290ead9b88f3da026d2" value="form-531f740522f8c290ead9b88f3da026d2" /> I need in id/value. Here is my code: mainPageData = cookieOpener.open('http://page.com').read() soupHandler = BeautifulSo...

Pyinotify doesn't run with pygtk

Hi everyone, I'm newbie in python and I'm trying to use pyinotify with a GUI interface using pygtk. I have two classes, my gtk class which doesn't do much, only displays stuff, and a class that handles the monitoring. When I run them separately they do their work but when I try to load the gtk class from the other one, it only runs the ...

Python, store a dict in a database

What's the best way to store and retrieve a python dict in a database? ...

Referring to objects inside a list without using references or indices

I'm using python for my shopping cart class which has a list of items. When a customer wants to edit an item, I need to pass the JavaScript front-end some way to refer to the item so that it can call AJAX methods to manipulate it. Basically, I need a simple way to point to a particular item that isn't its index, and isn't a reference to...

New to PyDev, question about auto completion.

I installed Eclipse and PyDev and I'm wondering if I have to setup anything else? The reason I'm asking is that I'm finding the auto complete isn't working in certain cases. For example, if I have a variable a_string, I'd like to see a list of available methods once I type "a_string." or if I have an array I'd like to see what methods i...

SqlAlchemy hangs after adding record in MS SQL

I'm running SQLAlchemy on Jython and trying to connect to a MS SQL database using jTDS with windows authentication. I can query and delete just fine but when I try to insert new values it will hang when I commit. print 'before add' session.add(newVal) print 'after add' session.commit() print 'after commit' I see the first two print s...

Scalable chat site in python

Hey guys, I have an idea that I'd like to start implementing that at the crux of it, will basically be a chat website, and will need to support multiple rooms. Quite frankly, I'm not too sure where to begin with regards to setting up a very sturdy/scalable chat system in python (or another language if you guys believe it to be a better a...

Sort a list of dicts by dict values

I have a list of dictionaries: [{'title':'New York Times', 'title_url':'New_York_Times','id':4}, {'title':'USA Today','title_url':'USA_Today','id':6}, {'title':'Apple News','title_url':'Apple_News','id':2}] I'd like to sort it by the title, so elements with A go before Z: [{'title':'Apple News','title_url':'Apple_News','id':2}, {'...

In python, a good way to remove a list from a list of dicts

I have a list of dicts: list = [{'title': u'Politics', 'id': 1L, 'title_url': u'Politics'}, {'id': 3L, 'title_url': u'Test', 'title': u'Test'}] I'd like to remove the list item with title = 'Test' What is the best way to do this given that the order of the key/value pairs change? Thanks. ...

Making REST calls only available to local applications?

Suppose I have a url like http://mysite.com/get-users which returns a JSON object of all users. But, I don't want anyone (or any bots) to be able to go to this url to fetch this information. I want it to only respond to calls from other local modules in the same website. How would I go about implementing someting like this? ...

Python timezone issue?

im having troubles with parsing a feed and getting the time. i am using dateutil.parser from dateutil.parser import parse print updated, parse(updated ), parse( updated ).utcoffset() this should be a time in cali, output 2010-05-20T11:00:00.000-07:00 2010-05-20 11:00:00.000000-07:00 -1 day, 17:00:00 why is the offset -1 day 17 ho...

how to import Java class with Python using Eclipse?

Hi, I'm trying to write Jython where the Python file imports classes from Java I'm using Eclipse with PyDev. My Python code looks like: from eclipsejavatest import eclipseJavaTest from eclipsejavatest import JavaClass class eclipsePyPrint(eclipseJavaTest): def eclipsepyMain(self): print "python main method" ecli...

Python: set a function timeout without using signal or threads?

Is there a way to have a function raise an error if it takes longer than a certain amount of time to return? I want to do this without using signal (because I am not in the main thread) or by spawning more threads, which is cumbersome. ...

how to delete old image when update ImageField?

hi using Django to create a stock photo site, i have a ImageField in my model, the problem is that when the user update the image field, the original image file isn't deleted from the hard disk. how can I make to delete those images after an update? Thanks! ...

Application closes on Nokia E71 when using urllib.urlopen

Hello, Im running the following code on my Nokia E71. But after the text input, the program closes abruptly. I have a GPRS connection on my phone,but i still seem to be having some problem with urllib.urlopen The code is as follows : import appuifw,urllib amountInDollars = appuifw.query(u"Enter amount in Dollars","text") data=urllib....

Python OOP and lists

Hi, I'm new to Python and it's OOP stuff and can't get it to work. Here's my code: class Tree: root = None; data = []; def __init__(self, equation): self.root = equation; def appendLeft(self, data): self.data.insert(0, data); def appendRight(self, data): self.data.append(data); def c...

Crossfading audio with PyQT4 and Phonon

I'm trying to get audio files to crossfade with phonon. I'm using PyQT4. I have tracks queuing properly, but I'm stuck with the fade effect. I think I need to be using the KVolumeFader effect. Here's my current code: def music_play(self): self.delayedInit() self.m_media.setCurrentSource(Phonon.MediaSource(self.playlist[self....

Replacing backslashes in Python strings

I have some code to encrypt some strings in Python. Encrypted text is used as a parameter in some urls, but after encrypting, there comes backslashes in string and I cannot use single backslash in urllib2.urlopen. I cannot replace single backslash with double. For example: print cipherText '\t3-@\xab7+\xc7\x93H\xdc\xd1\x13G\xe1\xfb' ...