python

How can I make a while True break if certain key is pressed? [Python]

My script make a while True: begin with the F4 pressed, but I want it to stop when the F2 is pressed, how can I do it? I'm trying this (using pyhook) but doesn't work... def onKeyboardEvent(event): if event.KeyID == 115: #F4 while True: selectAndCopy(468,722) getClipboard() time.slee...

Tkinter removing standard window in Ubuntu

Is there a command similar to "wm_overrideredirect" for Ubuntu? I want My program to be displayed without the standard window. ...

Generate multiple random numbers to equal a value in python

So here is the deal: I want to (for example) generate 4 pseudo-random numbers, that when added together would equal 40. How could this be dome in python? I could generate a random number 1-40, then generate another number between 1 and the remainder,etc, but then the first number would have a greater chance of "grabbing" more. ...

Get defining class of unbound method object in Python 3

Say I want to make a decorator for methods defined in a class. I want that decorator, when invoked, to be able to set an attribute on the class defining the method (in order to register it in a list of methods that serve a particular purpose). In Python 2, the im_class method accomplishes this nicely: def decorator(method): cls = met...

Efficient way to read a specific line number of a file. (BONUS: Python Manual Misprint)

I have a 100 GB text file, which is a BCP dump from a database. When I try to import it with BULK INSERT, I get a cryptic error on line number 219506324. Before solving this issue I would like to see this line, but alas my favorite method of import linecache print linecache.getline(filename, linenumber) is throwing a MemoryError. Inte...

How do I store then retrieve Python-native data structures into and from a file?

I am reading an XML file and reorganizing the desired data into Python data structures (lists, tuples, etc.) For example, one of my XML parser modules produces the following data: # data_miner.py animals = ['Chicken', 'Sheep', 'Cattle', 'Horse'] population = [150, 200, 50, 30] Then I have a plotter module that roughly says, e.g.: # ...

How can I add some string to a list in order to make a count word? [Python]

I want to simply add some word to a list and then count how many words are in there... And check if the word isn't in the list already. How can I do it? ...

developing a scalabe chat system.

I am a java developer and am pretty comfortable with develeoping webapps in java/jsp/servlets. I want to develop a video web based chat website.people should be able to chat with each other using my website.People dont need to use any client app installed on their pc in order to chat with others. My website should be scalable.It should...

Creating a gui around a python script using Tkinter

I have an existing python script and I want to wrap it in a GUI. Since I already have tkinter installed I would like to use it if possible. At the moment my script has many places where it asks for user input using raw_input(). I would like to replace these with either a modal pop-up asking for user input or (preferably) an Entry obje...

Display simple calendar on screen in python S60 (pyS60)

Hi I am trying to develop a simple calendar based application using pyS60. I need to display a calendar as part of the form. I have searched but I couldn't find anything useful in the e32calendar documentation. I can get a calendar on the canvas but its not interactive. But i want one which is interactive ( just like inbuilt calendar in...

Joining List has integer values with python

I need to join a list of items many of the items I add to the list is a integer returend value from function i.e myList.append(munfunc()) how should i convert the returned result to string in order to join it with the list. did i need to do the following for every integer value : myList.append (str(myfunc()) or this is not the pyth...

instantiate python class from class available as string , only in memory!

Hi, I'm using Reportlab to create PDFs. I'm creating two PDFs which I want to merge after I created them. Reportlab provides a way to save a pycanvas (source) (which is basically my pdf file in memory) as a python file, and calling the method doIt(filename) on that python file, will recreate the pdf file. This is great, since you can co...

Cannot change content of list within list. Can anybody explain why?

I have a month variable which is a list of lists of tuples. Each list represents a week and each day is a tuple of the day of the month and the week day. I wish to make my month a list of lists of month days. I tried to do it like this: for week in month: week = [day[0] for day in week] for [[(1, 1), (2, 2)], [(3, 3), (4, 4)]] I e...

django static annotation

Hi, I want to add a static value to the results of a database query using django (so not using 'raw' SQL) For example, if I have an object Car with fields make, model, and color, then I want my results set with extra static value to look something like this: make model color sales ---- ----- ----- ----- nissan ...

Federated identity on Google App Engine

I am successful with the both methods below, to log on using federated log in for my site on Google App Engine (Python) users.create_login_url("\", "google", "https://www.google.com/accounts/o8/id") users.create_login_url("\", "yahoo", "http://open.login.yahooapis.com/openid20/www.yahoo.com/xrds") I wish to provide more log in optio...

django annotation and filtering

Hi, Hopefully this result set is explanatory enough: title text total_score already_voted ------------- ------------ ----------- ------------- BP Oil spi... Recently i... 5 0 J-Lo back ... Celebrity ... 7 1 Don't Stop... If there w... 9 0 Austr...

wxPython and py2app, CreateActCtx error 0x00000008 (Not enough disk space available)

I've been developing an application that uses wxPython as the GUI librar, and py2exe so that I can easily distribute it, however I have just now tested py2exe and the following error appears when the executable is launched. 12:13:08: Debug: src/helpers.cpp(140): 'CreateActCtx' failed with error 0x00000008 (Not enough disk space availabl...

Django - make file I/O thread safe

Hi, I want to read and write python-source-files from the file system in a thread-safe way. open("n2.py","w").write(my_new_py_class) from myproject import n2 #do something with n2 I assume that this is not thread-safe, since a request2 could modify the file before request1 is loading and executing it. I would like to achieve somethin...

Parsing JavaScript argument values in python

Is there a way to parse the argument values passed to a JavaScript function in python? I want to be able to automatically document JavaScript function calls in order to make sure they have the right arguments passed to them. For example, in: function mymethod(fruit, vegetable, drink) { // dummy function } function drink(drink) ...

PyGTK: adding text over widgets

Hi, I'm developing a GTK app, and would like to print some messages over existing widgets rather than displaying them in the status bar, kind of like the way Mendeley does it when no document is selected: (as opposed to what is displayed in the right pane when you select a document:) Should I dynamically create a panel, label, ......