python中walk函数_python __init__「建议收藏」

python中walk函数_python __init__「建议收藏」walk(a)它的作用是输出a路径下的所有子目录组成的三元组‘(路径,[包含目录],[包含文件])’importosforiinos.walk(“Lib”):print(i)我这里返回的有点多(‘

walk(a)
它的作用是输出a路径下的所有子目录组成的三元组
‘(路径,[包含目录],[包含文件])’

import os
for i in os.walk("Lib"):
    print(i)

我这里返回的有点多

('Lib', ['site-packages', 'tcl8.6'], [])
('Lib\\site-packages', ['pip-19.0.3-py3.7.egg'], ['easy-install.pth', 'setuptools-40.8.0-py3.7.egg', 'setuptools.pth'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg', ['EGG-INFO', 'pip'], [])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\EGG-INFO', [], ['dependency_links.txt', 'entry_points.txt', 'not-zip-safe', 'PKG-INFO', 'SOURCES.txt', 'top_level.txt'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip', ['_internal', '_vendor'], ['__init__.py', '__main__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_internal', ['cli', 'commands', 'models', 'operations', 'req', 'utils', 'vcs'], ['build_env.py', 'cache.py', 'configuration.py', 'download.py', 'exceptions.py', 'index.py', 'locations.py', 'pep425tags.py', 'pyproject.py', 'resolve.py', 'wheel.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_internal\\cli', [], ['autocompletion.py', 'base_command.py', 'cmdoptions.py', 'main_parser.py', 'parser.py', 'status_codes.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_internal\\commands', [], ['check.py', 'completion.py', 'configuration.py', 'download.py', 'freeze.py', 'hash.py', 'help.py', 'install.py', 'list.py', 'search.py', 'show.py', 'uninstall.py', 'wheel.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_internal\\models', [], ['candidate.py', 'format_control.py', 'index.py', 'link.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_internal\\operations', [], ['check.py', 'freeze.py', 'prepare.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_internal\\req', [], ['constructors.py', 'req_file.py', 'req_install.py', 'req_set.py', 'req_tracker.py', 'req_uninstall.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_internal\\utils', [], ['appdirs.py', 'compat.py', 'deprecation.py', 'encoding.py', 'filesystem.py', 'glibc.py', 'hashes.py', 'logging.py', 'misc.py', 'models.py', 'outdated.py', 'packaging.py', 'setuptools_build.py', 'temp_dir.py', 'typing.py', 'ui.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_internal\\vcs', [], ['bazaar.py', 'git.py', 'mercurial.py', 'subversion.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor', ['cachecontrol', 'certifi', 'chardet', 'colorama', 'distlib', 'html5lib', 'idna', 'lockfile', 'msgpack', 'packaging', 'pep517', 'pkg_resources', 'progress', 'pytoml', 'requests', 'urllib3', 'webencodings'], ['appdirs.py', 'distro.py', 'ipaddress.py', 'pyparsing.py', 'retrying.py', 'six.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\cachecontrol', ['caches'], ['adapter.py', 'cache.py', 'compat.py', 'controller.py', 'filewrapper.py', 'heuristics.py', 'serialize.py', 'wrapper.py', '_cmd.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\cachecontrol\\caches', [], ['file_cache.py', 'redis_cache.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\certifi', [], ['cacert.pem', 'core.py', '__init__.py', '__main__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\chardet', ['cli'], ['big5freq.py', 'big5prober.py', 'chardistribution.py', 'charsetgroupprober.py', 'charsetprober.py', 'codingstatemachine.py', 'compat.py', 'cp949prober.py', 'enums.py', 'escprober.py', 'escsm.py', 'eucjpprober.py', 'euckrfreq.py', 'euckrprober.py', 'euctwfreq.py', 'euctwprober.py', 'gb2312freq.py', 'gb2312prober.py', 'hebrewprober.py', 'jisfreq.py', 'jpcntx.py', 'langbulgarianmodel.py', 'langcyrillicmodel.py', 'langgreekmodel.py', 'langhebrewmodel.py', 'langhungarianmodel.py', 'langthaimodel.py', 'langturkishmodel.py', 'latin1prober.py', 'mbcharsetprober.py', 'mbcsgroupprober.py', 'mbcssm.py', 'sbcharsetprober.py', 'sbcsgroupprober.py', 'sjisprober.py', 'universaldetector.py', 'utf8prober.py', 'version.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\chardet\\cli', [], ['chardetect.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\colorama', [], ['ansi.py', 'ansitowin32.py', 'initialise.py', 'win32.py', 'winterm.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\distlib', ['_backport'], ['compat.py', 'database.py', 'index.py', 'locators.py', 'manifest.py', 'markers.py', 'metadata.py', 'resources.py', 'scripts.py', 't32.exe', 't64.exe', 'util.py', 'version.py', 'w32.exe', 'w64.exe', 'wheel.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\distlib\\_backport', [], ['misc.py', 'shutil.py', 'sysconfig.cfg', 'sysconfig.py', 'tarfile.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\html5lib', ['filters', 'treeadapters', 'treebuilders', 'treewalkers', '_trie'], ['constants.py', 'html5parser.py', 'serializer.py', '_ihatexml.py', '_inputstream.py', '_tokenizer.py', '_utils.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\html5lib\\filters', [], ['alphabeticalattributes.py', 'base.py', 'inject_meta_charset.py', 'lint.py', 'optionaltags.py', 'sanitizer.py', 'whitespace.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\html5lib\\treeadapters', [], ['genshi.py', 'sax.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\html5lib\\treebuilders', [], ['base.py', 'dom.py', 'etree.py', 'etree_lxml.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\html5lib\\treewalkers', [], ['base.py', 'dom.py', 'etree.py', 'etree_lxml.py', 'genshi.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\html5lib\\_trie', [], ['datrie.py', 'py.py', '_base.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\idna', [], ['codec.py', 'compat.py', 'core.py', 'idnadata.py', 'intranges.py', 'package_data.py', 'uts46data.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\lockfile', [], ['linklockfile.py', 'mkdirlockfile.py', 'pidlockfile.py', 'sqlitelockfile.py', 'symlinklockfile.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\msgpack', [], ['exceptions.py', 'fallback.py', '_version.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\packaging', [], ['markers.py', 'requirements.py', 'specifiers.py', 'utils.py', 'version.py', '_compat.py', '_structures.py', '__about__.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\pep517', [], ['build.py', 'check.py', 'colorlog.py', 'compat.py', 'envbuild.py', 'wrappers.py', '_in_process.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\pkg_resources', [], ['py31compat.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\progress', [], ['bar.py', 'counter.py', 'helpers.py', 'spinner.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\pytoml', [], ['core.py', 'parser.py', 'test.py', 'utils.py', 'writer.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\requests', [], ['adapters.py', 'api.py', 'auth.py', 'certs.py', 'compat.py', 'cookies.py', 'exceptions.py', 'help.py', 'hooks.py', 'models.py', 'packages.py', 'sessions.py', 'status_codes.py', 'structures.py', 'utils.py', '_internal_utils.py', '__init__.py', '__version__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\urllib3', ['contrib', 'packages', 'util'], ['connection.py', 'connectionpool.py', 'exceptions.py', 'fields.py', 'filepost.py', 'poolmanager.py', 'request.py', 'response.py', '_collections.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\urllib3\\contrib', ['_securetransport'], ['appengine.py', 'ntlmpool.py', 'pyopenssl.py', 'securetransport.py', 'socks.py', '_appengine_environ.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\urllib3\\contrib\\_securetransport', [], ['bindings.py', 'low_level.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\urllib3\\packages', ['backports', 'ssl_match_hostname'], ['six.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\urllib3\\packages\\backports', [], ['makefile.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\urllib3\\packages\\ssl_match_hostname', [], ['_implementation.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\urllib3\\util', [], ['connection.py', 'queue.py', 'request.py', 'response.py', 'retry.py', 'ssl_.py', 'timeout.py', 'url.py', 'wait.py', '__init__.py'])
('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\pip\\_vendor\\webencodings', [], ['labels.py', 'mklabels.py', 'tests.py', 'x_user_defined.py', '__init__.py'])
('Lib\\tcl8.6', [], ['init.tcl'])

我们不看那么多
在这里插入图片描述
site-packages和tcl8.6 是Lib下面的目录,可以看出Lib下面没有文件
所以第一行返回值为:

('Lib', ['site-packages', 'tcl8.6'], [])
#第一个 第一个下的两个文件夹 第一个下没有文件,所以这个列表为空

继续分析:
在这里插入图片描述
site-packages文件夹包含

pip-19.0.3-py3.7.egg, 'easy-install.pth', 'setuptools-40.8.0-py3.7.egg', 'setuptools.pth

第二行为:

('Lib\\site-packages', ['pip-19.0.3-py3.7.egg'], ['easy-install.pth', 'setuptools-40.8.0-py3.7.egg', 'setuptools.pth'])

也就是说‘pip-19.0.3-py3.7.egg’是个文件夹
‘easy-install.pth’, ‘setuptools-40.8.0-py3.7.egg’, ‘setuptools.pth’这3个是文件
但是setuptools-40.8.0-py3.7.egg这货为什么是个文件呢,我有点晕,那应该就是个目录吧


在这里插入图片描述
可以看出pip-19.0.3-py3.7.egg下面有两个文件夹 EGG-INFO和pip,这个pip-19.0.3-py3.7.egg下面没有文件。
第三行输出:

('Lib\\site-packages\\pip-19.0.3-py3.7.egg', ['EGG-INFO', 'pip'], [])

应该都懂了吧


看第四行:
在这里插入图片描述

('Lib\\site-packages\\pip-19.0.3-py3.7.egg\\EGG-INFO', [], ['dependency_links.txt', 'entry_points.txt', 'not-zip-safe', 'PKG-INFO', 'SOURCES.txt', 'top_level.txt'])

可以看出EGG-INFO下面已经没有文件夹了,所以就改道了

Lib\\site-packages\\pip-19.0.3-py3.7.egg\\EGG-INFO#到EGG-INFO这一代断了

接下来就开始EGG-INFO的兄弟pip继续繁衍
Lib\site-packages\pip-19.0.3-py3.7.egg\pip

差不多就这样
来张小甲鱼的图镇帖
在这里插入图片描述

今天的文章python中walk函数_python __init__「建议收藏」分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/64901.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注