jinja2: get loop index of outer loop
In jinja, the variable loop.index holds the iteration number of the current running loop. When I have nested loops, how can I get in the inner loop the current iteration of an outer loop? ...
In jinja, the variable loop.index holds the iteration number of the current running loop. When I have nested loops, how can I get in the inner loop the current iteration of an outer loop? ...
I am interested in controlling an interactive CLI application from python calls. I guess at the most basic level I need a python script that will start a CLI application on the host OS. Pipe anything from stdin to the cli application, and then pipe any output from the cli application to stdout. From this base It should be pretty straig...
This is the script I have: import BeautifulSoup if __name__ == "__main__": data = """ <root> <obj id="3"/> <obj id="5"/> <obj id="3"/> </root> """ soup = BeautifulSoup.BeautifulStoneSoup(data) print soup When ran, this prints: <root> <obj id="3"></obj> <obj id="5"></obj> <obj id=...
I am messing around with the combination of buildout and virtualenv to setup an isolated development environment in python that allows to do reproducible builds. There is a recipe for buildout that let's you integrate virtualenv into buildout: tl.buildout_virtual_python With this my buildout.cfg looks like this: [buildout] develop ...
Hi, Thanks in advance. I have a string: A = 'asdfghjklmn' How can I get a substring having a maximum length which is a multiple of three? ...
I have a list composed of [start position, stop position, [sample names with those positions]] My goal is to remove the duplicates with exact start and stop positions and just add the extra sample to the sample names section. The problem I'm encountering is that when I delete from the list, I end up with an out of range error, because...
I need to write a class that allows a subclass to set an attribute with the name of a function. That function must then be callable from instances of the class. For example, I say I need to write a Fruit class where the subclass can pass in a welcome message. The Fruit class must expose an attribute print_callback that can be set. cla...
If I'm parsing an XML document using lxml, is it possible to view a text representation of an element? I tried to do : print repr(node) but this outputs <Element obj at b743c0> What can I use to see the node like it exists in the XML file? Is there some to_xml method or something? ...
I have an inline model formset, and I'd like to make fields non-editable if those fields already have values when the page is loaded. If the user clicks an "Edit" button on that row, it would become editable and (using JavaScript) I would replace the original widgets with editable ones. I'd like to do something like this when loading t...
I'm building a debugging tool. IPython lets me do stuff like MyCls?? And it will show me the source. ...
I am looking for a library that will allow me to read a mysql dump. I don't want to have to create a MySQL database and import the library and use the MySQL API. I would prefer simply a library that can parse the mysql dump format. I prefer a python library, but other scripting languages are okay. ...
I know how to do this the other way around... it would be: >>> dt.rfc822() 'Sun, 09 Mar 1997 13:45:00 -0500' ...
Can I make assert throw an exception that I choose instead of AssertionError? UPDATE: I'll explain my motivation: Up to now, I've had assertion-style tests that raised my own exceptions; For example, when you created a Node object with certain arguments, it would check if the arguments were good for creating a node, and if not it would...
OK, the docs for Python's libxml2 bindings are really ****. My problem: An XML document is stored in a string variable in Python. The string is a instance of Unicode, and there are non-ASCII characters in it. I want to parse it with libxml2, looking something like this: # -*- coding: utf-8 -*- import libxml2 DOC = u"""<?xml version="1...
Hi Community, I'm getting the (probably trivial) error, but completely clueless about the possible causes. I want to insert two object in the DB using SQLAlchemy. Those objects are related, here are the declarations. Class User: class User(Base): __tablename__ = 'cp_user' id = Column(Integer, Sequence('id_seq'), primary_key=Tr...
Hi all, I am trying to trying to retrieve some values from a user using a QLineEdit widget. When a QPushButton raises a clicked event, I want the text to be retrieved from all QLineEdit widgets and stored in a local MySQL databaase. However, when I try to use string substition in the insert statement, the values don't get substituted. H...
Right now, I can crawl regular pages using urllib2. request = urllib2.Request('http://stackoverflow.com') request.add_header('User-Agent',random.choice(agents)) response = urllib2.urlopen(request) htmlSource = response.read() print htmlSource However...I would like to simulate a POST (or fake sessions)? so that I can go into Facebook ...
I'm looking for the Clojure/Java equivalent to Python's lxml library. I've used it a ton in the past for parsing all sorts of html (as a replacement for BeautifulSoup) and it's great to be able to use the same elementtree api for xml as well -- really a trusted friend! Can anyone recommend a similar Java/Clojure library? About lxml ...
When running.. python setup.py sdist register upload ..I get the following output: running register We need to know who you are, so please choose either: 1. use your existing login, 2. register as a new user, 3. have the server generate a new password for you (and email it to you), or 4. quit Your selection [default 1]: 1 Userna...
I am using Ubuntu 9.10 beta, whose repositories contain boost 1.38. I would like to build the hello-world example. I followed the instructions here (http://www.boost.org/doc/libs/1%5F40%5F0/libs/python/doc/tutorial/doc/html/python/hello.html), found the example project, and issued the "bjam" command. I have installed bjam and boost-bu...