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

Резултати

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

Пребарај: #aigenerated

当前筛选 #aigenerated清除筛选
Custom Emoji Packs

@CustomEmojiPacks · Post #879 · 09.06.2025 г., 22:20

We've brought back the ❤️ reaction and removed the 💫 option. We originally added the star just for fun, but it started to feel unfair - it was appearing on messages that included packs from other people. Even though the donations it generated were minimal and insignificant to us, I still felt bad about it. Anyway, I want to clarify what's been happening with this channel lately. 📰 A few months ago, Telegram placed restrictions on my account for no apparent reason - I wasn't allowed to post in public groups due to some "illegal content". It took me a while to realize that our community group had disappeared too. I'll admit it, our moderation wasn't the best, but we tried to block and remove spam, crypto scams, and anything related to drugs, porn etc, but in the end, our group ended up being deleted. I reached out to some Telegram volunteers, and after a few weeks I was unbanned. They told me I should’ve enabled the new aggressive anti-spam feature, so if you manage a large community, I strongly recommend turning it on. That way, a few troublemakers won’t end up causing problems for everyone. 🚨 That said, technology is evolving at an exponential rate, and with the arrival of AI generated emojis, we also want to evolve this channel into something new. Right now, you can generate an emoji on iOS or certain websites in just a few seconds, which takes away the magic of designing a set from scratch with vector graphics and countless cups of coffee. We still believe in the secret art of emoji creation, but it's fading faster and faster. That's why we're adding the ability to direct message us using the latest Telegram feature, so that you can share your packs, tell us your story and promote your own work - and request collaborations, too. We’ll review each submission, allowing you, in a way, to give us direct post suggestions, resulting in more frequent posts and better management, without the risk of creating another group just to get banned again. We have more ideas for oh how to evolve this community, but we also want to hear yours. At this point, we think the channel needs a new #aigenerated hashtag for emoji packs made with AI tools like ChatGPT or websites such as emojis.com - one of the most advanced AI emoji generators right now (not sponsored, by the way). So, keep creating incredible art in every form. Use AI to push the boundaries of what the human mind can do, without replacing it. Find the right balance, blending AI-generated ideas with your own artistic vision and creativity. That, I believe, must be the right way to create and communicate without getting replaced by technology in future generations. 🚀

Hashtags

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