问题
Unable to understand this: When I run using python shell it works but doesn't: when invoked using Iron python. It throws above error
C#:
scriptEngine.ExecuteFile(path);
var testFn = scriptScope.GetVariable("InputSelection");
var stream = new MemoryStream();
scriptEngine.Runtime.IO.SetOutput(stream, Encoding.Default);
scriptEngine.Operations.Invoke(testFn);
Python:
def send_data(message,check):
if message:
ser.write(message.encode('utf-8'))
time.sleep(2)
response = ser.read(1024)
def InputSelection():
send_data("Hello","Hello")
回答1:
Looks like you're hitting a bug in IronPython. In the meantime you can workaround it by using:
ser.write(bytes(message.encode('utf-8')))
来源:https://stackoverflow.com/questions/24620217/iron-python-error-expected-type-bytes-or-bytearray-got-type-str-for-se