os.path.getsize 无效语法错误
os.path.getsize Invalid syntax error
首先,代码如下,
import sys
import os
import latexmake
import mysql.connector
conn = mysql.connector.connect(user='root',password='oilwell',host='localhost',database='sqlpush1')
with conn:
mycursor = conn.cursor()
mycursor=execute("SELECT DATE,oil,gas,oilprice,gasprice,totrev FROM results WHERE DATE BETWEEN '2011-01-01' AND '2027-12-01'")
rows = mycursor.fetchall()
a.write("\documentclass{standalone}\usepackage{booktabs}\n\n\usepackage{siunitx}\r \n\
\r\n\begin{document}\r\n\begin{tabular}{ccS[table-format = 5.2]} \\ \toprule\r")
a.write("Date & Oil & Gas & Oil price & Gas price & Total Revenue \\ \midrule \r")
for row in rows:
a = open("testtest.tex", "w")
a.write("" + str(row[0]) + " & " + str(row[1]) + " & " + str(row[2]) + " & " + str(row[3]) + " & " + str(row[4]) + " & " + str(row[5]) + " \\ \r")
a.write("\bottomrule \end{tabular}\r\end{document}")
a.close
print os.path.getsize("testtest.tex")
os.system('latexmk.py -q testtest.tex')
mycursor.close()
conn.close()
在 运行 IDLE 之后,在行 "os.path.getsize"
上弹出一个名为 "Invalid Syntax" 的错误
我一开始确实导入了os,不知道为什么。
感谢您的帮助。
此致,
程
问题不在于 os.path.getsize
,而是 print
。您正在使用 Python 3 并且 print
现在是一个函数,因此需要括号。
print(os.path.getsize("testtest.tex"))
此外,如果您真的调用了 close
而不是仅仅引用它,那就太好了(尽管不可否认,您永远不会注意到此脚本中的内容):
a.close()
首先,代码如下,
import sys
import os
import latexmake
import mysql.connector
conn = mysql.connector.connect(user='root',password='oilwell',host='localhost',database='sqlpush1')
with conn:
mycursor = conn.cursor()
mycursor=execute("SELECT DATE,oil,gas,oilprice,gasprice,totrev FROM results WHERE DATE BETWEEN '2011-01-01' AND '2027-12-01'")
rows = mycursor.fetchall()
a.write("\documentclass{standalone}\usepackage{booktabs}\n\n\usepackage{siunitx}\r \n\
\r\n\begin{document}\r\n\begin{tabular}{ccS[table-format = 5.2]} \\ \toprule\r")
a.write("Date & Oil & Gas & Oil price & Gas price & Total Revenue \\ \midrule \r")
for row in rows:
a = open("testtest.tex", "w")
a.write("" + str(row[0]) + " & " + str(row[1]) + " & " + str(row[2]) + " & " + str(row[3]) + " & " + str(row[4]) + " & " + str(row[5]) + " \\ \r")
a.write("\bottomrule \end{tabular}\r\end{document}")
a.close
print os.path.getsize("testtest.tex")
os.system('latexmk.py -q testtest.tex')
mycursor.close()
conn.close()
在 运行 IDLE 之后,在行 "os.path.getsize"
上弹出一个名为 "Invalid Syntax" 的错误我一开始确实导入了os,不知道为什么。
感谢您的帮助。
此致,
程
问题不在于 os.path.getsize
,而是 print
。您正在使用 Python 3 并且 print
现在是一个函数,因此需要括号。
print(os.path.getsize("testtest.tex"))
此外,如果您真的调用了 close
而不是仅仅引用它,那就太好了(尽管不可否认,您永远不会注意到此脚本中的内容):
a.close()