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

Резултати

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

Пребарај: #ubuntu

当前筛选 #ubuntu清除筛选
404 Information

@Info404 · Post #65425 · 24.04.2026 г., 16:27

Ubuntu 26.04 LTS 释出 2026-04-24 13:56 by 艾米七号 Canonical 释出了代号为 Resolute Raccoon 的 Ubuntu 26.04 LTS。同时释出的还有衍生版本 Edubuntu、Kubuntu、Lubuntu、Ubuntu Budgie、Ubuntu Cinnamon、Ubuntu Kylin、Ubuntu Studio、Ubuntu Unity 和 Xubuntu。Ubuntu Desktop、Ubuntu Server、Ubuntu Cloud、Ubuntu WSL 和 Ubuntu Core 将获得五年的支持,其余版本获得三年的支持,付费扩展支持 ESM (Expanded Security Maintenance)为十年 。Ubuntu 26.04 采用最新的 Linux 7.0 kernel,GNOME 50 桌面环境,引入了基于 TPM 的全盘加密,GStreamer 1.28,沙盒图形加载,Chrony 4.8,等等。 https://discourse.ubuntu.com/t/ubuntu-26-04-resolute-raccoon-lts-released/80833 #Ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18800 · 15.05.2026 г., 03:01

📰 Ubuntu 25.10 Users Can Now Upgrade to Ubuntu 26.04 LTS, Here’s How A step-by-step and easy-to-follow tutorial (with screenshots) on how to upgrade your Ubuntu 25.10 (Questing Quokka) installations to Ubuntu 26.04 LTS (Resolute Raccoon). 🔗 Source: https://9to5linux.com/ubuntu-25-10-users-can-now-upgrade-to-ubuntu-26-04-lts-heres-how #ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18708 · 08.05.2026 г., 08:16

📰 Ubuntu Snap Prompting Improvements If you haven’t tried Ubuntu’s ‘Permission Prompting’ feature for a while, there’s more reason to do so in the latest release. Canonical’s Oliver Calder has shared an update on recent improvements to the security feature, which sets out to “empower users” by letting them decide what software can access on the rest of the system at runtime rather than retrospectively. 🔗 Source: https://www.omgubuntu.co.uk/2026/05/ubuntu-snap-prompting-client-improved #ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18703 · 07.05.2026 г., 17:55

📰 Ubuntu Touch 24.04-1.3 Lands as UBports Prepares 24.04-2.0 UBports releases Ubuntu Touch 24.04-1.3 while preparing 24.04-2.0, targeting a newer Morph Browser stack with Qt 6 work. 🔗 Source: https://linuxiac.com/ubuntu-touch-24-04-1-3-released/ #ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18696 · 07.05.2026 г., 08:38

📰After Days of DDoS, Now Ubuntu's Twitter Account Seems to be Compromised A fake AI agent, a near-identical Ubuntu URL, and a crypto wallet prompt, here's how hackers used Ubuntu's own branding against its users. 🔗 Source: https://feed.itsfoss.com/link/24361/17335930/ubuntu-twitter-compromised #ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18694 · 07.05.2026 г., 06:14

📰 Ubuntu’s old Unity desktop remade in Wayfire and Libadwaita If Canonical hadn’t burned through cash and goodwill during its smartphone detour in the mid-2010s, Ubuntu would likely still ship with the Unity desktop today – albeit in an evolved form. What would that form actually look like? Well, you don’t have to shut your eyes and imagine, thanks to Ubuntu community member Muqtxdir, who’s experiment in “re-building ubuntu’s unity shell in a wayfire session through gtk4-layer-shell and libadwaita... 🔗 Source: https://www.omgubuntu.co.uk/2026/05/ubuntu-unity-desktop-wayfire-recreation #ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18644 · 01.05.2026 г., 14:01

📰 Major DDoS attack knocks Ubuntu websites, Snap store offline If you’re having trouble accessing the Ubuntu website, the Snap store or Launchpad then you’re not alone: Canonical’s websites are currently facing a “sustained, cross-border” DDoS attack. The company says it is “working to address” the attack and will provide more details shortly. Some websites and services have been affected for as long as 14 hours (at the time of writing). 🔗 Source: https://www.omgubuntu.co.uk/2026/05/ubuntu-websites-ddos-attack #ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18620 · 29.04.2026 г., 22:51

📰 Enabling Ubuntu Pro in Security Center is super easy Ubuntu 26.04 LTS dropped the Software & Updates utility from default installs and added Ubuntu Pro settings to the Security Center app. But is the setup experience any better? The short answer is yes, mostly. The range of options mirrors what was in the old Software & Updates > Ubuntu Pro tab, but the layout is less cramped, with more room for concise explanations of what each setting and toggle does. Enrolling is improved too. 🔗 Source: https://www.omgubuntu.co.uk/2026/04/enable-ubuntu-pro-security-center #ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18586 · 27.04.2026 г., 13:07

📰 Ubuntu 16.04 LTS (Xenial Xerus) Reaches End of Standard ESM Support With the end of standard ESM support for Ubuntu 16.04 LTS, users must now choose between a staged upgrade or extended paid security coverage. 🔗 Source: https://linuxiac.com/ubuntu-16-04-lts-reaches-end-of-standard-esm-support/ #ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18553 · 24.04.2026 г., 07:28

📰 5 Reasons to Upgrade to Ubuntu 26.04 (and 3 Reasons to Stay Away) Should you skip this new release or jump on the bandwagon and upgrade to 26.04? Let me help you with that. 🔗 Source: https://feed.itsfoss.com/link/24361/17324480/ubuntu-26-04-upgrade-or-not #ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18526 · 22.04.2026 г., 10:54

📰 Ghostty OpenGL-Accelerated Terminal Available On Ubuntu 26.04 LTS Since Ubuntu 25.04 Ptyxis has been the default terminal emulator after it initially became available in Ubuntu 24.10. For the upcoming Ubuntu 26.04 LTS release, Ptyxis remains the default but Ghostty is now available too... 🔗 Source: https://www.phoronix.com/news/Ghostty-Ubuntu-26.04 #ubuntu

Hashtags

Linuxgram 🐧

@linuxgram · Post #18516 · 21.04.2026 г., 18:20

📰 Ubuntu 26.04 LTS: What’s new since 24.04? If you plan to upgrade to Ubuntu 26.04 LTS ‘Resolute Raccoon’ from Ubuntu 24.04 LTS, you’re going to inherit two years worth of improvements. As an LTS-to-LTS jump, you don’t simply benefit from what’s new in Ubuntu 26.04, but everything else added in the 3 interim releases prior, namely Ubuntu 24.10, 25.04 and 25.10. Ubuntu 26.04 LTS does plenty of things that 24. 🔗 Source: https://www.omgubuntu.co.uk/2026/04/ubuntu-26-04-lts-changes-since-24-04 #ubuntu

Hashtags

123•••910
ПретходнаСтраница 1 од 10Следна