Pythonの新機能といくつかのガイダンスを探しています。私は (各店舗のために1つの)フォルダ内の何百ものテキストファイルをループし、ストアID(テキスト文書のタイトルで与えられたxxx2902ncjc)を持つCSVファイルを生成しようとしています。 (すなわち、maxPeople = 31、またはspace_temp = 78など)。各テキストファイルには場所によって異なるパラメータがある可能性があるので、私は以下のforループの一意の変数をすべて取得しました。 2番目のfor-loopにあるすべてのストアIDを取得しました。それは私が今までに得たすべてです。テキストファイルでいっぱいのループスルーフォルダー、変数の値を取得、CSVとstoreIDと変数名を一致させて埋め込みます。
1)このすべてをExcelにインポートする方法を理解する、2)正しいパラメータでIDを格納することを各ファイル名のスライスに保存する方法3)ストアIDと変数へのパラメータを一致させる優れた方法です。
私は次に何をすべきか分かりません。私はsuuuper初心者ですので、すべての助けは非常に高く評価されるでしょう。乾杯。
import os, sys, glob
path = r"C:\Users\XXXXX" #insert folder for data here
dirs=os.listdir(path)
fullfilenames=[]
variablelist=[]
allvariables=[]
variables=[]
for file in os.listdir(path):
if ".prop" in file:
fullfilenames.append(path+'\\'+file)
for name in fullfilenames: #create list of StoreIDs
index_of_c = name.index('qPA')
file_name= name[index_of_c:] #cuts off path
file_name=file_name.rsplit(".",1)[0] #removes extension
SiteID= file_name[4:] #splits filename into Site ID
print (SiteID) #prints SiteID
for file in fullfilenames:
f = open(file,'r') #opens the file and enters reading mode
content=f.readlines() #reads each line of file and seperates based on whitespace
for line in content:
variables.append(line.split('=')[0]) #splits up each line of each file, specified before the "="
for variable in variables:
if variable not in allvariables: #checks if variable is included in the variable list
allvariables.append(variable) #if variabe isn't include in the list, it adds it to list
def createkeys():
print(allvariables)
print(type(allvariables))
print(len(allvariables))
[編集]あなたの質問と '.prop'ファイルとあなたの予想出力からのデータの少なくとも3行を示しています。 – stovfl