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

Резултати

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

Пребарај: #wait

当前筛选 #wait清除筛选
Social Justice Watch

@social_justice_watch · Post #17065 · 05.09.2022 г., 02:13

I wonder how many gay people are actually transgender & dont know it because people thing being transgender is transitioning when it’s literally just not being cis. like I had a friend tell me last night “all my life I wanted to be a girl. even to this day, like if someone told me I could transition & look like you or *insert another trans woman idk* I would do it in a heartbeat” and when I was like omg ur transgender he was surprised? like he was like wait just wanting to be a girl makes me transgender even if I dont do anything about it? and like its harder to pinpoint non binary people but if u have a desire be a different gender ur transgender. transitioning is a choice but being transgender is not. “One of the symptoms of being a girl is wanting to be a girl.” Don’t remember where I heard that but the quote is my life. This is one of the posts I can explicitly pinpoint as helping me realize that I might not be cis. The biggest symptom of being trans is wanting to not be your gender. It can also be dysphoria, it can also be euphoria, it can also be presentation, but wanting to be something else is all you really need. #wait so ur telling me#‘i dont want to have a gender’#can mean#‘i dont have a gender??’ I would also like to know… for reasons Confirmed. How to know you’re agender: You don’t want to be anything else. You look at the options for gender and gender presentation and decide to go back to bed Bold of you to assume I got out of bed Nah but seriously thanks for the insight So, if I look at gender and say “this is some bullshit and I want no part of it”, I guess that makes me agender? if that’s how you wanna identify, yeah. feeling anything mentioned in this post doesn’t mean you have to identify as trans, but feeling anything in this post is literally all that’s necessary to identify as trans if you want to. fuck gatekeepers forever. 👏if👏you👏don't👏feel👏cis👏you're👏possibly👏not👏cis👏 i mean this is literally what jvn said This is one of those things where you can go 25+ years of your life not realising that actually no not everyone secretly wishes they were some mashup of male and female and that you are, in fact, genderfluid as fuck. You can want to be the other gender. You can want to be another gender. You can want to divorce all connection to the gender you were born into. You can want to keep it as an origin point that shapes your journey. You can want to be more than one gender at once. You can want to be more than one gender, at different times. You can want to be no gender. You can want to be sort of in between genders. You can want to be both genders. You can want to be rid of gendered body parts you already have. You can want to keep gendered body parts while also being another gender. You can want to be rid of them but not want the side effects of excising them. You can feel dysphoria at being shaped like/viewed as/treated like a gender you don’t want. You can feel euphoria at being shaped like/viewed as/treated like a gender you do want. You can change your mind or adjust your goals or refine your wishes. You can be stationary and fixed in your identity. You can be fluid and changing. You can be extremely gendered in your presentation. You can be not very gendered in your presentation. You can be androgynous. You can be a little of both. You can be a lot of both. If gender is a line you can cross, as the words trans (across/on the other side of) and cis (here/on the same side of) indicate, you can cross it in any way you like, including dancing on top of it. Be happy. Be you. This is an extremely affirming post. https://genderkoolaid.tumblr.com/post/691574739639091200/i-wonder-how-many-gay-people-are-actually

Hashtags