python

Increment Numpy array with repeated indices

I have a Numpy array and a list of indices whose values I would like to increment by one. This list may contain repeated indices, and I would like the increment to scale with the number of repeats of each index. Without repeats, the command is simple: a=np.zeros(6).astype('int') b=[3,2,5] a[b]+=1 With repeats, I've come up with the fo...

Nested Scopes and Lambdas

def funct(): x = 4 action = (lambda n: x ** n) return action x = funct() print(x(2)) # prints 16 ... I don't quite understand why 2 is assigned to n automatically? ...

Python equivalent of PyErr_Print()

What is the Python API equivalent of PyErr_Print(), from the C interface? I'm assuming a call in either the sys, or traceback modules, but can't find any functions therein that make calls to PyErr_Print(). Addendum I'm after the Python call to get the same functionality as PyErr_PrintEx(), described as: Print a standard traceback to ...

Get original filename google app engine

When receiving a file upload on google app engine, the example assumes you're receiving a .png. However you only konw what the type of the image is by the extension on the filename. How do you get the original filename uploaded on GAE? ...

Force CherryPy Child Threads

Well, I want cherrypy to kill all child threads on auto-reload instead of "Waiting for child threads to terminate" because my program has threads of its own and I don't know how to get past this. CherryPy keeps hanging on that one line and I don't know what to do to get the 'child threads' to terminate... ` [05/Jan/2010:01:14:24] ENGI...

If I have this string in Python, how do I decode it?

s = 'Tara%2520Stiles%2520Living' How do I turn it into: Tara Stiles Living ...

Whats the working principle of omegle.com?

I came across omegle.com webiste.I know that picks two random strangers and pairs them up and then can chat. In short, i know the functionality of it. But i want to create a similar project as my final year project, so i want to understand the technical details of it. Can any one suggest which will be the best technology for devloping s...

Regex match of hexdigest in google app engine webapp WSGIApplication

application = webapp.WSGIApplication( [(r'/main/profile/([a-f0-9]{40})', ProfileHandler)], debug=True) The regex in the above parameter will not recognize a 40 hex long hexdigest in Google App Engine. I'm getting 404s instead of ProfileHandler being passed the matching 40 hex long profile ID. My app.yaml passes everything /mai...

Qt Python Calendar: selected day direct access

Hi Everybody, I have calendar that is working fine. Here is the function that display the full date: def selectDate(self,date): self.fullDate = str(date.day()) + " / " + str(date.month()) + " / " + str(date.year()) print "full date: %s" % self.fullDate And here the code with the calendar: def TabCalendar(self): self.cal...

Why is Django's Meta an old-style class?

I noticed that in Django models, there is a class Meta which makes some additional definitions about the model. My question is, why is this done as an old-style class? (i.e. not subclassing object?) Is there a reason for this or is this just a custom? Could I do it as a new-style class in my projects? ...

Asynchronous data through Bloomberg's new data API (COM v3) with Python?

Hi there, Does anyone know how to get asynchronous data through Bloomberg's new data API (COM v3) with Python? I found this code below on wilmott.com and it works just fine, but it's for the old API version. Does anyone know the corresponding code for the new version? from win32com.client import DispatchWithEvents from pythoncom impor...

String manipulation in Python

Hello, I am trying to write a command but I do not want one long line that looks untidy. I am looking to add the strings together to be executed as on command. I have some code below which is part of an email function: msg = MIMEText("The nightly build status was a SUCCESS\n\nBuild File: http://www.python.org\n\n Build Results File: htt...

Slow pyinotify.ThreadedNotifier.stop()

Hi all, I have a wxPython application that uses pyinotify (via ThreadedNotifier) to check when a certain file gets modified. When this happens, the application stops watching the file and does some stuff. Everything works fine, except that often the call to ThreadedNotifier.stop() takes a noticeable time, about 4 seconds... Other times, ...

Devloping a chat application in python

I want to develop a chat application similar to omegle.com. FUNCTIONALITY This website picks up two random people who are logged into the website and then pairs them for a chat session. Now if one of the party A disconnects then the other party B is informed and then the party B is connected to a different party. I want my application t...

Getting the Python PMW module?

I got a game which uses PMW in its code and I wanted to know is that already installed with Python, or does it come separate? Whre can I get it from so I could get this game running? I have difficulties opening it as it requires PMW. ...

Handle Arbitrary Exception, Print Default Exception Message

I have a program, a part of which executes a loop. During the execution of this loop, there are exceptions. Obviously, I would like my program to run without errors, but for the sake of progress, I would like the program to execute over the entire input and not stop when an exception is thrown. The easiest way to do this would be by impl...

Visual module in python assign objects

Hi all, I am a newb in Visual module in python, not really understand how does it assign a value to an objects. say from visual import * stars=[] galaxies=[] for i in range(10): stars+=[sphere('pos,radius,color.....')] for j in range(20): galaxies+=[sphere('pos,radius,color......')] for k in range(30): stars[k].pos=position...

What are Python metaclasses useful for?

What can be done with metaclasses that can't be in any other way? Alex Martelli told that there are tasks that can't be achieved without metaclasses here http://stackoverflow.com/questions/1779372/python-metaclasses-vs-class-decorators I'd like to know which are? ...

Limiting the features of an embedded python instance

Is there a way to limit the abilities of python scripts running under an embedded interpretor? Specifically I wish to prevent the scripts from doing things like the following: Importing python extension modules (ie .pyd modules), except those specifically allowed by the application. Manipulating processes in any way (ie starting new pr...

Nested functions in Python

def maker(n): def action(x): return x ** n return action f = maker(2) print(f) print(f(3)) print(f(4)) g = maker(3) print(g(3)) print(f(3)) # still remembers 2 ... why does the nested function remembers the first value (2) even though maker() has returned and exited by the time we call action()? ...