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

Резултати

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

Пребарај: #russianlanguageday

当前筛选 #russianlanguageday清除筛选
Russian Consulate in Cape Town

@rusconct · Post #1642 · 06.06.2024 г., 06:47

🎙 Foreign Minister Sergey Lavrov’s greetings on Russian Language Day 💬 This June 6, we celebrate the 225th birthday of Alexander Pushkin, the great Russian poet. The UN Russian Language Day is observed on the same day. Russian culture and science created their universally acclaimed masterpieces in the language which served as the mother tongue for Alexander Pushkin and Leo Tolstoy, Fyodor Dostoevsky and Ivan Turgenev. The role the Russian language plays in terms of enabling people of various ethnic backgrounds to communicate internationally can hardly be underestimated. Today, over 250 million people speak this language around the world. The fact that various multilateral structures have designated Russian as their official or working language demonstrates just how relevant it is in today’s world. Russian Language Day has been listed in the UN’s International Days and Weeks calendar as part of the programme to promote multilingualism and cultural diversity. The Russian language’s broad dissemination around the world, as well as our common past and far-reaching economic and people-to-people ties have come together to create a solid foundation for reinforcing integration processes across the European space. <...> 🤝 I am convinced that marking Russian Language Day, which is timed to coincide with the jubilee of our great poet, helps promote international cultural and educational cooperation and maintain an atmosphere of friendship and trust among nations. Read in full #RussianLanguageDay

Russian Mission to EU

@RussianMissionEU · Post #1474 · 06.06.2024 г., 18:25

🎙 Foreign Minister Sergey Lavrov’s greetings on Russian Language Day 💬 This June 6, we celebrate the 225th birthday of Alexander Pushkin, the great Russian poet. The UN Russian Language Day is observed on the same day. Russian culture and science created their universally acclaimed masterpieces in the language which served as the mother tongue for Alexander Pushkin and Leo Tolstoy, Fyodor Dostoevsky and Ivan Turgenev. The role the Russian language plays in terms of enabling people of various ethnic backgrounds to communicate internationally can hardly be underestimated. Today, over 250 million people speak this language around the world. The fact that various multilateral structures have designated Russian as their official or working language demonstrates just how relevant it is in today’s world. Russian Language Day has been listed in the UN’s International Days and Weeks calendar as part of the programme to promote multilingualism and cultural diversity. The Russian language’s broad dissemination around the world, as well as our common past and far-reaching economic and people-to-people ties have come together to create a solid foundation for reinforcing integration processes across the Eurasian space. <...> 🤝 I am convinced that marking Russian Language Day, which is timed to coincide with the jubilee of our great poet, helps promote international cultural and educational cooperation and maintain an atmosphere of friendship and trust among nations. Read in full #RussianLanguageDay

🇷🇺🇺🇳 On June 6, Russian Language Day was held at the headquarters of the United Nations Economic Commission for Africa (UNECA) in Addis Ababa. Executive Secretary of the UNECA H.E. Mr. Claver Gatete, Ambassador of Russia to Ethiopia H.E. Mr. Evgeny Terekhin, Ambassador of Armenia to Ethiopia H.E. Mr. Sahak Sargsyan addressed the audience. The cultural part of the event was opened by Russian folk songs and dances performed by teachers and students of the school at the Embassy. Representatives of the club of Russian compatriots in Ethiopia “Fatherland” demonstrated the costumes of the peoples of our country. Poems by A.Pushkin and N.Gumilyov, A.Akhmatova were performed by Ethiopian graduates of Russian universities and students of Russian language courses at the Russian Center for Science and Culture in Addis Ababa. #RussianLanguageDay

🎙 Foreign Minister Sergey Lavrov’s greetings on Russian Language Day 💬 This June 6, we celebrate the 225th birthday of Alexander Pushkin, the great Russian poet. The UN Russian Language Day is observed on the same day. Russian culture and science created their universally acclaimed masterpieces in the language which served as the mother tongue for Alexander Pushkin and Leo Tolstoy, Fyodor Dostoevsky and Ivan Turgenev. The role the Russian language plays in terms of enabling people of various ethnic backgrounds to communicate internationally can hardly be underestimated. Today, over 250 million people speak this language around the world. The fact that various multilateral structures have designated Russian as their official or working language demonstrates just how relevant it is in today’s world. Russian Language Day has been listed in the UN’s International Days and Weeks calendar as part of the programme to promote multilingualism and cultural diversity. The Russian language’s broad dissemination around the world, as well as our common past and far-reaching economic and people-to-people ties have come together to create a solid foundation for reinforcing integration processes across the Eurasian space. <...> 🤝 I am convinced that marking Russian Language Day, which is timed to coincide with the jubilee of our great poet, helps promote international cultural and educational cooperation and maintain an atmosphere of friendship and trust among nations. Read in full #RussianLanguageDay

Russian Mission to EU

@RussianMissionEU · Post #1470 · 06.06.2024 г., 12:26

🗓On 6 June, the birthday of the great Russian poet Alexander Pushkin, the international Russian Language Day is celebrated all over the world. 🇷🇺To mark the 225th anniversary of Pushkin's birth, Chargé d’Affaires a.i. of the Russian Mission to the EU Kirill Logvinov laid flowers at his monument in Brussels. 📝We suggest you read a passage from Pushkin's poem "To the Slanderers of Russia" (1831), which sounds more relevant today than ever: What stirs ye? Is it that this nation On Moscow's flaming wall, blood-slaked and ruin-quenched, Spurned back the insolent dictation Of Him before whose nod ye blenched? Is it that into dust we shattered The Dagon that weighed down the earth so wearily? And our best blood so freely scattered To buy for Europe peace and liberty? Ye 're bold of tongue — but hard, would ye in deed but try it. Or is the hero, now reclined in laurelled quiet, Too weak to fix once more Izmail's red bayonet? Or hath the Russian Tsar ever in vain commanded? Or must we meet all Europe banded? Have we forgot to conquer yet? Or rather, shall they not, from Perm to Tauris' fountains, From the hot Colchian steppes to Finland's icy mountains, From the grey Kreml's half-shattered wall, To far Kathay, in dotage buried, — A steely rampart close and serried, Rise, Russia's warriors, one and all? Then send your numbers without number, Your maddened sons, your goaded slaves, In Russia's plains there 's room to slumber, And well they 'll know their brethren's graves! #RussianLanguageDay#Pushkin

Russian Mission to ASEAN

@aseanrussia · Post #468 · 06.06.2023 г., 07:14

🗓 On June 6, Russia celebrates #RussianLanguageDay. On this day in 1799, the greatest poet, prose writer, playwright, historian, critic, and founder of the modern Russian literary language, Alexander Pushkin, was born. 🇷🇺 On June 6, 2011, the President of the Russian Federation signed an Executive Order on holding Russian Language Day annually in order to “preserve, support and promote the Russian language as a national treasure of the peoples of the Russian Federation, a means of international communication and an integral part of the cultural and spiritual heritage of world civilisation.” • Support and promotion of the Russian language abroad is one of the most important tools for expanding international cultural cooperation between Russia and other countries. • Russian has the status of a state and official language in Russia, Belarus, Kazakhstan, Kyrgyzstan, Tajikistan and other countries. 🇺🇳 Russian is the official or working language in a number of international organisations, including the UN and some of its specialised agencies, the SCO, OSCE, CIS, EAEU, ATS, CSTO, ISO, CES, GUAM, IFRC and ICRC. ❗️ The Russian language is one of the most popular languages in the world: • 6️⃣th most spoken language in the world; • 8️⃣th most widespread language; • 2️⃣nd by the number of websites on the Internet. In general, about 146 million citizens of the Russian Federation and 130 million people abroad speak Russian. #RussianLanguage#Pushkin

Россия в ОБСЕ

@RusMissionOSCE · Post #6920 · 06.06.2025 г., 07:56

🗓 June 6 is #RussianLanguageDay in Russia. ✍️#OnThisDay in 1799 the great Russian poet, writer, playwright, historian, publicist, creator of the modern Russian literary language Alexander #Pushkin was born. 🇷🇺 On June 6, 2011, the President of the Russian Federation signed a decree on the annual celebration of Russian Language Day in order to “preserve, support and develop the Russian language as a national treasure of the peoples of the Russian Federation, a tool of international communication and an integral part of the cultural and spiritual heritage of world civilization”. Russian is one of the most popular languages in the world. It has a rich literary heritage and is one of the most dynamic languages. Today, Russian is spoken by over 250 million citizens of Russia and other countries. Watch the video to learn more interesting facts 👆 #RussianLanguage

Russian Embassy in Cambodia

@russian_embassy_in_cambodia · Post #4720 · 06.06.2025 г., 06:26

🗓 June 6 is #RussianLanguageDay in Russia. ✍️#OnThisDay in 1799 the great Russian poet, writer, playwright, historian, publicist, creator of the modern Russian literary language Alexander #Pushkin was born. 🇷🇺 On June 6, 2011, the President of the Russian Federation signed a decree on the annual celebration of Russian Language Day in order to “preserve, support and develop the Russian language as a national treasure of the peoples of the Russian Federation, a tool of international communication and an integral part of the cultural and spiritual heritage of world civilization”. Russian is one of the most popular languages in the world. It has a rich literary heritage and is one of the most dynamic languages. Today, Russian is spoken by over 250 million citizens of Russia and other countries. Watch the video to learn more interesting facts 👆 #RussianLanguage

Russian Consulate in Cape Town

@rusconct · Post #2702 · 06.06.2025 г., 06:49

🗓 June 6 is #RussianLanguageDay in Russia. ✍️#OnThisDay in 1799 the great Russian poet, writer, playwright, historian, publicist, creator of the modern Russian literary language Alexander #Pushkin was born. 🇷🇺 On June 6, 2011, the President of the Russian Federation signed a decree on the annual celebration of Russian Language Day in order to “preserve, support and develop the Russian language as a national treasure of the peoples of the Russian Federation, a tool of international communication and an integral part of the cultural and spiritual heritage of world civilization”. Russian is one of the most popular languages in the world. It has a rich literary heritage and is one of the most dynamic languages. Today, Russian is spoken by over 250 million citizens of Russia and other countries. Watch the video to learn more interesting facts 👆 #RussianLanguage

🗓 June 6 is #RussianLanguageDay in Russia. ✍️#OnThisDay in 1799 the great Russian poet, writer, playwright, historian, publicist, creator of the modern Russian literary language Alexander #Pushkin was born. 🇷🇺 On June 6, 2011, the President of the Russian Federation signed a decree on the annual celebration of Russian Language Day in order to “preserve, support and develop the Russian language as a national treasure of the peoples of the Russian Federation, a tool of international communication and an integral part of the cultural and spiritual heritage of world civilization”. Russian is one of the most popular languages in the world. It has a rich literary heritage and is one of the most dynamic languages. Today, Russian is spoken by over 250 million citizens of Russia and other countries. Watch the video to learn more interesting facts 👆 #RussianLanguage

Russian Embassy in Cyprus

@rusembcy · Post #1842 · 06.06.2024 г., 05:24

🗓 June 6 is #RussianLanguageDay in Russia. ✍️#OnThisDay in 1799 the greatest poet, writer, playwright, historian, publicist, creator of the modern Russian literary language Alexander Pushkin was born. 🇷🇺 On June 6, 2011, the President of the Russian Federation signed a decree on the annual celebration of Russian Language Day in order to “preserve, support and develop the Russian language as a national treasure of the peoples of the Russian Federation, a tool of international communication and an integral part of the cultural and spiritual heritage of world civilization”. Russian is one of the most popular languages in the world. It is spoken by about 146 million citizens of the Russian Federation and 109 million abroad. Watch the video to learn more interesting facts 👆 #RussianLanguage#Pushkin

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