python

Google App Engine: Preferred/idiomatic way to "refresh" a model from the datastore?

I have observed the following: (Odp is a model) o = Odp.get(odpKey) o.foo = 0 foo() assert o.foo == 1 # fails def foo(): o = Odp.get(odpKey) o.foo += 1 o.put() It looks like the first copy of o isn't refreshed when it's underlying datastore representation is updated. So, what is the preferred way to refresh it? I was thi...

Django: NameError: name 'Category' is not defined

Hi, I'm practicing on Django and using some online tutorial to build a web blog. It went smoothly with the first project, yet when I tried the 2nd one, through developing the first view, there was this statement: categories = models.ManyToManyField(Category, related_name ="packages") In the tutorial, validating the model gives 0 er...

What is the Python equivalent of Perl's DBI?

What is Python's equivalent of Perl's DBI and how do I use it? More specifically, what is the Python equivalent of the following Perl code? use DBI; # connect to a MySQL database my $dbh = DBI->connect("dbi:mysql:database=$database; host=localhost; port=3306", $user, $pass); # select and read a few rows my $sth = $dbh->prepare("SELECT...

End-user-usable layout templating system

I'd like to build a cross-platform (linux and Windows at least) Python app that provides end users with the ability to create and modify layout templates for printed documents. These templates will be used to generate documents by merging them with the results of DB queries. It's important that the system be relatively easy to use and ...

Django admin - Edit parent model and related models on the same page

I want to be able to edit all data on one page. How can i achieve this ? Should i modify my models? If so, then how should i modify them? class TextStyle(models.Model): color = models.CharField(_("color"), max_length=7) style = models.CharField(_("style"), max_length=30) typeface = models.CharField(_("typeface"), max_lengt...

How do I get Monitor resolution in Python?

What is the simplest way to get monitor resolution (Preferably in a tuple)? ...

Python 2 vs. Python 3 - urllib formats

I'm getting really tired of trying to figure out why this code works in Python 2 and not in Python 3. I'm just trying to grab a page of json and then parse it. Here's the code in Python 2: import urllib, json response = urllib.urlopen("http://reddit.com/.json") content = response.read() data = json.loads(content) I thought the equiv...

Python curse getmouse function?

I'm trying to find a way to get mouse click event in curse module in Python. I read the document on http://docs.python.org/library/curses.html and it suggested to do c == curses.getch() if(c == curses.KEY_MOUSE): curses.getmouse() ... However, this "if statement" seems to never get triggered... and if I tried to move the getm...

Google App Engine: Devserver is hideously slow

My devserver has become hideously slow for some reason. (Python, Windows 7, GAE 1.3.3) I'm not sure if I'm doing something wrong, or if it's just not meant to handle the load I'm putting on it. I have 1000 models of a certain type in the datastore. I am trying to delete them with this method: def _deleteType(type): results = type.al...

Mac version of Python doesn't support UTF-8 in curses module? [Solved]

Hi, I'm trying to display a lot of unicode text in my curses application. My development machine is MacOSx 10.6 and I use the default python shipped with Apple. Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin When I added unicode text to the screen, the screen all messed up. I tried to ...

Model-View-Presenter and Three-Tier?

What is the difference between the two architectures: Model-View-Presenter and Three-Tier? I understand the definitions of each when read individually, but I can't readily see how they're different. Is it desktop vs web? I am currently developing a simple desktop application in Python to visualize a complicated data model via a GUI. ...

Python can't locate distutils_path on Mac OSX.

I've been using virtualenv + pip for python development. I'm not sure what happened, but suddenly whenever I try to run a command-line tool or import libraries, I get this error message: Traceback (most recent call last): File "/Users/kyle/.virtualenvs/fj/bin/pip", line 4, in <module> import pkg_resources File "/Users/kyle/.vir...

Pysqlite setup error

When intalling pysqlite on my Mac I get permission denied when it tries to create pysqlite2-doc dir. Any ideas why? Tia, FR ...

FTP request error. Django, FTP, Python

I'm trying to use this expression. And It tell me that: storbinary() takes at most 4 arguments (5 given) ftp.storbinary("STOR " + os.path.basename(name), StringIO(content_str), "rb", 8*1024) I can see here only 4 argument. where is hidden 5th argument. I'm confuse. ...

Matplotlib savefig image trim

The following sample code will produce a basic line plot with no axis and save it as an SVG file: import matplotlib.pyplot as plt plt.axis('off') plt.plot([1,3,1,2,3]) plt.plot([3,1,1,2,1]) plt.savefig("out.svg", transparent = True) Question 1) How do I set the resolution / dimensions off the image? Qestiion 2) There is padding on al...

how to make post requests in python/django?

as described in http://developers.facebook.com/docs/api#publishing i want to make a post request to update a users status .How do i make post requests in python / django? ...

Maintaining relationships between objects in Python

Consider the following hypothetical people management system. Suppose each Person object belong to a number of Group objects and each Group contains a number of Person objects. We could represent it by adding a list to each Person and each Group object, but then we have to keep this in sync when we create, delete or modify an object. On ...

Python Conditional Regular Expression

This is a question involving a conditional regular expression in python: I'd like to match the string "abc" with match(1)="a" match(2)="b" match(3)="c" but also match the string " a" with match(1)="a" match(2)="" match(3)="" The following code ALMOST does this, the problem is that in the first case match(1)="a" but in the secon...

Is it possible to install an msi using python?

is it possible to write a script in python that installs an msi? or is it possible to to make it through any other script? ...

If you add the same string to two different lists or collections in Python, are you using twice the memory?

For instance if you add the same string to a dict and a list? ...