python

Find string between two substrings

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

Controlling Browser using Python?

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

Running a .py file on LAMP (CentOS) server - from a PHP developer's perspective

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

Voice recognition : voice driven control

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

Why < is slower than >=

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

When is using __call__ a good idea?

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

Can't Pull Request Token from Google Data API via OAuth/Python

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

how to see the content of a particular file in .tar.gz archive without unzipping the contents?

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

Why python list slice assignment eats memory?

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

Annotate a django query via a reverse relationship

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

Decision maker question: compare ASP.NET / Ruby / Python on web UI controls

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

[python] can a python class contain an instance of itself as a data container

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

Best Python Tips for Beginners

Possible Duplicate: Best online resource to learn Python? Great tutorials for Python Novice ...

List all currently open file handles?

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

basic questions about "import"

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

python error when I use different systems!

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

how to send variable to javascript?

I am sending a tuple as my variable to javascript. But i could not find a way. I am using bottle framework. ...

How to store python 2.6 value in regedit

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

Revert the `--no-site-packages` option with virtualenv

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

Assign multiple tags to one entry

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