@woojsung , You cannot declare variables in Python, since python doesn’t have “declaration” nor “variables” the way it exists in C sense. At least that’s what I know.
@su.lwpac, Thanks for the reply. Then does this mean the autocomplete for the type doesn’t work for “pt” in this context? If so what is a workaround for Python coders? Thanks,
In Python you don’t need to declare the variables by type, you simply define them in the scope that you need them. Other than that, the variables behave like in every other language.
In Python classes, there are also no private, public, or protected attributes and/or methods.
Everything is basically public, but what is often done for legibility is that supposedly private symbol names have an underscore as prefix (e.g. self._private_variable = 10). That’s purely visual though and not mandatory.
Since, there is no privacy so to speak, you also don’t really need get- or set-methods, expect maybe for code structuring. You simply can access every attribute or method by its description (e.g. MyClass.my_method()).
You seem to be on the right track.
Here’s an example on how I would probably do this:
import Rhino.Geometry as rg
class SomeClass:
def __init__(self):
"""Default constructor initialises this class"""
self._pt = rg.Point3d.Origin # _pt is a "private" attribute
def get_zval(self):
"""Returns the z-coordinate of _pt."""
return self._pt.z
if __name__ == "__main__":
sc = SomeClass() # instatiate a class instance
print( sc.get_zval() )
# Alternatively :
print( sc._pt.z ) # only fake private