0

friends.

I deal with an issue in TextMate, which I use to write code normally.
For my hash map script I need to encode a string into bytes.
As an example if I write:

password = "orange"
bytes_list = list(password.encode())
print(bytes_list)

The expected output is [111, 114, 97, 110, 103, 101] which I get if I run the script from Python's IDLE and even if I write the same code in my shell.

But if I run the code in TextMate, the result yields ['o', 'r', 'a', 'n', 'g', 'e'], so it's obvious, that the encode() function in TextMate is not working as expected.
The funny part is, that if I execute the code from TextMate to shell it doesn't work neither.

In the preferences of TextMate the Encoding is set to Unicode - UTF-8 and the Unicode bundle is installed.
I couldn't find any answer via Google to this topic. Maybe some of you came across such issue in the past.

Thanks for any help.

rmua
  • 5
  • 1

1 Answers1

0

Your TextMate is using Python 2.7:

$ python
Python 2.7.16 (default, Dec  3 2019, 07:02:07) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> password = "orange"
>>> bytes_list = list(password.encode())
>>> print(bytes_list)
['o', 'r', 'a', 'n', 'g', 'e']
>>>

Python 3 will give the output you expected:

$ python3
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> password = "orange"
>>> bytes_list = list(password.encode())
>>> print(bytes_list)
[111, 114, 97, 110, 103, 101]
>>>
ForceBru
  • 43,482
  • 10
  • 63
  • 98