到目前为止我的代码是一个基本上读取csv文件并打印其内容的函数:
def read(filename):
with open(filename, 'r') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
print(row)
Run Code Online (Sandbox Code Playgroud)
内容sailor.csv:
name, mean performance , std dev
Alice, 100, 0,
Bob, 100, 5,
Clare, 100, 10,
Dennis, 90, 0,
Eva, 90, 5,
Run Code Online (Sandbox Code Playgroud)
read('sailor.csv') 并运行该功能
电流输出:
['name', ' mean performance ', ' std dev']
['Alice', ' 100', ' 0', '']
['Bob', ' 100', ' 5', '']
['Clare', ' 100', ' 10', '']
['Dennis', ' 90', ' 0', '']
['Eva', ' 90', ' …Run Code Online (Sandbox Code Playgroud) 我似乎无法找到任何具体的内容.我知道,为了将一段代码分成多行,只需在行尾添加"_"即可.
但是,我注意到我的一些代码行仅在我使用"&_"时才有效,而下一行包含一组额外的语音标记,如果在一行上则不包括它们,为什么这是?
代码在一行:
Msg1 = MsgBox("Removing an LPA will remove ALL of their details from the database, including their documents - You cannot undo this action. Do you wish to continue?", vbYesNo, "WARNING!")
Run Code Online (Sandbox Code Playgroud)
代码行分开工作:
Msg1 = MsgBox("Removing an LPA will remove ALL of their details from the database," & _
"including their documents - You cannot undo this action. Do you wish to" & _
" continue?", vbYesNo, "WARNING!")
Run Code Online (Sandbox Code Playgroud)
分隔的代码行不起作用:
Msg1 = MsgBox("Removing an LPA will …Run Code Online (Sandbox Code Playgroud)