I want to use name from for an argument of a function. But from is a reserved keyword, so python will throw an exception if I decide to use this name for a variable.
How programmers in python deal with it? I think from is a common name for variables, in python as well. Is there any standards in python for how to rename the argument/variable in this case? Do they use prefixes/suffixes like from_?
Advertisement
Answer
Many languages have these challenges. Some ideas:
- As mentioned in the comments, tack an underscore on the end: from_
- Add context or type (also mentioned in comments): from=>from_list
- Mangle the spelling (from=>frm, e.g.class=>klassorcls)
- Use a synonym: from=>source
Each approach has its advantages and disadvantages.