Python 3.x 如果“名称”__主要内容:SyntaxError,但写得正确
我从它工作的另一个代码中复制了该部件,但是它给了我这个错误,我不知道原因: 如果name==“main”,错误就在这里:但我已经检查了空格和Python 3.x 如果“名称”__主要内容:SyntaxError,但写得正确,python-3.x,syntax-error,Python 3.x,Syntax Error,我从它工作的另一个代码中复制了该部件,但是它给了我这个错误,我不知道原因: 如果name==“main”,错误就在这里:但我已经检查了空格和 File "/Users/goncalo/Desktop/Python/GUI/Grafico/main.py", line 40 if __name__ == "__main__": ^ SyntaxError: invalid syntax 这是我的密码: #importar
File "/Users/goncalo/Desktop/Python/GUI/Grafico/main.py", line 40
if __name__ == "__main__":
^
SyntaxError: invalid syntax
这是我的密码:
#importar as bibliotecas
import sys
import pandas as pd
import matplotlib.pyplot as plt
from PyQt5 import uic, QtWidgets
qtCreatorFile = "Graficoteste.ui" #Innserir nome do arquivo
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
#seccao para adicionar os botoes
self.Botao1.clicked.connect(self.getCSV)
self.Botao2.clicked.connect(self.plot)
#seccao para adicionar funcoes
def plot(self):
x=self.df.loc[:][0]
plt.plot(x)
plt-show()
#Esta función abre el archivo CSV
def getCSV(self):
filePath, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', '/home')
if filePath != "":
print ("Dirección",filePath) #Opcional imprimir la dirección del archivo
self.df=pd.read_excel(str(filePath),header=None
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MyApp()
window.show()
sys.exit(app.exec_())
您之前忘记关闭该行的括号:
更改:
self.df=pd.read\u excel(str(filePath),header=None
收件人:
self.df=pd.read\u excel(str(filePath),header=None)
通常,当您收到一个
语法错误时,解释器告诉您错误在第40行,错误实际上是第39行缺少逗号、括号或引号。您之前忘记关闭该行的括号:
更改:self.df=pd.read\u excel(str(filePath),header=None
收件人:self.df=pd.read\u excel(str(filePath),header=None)
通常,当您收到语法错误时,解释器会告诉您错误在第40行,例如第39行,错误实际上是缺少逗号、括号或引号。检查抛出错误的行之前的行。检查抛出错误的行之前的行。