Background
Look at flower when you see the __main__.py file, do not know what to do with the specific?
So first test to see.
"Test Code"
The test code directory structure is as follows:
. '--Test |--__init__.py |--__main__.py |--dep.py
__init__.py is empty, indicating that test is a package
__main__.py content is as follows:
[Email protected] ice_test_m 20141024]# more test/__main__.py #!/usr/bin/env python2.7#-*-Coding:utf8-*from __future_ _ Import absolute_importfrom. dep Import DEPCLASSADEP = Depclass ()
dep.py content is as follows:
[Email protected] ice_test_m 20141024]# more Test/dep.pyclass Depclass (object): def __init__ (self): print " Init Depclass "
An error occurred while running __main__.py directly:
[Email protected] ice_test_m 20141024]#/test/__main__.py Traceback (most recent call last): File "./test/__main__ . Py ", line 6, in <module> DEP import depclassvalueerror:attempted relative import in Non-package
I've met this mistake before.
http://i.cnblogs.com/EditPosts.aspx?postid=4030852
A Python script that contains a relative path import cannot be run directly and can only be referenced as a module.
If you want to run it, you need to do this:
[Email protected] ice_test_m 20141024]# python2.7-m test.__main__ Init depclass
__main__.py usage of Python