Python variable and filename conflicts

Viewed 480

This is my project structure:

a
├── b.py
└── __init__.py
  • File b.py is empty.

  • File __init__.py is one line:

    b = 'this is a str'
    

Then the following program gives inconsistent result of a.b:

import a
print(a.b)    # str
import a.b
print(a.b)    # module

What is the best way of detecting this kind of name conflict between a variable and a filename?

1 Answers
Related