Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python c like struct

from typing import NamedTuple


class User(NamedTuple):
    name: str


class MyStruct(NamedTuple):
    foo: str
    bar: int
    baz: list
    qux: User


my_item = MyStruct('foo', 0, ['baz'], User('peter'))

print(my_item) # MyStruct(foo='foo', bar=0, baz=['baz'], qux=User(name='peter'))
Comment

python c like struct

from dataclasses import dataclass


@dataclass
class Point:
    x: float
    y: float
    z: float = 0.0


p = Point(1.5, 2.5)

print(p)  # Point(x=1.5, y=2.5, z=0.0)
Comment

PREVIOUS NEXT
Code Example
Python :: python json nan 
Python :: open python file with read write permissions 
Python :: ide for python 
Python :: newtorkx remove node 
Python :: split df coliumn 
Python :: pandas append sheet to workbook 
Python :: The MEDIA_URL setting must end with a slash. 
Python :: convert timestamp to period pandas 
Python :: merge sort python 
Python :: python greater than dunder 
Python :: root = tk() python 3 
Python :: setup mongodb database with django 
Python :: python count unique values in list 
Python :: convert to lwercase in df column 
Python :: python append to tuple list 
Python :: smallest possible number in python 
Python :: install python 3.4 mac terminal 
Python :: python [] for loop 
Python :: remove deprecation warning python 
Python :: trim strings python 
Python :: Insert between Characters Python 
Python :: python colored text in console 
Python :: column of lists pandas 
Python :: split string by special characters python 
Python :: multiprocessing while applying a function in pandas 
Python :: python find oldest and newest date 
Python :: python observer pattern 
Python :: DIF_GCD solution 
Python :: Palindrome in Python Using while loop for string 
Python :: how to define a functio in python 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =