Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # I have a large number of variables defined as:
  2.  
  3. PLUS = Operator(['+'])
  4. UPLUS = Operator(['+'], 50, Associativity.RIGHT, Arity.UNARY)
  5. MIN = Operator(['-'])
  6. UMIN = Operator(['-', '~'], 50, Associativity.RIGHT, Arity.UNARY)
  7. ...
  8.  
  9. # Is there a way to group those variables into a list (without rewriting all their names - I'll likely be adding additional ones later, and it would be safer to only have to add them in one place)? I still need all of them as separate variables as well. The reason I need a list is because at some point I need to iterate through all of them.
  10.  
  11. # In other words I want to avoid having to do this:
  12.  
  13. PLUS = Operator(['+'])
  14. UPLUS = Operator(['+'], 50, Associativity.RIGHT, Arity.UNARY)
  15. ...
  16. operators = [PLUS, UPLUS, ...]
  17.  
  18. # And instead do something like:
  19.  
  20. operators = [
  21.     PLUS = Operator (['+']),
  22.     UPLUS = Operator(['+'], 50, Associativity.RIGHT, Arity.UNARY),
  23.     ...
  24. ]
  25.  
  26. # The above obviously does not work (throws a syntax error), but is there a way to accomplish this?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement