带空格的python列表文件

2024-10-02 10:19:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

基本上就是从每个文件中提取md5。问题是有空格的文件,程序的解决方案可以考虑到这些文件,而不是跳过它们。在

def onepath(archivo):
        logging.basicConfig(filename=salida,filemode="w", format='%(message)s', level=logging.DEBUG)
        for filename in (file for file in os.listdir(archivo)):
                with open(filename) as checkfile:
                        logging.info("MD5 " + "(%s) = " % filename + hashlib.md5(checkfile.read()).hexdigest())

我在读shlex方法,但不确定如何实现。在

你能帮我吗?在


我认为有空格的文件正在显示。我做了一个简短的片段,我面对的问题是我无法控制Linux如何理解文件名上的空格,以便做到以下几点:

在shell中显示:

bash-3.2$ ./comodin.py ./espacio/ Boxx view.pdf cp: Boxx view.pdf: No such file or directory hola.txt hola.txt -> /tmp/hola.txt bash-3.2$


Tags: 文件intxtbashviewforloggingfilename
1条回答
网友
1楼 · 发布于 2024-10-02 10:19:39
def onepath(archivo):
    logging.basicConfig(filename=salida,filemode="w", format='%(message)s', level=logging.DEBUG)
    for filename in os.listdir(archivo):
        filepath = os.path.join(archivo, filename)
        with open(filepath) as checkfile:
            logging.info("MD5 " + "(%s) = " % filename + hashlib.md5(checkfile.read()).hexdigest())

相关问题 更多 >

    热门问题