Click here to Skip to main content
15,848,261 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
(0, b'a = 4; print("Expected a = 4. Actual a = {} ".format(a))\r\n')

#i am sending this command to python
var command1topython = "a = 4; print(\"Expected a = 4. Actual a = {} \".format(a))";
sw.WriteLine(command1topython);



.py file

resp = win32file.ReadFile(pipe_handle, 64*1024)
print(resp) #what i read data here (0, b'a = 4; print("Expected a = 4. Actual a = {} ".format(a))\r\n')
exec(resp) #while using exec the method i am geting error like, exec() arg 1 must be a string, bytes or code object


#so what i am sending command i need to read same
my expected readData in python : "a = 4; print(\"Expected a = 4. Actual a = {} \".format(a))";
but what i am geting is : (0, b'a = 4; print("Expected a = 4. Actual a = {} ".format(a))\r\n')

#so if you do python side
resp= (0, b'a = 4; print("Expected a = 4. Actual a = {} ".format(a))\r\n')
exec(resp)
you will get error like exec() arg 1 must be a string, bytes or code object
how do solve this issue


What I have tried:

i tried strip method but didn't get
Posted
Updated 12-Aug-22 0:24am
v2

1 solution

Please do what I suggested in your original question on this subject. What you have shown above is merely the output, not the code that produced it.

And if I pass that command string direct to Python I get:
\VSCode\Python>python -c "a = 4; print(\"Expected a = 4. Actual a = {} \".format(a))";
Expected a = 4. Actual a = 4
 
Share this answer
 
Comments
Richard MacCutchan 12-Aug-22 4:51am    
We need to see the complete code in order to help you. Please use the Improve question link above, and add complete details to your question.
Richard MacCutchan 12-Aug-22 5:41am    
I cannot find a definitive answer, but can only assume that the first element of the tuple is a status code sent from Python. It is a simple matter using the String class in C# to extract the text that you are interested in.
HelpMewithCode 12-Aug-22 5:58am    
just simple question if didn't understand

resp= (0, b'a = 4; print("Expected a = 4. Actual a = {} ".format(a))\r\n')

its posible in python remove 0,b from tuple so i can get my output like this
("a = 4; print(\"Expected a = 4. Actual a = {} \".format(a))")

if possible help with method
Richard MacCutchan 12-Aug-22 7:25am    
As I keep saying, please show us the actual code you are using. We cannot guess what happens in either the Python or the C# code, so we cannot give a definitive answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900