View Single Post
  #3   Spotlight this post!  
Unread 18-09-2012, 00:43
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,043
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: "compiler" constants

As you've found out, there are no such things as constants in Python.

There are other oddities that people used to other languages find weird at first. No such thing as private variables in a class or module. Just about everything happens to be a variable of some kind. No enums (though there are neat tricks to simulate enums).

For fun, you can also define functions inside other functions:

Code:
>>> def some_fn():
...     x = 1
...     def _some_other_fn():
...         print x
...     _some_other_fn()
... 
>>> some_fn()
1
Functions can actually be treated like variables too.

Code:
>>> def fn():
...     pass
... 
>>> x = fn
>>> x
<function fn at 0x7ffe4c917578>
>>> x.y = 1
>>> x
<function fn at 0x7ffe4c917578>
>>> x.y
1
But, to actually answer your question, this SO post has a reasonable set of answers about Python's scoping rules.
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote