0

I am importing a module (i am using its name as module only). Whenever i press

module.__name__ 

it is showing some name Module.module

when i did

print module 

,i go to the path mentioned. I don't have the module, it has a pyd file. I am completely confused about python importing process,What exactly is __name__? How does change in __name__ change the way we import, how does main change while importing

BrenBarn
  • 242,874
  • 37
  • 412
  • 384
Pradyumna
  • 167
  • 2
  • 12

1 Answers1

2

You have several different questions here. __name__ is the name of the module, including any packages from which it was imported. For the __main__ issue, see the link Blender provided. I don't understand what you mean by "change in __name__ changes the way we import".

As for the .pyd file, that is a Python extension written in C. It is basically a DLL that can be imported as a Python module. You can use it from Python, but it's not written in Python.

BrenBarn
  • 242,874
  • 37
  • 412
  • 384
  • e.g., relative imports use `__name__` to find where the module is in package hierarchy i.e., by changing `__name__` you can change what get imported though it is unlikely that OP means exactly that. – jfs Dec 28 '12 at 08:44
  • change in __name__ i mean now i can use modules by the name printed out when "module.__name__" is pressed though there is no module by that name – Pradyumna Dec 28 '12 at 09:02
  • if __name__ is the name of the module when i do module.__name__ why is it showing Module.module but not just the name by which i imported it with – Pradyumna Dec 28 '12 at 09:10
  • @user1869634: `print module` doesn't print `.__name__` it prints module object itself (its representation as a string) that probably includes its type, name, filename. – jfs Dec 28 '12 at 09:14