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.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
AppHandwerker
  • 1,758
  • 12
  • 22

3 Answers3

2

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

data = dict((k,request.form[k]) for k in request.form.iterkeys())
ebarr
  • 7,704
  • 1
  • 29
  • 40
1

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

Yosi
  • 59
  • 3
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.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358