@dreamsgallerys · Post #2058 · 08.02.2024 г., 13:56
#MJ
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
Пребарај: #mj
@dreamsgallerys · Post #2058 · 08.02.2024 г., 13:56
#MJ
Hashtags
@stablediffusion · Post #1512 · 28.09.2022 г., 06:20
dante and virgil standing in a cue to a cashier in a modern supermarket, dante pushing a trolley, in gustav dore style, etched engraving, super high details #MJ • Creator
Hashtags
@stablediffusion · Post #1500 · 27.09.2022 г., 15:03
#mj
Hashtags
@stablediffusion · Post #1479 · 26.09.2022 г., 14:02
Подборка поездов #mj
Hashtags
@stablediffusion · Post #1476 · 26.09.2022 г., 05:32
pioneer with a camera, in the rays of the sun, Artgem and greg rutkowski masterpiece, hyperrealistic surrealism, award winning masterpiece with incredible details :: in the style of devilman #mj
Hashtags
@stablediffusion · Post #1392 · 24.09.2022 г., 10:17
wlop. room. garden. disney princess, art, highly detailed, digital painting, artstation, young girl, long hair, cute girl, belly dance, blueprint, detailed eyes, perfect faces, fine details, room, cute, elegant, art, gold sharms, concept art, smooth, sharp focus, illustration, artgerm, wlop, craig mullins, greg rutkowski --test --creative --upbeta --ar 1:2 #mj
Hashtags
@stablediffusion · Post #1323 · 21.09.2022 г., 12:30
ferrari camping bus in the beautiful mountains, intricate exterior, campsite, ultra detailed, photorealistic, octane render #mj • Creator
Hashtags
@stablediffusion · Post #1245 · 19.09.2022 г., 11:51
nuclear strike in eye, superrealism, close look, cg, cinematic --v 3 --s 5000 #mj
Hashtags
@inbox_all · Post #108 · 07.05.2021 г., 08:17
BILLIE JEAN (HIStory Tour, Munich 1997) 迈克尔·杰克逊(Michael Jackson)1997 年 HIStory 巡演德国慕尼黑演唱会表演《BILLIE JEAN》现场片段。 HIStory 世界巡回演唱会是 MJ 的第三次世界巡回演唱会,也是最后一次。1996年9月7日开始,1997年10月15日结束,横跨非洲、亚洲、欧洲、大洋洲和夏威夷。此次巡演共82场演出,共计4500000歌迷入场,总收入高达1.63亿美元,创造惊人神话。 1997 年 HIStory 巡演德国慕尼黑演唱会现场完整视频链接(4K修复):LIVE IN MUNICH, 1997 [ZDF Version] - HIStory World Tour (Munich, 1997) #音乐#MJ
@PensivePost · Post #5053 · 01.04.2021 г., 08:33
When you face your demon. The day when you feel every possible pain, confusion, darkness, the negativity you can imagine. When you can't able to sleep when you can't able to breathe peacefully, and so on. Consider this now you found your demon. You feel helpless, you feel so numb, you feel lost. But you know what? Even in the night of darkness, there is still hope of light that waiting for you. Gautam Buddha once said, whenever you fall into the worst situation never forget to pursue something good from it. Make your pain your best teacher your best friend. You're pain always trying to say become better than you used to be. Become stronger than you used to be. • This Universe beyond our thinking and imagination. In this universe, there is something or nothing. We don't know. No one does. I don't know where you live but I know you live somewhere in the world in this tiny world, we don't know why we here, we don't know why we born. We come into this world. We spend our lives with our loved ones, then we die they will cry and they will move on because this is very difficult to live with that pain and they also die one day. If you do something to help this world some more people remember you and some will cry some will not and they also move on. Something always with you withing you but we always underestimate that sense of existence. In this new world, we always greedy to feed logic and reasoning but our small brain not made out for that, this universe beyond our mind. Thoughts come and goes. Days come and goes. The feeling comes and goes. People come and goes. What remains at this moment? You! When you're day will come you also leave this world. Understand this and be grateful for this precious life. Be kind, be honest add value to your life. Find something that you can live or die for. Find your calling. Suppose even if you don't achieve what you planned for the last day of your life, you will have a smile of satisfaction on your face that you never give up you always stand back when you fall. You always fight back. This only enough to make you smile on your last day. When someone decides to give that precious life to something he/she loves, The great infinite universe starts giving them energy, potential, the courage to do that thing. Then nothing seems that important than your purpose. Believe in yourself the more you hurt the more you will become stronger. Have faith in my words, forgive yourself for everything and start again my love. Thanks for reading. #MJ#Review#story
@stablediffusion · Post #1649 · 05.10.2022 г., 11:07
Futuristic spaceship close-up, hidden in the forest, russian wooden buildings, the atmosphere of ancient Russia, Russian folklore, in the style of Shishkin --ar 16:9 --test --creative #Конкурс #MJ
@stablediffusion · Post #1615 · 02.10.2022 г., 12:52
old black and white photo, robot barber, 1850s style, by Studio Ghibli, ultra detailed, photo realistic --ar 9:12 --test --creative #конкурс#mj