0

this runs fine on my local machine, but as soon as I deploy it the service fails saying invalid syntax "for"

  data = {k: request.form[k] for k in request.form.iterkeys()}   
SyntaxError: invalid syntax

Appreciate the help on this, it's been a very long time since I did anything with Python and this one has got me stumped.

4
  • what versions of Python are you running locally and for the service? Commented Jan 21, 2014 at 22:29
  • 1
    upgrade to python 2.7 Commented Jan 21, 2014 at 22:29
  • 1
    The syntax requires Python 2.7 or newer. Does your server run 2.6 perhaps? Commented Jan 21, 2014 at 22:29
  • Also see Dict comprehension with Python 2.6 Commented Jan 21, 2014 at 22:31

3 Answers 3

2

As others have mentioned, this is probably a version issue. Try:

data = dict((k,request.form[k]) for k in request.form.iterkeys())
Sign up to request clarification or add additional context in comments.

Comments

1

The python version on your local machine might be different from the version you have on the server.

2 Comments

I will check that now.
ah yes, i'm running 2.7 server is running 2.6 - Will see if I can't get that changed. Then try again.
0

Dict comprehensions are a relatively new addition to 2.x. Convert it to a genex that generates (key, value) pairs and pass it to the dict() constructor.

2 Comments

Could provide an example. Not trying to be cheeky, just not familiar with Python.
@SimonH: I linked you to a post with an example in the comments on your question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.