i'm getting crazy trying to simply print something in python3. So i hope in any of you explayning me what's the strange idea there's behind this
I come from php, so for me it was "echo $something" and php was casting the var to what it was needed to be printed.
Then python 2, i had to "cast" everything with a (simple) str()
For example, to print my wind sensor reading i can do something like this
Code: Select all
print("TX23 sensor reading") print("Datetime: " + datetime.datetime.fromtimestamp(output['timestamp']).strftime('%d/%m/%Y - %H:%M:%S')) print("Speed: " + str(data['speed']) + " m/s") print("Direction: " + str(data['direction'])) print("Degrees: " + str(data['degrees']) + "°")
Can you see that code? it works if i execute the script from cli.
But if i execute it from a web page the magic:
- Error: 'ascii' codec can't encode character '\xb0' in position 18: ordinal not in range(128)
wtf?? it is going well from cli!
So since this point i really lost myself.. tried encode("utf-8"), tried format, but i simply did not understand the ratio so i'm moving blindly
Please guide me
PS: the script itself should be utf-8 (i added the #coding=utf-8 at the start of it), but it's clear i'm missing something bigger
PS: i'd like more something working in python 2 AND 3..