talloaktrees
talloaktrees

Reputation: 3718

How do I read code where "from <module> import *" is used?

Suppose I read code written by someone else where "from import *" is used, how can I determine what module a function is from? Is this the reason why some people frown upon "from import *"?

Upvotes: 2

Views: 1079

Answers (2)

citxx
citxx

Reputation: 2545

from ... import * is the bad style not recommended by PEP8 (python style guide). There are no ways to know which module is function from except the editing the code (replacing from ... impot * to 'import ...' and looking for errors). Unfortunately, those errors will occur only when corresponding parts of code is executed.

Upvotes: 3

Fred Foo
Fred Foo

Reputation: 363567

Yes, this is why from <module> import * is considered bad style. What you can do is remove these * imports one by one, then check which NameErrors you get and solve them one by one by explicit imports.

Upvotes: 5

Related Questions