-2

Given the function header:

myfunction(from):
  #some code

I get a syntax error. Is this because "from" is a keyword in Python? If so are all keywords barred from being used as variable names?

Matthew Frost
  • 578
  • 5
  • 13
  • 2
    Also see [here](http://stackoverflow.com/questions/7219082/uses-of-pythons-from-keyword) and [here](http://stackoverflow.com/questions/14595922/list-of-python-keywords). Try to make a greater effort at research before posting questions. – TigerhawkT3 Dec 27 '15 at 12:53

1 Answers1

1

It's a keyword so you can't use it as a name, try:

def my_function(from_):
   # some code
bakkal
  • 54,350
  • 12
  • 131
  • 107
  • Thanks for the confirmation. Is this a common convention in Python to use "keyword_" if you desire to use a keyword as a variable? – Matthew Frost Dec 27 '15 at 12:54
  • Since `_from` _convention_ is used for private names, I use `from_`, or e.g. `from_email` to avoid the keyword conflict – bakkal Dec 27 '15 at 12:56
  • See [here](http://stackoverflow.com/questions/16095188/is-there-a-python-naming-convention-for-avoiding-conflicts-with-standard-module) for info about a trailing underscore. – TigerhawkT3 Dec 27 '15 at 12:58