Forums

Python **problem

I have the following code:

def render(templateName, **data):
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    arg = {}
    arg['alphabet'] = alphabet
    temp = {**arg, **data} #This line has a syntax error!

    return render_template(templateName, **temp)

This function is working fine on my home pc. But running it on the server i get a syntax error.

Can someone help me please?

I tried this. The syntax error occurs for 2.7 but not 3.4. Switch to Python 3.

In 2.7, you can use dict.update() to merge data into arg e.g.

arg['alphabet'] = alphabet
arg.update(data)

return render_template(templateName, **arg)

No need for temp unless you need to use arg in its original form for another purpose within the function.