Python treat module name as 'NoneType'
Question: I have a piece of code that behaves strangely.

At the beginning, I import a module, which is a python binding for a C
library.

    
    
    try:
        import pyccn
    except:
        print "ERROR: PyCCN is not found"
        exit(1)
    

Later in my code, I use pyccn module to do quite a lot stuff, and it was
working as expected (almost). Now after working correctly for quite a while,
it gives me the error:

    
    
     Traceback (most recent call last):
       File "./ndn-ls-keys.py", line 185, in upcall
         if kind == pyccn.UPCALL_CONTENT_UNVERIFIED:
     AttributeError: 'NoneType' object has no attribute 'UPCALL_CONTENT_UNVERIFIED'
    

So it say 'pyccn' is NoneType!! But it was working, I mean the same function
that includes line 185 was called multiple times before the error happens. And
the error happens consistently. I didn't redefine 'pyccn', was just using
'pyccn.foo(), pyccn.bar(), etc'.

What are the possible reasons that this could happen?

P.S. The error happens at the end of my script. If I put a time.sleep(10)
there, then it happens after the sleeping...

Thanks!


Answer: I somehow solved this problem. Originally, immediately below the import for
PyCCN, I have two other imports:

    
    
        import xml.etree.ElementTree as ET
        import time
    

So the imports are global to this file.

Once I moved these two imports inside the function where they are actually
used, the problem went away!! The move is the only change and I don't know the
reason behind this fix.

Perhaps there is some conflicts between the imports due to some problem in
pyccn module? (I assume the standard libraries are not responsible for this
problem).

