ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
__magick¨¦__ metody
    v Pythonu(2.x)




   (ochutn¨¢vka)

                     Jirka Vejra?ka (@JirkaV)
                                @naPyVo #22
class Person(models.Model):
   name = models.CharField(max_length=128)

   def __unicode__(self):
      return self.name

class MojeTrida(object):
   def __init__(self, data):
      self.data = data
>>> mylist = []
>>> dir(mylist)
['__add__', '__class__', '__contains__', '__delattr__',
'__delitem__', '__delslice__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__',
'__getitem__', '__getslice__', '__gt__', '__hash__',
'__iadd__', '__imul__', '__init__',
 '__iter__', '__le__', '__len__', '__lt__', '__mul__',
'__ne__', '__new__', '__reduce__', '__reduce_ex__',
'__repr__', '__reversed__', '__rmul__', '__setattr__',
'__setitem__', '__setslice__', '__sizeof__', '__str__',
'__subclasshook__', 'append', 'count', 'extend',
'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
>>> mystring = 'My hovercraft if full of eels'


>>> if mystring.index('full') > 0:

>>> if ¡®full¡¯ in mystring:

object.__contains__(self, item)
Called to implement membership test operators. Should return
true if item is in self, false otherwise. For mapping objects, this
should consider the keys of the mapping rather than the values
or the key-item pairs.
>>> 'full' in 'My hovercraft is full of eels¡®
True

>>> class MyStr(str):
...  def __contains__(self, elem):
...     return False

>>> mystring = MyStr('My hovercraft is full of eels')
>>> mystring
'My hovercraft is full of eels'
>>> 'full' in mystring
False
>>> class SortedList(list):
...  def __getitem__(self, key):
...     return sorted(self)[key]

>>> mylist = SortedList([5, 7, 2, 12, 1, 0, 42, 9])
>>> mylist[0]
0
>>> mylist[-1]
42
>>> for x in mylist:
...  print x,
...
5 7 2 12 1 0 42 9
>>> import IPy
>>> class Network(list):
...   def __len__(self):
...      return sum([len(IPy.IP(x)) for x in self])
...
>>> firma = Network(['10.0.10.0/24',
'10.0.20.128/26', '10.0.30.0/25'])

>>> firma
['10.0.10.0/24', '10.0.20.128/26', '10.0.30.0/25']
>>> len(firma)
448
>>> class DobryPrezident(object):
...  def __init__(self, prijmeni):
...     self.prijmeni = prijmeni
...  def __nonzero__(self):
...     return self.prijmeni == 'Cimrman¡®

>>> dobry_prezident = DobryPrezident('stara Vomackova')
>>> if dobry_prezident:
...  print 'Mame ji radi!'

>>> dobry_prezident = DobryPrezident('Cimrman')
>>> if dobry_prezident:
...  print 'Budoucnost patri aluminiu!'
...
Budoucnost patri aluminiu!
Dotazy?




Naps¨¢no s pou?it¨ªm fontu Aver¨ªa (iotic.com/averia/)

More Related Content

What's hot (20)

Python Day1
Python Day1Python Day1
Python Day1
Mantavya Gajjar
?
Swift?? ???? ??? (Tail Recursion)
Swift?? ???? ??? (Tail Recursion)Swift?? ???? ??? (Tail Recursion)
Swift?? ???? ??? (Tail Recursion)
?? ?
?
I regret nothing
I regret nothingI regret nothing
I regret nothing
?ukasz Langa
?
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
Jonathan Wage
?
Ecto DSL Introduction - Yurii Bodarev
Ecto DSL Introduction - Yurii BodarevEcto DSL Introduction - Yurii Bodarev
Ecto DSL Introduction - Yurii Bodarev
Elixir Club
?
4.1 PHP Arrays
4.1 PHP Arrays4.1 PHP Arrays
4.1 PHP Arrays
Jalpesh Vasa
?
Python Modules, Packages and Libraries
Python Modules, Packages and LibrariesPython Modules, Packages and Libraries
Python Modules, Packages and Libraries
Venugopalavarma Raja
?
RxSwift ?????????
RxSwift ?????????RxSwift ?????????
RxSwift ?????????
Suyeol Jeon
?
PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
Sanketkumar Biswas
?
µÚ¶þ½² Ô¤±¸-Python»ùµA
µÚ¶þ½² Ô¤±¸-Python»ùµAµÚ¶þ½² Ô¤±¸-Python»ùµA
µÚ¶þ½² Ô¤±¸-Python»ùµA
anzhong70
?
µÚ¶þ½² Python»ùµA
µÚ¶þ½² Python»ùµAµÚ¶þ½² Python»ùµA
µÚ¶þ½² Python»ùµA
juzihua1102
?
Intro programacion funcional
Intro programacion funcionalIntro programacion funcional
Intro programacion funcional
NSCoder Mexico
?
PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007
Damien Seguy
?
Python Modules and Libraries
Python Modules and LibrariesPython Modules and Libraries
Python Modules and Libraries
Venugopalavarma Raja
?
Python ?? ?????
Python ?? ?????Python ?? ?????
Python ?? ?????
? ?
?
Closure, Higher-order function in Swift
Closure, Higher-order function in SwiftClosure, Higher-order function in Swift
Closure, Higher-order function in Swift
SeongGyu Jo
?
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
Basuke Suzuki
?
Begin with Python
Begin with PythonBegin with Python
Begin with Python
Narong Intiruk
?
Chap 3php array part1
Chap 3php array part1Chap 3php array part1
Chap 3php array part1
monikadeshmane
?
ºÃ¤ß¤ÎÈÕ±¾¾Æ¤ò…פߤ¿¤¤£¡ ?¤µ¤±¤Î¤ï¥Ç©`¥¿¤Ç̽¤¹×ԷֺäߤξÆ??
ºÃ¤ß¤ÎÈÕ±¾¾Æ¤ò…פߤ¿¤¤£¡ ?¤µ¤±¤Î¤ï¥Ç©`¥¿¤Ç̽¤¹×ԷֺäߤξÆ??ºÃ¤ß¤ÎÈÕ±¾¾Æ¤ò…פߤ¿¤¤£¡ ?¤µ¤±¤Î¤ï¥Ç©`¥¿¤Ç̽¤¹×ԷֺäߤξÆ??
ºÃ¤ß¤ÎÈÕ±¾¾Æ¤ò…פߤ¿¤¤£¡ ?¤µ¤±¤Î¤ï¥Ç©`¥¿¤Ç̽¤¹×ԷֺäߤξÆ??
Takashi Kitano
?
Swift?? ???? ??? (Tail Recursion)
Swift?? ???? ??? (Tail Recursion)Swift?? ???? ??? (Tail Recursion)
Swift?? ???? ??? (Tail Recursion)
?? ?
?
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
Jonathan Wage
?
Ecto DSL Introduction - Yurii Bodarev
Ecto DSL Introduction - Yurii BodarevEcto DSL Introduction - Yurii Bodarev
Ecto DSL Introduction - Yurii Bodarev
Elixir Club
?
Python Modules, Packages and Libraries
Python Modules, Packages and LibrariesPython Modules, Packages and Libraries
Python Modules, Packages and Libraries
Venugopalavarma Raja
?
µÚ¶þ½² Ô¤±¸-Python»ùµA
µÚ¶þ½² Ô¤±¸-Python»ùµAµÚ¶þ½² Ô¤±¸-Python»ùµA
µÚ¶þ½² Ô¤±¸-Python»ùµA
anzhong70
?
µÚ¶þ½² Python»ùµA
µÚ¶þ½² Python»ùµAµÚ¶þ½² Python»ùµA
µÚ¶þ½² Python»ùµA
juzihua1102
?
Intro programacion funcional
Intro programacion funcionalIntro programacion funcional
Intro programacion funcional
NSCoder Mexico
?
PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007PHP and MySQL Tips and tricks, DC 2007
PHP and MySQL Tips and tricks, DC 2007
Damien Seguy
?
Python ?? ?????
Python ?? ?????Python ?? ?????
Python ?? ?????
? ?
?
Closure, Higher-order function in Swift
Closure, Higher-order function in SwiftClosure, Higher-order function in Swift
Closure, Higher-order function in Swift
SeongGyu Jo
?
ºÃ¤ß¤ÎÈÕ±¾¾Æ¤ò…פߤ¿¤¤£¡ ?¤µ¤±¤Î¤ï¥Ç©`¥¿¤Ç̽¤¹×ԷֺäߤξÆ??
ºÃ¤ß¤ÎÈÕ±¾¾Æ¤ò…פߤ¿¤¤£¡ ?¤µ¤±¤Î¤ï¥Ç©`¥¿¤Ç̽¤¹×ԷֺäߤξÆ??ºÃ¤ß¤ÎÈÕ±¾¾Æ¤ò…פߤ¿¤¤£¡ ?¤µ¤±¤Î¤ï¥Ç©`¥¿¤Ç̽¤¹×ԷֺäߤξÆ??
ºÃ¤ß¤ÎÈÕ±¾¾Æ¤ò…פߤ¿¤¤£¡ ?¤µ¤±¤Î¤ï¥Ç©`¥¿¤Ç̽¤¹×ԷֺäߤξÆ??
Takashi Kitano
?

Similar to Magicke metody v Pythonu (20)

Python ?? ??
Python ?? ??Python ?? ??
Python ?? ??
? ?
?
Python Metaclasses
Python MetaclassesPython Metaclasses
Python Metaclasses
Nikunj Parekh
?
Python magicmethods
Python magicmethodsPython magicmethods
Python magicmethods
dreampuf
?
Python Programming-UNIT-II - Strings.pptx
Python Programming-UNIT-II - Strings.pptxPython Programming-UNIT-II - Strings.pptx
Python Programming-UNIT-II - Strings.pptx
KavithaDonepudi
?
From mysql to MongoDB£¨MongoDB2011±±¾©½»Á÷»á£©
From mysql to MongoDB£¨MongoDB2011±±¾©½»Á÷»á£©From mysql to MongoDB£¨MongoDB2011±±¾©½»Á÷»á£©
From mysql to MongoDB£¨MongoDB2011±±¾©½»Á÷»á£©
Night Sailer
?
Bottle, o full stack sem Django
Bottle, o full stack sem DjangoBottle, o full stack sem Django
Bottle, o full stack sem Django
Thiago Avelino
?
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Maulik Borsaniya
?
Intro to Python
Intro to PythonIntro to Python
Intro to Python
OSU Open Source Lab
?
Objective-c Runtime
Objective-c RuntimeObjective-c Runtime
Objective-c Runtime
Pavel Albitsky
?
Chapter 2 wbp.pptx
Chapter 2 wbp.pptxChapter 2 wbp.pptx
Chapter 2 wbp.pptx
40NehaPagariya
?
?????? ???? ? ???? ?????? ???? ??? ??? ??????
?????? ???? ? ???? ?????? ???? ??? ??? ???????????? ???? ? ???? ?????? ???? ??? ??? ??????
?????? ???? ? ???? ?????? ???? ??? ??? ??????
Mohammad Reza Kamalifard
?
Python_Object_Oriented_Programming.pptx
Python_Object_Oriented_Programming.pptxPython_Object_Oriented_Programming.pptx
Python_Object_Oriented_Programming.pptx
Koteswari Kasireddy
?
WordPress 3.1 at DC PHP
WordPress 3.1 at DC PHPWordPress 3.1 at DC PHP
WordPress 3.1 at DC PHP
andrewnacin
?
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdf
Koteswari Kasireddy
?
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
Mohamed Mosaad
?
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
Bryan Helmig
?
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection api
trygvea
?
Object Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonObject Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in Python
Tendayi Mawushe
?
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
PrinceGuru MS
?
Arrays
ArraysArrays
Arrays
Saranya saran
?
Python ?? ??
Python ?? ??Python ?? ??
Python ?? ??
? ?
?
Python magicmethods
Python magicmethodsPython magicmethods
Python magicmethods
dreampuf
?
Python Programming-UNIT-II - Strings.pptx
Python Programming-UNIT-II - Strings.pptxPython Programming-UNIT-II - Strings.pptx
Python Programming-UNIT-II - Strings.pptx
KavithaDonepudi
?
From mysql to MongoDB£¨MongoDB2011±±¾©½»Á÷»á£©
From mysql to MongoDB£¨MongoDB2011±±¾©½»Á÷»á£©From mysql to MongoDB£¨MongoDB2011±±¾©½»Á÷»á£©
From mysql to MongoDB£¨MongoDB2011±±¾©½»Á÷»á£©
Night Sailer
?
Bottle, o full stack sem Django
Bottle, o full stack sem DjangoBottle, o full stack sem Django
Bottle, o full stack sem Django
Thiago Avelino
?
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Maulik Borsaniya
?
?????? ???? ? ???? ?????? ???? ??? ??? ??????
?????? ???? ? ???? ?????? ???? ??? ??? ???????????? ???? ? ???? ?????? ???? ??? ??? ??????
?????? ???? ? ???? ?????? ???? ??? ??? ??????
Mohammad Reza Kamalifard
?
Python_Object_Oriented_Programming.pptx
Python_Object_Oriented_Programming.pptxPython_Object_Oriented_Programming.pptx
Python_Object_Oriented_Programming.pptx
Koteswari Kasireddy
?
WordPress 3.1 at DC PHP
WordPress 3.1 at DC PHPWordPress 3.1 at DC PHP
WordPress 3.1 at DC PHP
andrewnacin
?
Object_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdfObject_Oriented_Programming_Unit3.pdf
Object_Oriented_Programming_Unit3.pdf
Koteswari Kasireddy
?
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
Mohamed Mosaad
?
Stupid Awesome Python Tricks
Stupid Awesome Python TricksStupid Awesome Python Tricks
Stupid Awesome Python Tricks
Bryan Helmig
?
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection api
trygvea
?
Object Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in PythonObject Orientation vs Functional Programming in Python
Object Orientation vs Functional Programming in Python
Tendayi Mawushe
?
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
PrinceGuru MS
?

Recently uploaded (20)

FinTech - US Annual Funding Report - 2024.pptx
FinTech - US Annual Funding Report - 2024.pptxFinTech - US Annual Funding Report - 2024.pptx
FinTech - US Annual Funding Report - 2024.pptx
Tracxn
?
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
ScyllaDB
?
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & TipsTrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc
?
Deno ...................................
Deno ...................................Deno ...................................
Deno ...................................
Robert MacLean
?
UiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilitiesUiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilities
DianaGray10
?
Q4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor PresentationQ4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor Presentation
Dropbox
?
Cloud of everything Tech of the 21 century in Aviation
Cloud of everything Tech of the 21 century in AviationCloud of everything Tech of the 21 century in Aviation
Cloud of everything Tech of the 21 century in Aviation
Assem mousa
?
Build with AI on Google Cloud Session #4
Build with AI on Google Cloud Session #4Build with AI on Google Cloud Session #4
Build with AI on Google Cloud Session #4
Margaret Maynard-Reid
?
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Jonathan Bowen
?
Computational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the WorldComputational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the World
HusseinMalikMammadli
?
MIND Revenue Release Quarter 4 2024 - Finacial Presentation
MIND Revenue Release Quarter 4 2024 - Finacial PresentationMIND Revenue Release Quarter 4 2024 - Finacial Presentation
MIND Revenue Release Quarter 4 2024 - Finacial Presentation
MIND CTI
?
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog GavraReplacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
ScyllaDB
?
The Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nesThe Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nes
ScyllaDB
?
Transform Your Future with Front-End Development Training
Transform Your Future with Front-End Development TrainingTransform Your Future with Front-End Development Training
Transform Your Future with Front-End Development Training
Vtechlabs
?
DealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures CapitalDealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures Capital
Yevgen Sysoyev
?
EaseUS Partition Master Crack 2025 + Serial Key
EaseUS Partition Master Crack 2025 + Serial KeyEaseUS Partition Master Crack 2025 + Serial Key
EaseUS Partition Master Crack 2025 + Serial Key
kherorpacca127
?
Understanding Traditional AI with Custom Vision & MuleSoft.pptx
Understanding Traditional AI with Custom Vision & MuleSoft.pptxUnderstanding Traditional AI with Custom Vision & MuleSoft.pptx
Understanding Traditional AI with Custom Vision & MuleSoft.pptx
shyamraj55
?
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
?
Field Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci ResearchField Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci Research
Vipin Mishra
?
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
Safe Software
?
FinTech - US Annual Funding Report - 2024.pptx
FinTech - US Annual Funding Report - 2024.pptxFinTech - US Annual Funding Report - 2024.pptx
FinTech - US Annual Funding Report - 2024.pptx
Tracxn
?
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
30B Images and Counting: Scaling Canva's Content-Understanding Pipelines by K...
ScyllaDB
?
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & TipsTrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc Webinar - Building your DPIA/PIA Program: Best Practices & Tips
TrustArc
?
Deno ...................................
Deno ...................................Deno ...................................
Deno ...................................
Robert MacLean
?
UiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilitiesUiPath Document Understanding - Generative AI and Active learning capabilities
UiPath Document Understanding - Generative AI and Active learning capabilities
DianaGray10
?
Q4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor PresentationQ4 2024 Earnings and Investor Presentation
Q4 2024 Earnings and Investor Presentation
Dropbox
?
Cloud of everything Tech of the 21 century in Aviation
Cloud of everything Tech of the 21 century in AviationCloud of everything Tech of the 21 century in Aviation
Cloud of everything Tech of the 21 century in Aviation
Assem mousa
?
Build with AI on Google Cloud Session #4
Build with AI on Google Cloud Session #4Build with AI on Google Cloud Session #4
Build with AI on Google Cloud Session #4
Margaret Maynard-Reid
?
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Formal Methods: Whence and Whither? [Martin Fr?nzle Festkolloquium, 2025]
Jonathan Bowen
?
Computational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the WorldComputational Photography: How Technology is Changing Way We Capture the World
Computational Photography: How Technology is Changing Way We Capture the World
HusseinMalikMammadli
?
MIND Revenue Release Quarter 4 2024 - Finacial Presentation
MIND Revenue Release Quarter 4 2024 - Finacial PresentationMIND Revenue Release Quarter 4 2024 - Finacial Presentation
MIND Revenue Release Quarter 4 2024 - Finacial Presentation
MIND CTI
?
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog GavraReplacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
Replacing RocksDB with ScyllaDB in Kafka Streams by Almog Gavra
ScyllaDB
?
The Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nesThe Future of Repair: Transparent and Incremental by Botond De?nes
The Future of Repair: Transparent and Incremental by Botond De?nes
ScyllaDB
?
Transform Your Future with Front-End Development Training
Transform Your Future with Front-End Development TrainingTransform Your Future with Front-End Development Training
Transform Your Future with Front-End Development Training
Vtechlabs
?
DealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures CapitalDealBook of Ukraine: 2025 edition | AVentures Capital
DealBook of Ukraine: 2025 edition | AVentures Capital
Yevgen Sysoyev
?
EaseUS Partition Master Crack 2025 + Serial Key
EaseUS Partition Master Crack 2025 + Serial KeyEaseUS Partition Master Crack 2025 + Serial Key
EaseUS Partition Master Crack 2025 + Serial Key
kherorpacca127
?
Understanding Traditional AI with Custom Vision & MuleSoft.pptx
Understanding Traditional AI with Custom Vision & MuleSoft.pptxUnderstanding Traditional AI with Custom Vision & MuleSoft.pptx
Understanding Traditional AI with Custom Vision & MuleSoft.pptx
shyamraj55
?
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
?
Field Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci ResearchField Device Management Market Report 2030 - TechSci Research
Field Device Management Market Report 2030 - TechSci Research
Vipin Mishra
?
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
[Webinar] Scaling Made Simple: Getting Started with No-Code Web Apps
Safe Software
?

Magicke metody v Pythonu

  • 1. __magick¨¦__ metody v Pythonu(2.x) (ochutn¨¢vka) Jirka Vejra?ka (@JirkaV) @naPyVo #22
  • 2. class Person(models.Model): name = models.CharField(max_length=128) def __unicode__(self): return self.name class MojeTrida(object): def __init__(self, data): self.data = data
  • 3. >>> mylist = [] >>> dir(mylist) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
  • 4. >>> mystring = 'My hovercraft if full of eels' >>> if mystring.index('full') > 0: >>> if ¡®full¡¯ in mystring: object.__contains__(self, item) Called to implement membership test operators. Should return true if item is in self, false otherwise. For mapping objects, this should consider the keys of the mapping rather than the values or the key-item pairs.
  • 5. >>> 'full' in 'My hovercraft is full of eels¡® True >>> class MyStr(str): ... def __contains__(self, elem): ... return False >>> mystring = MyStr('My hovercraft is full of eels') >>> mystring 'My hovercraft is full of eels' >>> 'full' in mystring False
  • 6. >>> class SortedList(list): ... def __getitem__(self, key): ... return sorted(self)[key] >>> mylist = SortedList([5, 7, 2, 12, 1, 0, 42, 9]) >>> mylist[0] 0 >>> mylist[-1] 42 >>> for x in mylist: ... print x, ... 5 7 2 12 1 0 42 9
  • 7. >>> import IPy >>> class Network(list): ... def __len__(self): ... return sum([len(IPy.IP(x)) for x in self]) ... >>> firma = Network(['10.0.10.0/24', '10.0.20.128/26', '10.0.30.0/25']) >>> firma ['10.0.10.0/24', '10.0.20.128/26', '10.0.30.0/25'] >>> len(firma) 448
  • 8. >>> class DobryPrezident(object): ... def __init__(self, prijmeni): ... self.prijmeni = prijmeni ... def __nonzero__(self): ... return self.prijmeni == 'Cimrman¡® >>> dobry_prezident = DobryPrezident('stara Vomackova') >>> if dobry_prezident: ... print 'Mame ji radi!' >>> dobry_prezident = DobryPrezident('Cimrman') >>> if dobry_prezident: ... print 'Budoucnost patri aluminiu!' ... Budoucnost patri aluminiu!
  • 9. Dotazy? Naps¨¢no s pou?it¨ªm fontu Aver¨ªa (iotic.com/averia/)