lxml python 2.5 ElementMaker syntax error

I have the following code:

from lxml.builder import ElementMaker E = ElementMaker() params = [E.param('1'), E.param('2')] E.p( *params, count='2')

This works fine in python 2.6, but when I run it with python 2.5, I get the following error:

E.p( *params, count='2') ^ SyntaxError: invalid syntax

I can't figure out why this is happening. Why does 2.5 throw this error? How can I fix it?

--------------Solutions-------------

You can't follow * with keyword arguments in Python before 2.6. You can try:

E.p(*params, **{'count': '2'})

or if you'd rather:

E.p(*params, **dict(count='2')})

Category:python Time:2011-03-15 Views:1

Related post

  • Python exception text on syntax errors (boost library) 2011-02-17

    I've got this code snnipet (the whole program compiles and links correctly): ... try { boost::python::exec_file( "myscript.py", // this file contains a syntax error my_main_namespace, my_local_namespace ); return true; } catch(const boost::python::er

  • Trying to convert php to python and getting a syntax error 2011-03-29

    I'm trying to convert some php code into python and am using curl. I've gotten most of it to be accepted, but when it gets to the result = pycurl.exec(Moe) it keeps throwing a syntax error. I guess that I'm not filling out the exec field correctly, b

  • python 3 IRC bot syntax error 2011-07-25

    Okay, first off. I'm very new to python, and I've just started to teach myself python 3 As a fun project to help me learn I decieded to do an IRC Bot, I figured I'll follow a basic tutorial on creating a basic bot, and as I learn I could add more to

  • Is there a better way to check Python code for a syntax errors without external modules? 2011-07-29

    As the title says, is there a better way to check a Python source for syntax errors without the use of external modules? I mean, in sense of a more Pythonic style or a more performant way. def CheckSyntax(source, raw = False): lines = source.count("\

  • Python sqlite3 create table syntax error 2011-08-02

    Whenever I try to create a table using python and sqlite3, it gives me the following error: Traceback (most recent call last) File "directory.py", line 14, in <module> 'Children' TEXT, 'Other' TEXT, 'Masul' TEXT);''') sqlite3.OperationalError:

  • Why does this python code have a syntax error? 2013-01-29

    To practice python, I made a simple class for a tree structure in which each node can have infinite child nodes. class Tree(): def __init__(self, children, val): self.children = children self.val = val def add(self, child): self.children.append(child

  • Basic Python Hello World Program Syntax Error 2012-01-05

    I am not that really new in Programming but in Python I am really a newbie, and so when I started learning Python from the tutorials they encouraged me to use the IDLE editor for Python. And so as a newbie I had this weird Hello World problem. as you

  • Why is python giving me a Syntax error? 2012-04-28

    I have this code from a tutorial: #File called test 1 def sanitize(time_string): 2 if '-' in time_string: 3 splitter = '-' 4 elif ':' in time_string: 5 splitter = ':' 6 else: 7 return(time_string) 8 (mins, secs) = time_string.split(splitter) 9 return

  • syntax error in python: 2010-06-14

    This question already has an answer here: Syntax error on print with Python 3 6 answers I'm learning python. It gives syntax error in this script. I'm unable to figure out. import exceptions class FOUND(Exception): pass x = [1,2,3,4,56,73,29,35,12,32

  • Python print statement "Syntax Error: invalid syntax" 2011-09-28

    This question already has an answer here: Syntax error on print with Python 3 6 answers Why is Python giving me a syntax error at the simple print statement on line 9? import hashlib, sys m = hashlib.md5() hash = "" hash_file = raw_input("What is the

  • Export PYTHONPATH - syntax error 2010-06-24

    I need to connect MySQLdb - module. I download MySQLdb - module and install it. But when i write (in python interactive shell): import MySQLdb - i get no module named MySQLdb. Then i decided to include MySQLdb directory in PYTHONPATH variable. I writ

  • Check if string contains one value or another, syntax error? 2010-10-30

    I'm coming from a javascript backend to Python and I'm running into a basic but confusing problem I have a string that can contain a value of either 'left', 'center', or 'right'. I'm trying to test if the variable contains either 'left' or 'right'. I

  • psycopg2 fails on execute many statement with syntax error 2011-11-12

    I have data coming from mongodb which looks like data = ( { u'name': 'A', u'primary_key': 1 }, { u'name': 'B', u'primary_key': 2 }, { u'name': 'C', u'primary_key': 3 } ) when I call the following cur = conn.cursor() cur.executemany("""INSERT INTO ddm

  • Python weird SyntaxError: invalid syntax 2012-04-22

    I tried to run this python code but received syntax error after this line: from tempfile import NamedTemporaryFile #!/usr/bin/env python from sys import argv from subprocess import check_call from os.path import basename, splitext, join from tempfile

  • Syntax error whenever I put Python code inside a Django template 2008-11-09

    I'm trying to do the following in my Django template: {% for embed in embeds %} {% embed2 = embed.replace("&lt;", "<") %} {{embed2}}<br /> {% endfor %} However, I always get an invalid block or some syntax error when I do anything like t

  • Syntax error on print with Python 3 2009-05-05

    Why do I receive a syntax error when printing a string in Python 3? >>> print "hello World" File "<stdin>", line 1 print "hello World" ^ SyntaxError: invalid syntax --------------Solutions------------- In Python 3.0, print became a fun

  • gnuplot syntax error when using python 2009-06-24

    I am just about to find out how python and gnuplot work together. On http://wiki.aims.ac.za/mediawiki/index.php/Python:Gnuplot_module I found an introduction and I wanted to execute it on my Ubuntu machine. import Gnuplot gp = Gnuplot.Gnuplot(persist

  • SQL syntax error using Python and psycopg 2009-11-22

    How can you fix this SQL-code? My Python code: import os, pg, sys, re, psycopg2 conn = psycopg2.connect("dbname=tk user=masi password=123") cur = conn.cursor() cur.execute("""INSERT INTO courses ('course_nro') VALUES ( `:1` )""", ['hen']) I get: Trac

  • Why is this a python syntax error during an initialisation? 2009-12-23

    This code: class Todo: def addto(self, list_name="", text=""): """ Adds an item to the specified list. """ if list_name == "": list_name = sys.argv[2] text = ''.join(sys.argv[3:] todo_list = TodoList(getListFilename(list_name)) produces a syntax erro

Copyright (C) pcaskme.com, All Rights Reserved.

processed in 0.557 (s). 13 q(s)