python

How can I remove part of an string on the re.search result?

text = urllib.urlopen('www.text.com').read() frase = re.search("your text here(.*)", text).group() With these code, I get the result as "your text here mister"... How can I remove the your text here from the result, staying only with the "mister" part? ...

Trying to write to binary plist format from Python (w/PyObjC) to be fetch and read in by Cocoa Touch.

I'm trying to serve a property list of search results to my iPhone app. The server is a prototype, written in Python. First I found Python's built-in plistlib, which is awesome. I want to give search-as-you-type a shot, so I need it to be as small as possible, and xml was too big. The binary plist format seems like a good choice. Unfort...

Conversion from JavaScript to Python code?

Is there a relatively quick program out there to accomplish at least the basics of this? Just a few regexes? I'm willing to do some manual conversion, but this is a pretty big set of scripts. ...

Regular expression to ignore a certain number of character repetitions

I'm trying to write a parser that uses two characters as token boundaries, but I can't figure out the regular expression that will allow me to ignore them when I'm regex-escaping the whole string. Given a string like: This | is || token || some ||| text I would like to end up with: This \| is || token || some \|\|\| text where all...

Passing multiple arguments from IronPython to .NET method.

Hi, I have a class in .NET (C#): public class MyHelper { public object exec( string script, params object[] arguments ) { // execute script with passed arguments in some external enviroment } } I'm using IronPython runtime in my code to run python scripts, which should in some cases call the "exec" method. I would lik...

How to run a python script without specifying the file extension (cross platform solution)?

Let's say that we have a Python script do.py and we want to be able to call it without extension, like do or ./do. If we rename the file from do.py to do and assure we have a valid shebang line it will work for all platforms but Windows. On Windows there is no way of executing file without extension. On Windows, if we keep the origina...

Is it OK to do 302s for architecture in my web applciation?

For example, in my index(request): def index(request): if logged_in: return HttpResponseRedirect("/home_profile") else: return HttpResponseRedirect("/login") This way, when the user hits my home page...he is redirected appropriately. Is this a good architecture? Or will this cause caching problems, etc? ...

What does plus equals (+=) do in Python?

My friend sent me the following Python code to demonstrate what she thinks is wrong with Python. At the moment, I have to agree with her. All of the experienced programmers I've shown this to are equally confused. Can anyone tell me what is going on? class foo: bar = [] def __init__(self,x): self.bar += [x] clas...

Parameters not getting passed properly

Here's an excerpt of my code: def listFrom(here): print "[DBG] here: " + here def book(here, there, amount): print "[DBG] here: " + here + "; there: " + there + "; amount: " + str(amount) # Code that takes input and stores it into the string input # Yes, I know this is dangerous, but it's part of a # school assignment where w...

Python: passing a function with parameters as parameter

def lite(a,b,c): #... def big(func): # func = callable() #... #main big(lite(1,2,3)) how to do this? in what way to pass function with parameters to another function? ...

How do I temporarily disable AppStats in my Google App Engine application?

I recently configured my app to use the new AppStats feature of GAE. However, while debugging it, the extremely verbose logging from AppStats is annoying & I'd like to disable it while I'm debugging and then turn it back on later. Surely there is a single line I can add to or modify in a config file that will let me do this. ...

Dictionary copy problem

Hi All, I am having a dictionary like as dict1 = { 0 : 0, 1 : 1, 2 : { 0: 0, 1 : 1}} ( which is also having a dictionary as value). I want to keep store these value same for some modification checking purpose. So now i am copy this dictionary content into another dictionary as dict2 = dict1.copy().Now i am changing the values of dict2 ...

What's wrong with this string normilizer Python snippet?

It seems that every time I think I mastered encoding, I find something new to puzzle me :-) I'm trying to get rid of French accents from an UTF-8 string: >>> import unicodedata >>> s = u"éèêàùçÇ" >>> print(unicodedata.normalize('NFKD', s).encode('ascii','ignore')) I expected eeeaucC as an output and got instead AA AaA A1AA using Py...

Dynamic Event Conditions

Consider that we've a class named Foo that fires "ready" event when it's ready. from observer import SubjectSet class Foo: def __init__(self): self.events = SubjectSet() self.events.create('ready') def do_sth(self): self.events.fire('ready') As you see, do_sth method makes ready instances of the Foo class. But subcla...

webcam motion tracking with Python

Is there a simple way to track the motions of a single entity in a webcam feed? For example, I imagine a "hello world" app with an index finger used as mouse pointer. I realize there's still a lot of basic research in this area, so it might be too early to expect an easy to use, generic abstraction. For the sake of completeness, I've s...

GraphicsPath doesn't always refresh itself

The simple curve in this application only appears when it's dragged off the screen, or the window is resized. When the application just starts up it doesn't appear, and when the window is maximized or minimized it also disappears. However, all of these times, "Path Drawn" is printed, so all of the painting functions are called. Is there ...

Share data between mod_python processes

I'm running mod_python under Apache. If I've understood correctly, each Apache process runs its own Python interpreter. What would be the best way to share a tiny amount of data across all the processes? I'm talking about just a few hundred bytes here, making something database based completely overkill. ...

What's a good Python Subversion library?

I'm looking for a good python library to manipulate subversion repositories. I'm trying out PySvn, but finding that it can't handle something like pysvn.Client().info("/path/to/svn/repo") because it's not a working copy. Anyone know of any good libraries that can handle this kind of thing? Update - I'll try to simplify it - I want to...

How to write a pager for Python iterators?

I'm looking for a way to "page through" a Python iterator. That is, I would like to wrap a given iterator iter and page_size with another iterator that would would return the items from iter as a series of "pages". Each page would itself be an iterator with up to page_size iterations. I looked through itertools and the closest thing ...

Scraping for a "preview" of a webpage - Python

Hi folks, I'm indexing a list of links, these links update quite often so I'm automating thumbnails for the sites. For most sites it's easy, as I just grab the biggest image on the page hoping it describes the content. But other times there are videos as main content of the page. Does somebody have tips with dealing with this? That...