我想第一次使用python CSV阅读器.我有一个方法要求用户选择他们想要解析的文件,然后它将该文件路径传递给parse方法:
def parse(filename):
parsedFile = []
with open(filename, 'rb') as csvfile:
dialect = csv.Sniffer().sniff(csvfile.read(), delimiters=';,|')
csvfile.seek(0)
reader = csv.reader(csvfile, dialect)
for line in reader:
parsedFile.append(line)
return(parsedFile)
def selectFile():
print('start selectFile method')
localPath = os.getcwd() + '\Files'
print(localPath)
for fileA in os.listdir(localPath):
print (fileA)
test = False
while test == False:
fileB = input('which file would you like to DeID? \n')
conjoinedPath = os.path.join(localPath, fileB)
test = os.path.isfile(conjoinedPath)
userInput = input('Please enter the number corresponding to which client ' + …Run Code Online (Sandbox Code Playgroud)