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

Резултати

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

Пребарај: #youth

当前筛选 #youth清除筛选
Trump's Ear

@trumpsear_tg · Post #1766 · 11.11.2025 г., 21:50

The majority of young Americans want to leave the country, a new report from the American Psychological Association showed that 63% of Americans between the ages of 18 and 34 were thinking about emigrating. 🌍 There are 53% of such parents. In the whole country, anxiety is even higher: 76% of adults admitted that they are worried about the state of the country — political division, instability and a sense of uncertainty about the future. Many of the respondents feel isolated and tired. 😟 People who are particularly hard—pressed by the division in the country are more likely to complain of anxiety and health problems - they have higher levels of chronic diseases and fatigue. 🩺 People with high levels of loneliness are more likely to cancel appointments, sleep poorly, and stop taking care of themselves. 🛌 69% of Americans are worried about fakes, 57% are worried about the growing influence of AI, especially young people and parents. 🤖 But 84% are confident that they will be able to build a good life, and 73% believe that they can change the country's future for the better. 💪 #Youth#Poll 👂More on Trump's Ear

Hashtags

Trump's Ear

@trumpsear_tg · Post #2137 · 11.02.2026 г., 19:41

President Donald Trump's administration is now aiming to make the voting process harder for college-age young adults ahead of November's midterm elections. That's according to a Monday op-ed by MS NOW's Ja'han Jones, who wrote that the Trump administration's Department of Education may be exploring a way to curb young voter turnout with a newly announced investigation into Tufts University. The Education Department announced its new probe in a recent press release, saying the Boston, Massachusetts-based school may have been "illegally sharing college students’ data with third parties to influence elections." The investigation is centered on Tufts' National Study of Learning, Voting, and Engagement (NSLVE). Tufts describes the NSLVE as "a service to over 1,000 U.S. colleges and universities that can use it to understand and improve their student voting rates." However, the Trump administration is saying the program could have potentially violated the Family Educational Rights and Privacy Act. "American colleges and universities should be focused on teaching, learning, and research — not influencing elections," Education Secretary Linda McMahon stated. "The Biden Administration, with little to no regard for student privacy laws, openly encouraged institutions to share and utilize student data in order to target certain populations." #Trump#Elections#Youth 👂More on Trump's Ear ⚠️

Amazing Geography 🌍

@amazingeo · Post #420 · 28.10.2025 г., 20:31

🌍 More than 40% of the world's population is under age 25—a record share of young people. This youth wave is largest in Africa and South Asia, shaping future trends worldwide. ✨ #demography⚡#youth⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

🌐 Organized by youth, for youth: the World Bank Group #Youth Summit is back! 💡 The 11th edition of the World Bank Group Youth Summit is on the theme of Digital Transformation and will engage thousands of participants from around the world. 🧭 The Summit is the largest worldwide annual gathering of youth (aged 18-35) hosted by the World Bank Group. ✅ This year's theme, Powering Progress: Youth Leading the Digital Transformation, will focus on three subthemes: Digital Access and Inclusion, Artificial Intelligence, and Sustainable Technology for a Livable Planet. 📲 Join the event online or in person on May 30-31 in Washington DC. 📝 Seats are limited, so APPLY NOW! Applications are reviewed on a rolling basis, and the deadline is April 25th, 2024. ℹ️ For more information, please consult the Summit's website or email [email protected]. 🗣️ Don't miss out on this opportunity to engage with your peers on the most pressing topics facing our generation! 🔎http://wrld.bg/LxEs50QTffx #WBGYouthSummit

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