dunder包属性不返回包名

时间:2018-01-26 13:22:00

标签: python

只是想获得给定模块的包名,为什么dunder 属性不起作用?

import sys, inspect, os, numpy as np
print("The os package name is " + os.__package__)
print("The np package name is " + np.__package__)
print("The inspect package name is " + inspect.__package__)
print("The sys package name is " + sys.__package__) 

我从上面得到的内容如下:

The os package name is 
The np package name is numpy
The inspect package name is 
The sys package name is

正如您所看到的,它仅适用于numpy,不适用于其他人。有人可以开导我为什么?我错过了什么?

1 个答案:

答案 0 :(得分:1)

查看PEP366

另请查看其他StackOverflow帖子whats-the-purpose-of-the-package-attribute-in-python