Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

attr module python

>>> from attr import attrs, attrib, Factory
>>> @attrs
... class SomeClass(object):
...     a_number = attrib(default=42)
...     list_of_numbers = attrib(default=Factory(list))
...
...     def hard_math(self, another_number):
...         return self.a_number + sum(self.list_of_numbers) * another_number
>>> SomeClass(1, [1, 2, 3])
SomeClass(a_number=1, list_of_numbers=[1, 2, 3])
Comment

PREVIOUS NEXT
Code Example
Python :: find prime in python list 
Python :: combine list of dicts 
Python :: python slice 
Python :: rename column by indexing 
Python :: bracket balanced or not in python 
Python :: how to check django version 
Python :: list to dataframe columns 
Python :: how to draw a single pixel in pyglet 
Python :: how to get the year and month in python 
Python :: message handler python telegram bot example 
Python :: def python 
Python :: python checking for NoneType 
Python :: compile python to exe bash 
Python :: python assert is datetime 
Python :: python returned non-zero exit status 1. 
Python :: python 2.7 venv 
Python :: python turtle shapes 
Python :: format date string python 
Python :: python trim 
Python :: python __repr__ 
Python :: indexes meta django 
Python :: appending to a list python 
Python :: python - extract the price from a string 
Python :: python sqrt function 
Python :: if condition in print statement python 
Python :: draw bounding box matplotlib 
Python :: python dict del key 
Python :: python round 1 decimal place 
Python :: push notification using python 
Python :: make parameter optional python 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =