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

Резултати

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

Пребарај: #restomod

当前筛选 #restomod清除筛选
Car News

@car_news · Post #994 · 12.02.2025 г., 15:31

📰Interior of Maserati restomod for 585 thousand euros revealed 🚘 Italian company Modena Automobiliannounced the creation of a restomod Maserati Biturbo Shamal in November last year. Visually it refers to a rare model Maserati Shamal, but as a donor involved more mass Maserati Biturbo. Now the first renderings of the exterior were published, and there are images of the interior, made in a deliberately analog style. ℹ️ It generally repeats the original interior of the Maserati Biturbo – for example, the contours of the front panel and the center console were recreated. The equipment is promised to include Recaro Classic seats and climate control, a removable handheld chronometer will appear on the front panel, and acoustics can be chosen among the brands Bose, JBL or Alpine. The car will also have a rear sofa that is restored seats from the classic Maserati Biturbo. @CarsNews #Maserati#restomod

Auto Life

@revheadcrypto · Post #86 · 12.07.2024 г., 08:53

A Ferrari F355 from the 1990s has been transformed into a carbon fiber restomod, with the exterior design led by former Jaguar designer Ian Callum. The exterior panels of this restomod by Evoluto Automobili are crafted from carbon fiber. The interior can be customized with carbon fiber, suede, and other materials chosen by the client. The restomod retains the stock 3.5-liter V8 engine from the F355, but the engine undergoes serious modifications. It is claimed to deliver 420 hp and is paired with a six-speed manual transmission. A total of 55 units will be produced.🏎️💨 #FerrariF355#Restomod#Cars#Auto#LuxuryCars

Auto Life

@revheadcrypto · Post #174 · 26.07.2024 г., 10:10

Introducing the stunning European RS by Thorney Kelham, a reimagined classic Porsche 911 available for $750,000! 🚗 This project enhances the exterior and interior design, widens the track, upgrades the suspension, and installs carbon-ceramic brakes. 💥 The base engine is a 3.8-liter flat-six from the Porsche 911 (993), tuned to 390 hp. For a premium option, a 4.0-liter unit producing 406 hp is offered, with the top-tier 3.8-liter engine spinning up to 10,000 rpm. 🏁 Only 25 units will be crafted! Get your hands on this masterpiece now! 🔥#ThorneyKelham#EuropeanRS#Porsche911#Restomod#LuxuryCars#Auto

Auto Life

@revheadcrypto · Post #429 · 03.09.2024 г., 09:21

🚗✨ Introducing the stunning restomod Jaguar XK120, designed by former McLaren designer Paul Howse! 🌟 With a starting price of £550,000 (over $720,000), only 25 exclusive units will be produced. Each European GT features a lightweight alloy body, giving it a wider and lower stance than the original. Under the hood, the iconic 3.8L inline-six engine has been completely reimagined, delivering an impressive 300 or 340 horsepower—up from the original 220 hp! 💪🔥 #JaguarXK120#Restomod#EuropeanGT#PaulHowse#LuxuryCars#CarEnthusiasts#Auto🚘

Auto Life

@revheadcrypto · Post #357 · 20.08.2024 г., 18:54

🚗✨ Introducing the Veloce12: A Stunning Restomod of the Ferrari 550 Maranello! ✨🚗 For €690,000, Touring Superleggera has reimagined the iconic 550 Maranello into the breathtaking Veloce12! 😍 🔍 Key Features: - Custom Carbon Fiber Body: Crafted from scratch for a lightweight and sleek design. - Modern Lighting: Upgraded LED headlights and taillights for a contemporary touch. 💡 - Revamped Interior: A complete redesign that maintains the classic essence of the original. 🛋️ 💥 Power Upgrade: The atmospheric V12 now boasts an impressive 510 hp (up from 485 hp) with enhanced cooling and a custom exhaust system. 🔥 🛑 Performance Brakes: Equipped with powerful Brembo calipers for ultimate stopping power! 🚀 #Veloce12#Ferrari550#Restomod#TouringSuperleggera#CarEnthusiast#Supercar#LuxuryCars#Auto🚘💖

Auto Life

@revheadcrypto · Post #387 · 25.08.2024 г., 23:56

🚗✨ Restomod Magic: BMW 8 Series Reimagined! ✨🚗 Check out this stunning restomod of the first-generation BMW 8 Series! 🏎️💨 🔧 Upgrades Include: - Carbon Fiber Panels: Lightweight and sleek! 🖤 - Powerful V10 Engine: Swapped from the BMW M5 (E60) and bored out to 5.8 liters! 💥 - Modern Interior Touches: Blending classic with contemporary! 🛋️ #BMW#Restomod#8Series#M5#CarEnthusiast#ClassicMeetsModern#CarbonFiber#V10Power#Auto🚘💫

Auto Life

@revheadcrypto · Post #193 · 29.07.2024 г., 12:42

Just sold at auction! 🚗💰 This stunning Alfa Romeo 2000 GTV restomod with a carbon fiber body went for $220,000. 🤑 It took around four years to build this beauty, with everything from the chassis to the powertrain being completely overhauled. 🛠️ Italian specialists worked on the chassis and body, while the rest of the work was done in Canada. The upgraded 2.0 carbureted engine's exact output isn't specified, but the original Alfa Romeo 2000 GTV came with a 130-horsepower engine. 🏁 #AlfaRomeo#2000GTV#Restomod#CarbonFiber#Auction#ClassicCar#LuxuryCar#ItalianStyle🇮🇹

Auto Life

@revheadcrypto · Post #630 · 09.11.2024 г., 10:04

🚗💨Introducing the Doughboy: A Mind-Blowing Restomod with 2838 HP!💥 At the SEMA Show, we unveiled a beast that redefines power and performance! 🔥 This incredible V8 engine boasts a staggering 8.8 liters of displacement and is equipped with dual turbochargers, pushing the limits of automotive engineering. 💪✨ 🔧 With the engine strategically shifted 40 cm back towards the center of the wheelbase, every detail has been meticulously crafted from scratch, including the intake, exhaust, and cooling systems. 🛠️ 💎 Custom parts were expertly created using CNC machining and 3D printing technology, showcasing innovation at its finest. Get ready to experience the future of restomods! 🚀 #Doughboy#SEMA2023#Restomod#V8Power#Turbocharged#CarEnthusiast#AutomotiveInnovation#CustomCars#CNC#Auto