小编Cha*_*eld的帖子

如何自动打开给定文件夹中的所有文本文件?

file_name=[]
user_input= input('File name: ')
while user_input != "":
    part_name.append(user_input)
    user_input = input('File Name: ')

measure_list=[]    
for f in file_name :
    with open("/Users/Desktop/File/%s.txt" %f ,"r",encoding="UTF-16") as read_file:
Run Code Online (Sandbox Code Playgroud)

这是我目前现有的代码。它接受用户输入以搜索用户指定的文件,然后将该文件添加到列表中,并通过循环逐个打开每个文件。我想尝试使其更加自动化,以便脚本将自动抓取给定文件夹中的所有文件以用于此过程,而不是用户必须输入每个文件的名称。关于如何使这更加自动化的任何建议?

python python-3.x

5
推荐指数
1
解决办法
1834
查看次数

在python中,如何扫描具有一个长行的文本文件并将项目分成不同的列?

我有一个看起来像这样的文本文件:

“Distance 1: Distance XY” 1 2 4 5 9  “Distance 2: Distance XY”  3 6 8 10 5  “Distance 3: Distance XY”  88 45 36 12 4   
Run Code Online (Sandbox Code Playgroud)

这一切都在一条大线上.我的问题是我如何采取这个并分开距离测量,以使线看起来更像这样:

“Distance 1: Distance XY” 1 2 4 5 9  
“Distance 2: Distance XY”  3 6 8 10 5  
“Distance 3: Distance XY”  88 45 36 12 4  
Run Code Online (Sandbox Code Playgroud)

我想这样做,为每个距离测量制作一本字典.

python

3
推荐指数
1
解决办法
117
查看次数

标签 统计

python ×2

python-3.x ×1