python模塊導入

[seemmo@RegionServer1 duwen]$ python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>> import Student
>>
>>
>>
>> s = Student()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>
>>
>> from Student import *
>>
>> s = Student()
>>

原因:

import module 和 from module import,區別是前者所有導入的東西使用時需加上模塊名的限定,而後者不要。

可以試試:

[seemmo@RegionServer1 duwen]$ python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>> import Student
>>
>> s = Student()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>
>>
>> s = Student.Student()
>>
>>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章