python

Best method of connection between automated python XMPP server and interface to django?

I have an XMPP server (likely — python, twisted, wokkel), which I prefer not to restart even in the development version, and I have some python module “worker” (which is interface to particular django project), which gets jid and message text and returns some response (text or XML, either way). The question is, what would be the best wa...

how do i stop beautiful soup from skipping rows while parsing?

while using beautifulsoup to parse a table in html every other row starts with <tr class="row_k"> instead of a tr tag without a class Sample HTML <tr class="row_k"> <td><img src="some picture url" alt="Item A"></td> <td><a href="some url"> Item A</a></td> <td>14.8k</td> <td><span class="drop">-555</span></td> <td> <img src="so...

Python mechanize ignores form input in the HTML

Got my little mechanize code: br.open('http://tumblr.com/customize'); print br.response().read() print br.form['edit_tumblelog[cname]'] # there definitely is edit_tumblelog # and br.form['edit_tumblelog[enable_cname]'] works fine Output: ... <br/> <input typ...

how to save Django xml in a file?

Hi, i have this function in a view that shows the xml in the browser, but what i want is to save the xml content in a file, to use in a Flash gallery. def build_xml_menu(request): rubros = Rubro.objects.all() familias = Familia.objects.all() context_data = {'rubros': rubros, 'familias': familias} return render_to_res...

Get POSIX/Unix time in seconds and nanoseconds in Python?

I've been trying to find a way to get the time since 1970-01-01 00:00:00 UTC in seconds and nanoseconds in python and I cannot find anything that will give me the proper precision. I have tried using time module, but that precision is only to microseconds, so the code I tried was: import time print time.time() which gave me a result ...

Migrating data from Plone to Liferay, or how could I retrieve information from Plone's Data.fs

Hello, all. I need to migrate data from a Plone-based portal to Liferay. Has anyone some idea on how to do it? Anyway, I am trying to retrieve data from Data.fs and store it in a representation easier to work, such as JSON. To do it, I need to know which objects I should get from Plone's Data.fs. I already got the Products.CMFPlone.Por...

How to split big numbers?

I have a big number, which I need to split into smaller numbers in Python. I wrote the following code to swap between the two: def split_number (num, part_size): string = str(num) string_size = len(string) arr = [] pointer = 0 while pointer < string_size: e = pointer + part_size arr.append(int(stri...

Elixir create_all() not creating database and tables

Hey, I'm using Elixir 0.7.1 , Sqlalchemy 0.6beta1 , MySQLdb 1.2.2. My Model file 'model.py' looks like this: from elixir import * from datetime import datetime class Author: first_name = Field(Unicode(64)) last_name = Field(Unicode(64)) class Article: title = Field(Unicode(64)) class Category: name = Field(Unicode(64)) setu...

Aggregating across columns in Django

I'm trying to figure out if there's a way to do a somewhat-complex aggregation in Django using its ORM, or if I'm going to have to use extra() to stick in some raw SQL. Here are my object models (stripped to show just the essentials): class Submission(Models.model) favorite_of = models.ManyToManyField(User, related_name="favorite_sub...

Suppose I have 400 rows of people's names in a database. What's the best way to do a search for their names?

They will also search part of their name. Not only words with spaces. If they type "Matt", I expect to retrieve "Matthew" too. ...

Python _ctypes import error on OSX 10.6

Hey all, I'm very new to Python development, and am having a problem with one of my apps in OSX. Technologies being used in this project python 2.6 django google app engine rpx (openid) When loading up the site on my windows app, there are no issues, but when trying to same app on OSX 10.6, I get the following issue: ImportError...

Pyro, Python dns name resolution across subnets

The task is to access/connect-to Pyro objects on computer A (Pyro's name servers are broadcasting both tcp and udp packets on port 9090), from computer B which is across the internets. I made a set of tunnels connecting A & B with autossh on 7766 & 9090 (the ports Pyro uses out of the box) which didn't seem to do the trick. My next thoug...

How do you NOT automatically dereference a db.ReferenceProperty in Google App Engine?

Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a way for me to do foo.bar without a query being made to Datastore? The docs say that foo.bar will be an instance of Key, so I would expect to be able to do foo.bar.id() and be able to get the id of the Bar that's associated with foo...

Python Libraries and drivers

I have no knowledge of Python. I started with .NET and than learned PHP. Someone later asked me to learn Ruby as well. I started learning it. Since last few months I am seeing many libraries and drivers written in Python. I want to know what are the advantages of Python over PHP/Ruby? What type of language it is and is there a need to le...

Python 3.1.1 'else if' Syntax

I'm a new Python programmer who is making the leap from 2.6.4 to 3.1.1. Everything has gone fine until I tried to use the 'else if' statement. The interpreter gives me a syntax error after the 'if' in 'else if' for a reason I can't seem to figure out. def function(a): if a == '1': print ('1a') else if a == '2' pr...

How do I set up QtDesigner for a project that has animated elements?

I'm writing a project to simulate creatures moving around a map. These can be represented by simple circles, but I need a map/grid and those circles animated on top of the map. What elements should I use in QtDesigner to set up for this kind of GUI in my project? I've yet to do anything like this before ...

Using Tkinter in python to edit the title bar

I am trying to add a custom title to a window but I am having troubles with it. I know my code isn't right but when I run it, it creates 2 windows instead, one with just the title tk and another bigger window with "Simple Prog". How do I make it so that the tk window has the title "Simple Prog" instead of having a new additional window. ...

Sending gzipped form data

I've heard how browsers can receive gzipped pages from the server. Can they also gzip form data that they send to the server? And if it's possible, how would I decompress this data on the server? I'm using AppEngine's webapp module, but a general explanation / pointers to tutorials would be sufficient. I've done some googling to no avai...

algorithm to find independent sets

Folks, I have a problem. I am a writing a script in python which consists of several modules. Some of the modules are dependent on other modules, hence they should be run only after the dependent modules are successfully run. So each modules derives from a base class module and overrides a list called DEPENDENCIES which is a list of depe...

Detect workstation/System Screen Lock using Python(ubuntu)

Is there anyway that we can detect when the system/screen gets locked and notify some event to trigger in Ubuntu ? ...