python

Iterative printing over parallel lists to print columns in Python

I have vsort and vsorta, both lists with equal numbers of items that should be right next to each other (about 250 elements per list). I want to print them as parallel columns, like so: >>> for x,y in vsort,vsorta: ... print x, y ... Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: too many value...

Add page break to Reportlab Canvas object.

I need to generate a 2 pages pdf report. Pages are completely independent. tried using: mycanvas.drawString(x, y, "Printing on Page 1") mycanvas._pageNumer = 2 mycanvas.drawString(x, y, "Printing on Page 2") and: mycanvas.drawString(x, y, "Printing on Page 1") P = PageBreak() P.drawOn(mycanvas, 0, 1000) mycanvas.drawString(x, y, "Pri...

How to remove elements from XML using Python

Hi, I got stuck with XML and Python. The task is simple but I couldn't resolve it so far and spent on that long time. I came here for an advice how to solve it with couple of lines. Thanks for any help with traversing the tree. I always ended up with too many or too few elements. Elements can be nested without limit. Given example is ju...

Why doesn't sys.stdout.write('\b') backspace against newlines?

Compare: for item in range(0, 5): sys.stdout.write('c') for item in range(0, 5): sys.stdout.write('\b') Works as you would imagine, but: for item in range(0, 5): sys.stdout.write('\n') for item in range(0, 5): sys.stdout.write('\b') still leaves you with five newline characters. Any ideas? ...

How do I yield a pre-unpacked list?

I have a list that is created within an itertools.groupby operation: def yield_unpacked_list(): for key, grp in itertools.groupby(something_to_groupby, key=lambda x: x[0]): subset_of_grp = list(item[2] for item in list(grp)) yield key, subset_of_grp If, for example, subset_of_grp turns out to be [1, 2, 3, 4] and [5...

How do I make bar plots automatically cycle across different colors?

In matplotlib, line plots color cycle automatically. These two line plots would have different colors. axes.plot(x1, y) axes.plot(x2, y) However, bar plots don't. Both these data series will have blue bars. axes.bar(x1, y) axes.bar(x2, y) How do I make bar plots cycle automatically across a predefined set of colors? ...

Associating properties to Class objects

I would like to define properties for classes, and be able to access them before I actually instantiate an object of that class. I'll give some context. My application handles a library of components. Each component is mapped to a Python class. Now I want to know what configuration a component needs, before actually instancing the class...

django weighted questionnaire?

Hello, I've been learning django off and on for a few years now and consider myself an advanced beginner, ha. I'm working on a "weighted questionnaire" (that's the best name I can give it anyway) for a client and have gone in circles about where to go with it. The client has come up with a series of yes or no questions and depending o...

html to text conversion using python language

import urllib2 from BeautifulSoup import * resp = urllib2.urlopen("file:///D:/sample.html") rawhtml = resp.read() resp.close() print rawhtml I am using this code to get text from a html document, but it also gives me html code. What should i do to fetch only text from the html document? ...

Real-world Jython applications

I recently started learning Python. Not yet ventured into coding. During one of my learning sessions, i came accross the term Jython. I googled it & got some information. I would like to know if anyone has implemented any real-world program using Jython. ...

Google App Engine w/ Django - InboundMailHandler appears to only work once

I'm writing an app for Google App Engine (with Python and Django) that needs to receive email and add some elements of the received email messages to a datastore. I am a very novice programmer. The problem is that the script I specify to handle incoming email appears to only run once (until the script is touched). Sending a test email ...

How do you grab a value from the scope from a string

from module import * # adds 'BlahRenderer', 'FooRenderer', 'BarRenderer', etc. class MyClass def __init__(self, value) renderer = "%sRenderer" % value self.RendererClass = ???? I know this can be done by doing the import inside __init__ and then doing locals()[renderer] but how do I do it if the import is at the top...

removing /n from list of words - python

Hi I have a list as below ['Jellicle', 'Cats', 'are', 'black', 'and', 'white,\nJellicle', 'Cats', 'are', 'rather', 'small;\nJellicle', 'Cats', 'are', 'merry', 'and', 'bright,\nAnd', 'pleasant', 'to', 'hear', 'when', 'they', 'caterwaul.\nJellicle', 'Cats', 'have', 'cheerful', 'faces,\nJellicle', 'Cats', 'have', 'bright', 'black', 'eyes...

How to find most common elements of a list?

Hi Given the following list ['Jellicle', 'Cats', 'are', 'black', 'and', 'white,', 'Jellicle', 'Cats', 'are', 'rather', 'small;', 'Jellicle', 'Cats', 'are', 'merry', 'and', 'bright,', 'And', 'pleasant', 'to', 'hear', 'when', 'they', 'caterwaul.', 'Jellicle', 'Cats', 'have', 'cheerful', 'faces,', 'Jellicle', 'Cats', 'have', 'bright', 'bl...

Keeping multiple clients showing up-to-date information in Python?

I am new to network programming but old to Python. I have a simple blotter program that is to be used on multiple client computers. The blotter works two ways, it can show and update the information in the database. To avoid any blotters showing old data, how can I make all blotters re-fetch information from the database as soon as anoth...

Finding the common elements of a list

Hi as per the earlier post. Given the following list: ['Jellicle', 'Cats', 'are', 'black', 'and', 'white,', 'Jellicle', 'Cats', 'are', 'rather', 'small;', 'Jellicle', 'Cats', 'are', 'merry', 'and', 'bright,', 'And', 'pleasant', 'to', 'hear', 'when', 'they', 'caterwaul.', 'Jellicle', 'Cats', 'have', 'cheerful', 'faces,', 'Jellicle', ...

Storing and escaping Django tags and filters in Django models

I am outputting content from my models to my templates, however some model fields call data stored in other models. This happens only in a few fields. I am wondering whether using an if tag to evaluate this would be more efficient compared to storing the django tags inside the models. Answers to this question say that storing django ta...

How to pass data to plugins in Python?

I'm implementing a simple plugin framework for a little Python program and wonder whether there are general best practices for transferring data to plugins? I'm new to Python and this is what I have come up with so far after doing some reading: I will not use global variables, instead data is going to be passed to the plugin classes on ...

smart automatic C code generator with nested if in python

I'm generating automatic C++ code from python, in particular I need to select some events for a list of events. I declare some selections: selectionA = Selection(name="selectionA", formula="A>10") selectionB = Selection(name="selectionB", formula="cobject->f()>50") selectionC = selectionA * selectionB # * means AND this generate the C...

Golem Python Framework

Hi, we started a new project Golem Python Framework. Golem is an engine for creating 2D games (strategies, arcades, games on chessboard) and to learn basics of programming. We are planning a website for trying work with Golem for scholars of elementary schools. You can read more about Golem at Wiki. What is your opinion? Official websit...