TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #241 · 5 мај

Можно ли в Python создавать бинарные файлы? Конечно можно. Для этого в Python есть следующие инструменты: ▫️ тип данных bytes и bytearray ▫️ открытие файла в режиме wb (write binary) или rb (read binary) ▫️ модуль struct Про модуль struct поговорим в первую очередь. Файл в формате JSON или Yaml внутри себя содержит разметку данных. Всегда можно определить где список начался а где закончился. Где записана строка а где словарь. То есть формат записи данных содержит в себе элементы разметки данных. В binary-файле данные не имеют визуальной разметки. Это просто байты, записанные один за другим. Правила записи и чтения находятся вне файла. Модуль struct как раз и помогает с организацией данных в таком файле с помощью определения форматов записи для разных частей файла. Модуль struct преобразует Python-объекты в массив байт, готовый к записи в файл и имеющий определённый вид. Для этого всегда следует указывать формат преобразования (или, как оно здесь называется - запаковки). Формат нужен для того, чтобы выделить достаточное количество байт для записи конкретного типа объекта. В последствии с помощью того же формата будет производиться чтение. При этом следует помнить что мы говорим о типах языка С а не Python. Именно формат определяет, что записано в конкретном месте файла, число, строка или что-то еще. Вот какие токены формата у нас есть. Помимо этого, первым символом можно указать порядок байтов. На разных системах одни и те же типы данных могут записываться по-разному, поэтому желательно указать конкретный способ из доступных. Если этого не сделать, то используется символ '@', то есть нативный для текущей системы. В строке формата мы пишем в каком порядке и какие типы собираемся преобразовать в байты. Запакуем в байты простое число, токен "i". >>> import struct >>> struct.pack('=i', 10) b'\n\x00\x00\x00' Теперь несколько float, при этом нужно передавать элементы не массивом а последовательностью аргументов. >>> struct.pack('=fff', 1.0, 2.5, 4.1) b'\x00\x00\x80?\x00\x00 @33\x83@' Вместо нескольких токенов можно просто указать нужное количество элементов перед одним токеном, результат будет тот же. >>> struct.pack('=3f', 1.0, 2.5, 4.1) b'\x00\x00\x80?\x00\x00 @33\x83@' Теперь запакуем разные типы >>> data = struct.pack('=fiQ', 1.0, 4, 100500) я запаковал типы float, int и unsigned long long (очень большой int, на 8 байт) b'\x00\x00\x80?\x04\x00\x00...' Распаковка происходит аналогично, но нужно указать тот же формат, который использовался при запаковке. Результат возвращается всегда в виде кортежа. >>> struct.unpack('=fiQ', data) (1.0, 4, 100500) Как видите, ничего страшного! #lib#basic

Hashtags

Резултати

Пронајдени 33 слични објави

Пребарај: #groups

当前筛选 #groups清除筛选
The Telegram Times

@TheTGTimes · Post #272 · 14.02.2024 г., 14:06

📰Group Appearance Settings Upgrading your group will unlock new features for the group: - Color and Profile Logo - Group Status Emoji - Group Theme and Wallpaper - Group Emoji Pack #Boost | #Groups 👉The TG Times

The Telegram Times

@TheTGTimes · Post #264 · 13.02.2024 г., 10:22

📰Group Custom Emoji Pack Group Admins can set a Custom Emoji Pack for the group. All members can use emojis from this pack in the group, even without ⭐️ Premium subscription. #Boost | #Groups 👉The TG Times

The Telegram Times

@TheTGTimes · Post #262 · 13.02.2024 г., 10:14

📰Boost to send messages in the group Group admins can choose how many boosts a user must give to the group to bypass restrictions on sending messages. #Boost | #Groups 👉The TG Times

The Telegram Times

@TheTGTimes · Post #248 · 31.01.2024 г., 08:45

📰Boosting Groups Changes in the configuration of Telegram for macOS show that it will be possible to boost groups. After upgrading groups, the ability to set the background for the group, choose the status emoji and choose the emoji pack for the group will be added. It seems that just as in groups, the special sticker pack for that group can be set, it will also be possible to choose the emoji pack. Thanks to @tgcrawl #Boost | #Groups 👉The TG Times

TGBlogLeaks

@TGBlogLeaks · Post #350 · 31.01.2024 г., 09:03

📰Boosting Groups Changes in the configuration of Telegram for macOS show that it will be possible to boost groups. After upgrading grouos, the ability to set the background for the group, choose the status emoji and choose the emoji pack for the group will be added. It seems that just as in groups, the special sticker pack for that group can be set, it will also be possible to choose the emoji pack. Thanks to @tgcrawl #Boost | #Groups 👉The TG Times

iDubTG

@idubtg · Post #501 · 31.01.2024 г., 11:21

📰Boosting Groups Changes in the configuration of Telegram for macOS show that it will be possible to boost groups. After upgrading grouos, the ability to set the background for the group, choose the status emoji and choose the emoji pack for the group will be added. It seems that just as in groups, the special sticker pack for that group can be set, it will also be possible to choose the emoji pack. Thanks to @tgcrawl #Boost | #Groups 👉The TG Times

BotsGram®

@botsgram_cu · Post #3776 · 04.04.2021 г., 11:12

@TheNexasMusic_bot Qué puede hacer este bot? Con este bot puedes reproducir música nn grupos de telegram a través del chat de voz! Idioma: Inglés (visto en @BotsGram_cu) #groups, #music

BotsGram®

@botsgram_cu · Post #3774 · 04.04.2021 г., 01:31

@Gramaphone_voice_bot Qué puede hacer este bot? Con este bot puedes reproducir música nn grupos de telegram a través del chat de voz! Idioma: Inglés (visto en @BotsGram_cu) #groups, #music

BotsGram®

@botsgram_cu · Post #3712 · 24.03.2021 г., 11:04

@MultiForwardBot Qué puede hacer este bot? Este bot reenvía mensajes y medios de tu canal a grupos ilimitados de telegram! Idioma: Inglés, Italiano, Español (visto en @BotsGram_cu) #channel, #groups

ПретходнаСтраница 1 од 3Следна