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

Резултати

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

Пребарај: #character

当前筛选 #character清除筛选

😄Character ➖➖➖➖➖➖ Character is a noun and it can mean: 🔘 'a person in a book or a film' 🔜The best friend is my favourite character. 🔘‘the quality that makes someone who they are’. 🔜He has a forgiving character. 🔘someone who is mentally strong can 'have a lot of character' or 'be a strong character'. 🔜She'll be a great manager; she has a lot of character. 🔜You'll need to be a strong character to get through this challenge. 🔘‘the quality that makes places and things interesting, different or attractive’. 🔜It's a beautiful village, full of character. #Character👨‍🏫@America ➖➖➖➖➖➖➖➖➖➖➖➖ 🆕 Crypto News @Money 😁 Crypto Game @Egame 🇺🇸 US News @America 🇯🇵 Japan News @Japan 🇦🇪 UAE News @Dubai ▶️ Popular Movies @Videos 😜 Best Funny Video @Funnys

Hashtags

No Midjourney

@midjourney · Post #6289 · 30.09.2024 г., 05:51

Discord @andreholzmeister Midjourney #character an elegant man character, luxury brand, minimalist, tall, thin, long legs, short torso, smile, joy, happy, art deco, modern, 3D, octane —v 5.2 @midjourney • @midjourney_ru

Hashtags

No Midjourney

@midjourney · Post #6281 · 29.09.2024 г., 04:38

Discord @casajordi Midjourney #character Photography, masterpiece of black and white soft portrait photography, art by Irving Penn A chic Bengal Tiger with fashion dress, clothes by Balenciaga, ultra realistic minimalist fashion photography, art by mario testino for vogue, chic, elegant, haute couture, natural light, minimalist background @midjourney • @midjourney_ru

Hashtags

No Midjourney

@midjourney · Post #6274 · 27.09.2024 г., 10:13

Discord @madhutungnirun Midjourney #character art russia, angel, portrait, painting, art deco, russianart, french art digital painting, in the style of light sky-blue and light gold,, photorealistic fantasies, princesscore, elegant, emotive faces, rococo portraitures, close up, soft, romantic scenes @midjourney • @midjourney_ru

Hashtags

No Midjourney

@midjourney · Post #6266 · 26.09.2024 г., 10:11

Discord @y0844 Midjourney #character cute monkey monster wearing Chinese martial arts costumes, Chinese Wuxia, Chinese painting style, cartoon IP, movie lights, clean white background, advanced color scheme, octane rendering, full body, Extreme detail, Kung Fu, surrealism, 3D, Behance, Pinterest, trendy blind box toys, award winning @midjourney • @midjourney_ru

Hashtags

No Midjourney

@midjourney · Post #6257 · 24.09.2024 г., 04:58

Discord @_ingunn Midjourney #character beautiful fire girl with iridescent skin, shimmering rainbow colours, hyper realistic photography —sref 3120277969 @midjourney • @midjourney_ru

Hashtags

No Midjourney

@midjourney · Post #6252 · 23.09.2024 г., 03:34

Discord @judaz.pham Midjourney #character goat as girl with the pearl earring 🐱 t.me/midjourney_ru 🐱t.me/midjourney_character 🐱t.me/midjourney_dark

Hashtags

No Midjourney

@midjourney · Post #6245 · 21.09.2024 г., 04:22

Discord @johnjbamboo Midjourney #character color streetphotography of a person in Shanghai, in the style of Magnum Photo with motion blur and foreground blur, reflections @midjourney • @midjourney_ru

Hashtags

No Midjourney

@midjourney · Post #6240 · 20.09.2024 г., 03:59

Discord @zxq6826 Midjourney #character Richard Scarry's Picture Book Style: A lovely Tortoiseshell cat and Mother Tortoiseshell cat,red lips,big eyes, multiple poss and expressions as, Happy, gentle, cute,happy,coquettish,as an illustration set, chibi,pixar animation,3d,8k,dynamic pose, dark white,group,expression collection —niji 5 @midjourney • @midjourney_ru

Hashtags

No Midjourney

@midjourney · Post #6234 · 18.09.2024 г., 03:34

Discord @apptist Midjourney #character A cute, simple toy-like pink hippo face with a white background. The hippo's mouth is wide open, showing smooth, toothless gums. It has big, expressive eyes, a rounded snout, and a cheerful expression. The face is bright pink and smooth, with no body parts visible. The design is playful and inviting for a children's game 🐟 t.me/midjourney_ru 🐽t.me/midjourney_character 🐟t.me/midjourney_dark

Hashtags

No Midjourney

@midjourney · Post #6227 · 17.09.2024 г., 04:59

Discord @centaur509 Midjourney #character Studio portrait photography of an old indian woman on a dark background, wearing a white shirt, with projection mapping onto her back. The image projected onto the back is a crowd of people @midjourney • @midjourney_ru

Hashtags

No Midjourney

@midjourney · Post #6218 · 15.09.2024 г., 04:25

Discord @superpedro4711 Midjourney #character etherreal ultra realistic futuristic eloquent cute adorable small Flying Squirrels with a huge human smile and big beautiful dreamy eyes eating Layer rice, sweet and sour chicken, pineapple chunks, and bell peppers. Top with sesame seeds and green onion, sitting in fantasy world, dark blue-purple sparkling tones background, lens flare, diffused lighting, fantasy, intricate, highly detailed, lifelike, concept art @midjourney • @midjourney_ru

Hashtags

123•••10•••20•••30•••40•••4344
ПретходнаСтраница 1 од 44Следна