python

python round problem

I am facing the problem while dividing my max_sum = 14 total_no=4 so when i do print "x :", (total_sum/total_no) , I get 3 and not 3.5 I tried many ways for printing but failed, can somebody let me know what way I get in 3.5 format? Thank you ...

Python - Minimum of a List of Instance Variables

I'm new to Python and I really love the min function. >>>min([1,3,15]) 0 But what if I have a list of instances, and they all have a variable named number? class Instance(): def __init__(self, number): self.number = number i1 = Instance(1) i2 = Instance(3) i3 = Instance(15) iList = [i1,i2,i3] Do I really have to someth...

I have to make mouse move until cursor change, but, how?

I want to make a little script that make the mouse moves until the icon changes, but I'm not having success with it... Here it's what I'm trying def enterLink(): mouseMove(*position[4]) for win32gui.GetCursorInfo()[1] == 65567: mouseMove(*position[5]) mouseMove(*position[4]) How I have to do this? The commands...

Break from for loop

Here is my code: def detLoser(frag, a): word = frag + a if word in wordlist: lost = True else: for words in wordlist: if words[:len(word) == word: return #I want this to break out. else: lost = True Where I have a return, I've tried putting in bot...

Is it possible to get a list of all versions of an app ?

Hello, the title speaks for itself. I play with GAE and some of my apps have versions like (1,2,3,4 and dev). So, is there a way to get all of them, so I could use it in my app to generate links to different versions ? ...

VoteHandler in Google App Engine

I am trying to have this function limit a user to only one vote per image. However it currently lets all votes through. If I change "if existing_vote != 0:" to "if existing_vote == 0:" it lets no votes through. Thoughts? class VoteHandler(webapp.RequestHandler): def get(self): #See if logged in self.Session = Session() if ...

Usability issues with xmpppy for non TLS/SSL connections to Openfire

I built some test tools using code snippets I found on this site for xmpppy. And I'm using the tools against Openfire XMPP server (on Windows). What's interesting is that the code samples here use port 5223, which is to enable TLS/SSL where available. My tools work fine under that. But we recently made a change to Openfire to not use TL...

Python programmer: Learning ruby (for rails)

I'm a moderately competent Python programmer, and am considering working on my first web-app; it seems a very large number of FOSS webapp code is written in Ruby (i.e. Rails), and I suspect that might help with my learning curve (i.e. for building a decent, if useless webapp). There is lots of material for learning Ruby on the interwebs...

How can I exit a while with a key ? [Python]

Possible Duplicate: How can I make a while True break if certain key is pressed? [Python] I have this code: def enterCategory(): time.sleep(0.2) if entercount == 1: mouseMove(*position[5]) while win32gui.GetCursorInfo()[1] != 65567: mouseMove(*position[5]) mouseMove(*position[4]...

Python convert formatted string to list.

I have a string "[u'foo']" (Yes, it includes the square brackets and the u''). I have to convert that to a list which looks like [u'foo']. list("[u'foo']") won't work. Any suggestions? ...

Returning a file to a WSGI GET request

Hi all, I'm new to WSGI on python; but have a windows server that's got isapi_wsgi installed on it. I also have a script that handles my GET requests all up and running great. The thing is, someone sends me a request, and I need to return a zip file to the requester. The following code is in my GET handler and it works, but doesn't seem...

A way to "listen" for changes to a file system from Python on Linux?

I want to be able to detect whenever new files are created or existing files are modified or deleted within a given directory tree (or set of trees). The brute force way to do this would be to just rescan the tree looking for changes, but I'm looking for a more "interrupt driven" solution where the file system tells my code what changed ...

Converting a 2D numpy array to a structured array

I'm trying to convert a two-dimensional array into a structured array with named fields. I want each row in the 2D array to be a new record in the structured array. Unfortunately, nothing I've tried is working the way I expect. I'm starting with: >>> myarray = numpy.array([("Hello",2.5,3),("World",3.6,2)]) >>> print myarray [['Hello' '...

Django: Exposing model method to admin.

Example model: class Contestant(models.Model): first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) email = models.EmailField() ... def send_registration_email(self): ... I'd like to be able to expose this method to the admin so that managers can login and manually cal...

CSS Templating system for Django / Python?

I'm wondering if there is anything like Django's HTML templating system, for for CSS.. my searches on this aren't turning up anything of use. I am aware of things like SASS and CleverCSS but, as far as I can tell, these still don't solve my issue as I want to dynamically generate a CSS file based on certain conditions, so that a differen...

Is there a way to save a captcha image and view it later in python?

I am scripting in python for some web automation. I know i can not automate captchas but here is what i want to do: I want to automate everything i can up to the captcha. When i open the page (usuing urllib2) and parse it to find that it contains a captcha, i want to open the captcha using Tkinter. Now i know that i will have to save th...

Help, the insertion cursor moves one line lower each time!

Every time this code is reopened the insertion cursor moves one line lower, how do I stop this? import Tkinter,pickle class Note(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent = parent self.Main() self.load_data() self.protocol("WM_DELETE_WINDOW", self.sa...

socket.getaddrinfo raises "Unknown host" mystery

I'm having a problem resolving a hostname using python's (2.6.2) socket class. From the shell I'm able to ping the hostname, and also resolve the hostname using the host command: host myhostname.mydomain.com When I attempt to resolve it with python, a socket.herror exception is raised with the message "[Errno 1] Unknown host" socket...

newbie python csv writer question: why every character separated?

hi, please excuse me for simple question: i tried to write simple csv file using csv module. however, the result is this: Spam |Baked Beans| / s e a r c h | | , | | A d v a n c e d | | S e a r c h / a b o u t / | | , | | A b o u t / n e w s / | | , | | N e w s / d o c / | | , | | D o c u m e n t a t i o n / d o w n l o a d / | | , | | ...

Using a Python GEDCOM parser: Receiving bad output (gedcom.Element instance at 0x00...)

I'm new to Python, and I can say off the bat my programming experience is nominal compared to many of you. Brace yourselves :) I have 2 files. A GEDCOM parser written in Python that I found from a user on this site (gedcom.py - http://ilab.cs.byu.edu/cs460/2006w/assignments/program1.html) and a simple GEDCOM file that I pulled from hei...