python

Organizing a large Python project that must share an internal state?

I'm currently in the middle of porting a fairly large Perl The problem is that it uses little Perl tricks to make its code available for useing. I've done about the same with Python, making the codebase one big module for importing. I've had a firm grasp of Python for a long time, but I have no experience with large projects written in P...

Easiest way to generate localization files

Hello - I'm currently writing an app in Python and need to provide localization for it. I can use gettext and the utilities that come with it to generate .po and .mo files. But editing the .po files for each language, one-by-one, seems a bit tedious. Then, creating directories for each language and generating the .mo files, one-by-one...

Parsing specific elements out of a very large HTML file

I have a very large HTML file (several megabytes). I know the data I want is under something like <div class=someName>here</div> What is a good library to parse through the HTML page so I can loop through elements and grab each someName? I want to do this in either C#, Python or C++. ...

Google App Engine: Intro to their Data Store API for people with SQL Background?

Hi All, Does anyone have any good information aside from the Google App Engine docs provided by Google that gives a good overview for people with MS SQL background to porting their knowledge and using Google App Engine Data Store API effectively. For Example, if you have a self created Users Table and a Message Table Where there is a ...

Best scripting language for web development

I have worked on some small web development projects where the server side languages have been PHP, Java and Lisp. Now I want to learn web development seriously. I don't want to use platforms based on PHP or Java. I also want to learn Python in general. Ease of implementation and learning value is more important to me than real-world imp...

setattr with kwargs, pythonic or not?

I'm using __init__() like this in some SQLAlchemy ORM classes that have many parameters (upto 20). def __init__(self, **kwargs): for k, v in kwargs.iteritems(): setattr(self, k, v) Is it "pythonic" to set attributes like this? ...

Apply multiple negative regex to expression in Python

This question is similar to "How to concisely cascade through multiple regex statements in Python" except instead of matching one regular expression and doing something I need to make sure I do not match a bunch of regular expressions, and if no matches are found (aka I have valid data) then do something. I have found one way to do it bu...

Understanding Python decorators

How can I make a decorator in Python that would do the following. @makebold @makeitalic def say(): return "Hello" which should return <b><i>Hello<i></b> I'm not trying to make HTML this way in a real application, just trying to understand how decorators and decorator chaining works. ...

Python: Locks from `threading` and `multiprocessing` interchangable?

Are the locks from the threading module interchangeable with those from the multiprocessing module? ...

Iterating over object instances of a given class in Python

Given a class that keeps a registry of its Objects: class Person(object): __registry = [] def __init__(self, name): self.__registry.append(self) self.name = name How would I make the following code work (without using Person.__registry): for personobject in Person: print personobject While researching I fou...

Unable to get a list of installed Python modules

I would like to get a list of Python modules, which are in my Python installation (UNIX server). How can you get a list of Python modules installed in your computer? ...

Python Check if one of the following items is in a list

I'm trying to find a short way to see if any of the following items is in a list, but my first attempt does not work. Besides writing a function to accomplish this, is the any short way to check if one of multiple items is in a list. >>> a = [2,3,4] >>> print (1 or 2) in a False >>> print (2 or 1) in a True ...

SQLAlchemy many-to-many orphan deletion

I'm trying to use SQLAlchemy to implement a basic users-groups model where users can have multiple groups and groups can have multiple users. When a group becomes empty, I want the group to be deleted, (along with other things associated with the group. Fortunately, SQLAlchemy's cascade works fine with these more simple situations). T...

Dynamic processes in Python

I have a question concerning Python multiprocessing. I am trying to take a dataset, break into chunks, and pass those chunks to concurrently running processes. I need to transform large tables of data using simple calculations (eg. electrical resistance -> temperature for a thermistor). The code listed below almost works as desired, but...

python write string directly to tarfile

Is there a way to write a string directly to a tarfile? From http://docs.python.org/library/tarfile.html it looks like only files already written to the file system can be added. ...

Python multiprocessing: Pool of custom Processes

I am subclassing the Process class, into a class I call EdgeRenderer. I want to use multiprocessing.Pool, except instead of regular Processes, I want them to be instances of my EdgeRenderer. Possible? How? ...

Python: Good place to learn about `multiprocessing.Manager`?

I want to learn to use multiprocessing.Manager. I looked at the documentation but it's not easy enough for me. Anyone knows of a good tutorial or something like that? ...

Can InstantDjango be Used Rather than the Normal Installation

Is it possible to do development just using Instant Django? Do I need to have the normal version working or can I just use this instant version? Has anyone used it? ...

Django: Adding additional properties to Model Class Object

This is using Google App Engine. I am not sure if this is applicable to just normal Django development or if Google App Engine will play a part. If it does, would you let me know so I can update the description of this problem. class MessageModel(db.Model): to_user_id = db.IntegerProperty() to_user = db.StringProperty(multiline=...

How do I tell matplotlib that I am done with a plot?

The following code plots two .ps files, but the second one contains both lines. import matplotlib import matplotlib.pyplot as plt import matplotlib.mlab as mlab plt.subplot(111) x = [1,10] y = [30, 1000] plt.loglog(x, y, basex=10, basey=10, ls="-") plt.savefig("first.ps") plt.subplot(111) x = [10,100] y = [10, 10000] plt.loglog(x, y,...