【发布时间】:2019-09-19 20:16:42
【问题描述】:
我真的需要一个系统调用列表,例如 os.system('ls' + input) 我当然试过谷歌搜索,但没有找到太多。
也尝试了不同的编码方式,但我无法让它工作。
import os
user_input = input("Specify directory: ")
directory = os.system('ls ' + str(user_input))
------------------------------------------------------------------
# I need a list made out of the directory variable.
# Also note that subprocessing doesn't work that well as it doesn't accept # bash special chars like '~/', whereas os.system() accepts that.
# What os.system(), subprocess.call() return is just a normal output and I # cannot get to list that.
# Also I have gotten my program to work with os.listdir() but os.listdir() # doesn't accept special chars like '~/'.
显然,如果有人能帮我解决这个问题,我将不胜感激。
谢谢。
【问题讨论】:
-
有更好的方法来列出目录中的文件,你真的需要使用
ls吗? -
directory.split()? -
@Sayse,感谢您的回复。你有什么建议?
-
@Netwave,由于某种原因,它不起作用,因为我已经尝试了几次。不过还是谢谢。
标签: python python-3.x command