Super tiny struct in python

I wish I could access the members by name without quotation marks without creating a separate "type" each time!

struct.py


class Struct(object):
    def __init__(self,**kargs):
        for key,val in kargs.iteritems():
            setattr(self,key,val)

if __name__ == '__main__':
    t = Struct(a=10,b=20,c=30)
    t.c = "<30>"
    print t.a, t.b, t.c
<MARKEDONE:~>
✏ ipy struct.py
10 20 <30>
<MARKEDONE:~>
✏

Maybe there is a better way. I'm a dead programmer, so I forgot a lot.

Recommended Posts

Super tiny struct in python
Quadtree in Python --2
Python in optimization
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Super easy! Python + Flask environment in Docker quickly
Get pointers to struct members in Python ctypes
Sorted list in Python
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 18 in Python
Singleton pattern in Python
File operations in Python
Key input in Python
Daily AtCoder # 33 in Python
Logistic distribution in Python
Daily AtCoder # 7 in Python
LU decomposition in Python
One liner in Python
Daily AtCoder # 24 in Python
case class in python