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?
...
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...
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.
...
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...
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...
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...
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?
...
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...
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...
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?
...
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.
...
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 ...
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...
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...
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...
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 ...
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.
...
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...
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 ...
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...