不带参数的情况下,返回当前本地范围内的名称列表。使用一个参数尝试返回该对象的有效属性列表。
所以我尝试在scrapy
模块内部查看
import scrapy
是正确的模块,还是我错了?
>>>dir(scrapy)
NameError:未定义名称“ scrapy”
我用python完成了newb,然后尝试了解其工作原理。
如何查看内部模块(例如文档示例)
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__loader__', '__name__',
'__package__', '__stderr__', '__stdin__', '__stdout__',
'_clear_type_cache', '_current_frames', '_debugmallocstats', '_getframe',
'_home', '_mercurial', '_xoptions', 'abiflags', 'api_version', 'argv',
'base_exec_prefix', 'base_prefix', 'builtin_module_names', 'byteorder',
'call_tracing', 'callstats', 'copyright', 'displayhook',
'dont_write_bytecode', 'exc_info', 'excepthook', 'exec_prefix',
'executable', 'exit', 'flags', 'float_info', 'float_repr_style',
'getcheckinterval', 'getdefaultencoding', 'getdlopenflags',
'getfilesystemencoding', 'getobjects', 'getprofile', 'getrecursionlimit',
'getrefcount', 'getsizeof', 'getswitchinterval', 'gettotalrefcount',
'gettrace', 'hash_info', 'hexversion', 'implementation', 'int_info',
'intern', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path',
'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1',
'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit',
'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout',
'thread_info', 'version', 'version_info', 'warnoptions']
答案 0 :(得分:2)
在您的python解释器中尝试一下:
In [1]: import scrapy
In [2]: dir(scrapy)
Out[2]:
['Field',
'FormRequest',
'Item',
'Request',
'Selector',
'Spider',
'__all__',
'__builtins__',
'__cached__',
'__doc__',
'__file__',
'__loader__',
'__name__',
'__package__',
'__path__',
'__spec__',
'__version__',
'_txv',
'exceptions',
'http',
'item',
'link',
'selector',
'signals',
'spiders',
'twisted_version',
'utils',
'version_info']
这在Python 2和3中都对我有效。我还确认了它在iPython和标准解释器中均有效。如果即使导入也对您不起作用,则可能是您的环境有些混乱,我们可以进一步排除故障。
import scrapy
是正确的模块,还是我错了?
在这种情况下,scrapy
是一个模块,import scrapy
是使该模块在调用导入的任何上下文中都可用的语法。 This section of the Python tutorial包含有关模块和导入的信息。