Some methods of the OS module in Python

Source: Internet
Author: User

Import Os,sys,time
Print (OS.GETCWD (), ' Get working directory ') #获取工作目录
Print (os.environ[' systemdrive '), ' Get system drive letter ') #获取系统盘符
Print (os.environ[' userprofile '), ' Get user directory ') #获取用户目录
Print (os.environ[' windir '), ' Get Windows directory ') #获取windows目录
For I in Os.walk (' F:\python ', topdown=false,onerror=none): #遍历文件目录
Print (i)
Time.sleep (0.5);

 Output results

F:\python\zw18\ Graduation Design Get working directory
C: Get system drive letter
C:\Users\Administrator getting the user directory
C:\WINDOWS getting the WINDOWS directory

(' F:\\python\\day1\\.idea ', [], [' Day1.iml ', ' modules.xml ', ' workspace.xml '])
(' F:\\python\\day1 ', ['. Idea '], [])
(' F:\\python\\zw18\\.idea\\dictionaries ', [], [' Administrator.xml '])
(' F:\\python\\zw18\\.idea\\inspectionprofiles ', [], [])
(' F:\\python\\zw18\\.idea ', [' dictionaries ', ' inspectionprofiles '], [' Encodings.xml ', ' misc.xml ', ' modules.xml ', ' Workspace.xml ', ' ZW18.IML '])
(' F:\\python\\zw18\\day1\\homework ', [], [' homework_1.py '])
(' f:\\python\\zw18\\day1\\__pycache__ ', [], [])
(' F:\\python\\zw18\\day1 ', [' homework ', ' __pycache__ '], [' Black_user.xml ', ' game.py ', ' hello.py ', ' homework.py ', ' input.py ', ' login.py '])
(' F:\\python\\zw18\\day2\\dada ', [], [])
(' f:\\python\\zw18\\day2\\__pycache__ ', [], [' LOGIN.CPYTHON-36.PYC '])
(' F:\\python\\zw18\\day2 ', [' Dada ', ' __pycache__ '], [' login.py ', ' shopping.py ', ' time.py ', ' data type. py ', ' module first knowledge. Py '])
(' F:\\python\\zw18\\day3 ', [], [' progress bar. Py '])
(' F:\\PYTHON\\ZW18\\QT ', [], [])
(' F:\\python\\zw18\\ Graduation Design ', [], [' qt.py ', ' Get memory _ process _ network. Py ', ' traverse directory. Py '])
(' F:\\python\\zw18 ', ['. Idea ', ' day1 ', ' day2 ', ' day3 ', ' Qt ', ' graduation design '], [])
(' f:\\python\\ directory \\.idea\\inspectionprofiles ', [], [])
(' f:\\python\\ directory \\.idea ', [' inspectionprofiles '], [' Misc.xml ', ' modules.xml ', ' workspace.xml ', ' directory. iML '])
(' f:\\python\\ directory \\venv\\Include ', [], [])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\EGG-INFO ', [], [' Dependency_links.txt ', ' Entry_ Points.txt ', ' not-zip-safe ', ' pkg-info ', ' requires.txt ', ' SOURCES.txt ', ' top_level.txt '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\commands ', [], [' check.py ', ' completion.py ' , ' download.py ', ' freeze.py ', ' hash.py ', ' help.py ', ' install.py ', ' list.py ', ' search.py ', ' show.py ', ' uninstall.py ', ' wheel.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\compat ', [], [' dictconfig.py ', ' __init__.py ‘])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\models ', [], [' index.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\operations ', [], [' check.py ', ' freeze.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\req ', [], [' req_file.py ', ' req_install.py ', ' req_set.py ', ' req_uninstall.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\utils ', [], [' appdirs.py ', ' build.py ', ' deprecation.py ', ' encoding.py ', ' filesystem.py ', ' glibc.py ', ' hashes.py ', ' logging.py ', ' outdated.py ', ' packaging.py ' , ' setuptools_build.py ', ' ui.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\vcs ', [], [' bazaar.py ', ' git.py ', ' mercurial.py ', ' subversion.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\cachecontrol\\caches ', [], [' File _cache.py ', ' redis_cache.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.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 '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\colorama ', [], [' ansi.py ', ' ansitowin32.py ', ' initialise.py ', ' win32.py ', ' winterm.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\distlib\\_backport ', [], [' misc.py ', ' shutil.py ', ' sysconfig.cfg ', ' sysconfig.py ', ' tarfile.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.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 ']
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib\\filters ', [], [' alphabeticalattributes.py ', ' base.py ', ' inject_meta_charset.py ', ' lint.py ', ' optionaltags.py ', ' sanitizer.py ', ' whitespace.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib\\treeadapters ', [], [' genshi.py ', ' sax.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib\\treebuilders ', [], [' base.py ', ' dom.py ', ' etree.py ', ' etree_lxml.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib\\treewalkers ', [], [' base.py ', ' dom.py ', ' etree.py ', ' etree_lxml.py ', ' genshi.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\html5lib\\_trie ', [], [' datrie.py ', ' py.py ', ' _base.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.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 '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\lockfile ', [], [' linklockfile.py ' , ' mkdirlockfile.py ', ' pidlockfile.py ', ' sqlitelockfile.py ', ' symlinklockfile.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\packaging ', [], [' markers.py ', ' requirements.py ', ' specifiers.py ', ' utils.py ', ' version.py ', ' _compat.py ', ' _structures.py ', ' __about__.py ', ' __init_ _.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\pkg_resources ', [], [' __init__.py ‘])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\progress ', [], [' bar.py ', ' counter.py ', ' helpers.py ', ' spinner.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\chardet ', [] , [' big5freq.py ', ' big5prober.py ', ' chardetect.py ', ' chardistribution.py ', ' charsetgroupprober.py ', ' charsetprober.py ', ' codingstatemachine.py ', ' compat.py ', ' constants.py ', ' cp949prober.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 ', ' latin1prober.py ', ' mbcharsetprober.py ', ' mbcsgroupprober.py ', ' mbcssm.py ', ' sbcharsetprober.py ', ' sbcsgroupprober.py ', ' sjisprober.py ' , ' universaldetector.py ', ' utf8prober.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\urllib3\\ Contrib ', [], [' appengine.py ', ' ntlmpool.py ', ' pyopenssl.py ', ' socks.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\urllib3\\ Packages\\ssl_match_hostname ', [], [' _implementation.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\urllib3\\ Packages ', [' ssl_match_hostname '], [' ordered_dict.py ', ' six.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\urllib3\\ Util ', [], [' connection.py ', ' request.py ', ' response.py ', ' retry.py ', ' ssl_.py ', ' timeout.py ', ' url.py ', ' __init__.py '] )
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages\\urllib3 ', [' Contrib ', ' packages ', ' util '], [' connection.py ', ' connectionpool.py ', ' exceptions.py ', ' fields.py ', ' filepost.py ', ' poolmanager.py ', ' request.py ', ' response.py ', ' _collections.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests\\packages ', [' Chardet ', ' URLLIB3 '], [' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\requests ', [' packages '], [' adapters.py ', ' api.py ', ' auth.py ', ' Cacert.pem ', ' certs.py ', ' compat.py ', ' cookies.py ', ' exceptions.py ', ' hooks.py ', ' models.py ', ' sessions.py ', ' status_codes.py ', ' structures.py ', ' utils.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor\\webencodings ', [], [' labels.py ', ' mklabels.py ', ' tests.py ', ' x_user_defined.py ', ' __init__.py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip\\_vendor ', [' CacheControl ', ' Colorama ', ' Distlib ', ' html5lib ', ' lockfile ', ' packaging ', ' pkg_resources ', ' progress ', ' requests ', ' webencodings '], [' appdirs.py ' , ' distro.py ', ' ipaddress.py ', ' ordereddict.py ', ' pyparsing.py ', ' re-vendor.py ', ' retrying.py ', ' six.py ', ' __init__.py ' ‘])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg\\pip ', [' commands ', ' compat ', ' models ', ' Operations ', ' req ', ' utils ', ' VCs ', ' _vendor '], [' basecommand.py ', ' baseparser.py ', ' cmdoptions.py ', ' download.py ', ' exceptions.py ', ' index.py ', ' locations.py ', ' pep425tags.py ', ' status_codes.py ', ' wheel.py ', ' __init__.py ', ' __main__. Py '])
(' f:\\python\\ directory \\venv\\Lib\\site-packages\\pip-9.0.1-py3.6.egg ', [' egg-info ', ' Pip '], [])
(' f:\\python\\ directory \\venv\\Lib\\site-packages ', [' Pip-9.0.1-py3.6.egg '], [' Easy-install.pth ', ' Setuptools-28.8.0-py3.6.egg ', ' setuptools.pth '])
(' f:\\python\\ directory \\venv\\Lib\\tcl8.6 ', [], [' INIT.TCL '])
(' f:\\python\\ directory \\venv\\Lib ', [' site-packages ', ' tcl8.6 '], [])
(' f:\\python\\ directory \\venv\\Scripts ', [], [' Activate ', ' activate.bat ', ' activate.ps1 ', ' deactivate.bat ', ' Easy_ ' install-3.6-script.py ', ' easy_install-3.6.exe ', ' easy_install-3.6.exe.manifest ', ' easy_install-script.py ', ' Easy_ Install.exe ', ' easy_install.exe.manifest ', ' pip-script.py ', ' pip.exe ', ' pip.exe.manifest ', ' pip3-script.py ', ' pip3.6-script.py ', ' pip3.6.exe ', ' pip3.6.exe.manifest ', ' pip3.exe ', ' pip3.exe.manifest ', ' pyexpat.pyd ', ' Python.exe ' , ' Python3.dll ', ' python36.dll ', ' pythonw.exe ', ' select.pyd ', ' sqlite3.dll ', ' tcl86t.dll ', ' tk86t.dll ', ' Unicodedata.pyd ', ' vcruntime140.dll ', ' winsound.pyd ', ' _asyncio.pyd ', ' _bz2.pyd ', ' _ctypes.pyd ', ' _ctypes_test.pyd ', ' _decimal.pyd ', ' _elementtree.pyd ', ' _hashlib.pyd ', ' _lzma.pyd ', ' _msi.pyd ', ' _multiprocessing.pyd ', ' _ Overlapped.pyd ', ' _socket.pyd ', ' _sqlite3.pyd ', ' _ssl.pyd ', ' _testbuffer.pyd ', ' _testcapi.pyd ', ' _testconsole.pyd ', ' _testimportmultiple.pyd ', ' _testmultiphase.pyd ', ' _tkinter.pyd '])
(' f:\\python\\ directory \\venv ', [' Include ', ' Lib ', ' Scripts '], [' pyvenv.cfg '])
(' f:\\python\\ directory ', ['. Idea ', ' venv '], [])
(' F:\\python ', [' day1 ', ' zw18 ', ' directory '], [])

Some methods of the OS module in Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.