Python3, Strings, & Arduino’s

Posted on
Fri Jul 15, 2022 12:46 pm
dawson1331 offline
Posts: 32
Joined: Oct 22, 2012

Python3, Strings, & Arduino’s

I have recently upgraded to the new Indigo release (2022.1.2). I guess that caused me to upgrade to Python3. It seems Python3 handles strings differently - which has caused many of my scripts to fail. The Indigo release notes were helpful during the conversion. Otherwise, I would have probably rolled back the release and stayed with Python2. This has been a lot of work for me so far - on scripts that I wrote many years ago and have had to re-learn how they work.

I still get the \t & \n for tab & newline and the b’ and u’ at the beginning and ending of some of my Indigo Variable Strings. I’ll study that next.

Some of my Arduino plug-in scripts are failing - and in a very subtle way. I use the Arduino plug-in a lot (it is one of my favorites). I use String Pins to send string data to the Arduino. Some of my strings contain ‘spaces’. When sending the data to the Arduino, the plug-in builds an HTTP url that contains that string and its ‘space’. The space causes the url to be malformed and therefore is not send to the Arduino. You have to look in the Arduino plug-in’s log file to see this.

I have read online about strings in Python3. They seem to be a mess. A few things have been made better, but overall, I don’t think the “unicode” issue is going to go away.

I do not know how to solve this problem. For now, I converted all the ‘spaces’ to an underscore just before I call the Arduino action. Does anyone have any other ideas?

Posted on
Fri Jul 15, 2022 12:58 pm
DaveL17 offline
User avatar
Posts: 6739
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Python3, Strings, & Arduino’s

We're going to need some examples in order to be of any help.

I don't agree that strings are a mess in Python 3. In fact, I think they're a huge improvement. All strings in Python 3 are Unicode strings, so there's no need to do any converting. What may be tripping you up (it did me at first) are byte to string conversions. Byte objects must be decoded:

Code: Select all
b"my_string".decode("utf-8")
I particularly like "f" strings in Python 3:

Code: Select all
f"My var value: {var1}"

# instead of

u"My var value: {0}".format(var1)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests