os.path.getsize语法错误无效

时间:2015-06-10 21:12:30

标签: python latex

首先,代码是下面的列表,

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”行上弹出一个名为“无效语法”的错误

我一开始就做了导入操作系统,我不知道为什么。

感谢您的帮助。

此致

1 个答案:

答案 0 :(得分:4)

os.path.getsize问题不在于print,而是print。您正在使用Python 3,print(os.path.getsize("testtest.tex")) 现在是一个函数,因此需要使用括号。

close

此外,如果你真的打电话给a.close() 而不仅仅是引用它,那就很好(尽管你可以在这个剧本中注意到):

function onEdit() {

  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getDataRange();
  var actCell = sheet.getActiveCell();
  var actData = actCell.getValue();
  var actRow = actCell.getRow();
  if (actData != '' && actRow != 1)  //Leaving out empty and header rows
  {
    range.getCell(actRow, 2).setBackground(actData);
  }

}