Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 没有这样的文件或目录';fiile';_Python - Fatal编程技术网

Python 没有这样的文件或目录';fiile';

Python 没有这样的文件或目录';fiile';,python,Python,我有一个问题,我想在Python3中运行srollbar中的一个文件,当我运行代码时,它向我显示了一个错误:没有这样的文件或目录“fiile” 我想通过按发送按钮发送滚动条中的文件, 我已经指定了发送按钮的命令 import serial import time from tkinter import filedialog from tkinter import * moha = Tk() def file(tk_event=None, *args, **kw): fiile= fi

我有一个问题,我想在Python3中运行srollbar中的一个文件,当我运行代码时,它向我显示了一个错误:没有这样的文件或目录“fiile” 我想通过按发送按钮发送滚动条中的文件, 我已经指定了发送按钮的命令

import serial
import time
from tkinter import filedialog
from tkinter import *


moha = Tk()
def file(tk_event=None, *args, **kw):
    fiile= filedialog.askopenfilename(filetypes=[('txt files','.txt'),('all 
    files','.*')])
    file_path.set(fiile)
    fichier = open(fiile, "r")
    print(fiile)


def moh():
    # Open grbl serial port
    s = serial.Serial('/dev/ttyS0',115200)

    # Open g-code file
    f = open('fiile', 'r')

    # Wake up grbl
    s.write("\r\n\r\n").encode("utf8")
    time.sleep(2)   # Wait for grbl to initialize
    s.flushInput()  # Flush startup text in serial input

    # Stream g-code to grbl
    for line in f:
        l = line.strip() # Strip all EOL characters for streaming
        print ('Sending: ' + l)
        s.write(l + '\n') # Send g-code block to grbl
        grbl_out = s.readline() # Wait for grbl response with carriage return
        print( ' : ' + grbl_out.strip())

    # Wait here until grbl is finished to close serial port and file.

    raw_input("  Press <Enter> to exit and disable grbl.")

    # Close file and serial port

    f.close()
    s.close()
file_path = StringVar()
entry = Entry(moha, textvariable=file=path)
entry.place(x=155, y=114)
b1= Button(moha, text="Selectionner un fichier", background='White', command=file).place(x=290, y=112)
b2= Button(moha, text="Send", background='White', command=moh).place(x=120, y=170)
导入序列号
导入时间
从tkinter导入文件对话框
从tkinter进口*
moha=Tk()
def文件(tk_事件=无,*参数,**千瓦):
fiile=filedialog.askopenfilename(文件类型=[('txt文件','.txt'),('all
文件“,”.')])
文件路径集(fiile)
fichier=打开(fiile,“r”)
打印(文件)
def moh():
#打开grbl串行端口
s=serial.serial('/dev/ttyS0',115200)
#打开g代码文件
f=打开('fiile','r')
#唤醒grbl
s、 写入(“\r\n\r\n”)。编码(“utf8”)
时间。睡眠(2)#等待grbl初始化
s、 flushInput()#在串行输入中刷新启动文本
#将g代码流到grbl
对于f中的行:
l=line.strip()#为流媒体删除所有下线字符
打印('发送:'+l)
s、 写入(l+'\n')#将g代码块发送到grbl
grbl_out=s.readline()#等待带有回车符的grbl响应
打印(“:”+grbl_out.strip())
#在此处等待,直到grbl完成关闭串行端口和文件。
原始输入(“按下退出并禁用grbl”)
#关闭文件和串行端口
f、 关闭()
s、 关闭()
文件路径=StringVar()
条目=条目(moha,textvariable=文件=路径)
入口位置(x=155,y=114)
b1=按钮(moha,text=“Selectionner un fichier”,background='White',command=file)。放置(x=290,y=112)
b2=按钮(moha,text=“Send”,background=“White”,command=moh)。位置(x=120,y=170)

感谢您将
文件路径
变量设置为
文件对话框的文件路径。因此,只需调用
file\u path.get()
即可获得文件路径。 在功能moh中:

#Open g-code file
f = open(file_path.get(),"r")

您确定这里显示的代码就是您正在使用的代码吗?看起来您正试图打开
“fiile”
,字符串文字,而不是变量
fiile
@aryamcarthy我不知道如何操作:/n您确定上面的代码就是您运行的代码吗?您能具体说明在上面的代码中哪里发生了错误吗?另外,请注意,在
entry=entry(moha,textvariable=file=path)
中,似乎有输入错误。考虑编辑它吧。