Question

Pourquoi est-ce se plaindre d'un syntaxe non valide?

#! /usr/bin/python

recipients = []
recipients.append('chris@elserinteractive.com')

for recip in recipients:
    print recip

Je continue à obtenir:

File "send_test_email.py", line 31
    print recip
              ^
SyntaxError: invalid syntax
Était-ce utile?

La solution

Si vous utilisez print Python 3 est une fonction. Appelez cela comme ceci:. print(recip)

Autres conseils

En python 3, impression n'est plus une déclaration, mais fonction .

Old: print "The answer is", 2*2
New: print("The answer is", 2*2)

Plus python 3 fonctionnalité print:

Old: print x,           # Trailing comma suppresses newline
New: print(x, end=" ")  # Appends a space instead of a newline

Old: print              # Prints a newline
New: print()            # You must call the function!

Old: print >>sys.stderr, "fatal error"
New: print("fatal error", file=sys.stderr)

Old: print (x, y)       # prints repr((x, y))
New: print((x, y))      # Not the same as print(x, y)!

Si c'est Python 3, print est maintenant une fonction. La syntaxe correcte serait

print (recip)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top