@Eternalanquan · Post #1685 · 18.02.2026 г., 03:48
day1 in mobile security #learn
Hashtags
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
Пребарај: #learn
@Eternalanquan · Post #1685 · 18.02.2026 г., 03:48
day1 in mobile security #learn
Hashtags
@arkibug · Post #442 · 17.05.2022 г., 06:10
A fun and colorful explanation of how DNS works. https://howdns.works english - episode 1🖼 es - de - fr #learn
Hashtags
@djangoproject · Post #545 · 11.01.2018 г., 14:08
https://online.dr-chuck.com/about.php This is the web site of the "University of Dr. Chuck". I teach a number of free/online/open courses based on free and open materials and this site is the course catalog for my free courses. #learn#python
@djangoproject · Post #524 · 17.12.2017 г., 16:42
https://python.swaroopch.com/ A Byte of #Python "A Byte of Python" is a free book on programming using the Python language. It serves as a tutorial or guide to the Python language for a beginner audience. If all you know about computers is how to save text files, then this is the book for you. #learn
@djangoproject · Post #486 · 31.10.2017 г., 19:49
https://intellipaat.com/tutorial/python-tutorial/ This #Python free tutorial is for beginners as an introduction to learn this powerful programming language. #learn
@djangoproject · Post #432 · 07.09.2017 г., 09:30
# In Python 3.4+ you can use # contextlib.suppress() to selectively # ignore specific exceptions: import contextlib with contextlib.suppress(FileNotFoundError): os.remove('somefile.tmp') # This is equivalent to: try: os.remove('somefile.tmp') except FileNotFoundError: pass # contextlib.suppress docstring: # # "Return a context manager that suppresses any # of the specified exceptions if they occur in the body # of a with statement and then resumes execution with # the first statement following the end of # the with statement." #python#learn
@djangoproject · Post #412 · 15.08.2017 г., 05:11
https://intellipaat.com/tutorial/python-tutorial/ Often, programmers fall for Python because of its minimum compilation time and speedier edit-test-debug cycle. Python is a go-programming language that has automated the way programmers code. This is indeed one of the major reasons developers have switched their interest to Python programming language. It helps you write simple scripts at relatively faster rate compared to Java, C, C++ . Get #Python Certification in just 16 Hours GET CERTIFIED #learn
@djangoproject · Post #284 · 31.03.2017 г., 06:53
http://docs.python-guide.org/en/latest/ Greetings, Earthling! Welcome to The Hitchhiker’s Guide to Python. This is a living, breathing guide. If you’d like to contribute, fork us on GitHub! This handcrafted guide exists to provide both novice and expert Python developers a best practice handbook to the installation, configuration, and usage of Python on a daily basis. This guide is opinionated in a way that is almost, but not quite, entirely unlike Python’s official documentation. You won’t find a list of every #Python web framework available here. Rather, you’ll find a nice concise list of highly recommended options. #learn
@djangoproject · Post #190 · 30.10.2016 г., 07:40
http://www.python-course.eu/finite_state_machine.php #learn#python
@tomoko_channel · Post #1700 · 01.05.2026 г., 04:16
5月决定就是: Complete CS146S "The Modern Software Developer" | 在一个月内完成「The Modern Software Developer」课程。 🌟🎉 恭喜恭喜!!! (2026-05-01 传送门) #learn#random_todolist
Hashtags
@tomoko_channel · Post #472 · 12.06.2024 г., 06:07
6月决定就是: Math | 数学基础 | 例如可以每天看一下 3Blue1Brown 的视频 🌟🎉 恭喜恭喜!!! (2024-06-12 传送门) #learn#random_todolist
Hashtags
@TFGames · Post #1714 · 28.12.2023 г., 20:51
#LEARN#BATTLE https://testflight.apple.com/join/zxzIw9a5