关于os.listdir的愚蠢问题 [英] stupid question about os.listdir
问题描述
行。我已经在Google群组和网络上搜索了这个,而且我没有找到答案。
没有找到答案。我是一个Python新手,并且我认为是一个基本问题。
。 os.listdir将路径名作为arg,但它没有
实际列出我传入的目录的内容。它总是在
当前目录上运行(无论脚本在哪里运行)我都要事先chdir
。是它应该如何工作?如果是这样的话,以路径名传递
是什么意思?
谢谢,
杰森>
OK. I''ve search on google groups and around the web for this and I
haven''t found an answer. I''m a Python newbie and have what I assume is
a basic question. os.listdir takes a pathname as an arg but it doesn''t
actually list the contents of the dir I pass in. it always operates on
the current dir (wherever the script is run) and I have to chdir
beforehand. Is that how its supposed to work? If so what is the point
in passing in a pathname?
thanks,
Jason
推荐答案
Jason Kratz写道:
Jason Kratz wrote:
好的。我已经搜索了谷歌小组和网络上的内容,我没有找到答案。我是一个Python新手,我认为是一个基本问题。 os.listdir将路径名作为arg,但它实际上并没有列出我传入的目录的内容。它总是在当前目录上运行(无论脚本在哪里运行)和我必须事先chdir
。是它应该如何工作?如果是这样的话,通过路径名是什么意思?
谢谢,
Jason
OK. I''ve search on google groups and around the web for this and I
haven''t found an answer. I''m a Python newbie and have what I assume is
a basic question. os.listdir takes a pathname as an arg but it doesn''t
actually list the contents of the dir I pass in. it always operates on
the current dir (wherever the script is run) and I have to chdir
beforehand. Is that how its supposed to work? If so what is the point
in passing in a pathname?
thanks,
Jason
oops。差点忘了。如果我在python解释器中以交互方式运行
它按预期工作。它从
命令行执行''python script.py'时它只使用当前目录。
oops. almost forgot. if I run interactively in the python interpreter
it works as I expect. its when doing ''python script.py'' from the
command line that it only uses the current directory.
Jason Kratz写道:
Jason Kratz wrote:
oops。差点忘了。如果我以交互方式运行python
解释器
它按预期工作。它从
命令行执行''python script.py'时它只使用当前目录。
oops. almost forgot. if I run interactively in the python
interpreter
it works as I expect. its when doing ''python script.py'' from the
command line that it only uses the current directory.
从未听说过这样的事情。这可能是你的剧本没有按照你期望的那样完成。
-
Erik Max弗朗西斯&& ma*@alcyone.com && http://www.alcyone.com/max/
__美国加利福尼亚州圣何塞市&& 37 20 N 121 53 W&& & tSftDotIotE
/ \天堂与地狱/在地球上
\ __ / Salt-n-Pepa
Never heard of any such thing. It''s likely that your script is not
quite doing what you expect it to.
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Heaven and Hell / Is on Earth
\__/ Salt-n-Pepa
On Fri,2003年6月27日02:22:36 GMT,Jason Kratz写道:
On Fri, 27 Jun 2003 02:22:36 GMT, Jason Kratz wrote:
os.listdir将路径名作为arg,但它实际上并未列出
我传入的目录的内容。
os.listdir takes a pathname as an arg but it doesn''t actually list the
contents of the dir I pass in.
请将问题简化为其他人可以检查的简单脚本,
并在此处发布。如果行为与你说的一样,它应该只有几行......
import os
os.listdir (''somethingyouthinkshouldwork'')
-
\上帝禁止任何书籍被禁止。这种做法是因为杀婴而不可原谅。 - Dame Rebecca West |
_o__)|
http: //bignose.squidly.org/ 9CFE12B0 791A4267 887F520C B7AC2E51 BD41714B
Please reduce the problem to a simple script that others can examine,
and post it here. If the behaviour is as you say, it should be only a
few lines long:
import os
os.listdir( ''somethingyouthinkshouldwork'' )
--
\ "God forbid that any book should be banned. The practice is as |
`\ indefensible as infanticide." -- Dame Rebecca West |
_o__) |
http://bignose.squidly.org/ 9CFE12B0 791A4267 887F520C B7AC2E51 BD41714B
这篇关于关于os.listdir的愚蠢问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!