What is the functionality of this line of code?

Asked

Viewed 109 times

3

1 answer

5


All right, let’s go

ser.write() is for "write" on serial port.

str() is to convert the value to string.

dataDict[] is a dictionary.

"\n" is to skip a line.

encode() is to convert to a set in bytes

In short, this section tells the serial the result of the conversion str() from the dictionary concatenated with a line break, converted into bytes.

Note: The function .write() only works with bytes, so the need for the .encode(), and this only works with strings, so the str()

  • I think you’re just sending out a dictionary value associated with the key (alpha, beta) + the breaking of lines, but I may be wrong.

  • 1

    Yes, so it’s a dictionary

  • What I mean is that your answer gives the impression that the entire dictionary is being converted to a string: Instead of writing "a conversion str() dictionary concatenated with a line break" I would use "a conversion str() of the value associated with tuple (alpha, beta) in the dictionary dataDict concatenated to a line break". It makes sense?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.