arduino - Error while filehandling in Blender using Python -
i'm trying read data in blender external device connected arduino , save onto file. gives error
syntaxerror: invalid syntax python script error controller "contr#contr#1": traceback (most recent call last): file "serialbge.py", line 6, in <module> f=open('abc.dat', 'r') ioerror: [errno 2] no such file or directory: 'abc.dat'
my code correct, , don't understand problem.
serial.py
:
import gamelogic import pickle import os os.system('dane.py') f=open('abc.dat', 'r') print "abc.dat = " x=pickle.load(f) print x print "end of abc.dat" f.close(); y=x[:] z in x: y.remove(z) print "removing " + str(z) print str(y) + " , " + str(x) f=open('abc.dat', 'w') pickle.dump(y, f) f.close() contr = gamelogic.getcurrentcontroller() location=contr.actuators["loc"] y = 0.001*(ord(z)-128) location.dloc=[y,0,0] contr.activate(location)
dane.py:
import serial import pickle serial.serial(com3,9600) port, open('abc.dat','r') f: in range(0, 10): x = port.read(size=1) y=pickle.load(f) f.close() f=open('abc.dat','w') in x: y.append(i) pickle.dump(y,f) f.close() port.close()
you getting error because file 'abc.dat' doesn't exist first time run program.
you need handle initial case, when run program first time, before 'abc.dat' exists.
Comments
Post a Comment