python import within import
Question: i am trying to import a module within a module and then access the lower level
module from the top, however it is not available. is this normal behaviour?

    
    
    # caller.py
    import first
    print second.some_var
    
    # first.py
    import second
    
    # second.py
    some_var = 1
    

running `caller.py` gives error

    
    
    NameError: name 'second' is not defined
    

do i have to `import second` within `caller.py`? this seems counter-intuitive
to me.


Answer: You can use

    
    
    import first
    print first.second.some_var
    

Having `second` appear in the namespace automatically just by importing
`first` would lead to lots of conflicts

This would also work

    
    
    from first import second
    print second.some_var
    

The use of wildcard

    
    
    from first import *
    

is discouraged because if someone adds extra attributes/functions to `first`
they may overwrite attributes you are using locally if they happen to choose
the same name

