python

Expanding elements in a list

Hi, I'm looking for a "nice" way to process a list where some elements need to be expanded into more elements (only once, no expansion on the results). Standard iterative way would be to do: i=0 while i < len(l): if needs_expanding(l[i]): new_is = expand(l[i]) l[i:i] = new_is i += len(new_is) else: i += 1 ...

How to start a local port on user's computer (Edited question)

Hi guys, sorry in the past I have not been able to formulate my question coherently. This will be my last try. =| Basically, I want to do something like this website is doing: http://www.ninjavideo.net/video/56388. They are rendering an iframe that points to a port on localhost. You will see nothing in the iframe if you dont have their ...

entropy in txt file

Hello, I have a text file with numbers in it as follows: 1231313123123123 1432423432535345 3532523452345345 1231423432453455 3434535345345345 3452353453253453 all the lines are the same length, I want to calculate entropy on each line and have output as: 2.64234234 2.65464564 2.35355435 etc. Right now with this piece of code I have...

Code review/mentoring service

Is there a resource where I can find reliably good programmers to read my code and tell me what I can do better? I would like to know if I can design my programs better, whether there are best practices that I'm not following, and whether I'm using the ideal tools for the task at hand. I would like more consistent and intensive mentoring...

Multithreading with pyqt - Can't get the separate threads running at the same time?

I am trying to get a PyQT GUI running ontop of my python application and I have tried to get it separated into 2 threads so the GUI would be responsive while my main running loop goes, but I have not been able to get it going. Maybe I am misunderstanding it. Here is what I've tried: My Window and Worker thread are defined as follows: ...

wxPython GUI: migrating gnuplot to matplotlib

I currently have a GUI built in wxPython with several sections, one of which displays a .png image of a plot: self.plot = wx.BitmapButton(self.pane_system, -1, wx.Bitmap("/home/myname/projects/newton/plot/src/graph.png", wx.BITMAP_TYPE_ANY)) In another part of the GUI, there is a place where I can edit parameters. The current setup is...

Python tables <-> sqlite Rosetta stone ?

Is there a "Rosetta stone" which shows how to use Python tables of namedtuples in sqlite3 ? Say we have a namedtuple Row and a list or dict rows: Row = namedtuple( "Row", "name city x y" ) rows = [None, Row( "Jones", "Boston", 3, 4 ), Row(...) ... ] # translate the following to sqlite please -- rows[id] rows[id] = Row(...) rows.ap...

Thread safe locale techniques

We're currently writing a web application based on a threaded python web server framework (cherrypy) and would like to simultaneously support users from multiple locales. The locale module doesn't appear to be thread safe. Are there 3rd party libraries or modules that provide locale parsing and formatting functionality in a thread-safe ...

Use a Glob() to find files recursively in Python?

This is what I have: Glob(os.path.join('src','*.c')) but I want to search the subfolders of src. Something like this would work: Glob(os.path.join('src','*.c')) Glob(os.path.join('src','*','*.c')) Glob(os.path.join('src','*','*','*.c')) Glob(os.path.join('src','*','*','*','*.c')) But this is obviously limited and clunky. ...

how to remove all instances of an element from a list in python

lets say I have a=[[1,1],[2,2],[1,1],[3,3],[1,1]] is there a function that remove all instances of [1,1] thanks ...

Getting correct string length in Python for strings with ANSI color codes

I've got some Python code that will automatically print a set of data in a nice column format, including putting in the appropriate ASCII escape sequences to color various pieces of the data for readability. I eventually end up with each line being represented as a list, with each item being a column that is space-padded so that the sam...

proxy-like python module

Can a python module hand over other module in case of self being imported? ...

how to check if request is ajax in turbogears

How do I go about checking if a request is an ajax request in a controller method in Turbogears? Further, is it possible to return a 'partial' much like in rails or symfony if the request is an ajax request. I know about the json decorator but I need a way to return a partial of a mako template (because I need to format the data and don'...

Python: range and xrange for 13-digit numbers?

range() and xrange() work for 10-digit-numbers. But how about 13-digit-numbers? I didn't find anything in the forum. Thanks in advance. ...

How can I catch server json response while uploading image using Ajax?

I have a form which is loaded via jQuery from the external template file: $('#imguploadform').html('&nbsp;').load('{% url upload_form %}'); In template it looks like this: <img src="{{ MEDIA_URL }}img/misc/upload.png" alt="Illustration" title="myimage" /> <form id="uploadForm" enctype="multipart/form-data" method="post" action="uploa...

Python: Print only the message on warnings

I'm issuing lots of warnings in a validator, and I'd like to suppress everything in stdout except the message that is supplied to warnings.warn(). I.e., now I see this: ./file.py:123: UserWarning: My looong warning message some Python code I'd like to see this: My looong warning message Edit 2: Overriding warnings.showwarning() tu...

Manage Increasingly complex Django URL views efficiently? (urls.py)

So, I have this Django application and I keep adding new features to provide ever more granular views of the data. To give a quick idea of the problem, here's a subset of urls.py: # Simple enough . . . (r'^$', 'index'), (r'^date/(?P<year>\d{4})$', 'index'), (r'^date/(?P<year>\d{4})-(?P<month>\d{2})$', 'index'), (r'^date/(?P<year>\d{4})...

Making a module global?

I would like to know why >>> def func2(): ... global time ... import time ... >>> time Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'time' is not defined >>> func2() >>> time <module 'time' (built-in)> >>> works, but >>> def func(): ... global module ... module="time" .....

readonly_field in django

Possible Duplicate: In a django form, How to make a field readonly (or disabled) so that it cannot be edited? I am making a production server in django admin where I have an integerfield available = models.IntegerField(blank=True, help_text="(updated on save)") I was wondering if I could make this a readonly field that wont...

Installing numpy broke NLTK (OS X 10.6.2, Python 2.6)

I had a working installation of NLTK (py26-nltk) on my Mac (OS X 10.6.2). Then I installed numpy. Now when I try to import nltk, I get this: >>> import nltk Traceback (most recent call last): File "<stdin>", line 1, in <module> File "nltk/__init__.py", line 83, in <module> from collocations import * File "nltk/collocations.py"...