O
Olive
I am learning python -
I am creating a new class: package (to analyse the packages database in
some linux distros). I have created a class package such that
package("string") give me an instance of package if string is a correct
representation of a package. I would like that if pack is already an
instance of package then package(pack) just return pack.
This is exactly the behaviour of many of the built-in types. For
example:
I note here that b is not a new instance of complex, it is another name
for a (as we can see with a is b). I would like to implement such
behaviour but I do not not how.
Olive
I am creating a new class: package (to analyse the packages database in
some linux distros). I have created a class package such that
package("string") give me an instance of package if string is a correct
representation of a package. I would like that if pack is already an
instance of package then package(pack) just return pack.
This is exactly the behaviour of many of the built-in types. For
example:
Code:
[oesser@pcolivier ~]$ python2
Python 2.7.3 (default, Apr 24 2012, 00:06:13)
[GCC 4.7.0 20120414 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.True
I note here that b is not a new instance of complex, it is another name
for a (as we can see with a is b). I would like to implement such
behaviour but I do not not how.
Olive