python

Giving anonymous users the same functionality as registered ones

I'm working on an online store in Django (just a basic shopping cart right now), and I'm planning to add functionality for users to mark items as favorite (just like in stackoverflow). Models for the cart look something like this: class Cart(models.Model): user = models.OneToOneField(User) class CartItem(models.Model): cart = m...

Need help for facebook fql query

Hi, I wanted to know why is this code wrong. new_query = "SELECT time,message FROM status WHERE (uid=%s % request.facebook.uid) AND time > someval.time" new_result = request.facebook.fql.query(new_query) Someval.time is correct time format according to facebook time format. So why does it gives me wrong code?? new_query = "SELECT ti...

Is there a uniform python library to transfer files using different protocols

I know there is ftplib for ftp, shutil for local files, what about NFS? I know urllib2 can get files via HTTP/HTTPS/FTP/FTPS, but it can't put files. If there is a uniform library that automatically detects the protocol (FTP/NFS/LOCAL) with URI and deals with file transfer (get/put) transparently, it's even better, does it exist? ...

Jump into a Python Interactive Session mid-program?

Hey I was wondering... I am using the pydev with eclipse and I'm really enjoying the powerful debugging features, but I was wondering: Is it possible to set a breakpoint in eclipse and jump into the interactive python interpreter during execution? I think that would be pretty handy ;) edit: I want to emphasize that my goal is not to j...

parsing in python

I have following string adId:4028cb901dd9720a011e1160afbc01a3;siteId:8a8ee4f720e6beb70120e6d8e08b0002;userId:5082a05c-015e-4266-9874-5dc6262da3e0 I need only the value of adId,siteId and userId. means 4028cb901dd9720a011e1160afbc01a3 8a8ee4f720e6beb70120e6d8e08b0002 5082a05c-015e-4266-9874-5dc6262da3e0 all the 3 in different varia...

Fedora Python Upgrade broke easy_install

Fedora Core 9 includes Python 2.5.1. I can use YUM to get latest and greatest releases. To get ready for 2.6 official testing, I wanted to start with 2.5.4. It appears that there's no Fedora 9 YUM package, because 2.5.4 isn't an official part of FC9. I downloaded 2.5.4, did ./configure; make; make install and wound up with two Python...

Are inner-classes unpythonic?

My colleague just pointed out that my use of inner-classes seemed to be "unpythonic". I guess it violates the "flat is better than nested" heuristic. What do people here think? Are inner-classes something which are more appropriate to Java etc than Python? NB : I don't think this is a "subjective" question. Surely style and aesthetics ...

Why does defining __getitem__ on a class make it iterable in python?

Why does defining __getitem__ on a class make it iterable? For instance if I write: class b: def __getitem__(self, k): return k cb = b() for k in cb: print k I get the output: 0 1 2 3 4 5 6 7 8 ... I would really expect to see an error returned from "for k in cb:" ...

Configure Apache to recover from mod_python errors

I am hosting a Django app on Apache using mod_python. Occasionally, I get some cryptic mod_python errors, usually of the ImportError variety, although not usually referring to the same module. The thing is, these seem to come up for a single forked subprocess, while the others operate fine, even when I force behavior that requires usin...

How can I make a class in python support __getitem__, but not allow iteration?

I want to define a class that supports __getitem__, but does not allow iteration. for example: class b: def __getitem__(self, k): return k cb = b() for x in cb: print x What could I add to the class b to force the "for x in cb:" to fail? ...

Does python-memcache use consistent hashing?

I'm using the python-memcache library, and I'm wondering if anyone knows if consistent hashing is used by that client as of 1.44. ...

Checking to See if a List Exists Within Another Lists?

Okay I'm trying to go for a more pythonic method of doing things. How can i do the following: required_values = ['A','B','C'] some_map = {'A' : 1, 'B' : 2, 'C' : 3, 'D' : 4} for required_value in required_values: if not required_value in some_map: print 'It Doesnt Exists' return False return True I looked at the ...

Using mx:RemoteObject with web2py's @service.amfrpc decorator.

I am using web2py (v1.63) and Flex 3. web2py v1.61 introduced the @service decorators, which allow you to tag a controller function with @service.amfrpc. You can then call that function remotely using http://..../app/default/call/amfrpc/[function]. See http://www.web2py.com/examples/default/tools#services. Does anybody have an example of...

Nokia N95 and PyS60 with the sensor and xprofile modules

I've made a python script which should modify the profile of the phone based on the phone position. Runned under ScriptShell it works great. The problem is that it hangs, both with the "sis" script runned upon "boot up", as well as without it. So my question is what is wrong with the code, and also whether I need to pass special parame...

What would be a good task for a test-driven development presentation?

Possible Duplicate: What would you like to see in a TDD demo? What is a good sample class to demonstrate TDD? I'd like to prepare a one-hour talk on test-driven development, using Python. But rather than describing what TDD is (and giving little examples), I'd like to choose some user stories that could be implemented usin...

FIFO (named pipe) messaging obstacles

I plan to use Unix named pipes (mkfifo) for simple multi-process messaging. A message would be just a single line of text. Would you discourage me from that? What obstacles should I expect? I have noticed these limitations: A sender cannot continue until the message is received. A receiver is blocked until there are some data. Nonblo...

how to parse windows inf files for python ?

hi please help me. example inf file : ;============================================================================= ; ; Copyright (c) Intel Corporation (2002). ; ; INTEL MAKES NO WARRANTY OF ANY KIND REGARDING THE CODE. THIS CODE IS ; LICENSED ON AN "AS IS" BASIS AND INTEL WILL NOT PROVIDE ANY SUPPORT, ; ASSISTANCE, INSTALLATION, TR...

Parsing HTTP User-Agent string

What is the best method to parse a User-Agent string in Python to reliably detect Browser Browser version OS Or perhaps any helper library that does it ...

str.startswith() not working as I intended

I'm trying to test for a /t or a space character and I can't understand why this bit of code won't work. What I am doing is reading in a file, counting the loc for the file, and then recording the names of each function present within the file along with their individual lines of code. The bit of code below is where I attempt to count th...

Really odd (mod)_python problem

Hello all, this one is hard to explain! I am writing a python application to be ran through mod_python. At each request, the returned output differs, even though the logic is 'fixed'. I have two classes, classA and classB. Such that: class ClassA: def page(self, req): req.write("In classA page") objB = ClassB() ...