special method in module

  • Thread starter =?ISO-8859-2?Q?Jan_Proch=E1zka?=
  • Start date
?

=?ISO-8859-2?Q?Jan_Proch=E1zka?=

Hello,
can have modules special methods?
althouht i think that no, i tried following example and i don't, why it
don't works:

----------------------------
file m2.py (imported module)

class Module:
def __getitem__(self,index):
return index
module=Module()
__getitem__=module.__getitem__

---------------------------

file m1.py (main program):

import m2

print m2.__getitem__(17) # prints 17
print m2[17] # raises error
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top