meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
programming:python [2017/08/07 22:29]
niziak
programming:python [2020/07/03 09:51] (current)
niziak ↷ Page moved from python to programming:python
Line 1: Line 1:
 +====== Python ======
 +
 +====== OOP ======
 +
 +===== Call parent constuctor ======
 +
 +<code python>​super().__init__()</​code>​
 +
 ====== String formatting ====== ====== String formatting ======
  
Line 18: Line 26:
 print("​{firstname} {lastname}"​.format(firstname="​Horst",​ lastname="​Gutmann"​)) print("​{firstname} {lastname}"​.format(firstname="​Horst",​ lastname="​Gutmann"​))
 </​code>​ </​code>​
 +
 +  * new f-strings in Python 3.6
 +<code python>
 +name = '​Fred'​
 +age = 42
 +print(f'​He said his name is {name} and he is {age} years old.')
 +</​code>​
 +
 +===== logger =====
 +
 +Logger is optimized to defer avaluation of arguments until it is needed, so for best performance use ''​%''​ formating.
 +Instead of this:
 +<code python>​logger.error('​oops caused by %s' % exc)</​code>​
 +do that:
 +<code python>​logger.error('​oops caused by %s', exc)</​code>​
 +
  
 ====== Exceptions ====== ====== Exceptions ======