python

group by year, month, day in a sqlalchemy

I want "DBSession.query(Article).group_by(Article.created.month).all()" But this query can't using How do I do this using SQLAlchemy? ...

Django - flush response?

I am sending an AJAX request to a Django view that can potentially take a lot of time. It goes through some well-defined steps, however, so I would like to print status indicators to the user letting it know when it is finished doing a certain thing and has moved on to the next. If I was using PHP it might look like this, using the flus...

Pygtk cellrender combox + progress bar in a treeview

So the issue is if the combobox of the row is open (pop'd up) and I update the progress bar value self.store.set(iter, 2, self.core.progress ) Then the combo box immediately closes, if the update happens a couple of times a second the combobox is useless... Is there a way to update the progress bar without causing the combobox to c...

Weird python behaviour on machine with ARM CPU

What could possibly cause this weird python behaviour? Python 2.6.2 (r262:71600, May 31 2009, 03:55:41) [GCC 3.3.4] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> .1 1251938906.2350719 >>> .1 0.23507189750671387 >>> .1 0.0 >>> .1 -1073741823.0 >>> .1 -1073741823.0 >>> .1 -1073741823.0 >>> It gives...

query for values based on date w/ Django ORM

I have a bunch of objects that have a value and a date field: obj1 = Obj(date='2009-8-20', value=10) obj2 = Obj(date='2009-8-21', value=15) obj3 = Obj(date='2009-8-23', value=8) I want this returned: [10, 15, 0, 8] or better yet, an aggregate of the total up to that point: [10, 25, 25, 33] I would be best to get this data direc...

REST / JSON / XML-RPC / SOAP

Sorry for being the 100000th person to ask the same question. But I guess my case is slightly distinctive. The application is that we'd like to have an Android phone client on 3g and a light python web service server. The phone would do most of the work and do a lot of uploading, pictures, GPS, etc etc. The server just has to respond w...

Set Max Width for Frame with ScrolledWindow in wxPython

I created a Frame object and I want to limit the width it can expand to. The only window in the frame is a ScrolledWindow object and that contains all other children. I have a lot of objects arranged with a BoxSizer oriented vertically so the ScrolledWindow object gets pretty tall. There is often a scrollbar to the right so you can scrol...

Importing external module in IronPython

I'm currently working on an application written in C#, which I'm embedding IronPython in. I generally have no problems about it, but there's one thing that I don't know how to deal with. I want to import an external module into the script. How can I do that? Simple import ext_lib doesn't work. Should I add a path to the lib to sys.path...

How to specify a configuration file for pylint under windows?

I am evaluating pylint as source code checker and I would like to customize the maximum number of characters on a single line. I would like to use a configuration file. I've generated a template thanks to the --generate-rcfile command and I've made my modification. I am trying to run pylint --rcfile=myfile.rc but I can see that my cha...

Python Changing module varibles in another module

Say I am importing the module 'foo' into the module 'bar'. Is it possible for me to change a global variable in foo inside bar? Let the global variable in foo be 'arbit'. Change arbit so that if bar were to call a function of foo that uses this variable, the updated variable is used rather than the one before that. ...

How to insert a row with autoincrement id in a multi-primary-key table?

I am writing a turbogears2 application. I have a table like this: class Order(DeclarativeBase): __tablename__ = 'order' # id of order id = Column(Integer, autoincrement=True, primary_key=True) # buyer's id buyer_id = Column(Integer, ForeignKey('user.user_id', onupdate="CASCADE", ondelete="CASCADE"), primary...

Algorithm to filter a set of all phrases containing in other phrase

Given a set of phrases, i would like to filter the set of all phrases that contain any of the other phrases. Contained here means that if a phrase contains all the words of another phrase it should be filtered out. Order of the words within the phrase does not matter. What i have so far is this: Sort the set by the number of words in ...

Is there a python library/module for creating a multi ssh connection?

I've been searching for a library that can access multiple ssh connections at once, Ruby has a Net::SSH::Multi module that allows multiple ssh connections at once. However I rather prefer coding this in Python, are there any similar SSH module for python? ...

Reading a Django model's field options

Is it possible to read a Django model's fields' options? For example, with the model: class MyModel(models.Model): source_url = models.URLField(max_length=500) ... i.e. how would I programmatically read the 'max_length' option from, say, within a view or form. My current workaround is to define a separate class attribute: cl...

Django: remove GROUP BY added with extra() method ?

Hi (excuse me for my bad english) ! When I make this: gallery_qs = Gallery.objects.all()\ .annotate(Count('photos'))\ .extra(select={'photo_id': 'photologue_photo.id'}) The sql query is : SELECT (photologue_photo.id) AS `photo`, `photologue_gallery`.* FROM `photologue_gallery` LEFT OUTER ...

Beginner graphics program in Python giving 'out of stack space' error

I'm currently learning Python using Zelle's Introductory text, and I'm trying to recreate one of the example programs which uses an accompanying file graphics.py. Because I'm using Python 3.1 and the text was written for 2.x though, I'm using the GraphicsPy3.py file found at http://mcsp.wartburg.edu/zelle/python and renaming it graphics...

How do I do Variable Variables in Python?

How do I accomplish this in Python? Here is an elaborative manual entry, for instance :http://us3.php.net/manual/en/language.variables.variable.php I hear this is a bad idea in general though, and it is a security hole in PHP. I'm curious if anyone knows how as well? ...

making python 2.6 exception backward compatible

I have the following python code: try: pr.update() except ConfigurationException as e: returnString=e.line+' '+e.errormsg This works under python 2.6, but the "as e" syntax fails under previous versions. How can I resolved this? Or in other words, how do I catch user-defined exceptions (and use their instance variables) ...

File open: Is this bad Python style?

To read contents of a file: data = open(filename, "r").read() The open file immediately stops being referenced anywhere, so the file object will eventually close... and it shouldn't affect other programs using it, since the file is only open for reading, not writing. EDIT: This has actually bitten me in a project I wrote - it prompte...

XML parsing in Python

I'd like to parse a simple, small XML file using python however work on pyXML seems to have ceased. I'd like to use python 2.6 if possible. Can anyone recommend an XML parser that will work with 2.6? Thanks ...