当前的驱动器和目录 [英] Current drive and directory
问题描述
有谁知道如何使用DOS
和/或Python显示当前目录?我已经在Python中尝试了os.pardir和os.curdir,但是他们返回的所有
都是
a几个时期...
Does anyone know how to display the current directory using DOS
and/or Python? I already tried os.pardir and os.curdir in Python, but all
they return are
a couple of periods...
import os
print os.curdir
..print os.pardir
import os
print os.curdir ..print os.pardir
...
...
推荐答案
" EAS" < ER **** @ attbi.nospam.com>写道:
"EAS" <er****@attbi.nospam.com> wrote:
有谁知道如何使用DOS
和/或Python显示当前目录?
Does anyone know how to display the current directory using DOS
and/or Python?
使用getcwd( )在os模块中的功能。
---- ==通过Newsfeed.Com发布 - 无限制 - 未经审查 - 安全Usenet新闻== ----
http://www.newsfeed.com 世界排名第一的新闻组服务! > 100,000新闻组
--- = 19东/西海岸专业服务器 - 通过加密的总隐私= ---
Use the getcwd() function in the os module.
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
何时何时我运行这个脚本:
print""" MS-DOS Prompt
''Q''退出"""
导入os
命令=""
而command.lower()!=" q" :
directory = os.getcwd()
print" \ n",directory," \b>",
command = raw_input(" \b")
os.system(command)
当我使用'时它不会更新目录' 'cd''用于命令提示符?
Howcome when I run this script:
print """MS-DOS Prompt
''Q'' to Quit"""
import os
command = ""
while command.lower() != "q":
directory = os.getcwd()
print "\n", directory, "\b>",
command = raw_input("\b")
os.system(command)
it doesn''t update the directory when I use ''cd'' for the command prompt?
" EAS"写道:
"EAS" wrote:
有谁知道如何使用DOS
和/或Python显示当前目录?我已经在Python中尝试了os.pardir和os.curdir,但是他们返回的所有内容都是几个时期...
Does anyone know how to display the current directory using DOS
and/or Python? I already tried os.pardir and os.curdir in Python, but all
they return are a couple of periods...
你读过罚款吗?文档?查看文件和
目录:
http://docs.python.org/lib/os-file-dir.html
os.getcwd( )返回驱动器/路径。
你可以使用os.path.splitdrive(os.getcwd())获取驱动器
和路径为两个单独的字符串。
curdir等在稍后的同一章中记录:
http://docs.python.org/lib/os-path.html
< / F>
did you read the fine documentation? look under "files and
directories":
http://docs.python.org/lib/os-file-dir.html
os.getcwd() returns the drive/path.
you can use os.path.splitdrive(os.getcwd()) to get the drive
and the path as two separate strings.
curdir etc is documented a little later in the same chapter:
http://docs.python.org/lib/os-path.html
</F>
这篇关于当前的驱动器和目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!