Can I reference 1 instance of an object by more names ?
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Wed May 23 03:24:11 EDT 2007
Stef Mientki a écrit :
> hello,
>
> I'm trying to build a simple functional simulator for JAL (a Pascal-like
> language for PICs).
> My first action is to translate the JAL code into Python code.
> The reason for this approach is that it simplifies the simulator very much.
> In this translation I want to keep the JAL-syntax as much as possible
> intact,
> so anyone who can read JAL, can also understand the Python syntax.
>
> One of the problems is the alias statement, assigning a second name to
> an object.
> I've defined a class IO_port,
> and I create an instance of that port with the name port_D
>
> port_D = IO_port('D')
>
> Now I want to assign a more logical name to that port,
> (In JAL: "var byte My_New_Name IS port_D")
>
> Is that possible ?
>
> I think the answer is "no",
> because the object itself is not mutable.
> Am I right ?
You're wrong. The fact that an object is mutable or not is totally
irrelevant here. In Python, 'variables' are in fact name=>ref_to_object
pairs in a namespace (while this may not always be technically true, you
can think of namespaces as dicts). So the name is nothing more than
this: a name. And you can of course bind as many names as you want to a
same object.
port_D = IO_port('D')
foo = port_D
bar = foo
bar is port_D
=> True
More information about the Python-list
mailing list