python

Python: Is there a way to generate xsd files based on xml examples

I have a list of xml examples I would like to turn into schemas (xsd files). Exactly what the trang tool does (http://www.thaiopensource.com/relaxng/trang.html). I don't like calling trang from my script (i.e doing os.system('java -jar trang...')) - is there a python package I can use instead? ...

itertools or hand-written generator - what is preferable?

I have a number of Python generators, which I want to combine into a new generator. I can easily do this by a hand-written generator using a bunch of yield statements. On the other hand, the itertools module is made for things like this and to me it seems as if the pythonic way to create the generator I need is to plug together various ...

Python 3, easy_install, pip and pypi

What is the current status of easy_install, pip and the repository (pypi.python.org) with regards to Python 3.x? Are there versions of easy_install and/or pip that can install the right versions of packages from there? Else, are they expected soon? ...

using unicode characters with wxPython

hi everybody! i have a problem with wxpython and his rich text control, when i try to insert unicode characters... \xb2 prints an apex '2', '\u2074' should print an apex '4'... edit: i use windows vista... and i tried 'coding cp1252 ' and 'utf-8' but with the same result... 2edit: on vista it crashs, on xp it shows a strange square (i g...

Multiprocessing with python

how can i control the return value of this function pool apply_asyn supposing that I have the following cool import multiprocessing: de fun(..) ... ... return value my_pool = multiprocessing.Pool(2) for i in range(5) : result=my_pool.apply_async(fun, [i]) some code going to be here.... digest_pool.close() digest_pool.join()...

django compressor and clevercss with absolute url paths

when using django, compressor, and clevercss, i set my css url to an absolute path. clevercss is then passed the path of the .ccss file without the COMPRESS_ROOT prefixed (the absolute path). when i set my css url to a relative path, clevercss processes the ccss files, but the browser then correctly looks for relatively placed css files ...

Editing values in a xml file with Python

Hey. I want to have a config.xml file for settings in a Python web app. I made car.xml manually. It looks like this: <car> <lights> <blinkers>off</blinkers> </lights> </car> Now I want to see whether the blinkers are on or off, using xml.etree.ElementTree. import xml.etree.ElementTree as ET tree = ET.parse('car.xml')...

python, sqlite3: Load existing db file to memory

Hi, I have an existing sqlite3 db file, on which I need to make some extensive calculations. Doing the calculations from the file is painfully slow, and as the file is not large (~10 MB), so there should be no problem to load it into memory. Is there a Pythonic way to load the existing file into memory in order to speed up the calculat...

Handling errors in Python scripts

Using pyblog.py, I got the following error, which I then tried to more gracefully handle: Traceback (most recent call last): File "C:\Python26\Lib\SITE-P~1\PYTHON~1\pywin\framework\scriptutils.py", line 325, in RunScript exec codeObject in __main__.__dict__ File "C:\Documents and Settings\mmorisy\Desktop\My Dropbox\python\better...

Why won't the len() function output anything in python 3.1.2?

I installed the 3.1.2 IDLE python console, then I entered this code: >>> a = ['a', 'b', 'c', 'd'] >>> len(a) 4 Directly from the python official docs http://docs.python.org/py3k/tutorial/introduction.html#lists But it does not work in the interpreter as it should, it does not return 4. What am I doing wrong? Are the official docs wr...

Jython - attempting to call functions from JFrame, receiving 'NoneType' error

So I'm playing around with Jython, trying to slap together a generic GUI. Nothing beyond what they have on the Jython Wiki for swing examples. So I declare a JFrame, and then try to add a panel, some text fields, all that good stuff. I get this error when I run it, however. "'NoneType' object has no attribute 'add'" Here's the basic cod...

Google App Engine counters

For all my data in the GAE Datastore I have a model for keeping track of counters/total number of records (since we can't use traditional SUM queries). I want to know the most efficient way of incrementing these global count values whenever I insert/delete a record. This is what I'm currently doing: counter = DBCounter.all().fetch(1) db...

Can modipyd run Doctests?

When doing quick scripts I like to use DocTests to make things a bit quicker, recently I saw someone using autospec at a recent DevCon I attended when they were introducing us to the concept of CodeKata. I spent the train ride home looking for a Python equivalent of Autospec & found modipyd, but I'm struggling to get it to run my doctes...

Doing something before program exit

How can you have a function or something that will be executed before your program quits? I have a script that will be constantly running in the background, and I need it to save some data to a file before it exits. Is there a standard way of doing this? ...

How to get the convert a Jython class to Java class in Jython intepreter?

I am trying to register a User Defined Function with Esper API. It take a class or string type arguement http://esper.codehaus.org/esper-4.0.0/doc/api/com/espertech/esper/client/ConfigurationOperations.html#addImport(java.lang.String) class MyUdf(): @staticmethod def udf(): return 50 conf.addImport(myudf.getClass().get...

Convert Python string to its ASCII representants

How do I convert a string in Python to its ASCII hex representants? Example: I want to result '\x00\x1b\xd4}\xa4\xf3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' in 001bd47da4f3. ...

Where do you get Python SOAPPy forwindows?

I can't seem to install it, computer doesn't know what to open it with, is there something wrong? Do you know a website where I can install it? ...

Google Chart API: trouble with rendering a XYLine graph

I'm trying to make an XYLine with the Google Chart API via the not-so-well-documented GChartWrapper libraries. Here's a portion of the code that is supposed to generate the graph: data = [] traffic_max = 0 date_minmax = [] #I have a number of timestamped readings in two series for site in sites: site_data = get_datapoints_for(site) ...

Python multiprocessing

Hi, I have a "master" process that needs to spawn some child processes. How can I manage these child processes? (for example, restart if the process is dead) Thanks! ...

Flask - how do I combine Flask-WTF and Flask-SQLAlchemy to edit db models?

I'm trying to create an edit page for an existing model (already saved to db). The form object expects a multidict instance to populate its fields. This is what I have: # the model - assumes Flask-SQLAlchemy from flaskext.sqlalchemy import SQLAlchemy db = SQLAlchemyd(app) class Person(db.Model): id = db.Column(db.Integer, primary...