How do I find a string between two substrings ('123STRINGabc' -> 'STRING')?
My current method is like this:
>>> start = 'asdf=5;'
>>> end = '123jasd'
>>> s = 'asdf=5;iwantthis123jasd'
>>> print((s.split(start))[1].split(end)[0])
iwantthis
However, this seems very inefficient and un-pythonic. What is a better way to do something like ...
Is it possible to control a web browser like Firefox using Python?
I would want to do things like
launch the browser
force clicks on URLs
take screenshots
etc.
...
I'm a LAMP developer trying out Python for the first time.. I'm okay with picking up the syntax, but I can't figure out how to run it on the server! I've tried the following
uploading filename.py to a regular web/public directory. chmod 777, 711, 733, 773... (variations of execute)
putting the filename.py in cgi-bin, chmod same as abov...
Hi all,
Few days ago i asked for a project idea for my B.tech Final year project.
Unfortunately couldn't got any cool idea.
Now I have got an idea which really pleases me and motivates me.
I want to ask to intelligent guys out there is following thing is feasible in 5 months:
The Project idea is :
"A Voice Driven Controlling of The...
Hi all,
I am using the following code to do the test and it seems like < is slower that >=., does anyone know why?
import timeit
s = """
x=5
if x<0: pass
"""
t = timeit.Timer(stmt=s)
print "%.2f usec/pass" % (1000000 * t.timeit(number=100000)/100000)
#0.21 usec/pass
z = """
x=5
if x>=0: pass
"""
t2 = timeit.Timer(stmt=z)
pr...
What are peoples' opinions on using the __call__. I've only very rarely seen it used, but I think it's a very handy tool to use when you know that a class is going to be used for some default behaviour.
...
I'm a true n00b (amateur, learning Python for fun), so as a programming exercise (to test my newfound knowledge of OAuth and App Engine), I adapted Mike Knapp's OAuth on App Engine code and was able to successfully get a request token and exchange it for an access token from Twitter.
However, when I attempted to do the same for Google's...
for ex abc.tar.gz has
abc/file1.txt
abc/file2.txt
abc/abc1/file3.txt
abc/abc2/file4.txt
i need to read/display the contents of file3.txt without extracting the file.
Thanks for any input.
...
Hi all!
I'm fighting a memory leak in a Python project and spent much time on it already. I have deduced the problem to a small example. Now seems like I know the solution, but I can't understand why.
import random
def main():
d = {}
used_keys = []
n = 0
while True:
# choose a key unique enough among used previ...
I have two models Property and Image, related by foreign key such that each Property has multiple instances of Image. I'm trying to retrieve a queryset of all the properties - listing all fields - and the number of images that each property has. I am aware that I could do this as two distinct queries, but I don't feel that this is a part...
I need to learn a language for writing web applications (not websites!).
After some research in google and stackoverflow I ended up that the choice should fall in:
1) Ruby + Rails
2) Python + Django
3) c# + ASP.NET
For sure even pickng one randomly would not be a bad choice, but my question here is specific to UI controls. I come fr...
Dear All,
Can a python class contain an instance of itself as a data container may look like this?
class A:
def __init__(self, val):
self.a = A(val)
self.val = val
aa = A(2)
#this will cause RuntimeError: maximum recursion depth exceeded
my purpose is using this class as a data container contain a copy inside if...
Possible Duplicate:
Best online resource to learn Python?
Great tutorials for Python Novice
...
Possible Duplicate:
check what files are open in Python
Hello,
Is it possible to obtain a list of all currently open file handles, I presume that they are stored somewhere in the environment.
I am interested in theis function as I would like to safely handle any files that are open when a fatal error is raised, i.e. close f...
I have some questions about Python's import statement:
What is the difference between import <module> and from <module> import *?
How can I import a module that is not in the same directory? (and not in PythonHome)
Please consider I am a Python newbie
...
When I use my system, there is no error in my python codes. When I use another system I get this error:(both systems have same version of python)
/usr/lib/pymodules/python2.6/matplotlib/numerix/__init__.py:18: DeprecationWarning:
**********************************************************
matplotlib.numerix and all its subpackages are d...
I am sending a tuple as my variable to javascript. But i could not find a way. I am using bottle framework.
...
Do anyone that have python 2.6 in window , can you guys please open the regedit and see where and how python 2.6 store in HKEY_LOCAL_MACHINE/SOFTWARE ? Somehow i lost it in my regedit and cant install a module ... googled it , but i cant found any answer and i dont have extra computer to try and many module that i needed for my school pr...
I have created a virtualenv using the --no-site-packages option and installed lots of libraries. Now I would like to revert the --no-site-packages option and use also the global packages.
Can I do that without recreating the virtualenv?
More precisely:
I wonder what exactly happens when creating a virtualenv using the --no-site-packag...
I have this simple model:
class Tag(models.Model):
title = models.SlugField()
created = models.datetime
def __unicode__(self):
return self.title
class Entry(models.Model):
title = models.CharField(max_length=30)
created = models.datetime
tags = models.ForeignKey(Tag)
categories = models.CharField(max...