python

set axis limits in matplotlib pyplot

Hello, I have two subplots in a figure. I want to set the axes of the second subplot such that it has the same limits as the first subplot (which changes depending on the values plotted). Can someone please help me? Here is the code: import matplotlib.pyplot as plt plt.figure(1, figsize = (10, 20)) ## First subplot: Mean value in each...

How to get the original value of changed fields?

I'm using sqlalchemy as my orm, and use declarative as Base. Base = declarative_base() class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) My question is, how do I know a user has been modified, and how to get the original values without query database again? user = Sess...

python: padding punctuation with white spaces (keeping punctuation)

What is an efficient way to pad punctuation with whitespace? input: s = 'bla. bla? bla.bla! bla...' desired output: s = 'bla . bla ? bla . bla ! bla . . .' Comments: I don't care how many whitespaces are there between tokens. (but they'll need to be collapsed eventually) I don't want to pad all punctuation. Say I'm interested o...

Django, Turbo Gears, Web2Py, which is better for what?

I got a project in mind that makes it worth to finally take the plunge into programming. After reading a lot of stuff, here and elsewhere, I'm set on making Python the one I learn for now, over C# or java. What convinced me the most was actually Paul Graham's excursions on programming languages and Lisp, though Arc is in the experiment...

changing the prompt style of a virtualenv instance with zsh

I would like the change my zsh prompt style for every virtualenv instances that i use or create. My actual promp is like this: declare PS1="%{$fg[magenta]%}%n%{$reset_color%} at %{$fg[yellow]%}%m%{$reset_color%} in %{$fg_bold[green]%}%3~ %{$reset_color%}" When i activate a virtualenv it just add some an information before the prompt:...

Abstract Django Application from "Project"

Hi All, I'm struggling to work out how best to do what I think I want to do - now it may be I don't have a correct understanding of what's best practice, so if not, feel free to howl at me etc. Basically, my question is, how do I abstract application functionality correctly, said functionality being found in an application that is part...

How to dynamically update values to arguments in Python loop?

Hello all, Python newbie here: I'm writing a market simulation in Python using Pysage, and want to generate an arbitrary number of agents (either buyers or sellers) using the mgr.register_actor() function, as follows: for name, maxValuation, endowment, id in xrange(5): mgr.register_actor(Buyer(name="buyer001", maxValuation=100, end...

Why would one use accelerators with fastcgi for PHP?

I'm a newbie to web technology, and still on a learning curve. Heard that, fastcgi would keep the compiled(interpreted) php code in memory, so why would one has to use op-code caching (apc or eaccelerators) for PHP? But I never heard of any such accelerators for Python. I'd expect as python and php are both interpreted language, it make...

When to use WSGI middleware?

I write a router that takes the path of a requests, match it against a regex and calls a WSGI handler, if the regex matches. The dict with the matching capturing groups is added to the envrion. Is it bad style to modify the environ with WSGI middleware? But is that what WSGI middleware was invented for? I've just read WSGI Middleware Co...

Python "ImportError: No module named" Problem

I'm running Python 2.6.1 on Windows XP SP3. My IDE is PyCharm 1.0-Beta 2 build PY-96.1055. I'm storing my .py files in a directory named "src"; it has an __init__.py file that's empty except for an "__author__" attribute at the top. One of them is called Matrix.py: #!/usr/bin/env python """ "Core Python Programming" chapter 6. A si...

How to control the size of the Windows shell window from within a python script?

When launching a script-type python file from Windows you get a windows shell type window where the script runs. How can the script determine and also set/control the Window Size, Screen Buffer Size and Window Position of said window?. I suspect this can be done with the pywin32 module but I can't find how. ...

Best practice for a recursive console tool in Python

What is the best practice (interface and implementation) for a command line tool that processes selected files in a directory tree? I give an example that comes to my mind, but I am looking for a 'best practice': flipcase foo.txt foo2.txt could process foo.txt and save the result as foo2.txt. flipcase -rv *.txt could process all ...

Clear the screen in python

Possible Duplicate: clear terminal in python How can I clear the window for all text, so that it looks like it has just been opened? I've heard os.system("clear") works, but it didn't. Using Python 2.6.5 on Windows 7 ...

Python Software design....

I am starting to use python,more. Is there a good way to keep python disk access to a minimum. Seems to me that everytime a *.py file runs, it hits a hard disk. Is there way to avoid hitting the harddisk, and keep *.py file in memory and access it there. Would creating a small gui using Wxframe, keep code in memory, and reuse work ...

PEP8 and PyQt, how to reconcile

I'm starting to use PyQt in some projects and I'm running into a stylistic dilemma. PyQt's functions use camel case, but PEP8, which I prefer to follow, says to use underscores and all lowercase for function names. So on the one hand, I can continue to follow PEP8, meaning that my code will have mixed functions calls to camel case and ...

[python] socket.error errno.EWOULDBLOCK

i'm reading some code and i've come across this line socket.error errno.EWOULDBLOCK can anyone tell me what the conditions have to be to raise this error? ...

How do I check if two variables reference the same object in Python?

x and y are two variables. I can check if they're equal using x == y. But how can I check if they have the same identity? Example: x = [1, 2, 3] y = [1, 2, 3] Now x == y is True because x and y are equal. However, x and y aren't the same object. I'm looking for something like sameObject(x,y) which in that case is supposed to be False...

When is the `==` operator not equivalent to the `is` operator? (Python)

I noticed I can use the == operator to compare all the native data types (integers, strings, booleans, floating point numbers etc) and also lists, tuples, sets and dictionaries which contain native data types. In these cases the == operator checks if two objects are equal. But in some other cases (trying to compare instances of classes I...

How to ignore pyc files in Netbeans project browser (regex question)

I want to ignore .pyc files in the Netbeans project browser. I think I found a way: TOOLS -> MISCELLANEOUS -> FILES . Here is a section called: Files ignored by the IDE . The field there is waiting for a regex describing the file pattern . The default value for that field is: ^(CVS|SCCS|vssver.?\.scc|#.*#|%.*%|_svn)$|~$|^\.(?!htacces...

Python: quickly loading 7 GB of text files into unicode strings

I have a large directory of text files--approximately 7 GB. I need to load them quickly into Python unicode strings in iPython. I have 15 GB of memory total. (I'm using EC2, so I can buy more memory if absolutely necessary.) Simply reading the files will be too slow for my purposes. I have tried copying the files to a ramdisk and th...