python-3.xamazon-web-servicesaws-iot-greengrass

syntax error in AWS Greengrass V2 hello_world.py


I am experimenting with AWS IoT greengrass V2. I am just following the manual that has the following python code:

import sys
import datetime

message = f"Hello, {sys.argv[1]}! Current time: {str(datetime.datetime.now())}."

# Print the message to stdout.
print(message)

# Append the message to the log file.
with open('/tmp/Greengrass_HelloWorld.log', 'a') as f:
    print(message, file=f)

According to my logging there is a syntax error in line 4. Replacing line 4 with the following works fine:

message = "Hello"

Does anyone see what is wrong with this line:

message = f"Hello, {sys.argv[1]}! Current time: {str(datetime.datetime.now())}."

Thanks.


Solution

  • I'm one of the documentation writers for AWS IoT Greengrass.

    Formatted strings literals (f"some content") are a feature of Python 3.6+, and this syntax results in a syntax error in earlier versions. The getting started tutorial requirements incorrectly list Python 3.5 as a requirement, but Python 3.5 doesn't support formatted string literals. We'll update this requirement to say 3.6 or update the script to remove the formatted string literal.

    To resolve this issue, you can upgrade to Python 3.6+ or modify the script to remove the formatted string literal. Thank you for finding this issue!