Теперь запакуем строку.
В этом случае следует передавать тип данных bytes.
>>> struct.pack('=s', b'a')
b'a'
Для записи слова следует указывать количество символов.
>>> struct.pack('=5s', b'hello')
b'hello'
Кстати, запакованный вид соответствует исходному тексту. Всё верно, символ есть в таблице ASCII, то есть его код попадает в диапазон 0-127, он может быть записан одним байтом и имеет визуальное представление. А вот что будет если добавить символ вне ASCII
>>> struct.pack(f'=s', b'ё')
SyntaxError: bytes can only contain ASCII literal characters.
Ошибка возникла еще на этапе создания объекта bytes, который не может содержать такой символ. Поэтому надо кодировать эти байты из строки.
>>> enc = 'ёжик'.encode('utf-8')
>>> struct.pack(f'={len(enc)}s', enc)
b'\xd1\x91\xd0\xb6\xd0\xb8\xd0\xba'
Заметьте, длина такой строки в байтах отличается от исходной длины, так как символы вне ASCII записываются двумя байтами и более. Поэтому здесь формат создаём на лету, используя получившуюся длину как каунтер токена.
#libs#basic
#CELR/USDT analysis :
#CELR is currently forming a triangle pattern. A breakout from this pattern is anticipated, with the price expected to test previous highs. A long entry is recommended upon a breakout above the $0.02130 level.
TF : 1D
Entry : $0.02130
Target : $0.03180
SL : $0.01695
#CELR/USDT analysis :
#CELR is currently in a downtrend, trading below the 200 EMA. The price is currently facing resistance in this zone. It is expected to reverse from this point and continue its bearish trend to test previous lows. Wait for a breakout below the $0.01114 level to consider going short.
TF : 4H
Entry : $0.01114
Target : $0.01014
SL : $0.01169
#CELR/USDT analysis :
#CELR is in a downtrend, trading below the 200 EMA. The price is forming LLs and LHs structure. Before continuing its bearish momentum, the price is expected to experience a pullback and test the resistance zone. Wait for the pullback for a short entry.
TF : 1H
Entry : $0.01142
Target : $0.01043
SL : $0.01177
#CELR/USDT analysis -
#CELR is in a downtrend, trading below the 200 EMA. The price is currently approaching a resistance zone. It is expected to be rejected from there and continue the bearish momentum towards the previous lows.
TF : 4h
Entry : $0.0157
Target : $0.0129
SL : $0.0164
#CELR/USDT BUY SETUP
CELR has broken out of the descending triangle and is currently testing it. A successful test will confirm a bullish move. Get ready for takeoff. 🚀