python

Python - Creating a "scripting" system

Hello, I'm making a wxpython app that I will compile with the various freezing utility out there to create an executable for multiple platforms. the program will be a map editer for a tile-based game engine in this app I want to provide a scripting system so that advanced users can modify the behavior of the program such as modifying p...

How to pause Python while Tkinter window is open?

I'm writing a program that sometimes encounters an error. When it does, it pops up a Tkinter dialog asking the user whether to continue. It's a more complicated version of this: keep_going = False KeepGoingPrompt(keep_going) if not keep_going: return The prompt sets keep_going to True or leaves it False. Problem is, the code seems ...

Always return proper URL no matter what the user enters?

I have the following python code from urlparse import urlparse def clean_url(url): new_url = urlparse(url) if new_url.netloc == '': return new_url.path.strip().decode() else: return new_url.netloc.strip().decode() print clean_url("http://www.facebook.com/john.doe") print clean_url("http://facebook.com/john.d...

Python save matplotlib figure on an PIL Image object

HI, is it possible that I created a image from matplotlib and I save it on an image object I created from PIL? Sounds very hard? Who can help me? ...

Why does Django's time filter not pickup the TIME_FORMAT by default?

Using {{today|time:"TIME_FORMAT"}} correctly localises times when I switch languages in my Django 1.2.3 project. E.g. for English I see "12:19 a.m." and when I switch to German it changes to "12:19:25". As far as I can tell from looking at the docs and code (defaultfilters.py and formats.py) just using {{today:time}} should do the same ...

Python YouTube Gdata Player Error

Hello, I'm trying something really simple: get a list of player urls from the youtube gdata module, def getlist(): index = 1 prev = 0 urls = [] while True: uri = "http://gdata.youtube.com/feeds/api/playlists/E005D335B57338D1?start-index=%i&max-results=50" % index feed = yt_service.GetYouTubeVideoFeed(uri) for en...

Why does this Python service stop by itself in spite of an infinite loop?

Hi, I managed to install a Python script as a service using this recipe at ActiveState: win-services-helper. In order to get much use out of it, I included the business end of my program by replacing lines 99 - 100: 95 class Test(Service): 96 def start(self): 97 self.runflag=True 98 while self.runflag: ...

How to make a screenshot in Windows 7 with python?

Hi, I along with some friends are trying to do an anti cheats for a game, we chose python because it is multiplatform. The problem is we're trying to make a screenshot of what is shown on the screen, not just the game (with OpenGL) but any windows that are open to detect programs that are superimposed on the image of the game (for examp...

Turn a hex string into a percent encoded string in Python

I have a string. It looks like s = 'e6b693e6a0abe699ab'. I want to put a percent sign in front of every pair of characters, so percentEncode(s) == '%e6%b6%93%e6%a0%ab%e6%99%ab'. What's a good way of writing percentEncode(s)? (Note, I don't care that unreserved characters aren't converted into ASCII.) I can think of big verbose ways o...

Python Variable References Tutorial

I need to explain how Python variables are references to objects to a collegue. E.g., how changing the value of an object in one place changes other variables that reference it. I remember reading a wonderful tutorial on that a long time ago. It had diagrams with lines connecting the variables to the objects and showed how those conne...

Iterator (iter()) function in Python.

For dictionary, I can use iter() for iterating over keys of the dictionary. y = {"x":10, "y":20} for val in iter(y): print val When I have the iterator as follows, class Counter: def __init__(self, low, high): self.current = low self.high = high def __iter__(self): return self def next(self):...

Any good references for python and C code mixing?

I've been looking at docs but I can't seem to understand very clearly, them do you guys know of anything that would be good at teaching it. Say I had a program, int main() { return 3; } How do I call cprogram.exe and get the return value (not neccesarily an int, structs too). I don't have a specific project that I'm working on, ju...

Read in CLI argumnet, then use regex's to look for it. -Python

Hello all! Sorry if this is probably a simple fix but I can't think of one. I am trying to take a command line argument (in this case a name) and search through a file hierarchy and keep track of the number of times that name comes up. I was just wondering how to store the CL input and then search through files using a regular expression...

developing for modularity & reusability: how to handle While True loops?

I've been playing around with the pybluez module recently to scan for nearby Bluetooth devices. What I want to do now is extend the program to also find nearby WiFi client devices. The WiFi client scanner will have need to have a While True loop to continually monitor the airwaves. If I were to write this as a straight up, one file prog...

Run command line arguments in python script

I have a program that is run from the command line like this python program.py 100 rfile How can I write a new script so that instead of running it with just the '100' argument, I can run it consecutively with a list of arguments like [50, 100, 150, 200]? Edit: The reason I am asking is that I want to record how 'program.py' executes...

Matplotlib how to draw on figure on PIL image

I've got a new problem here, I wish to inputs a PIL image object, and then draw the figure that generated from matplotlib, and then return the PIL image object. How could I achieve this? ...

Save images as string? IS it possible

Is it possible to save images as string, and then I load it up to Image? ...

Remove specific characters from a string in python

I'm trying to remove specific characters from a string using python. This is the code i'm using right now. Unfortunately it appears to do nothing to the string?? for char in line: if char in " ?.!/;:": line.replace(char,'') ...

python - multi line stdout refresh issue

Hello, I have a stats app written in python that on a timer refreshes the ssh screen with stats. Right now it uses os.system('clear') to clear the screen and then outputs a multi line data with the stats. I'd like to do just do a \r instead of executing the clear but that only works with one line, is it possible to do this with multipl...

Sieve of Eratosthenes - Finding Primes Python

Just to clarify, this is not a homework problem :) I wanted to find primes for a math application I am building & came across Sieve of Eratosthenes approach. I have written an implementation of it in Python. But it's terribly slow. For say, if I want to find all primes less than 2 million. It takes > 20 mins. (I stopped it at this poi...