python

On Google AppEngine what is the best way to merge two tables?

If I have two tables, Company and Sales, and I want to display both sets of data in a single list, how would I do this on Google App Engine using GQL? The models are: class Company(db.Model): companyname = db.StringProperty() companyid = db.StringProperty() salesperson = db.StringProperty() class Sales(db.Model): ...

How can I check if a box is alive or down using the ip address in Python?

I'm wondering how are you able to do this? ...

Numpy: Is there an array size limit?

I'm learning to use Numpy and I wanted to see the speed difference in the summation of a list of numbers so I made this code: np_array = numpy.arange(1000000) start = time.time() sum_ = np_array.sum() print time.time() - start, sum_ >>> 0.0 1783293664 python_list = range(1000000) start = time.time() sum_ = sum(python_list) print time....

tuple list from dict in python

How can I obtain a list of key-value tuples from a dict in python? Thanks ...

How can I read a python pickle database/file from C?

I am working on integrating with several music players. At the moment my favorite is exaile. In the new version they are migrating the database format from SQLite3 to an internal Pickle format. I wanted to know if there is a way to access pickle format files without having to reverse engineer the format by hand. I know there is the cPi...

Bruce Eckel's code snippet from Design Pattern: I'm confused on how it works

I've been reading Thinking in python by Bruce Eckel. Currently, I'm reading the Pattern Concept chapter. In this chapter, Eckel shows the different implementations of Singletons in python. But I have an unclear understanding of Alex Martelli's code of Singleton (utilizing inheritance, instead of privated nested class). This is my under...

simple python script to block nokia n73 screen

Hi, i want that upon opening my N73's camera cover,the camera software keeps working as usual,but that it is blocked by a black screen covering the whole screen so that it appears that the camera is not working... I know my requirement is weired but i need this.. ;) Can anyone guide me to write a python script that does exactly this......

Parse Gmail with Python and mark all older than date as "read"

Long story short, I created a new gmail account, and linked several other accounts to it (each with 1000s of messages), which I am importing. All imported messages arrive as unread, but I need them to appear as read. I have a little experience with python, but I've only used mail and imaplib modules for sending mail, not processing acco...

Python - Find Path to File Being Run

How can I find the full path to the currently running python script? That is to say, what do I have to put to achieve this: Nirvana@bahamut:/tmp$ python baz.py running from /tmp file is baz.py ...

Efficiency of using a Python list as a queue

A coworker recently wrote a program in which he used a Python list as a queue. In other words, he used .append(x) when needing to insert items and .pop(0) when needing to remove items. I know that Python has collections.deque and I'm trying to figure out whether to spend my (limited) time to rewrite this code to use it. Assuming that ...

Does IronPython implement python standard library?

I tried IronPython some time ago and it seemed that it implements only python language, and uses .NET for libraries. Is this still the case? Can one use python modules from IronPython? ...

Getting system status in python

Is there any way to get system status in python, for example the amount of memory free, processes that are running, cpu load and so on. I know on linux I can get this from the /proc directory, but I would like to do this on unix and windows as well. ...

Match all urls that aren't wrapped into <a> tag

Hi all! I am seeking for a regular expression pattern that could match urls in HTML that aren't wrapped into 'a' tag, in order to wrap them into 'a' tag further (i.e. highlight all non-highlighted links). Input is simple HTML with 'a', 'b', 'i', 'br', 'p' 'img' tags allowed. All other HTML tags shouldn't appear in the input, but tags m...

Django ModelChoiceField initial data not working for ForeignKey

I am filling my form with initial data using the normail: form = somethingForm(initial = { 'title' : something.title, 'category' : something.category_id, }) The title works fine, but if the category is a ModelChoiceField and a ForeignKey in the model, the init...

SQLAlchemy(Postgres) and transaction

I want a record from a table(queue) to be selected, locked(no other process can edit this record) and updated at a later point in time. I assumed if I put the whole querying and updating in a transaction, no other process can edit/query the same record. But I am not quite able to achieve this. def move(one, two): from settings import ...

in GTK, how do I get the original normal bg color of a widget?

I do this: self.origbg = self.style.bg[gtk.STATE_NORMAL] and later in my eventboxes I change the bgcolor to it by doing: self.modify_bg(gtk.STATE_NORMAL, color) However, the color actually changes! It's not the state_normal color that I get from looking at self.style.bg . On my Windows, it's a slightly lighter tint. How do ...

Python: Which modules for a discussion site?

A site should be ready in 6 days. I am not allowed to use any framework such as Django. I am going to use: Python modules HTMLGen to generate HTML code from class-based description SQLObject, relational tables onto Python's class model ? Other Python 2.5 A variant of the Postgres schema Super Smack for testing the schema Which m...

Django modelformset factories and many to many object relationships - how to pass it a particular value

Hey all, I have an issue where a particular modelform whose object is a many-to-many field pulls up the first entry there by default when passed to a modelformset_factory. An example follows: Say I have an Order object that has a many-to-many relationship with a Group. I have a form whose only editable field is a single input box with ...

Django RSS Feed Problems

I'm working on a blogging application, and trying to made just a simple RSS feed system function. However, I'm running into an odd bug that doesn't make a lot of sense to me. I understand what's likely going on, but I don't understand why. My RSS Feed class is below: class RSSFeed(Feed): title = settings.BLOG_NAME description = ...

read wordperfect files with python?

Hi all, I really need to work with information contained in word perfect 12 files without using WP's sluggish visual interface, but I can't find any detailed documentation about the file format or any python modules for reading/writing the files. I found a post on the web that seems to explain how to convert WP to text, but I didn't und...