是否可以在一行中有条件地为变量赋值?
dim a as string
dim b as string
a="hello world"
if a="hello world" then b="Yes" else b="No"
是否可以在一行中使用与SQL语法类似的方式执行上述代码 - 如下所示:
b = case when a="hello world" then "Yes" else "No" end
答案 0 :(得分:1)
这将是IIF功能。
import csv
import os
FIELDS = ('Employee id', 'Employee name', 'department', 'Age')
def read_file(file, keys):
output = dict.fromkeys(keys)
for line in file:
line = line.rstrip().split(': ')
output[line[0]] = line[1]
return output
with open('emp.csv', 'w', newline='') as destiny:
writer = csv.DictWriter(destiny, FIELDS)
writer.writeheader()
for x in range(1, 1001):
with open(os.path.normpath('C:\\test\\file{}.txt'.format(x))) as origin:
writer.writerow(read_file(file, FIELDS))
格式遵循问题的基本三元格式,真实条件,错误条件。该函数可以返回对象以及数据类型。