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 :: how to combine number of excel files into a single file using python or pandas 
Python :: how to extract column from numpy array 
Python :: how to make a new key in a dictionary python 
Python :: python get website chrome network tab 
Python :: plot multiple columns in different colors plotly 
Python :: plotting mean in density plot ggplot2 
Python :: normalized histogram pandas 
Python :: python find string in string 
Python :: how to install python packages in local directory 
Python :: h2o ai python 
Python :: ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters 
Python :: .size pandas 
Python :: python black 
Python :: install tabula 
Python :: histogram python 
Python :: how to find min, max in dictionaries 
Python :: fill_between matplotlib 
Python :: flask get with parameters 
Python :: pandas split cell into multiple columns 
Python :: TypeError: __init__(): incompatible constructor arguments. The following argument types are supported: 1. tensorflow.python._pywrap_file_io.BufferedInputStream(arg0: str, arg1: int) 
Python :: reactstrap example 
Python :: Reversing Ints 
Python :: python create sqlite db file 
Python :: hwo to except every error in python try statemen 
Python :: seaborn factorplot python 
Python :: fraction to float 
Python :: relative frequency histogram python 
Python :: sns swarm plot 
Python :: target encoder sklearn example 
Python :: python check if false in dict 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =