-2
|
|
└── a
|   ├── __init__.py
|   ├── a.py
└── b
    ├─__init__.py
    └── b.py

I want to use method from a.py in b.py

Dexter
  • 1
  • 3
  • 2
    `import a.a`…? `from a import a`…? `from a.a import *`…? – deceze Jan 24 '20 at 13:00
  • from a import * not working for me – Dexter Jan 24 '20 at 13:03
  • 1) Define what "not working for me" means. 2) I didn't suggest `from a import *`. – deceze Jan 24 '20 at 13:04
  • Yeah, you shouldn't be doing 'import *' if its not totally necessary, which isn't in this case. – Dolfa Jan 24 '20 at 13:05
  • @deceze @Dolfa And yes If he is facing issue in ``` from a import *``` then none of the import will work. He has to define path of module in code or in path. – Vaibhav Jadhav Jan 24 '20 at 13:39
  • @Vaibhav We don't know what the issue he's facing even is! Is it "module 'a' not found"? Then yes, it's a path issue. Or is it that `from a import *` imports everything from `a/__init__.py`, which is unexpected? – deceze Jan 24 '20 at 13:42
  • @deceze Actually in comments section he mentioned that ``` from a import *``` doesn't work. So i suggested to add path and check it – Vaibhav Jadhav Jan 24 '20 at 13:44
  • 2
    @Vaibhav But he doesn't say what "doesn't work" *means*! It could very well mean the import works just fine, but he's not finding what he expected since he imported the wrong thing. – deceze Jan 24 '20 at 13:46
  • @deceze Ya that might be the case. Will see if he comment anything :-) – Vaibhav Jadhav Jan 24 '20 at 13:46

1 Answers1

0

Suppose you have a method myMethod() in module a.py and you want to import this in b.py then you can first import module a.py in b.py by typing "import a" in b.py header then call the method using import name as a.myMethod() wherever required.

bihari_gamer
  • 422
  • 5
  • 15