【问题标题】:How can I append just just the path?我怎样才能只附加路径?
【发布时间】:2021-09-27 04:20:10
【问题描述】:

我想添加几个txt文件的路径。 这是我的输出:“<_io.textiowrapper name="(txt 文件的路径)" mode="r" encoding="cp1252">” 我只需要路径,而不是模式或编码。

import os
from os import listdir
from os.path import isfile, join
from config import cred
import mmap

path = (r"mypath")
dirfiles = []

for filename in os.listdir(path):
    with open(os.path.join(path, filename)) as f:
        try:
            dirfiles.append(f)
            print(dirfiles)      
        except:
            pass

提前致谢:D

【问题讨论】:

  • 如果你只想打印路径,为什么要打开文件?

标签: python python-3.x python-2.7 arraylist


【解决方案1】:

如果你只是想打印路径

for filename in os.listdir(path):
  print(os.path.join(path, filename))

【讨论】:

    猜你喜欢
    • 2022-12-05
    • 2014-05-15
    • 2021-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多