SlideShare ist ein Scribd-Unternehmen logo
1 von 56
Workshop:
Introductie tot Python
Vincent Claes
Introductie
• Python Syntax
• Communiceren met Hardware
• Webserver programmatie in Python
• Game Programming in Python
• Fun experiments
• https://github.com/pxltech/Python-Workshop/
Vincent Claes
Python: Introductie
• Python is a clear and powerful object-oriented programming language, comparable to Perl, Ruby,
Scheme, or Java.
• Some of Python's notable features:
• Uses an elegant syntax, making the programs you write easier to read.
• Is an easy-to-use language that makes it simple to get your program working. This makes Python ideal for
prototype development and other ad-hoc programming tasks, without compromising maintainability.
• Comes with a large standard library that supports many common programming tasks such as connecting to
web servers, searching text with regular expressions, reading and modifying files.
• Python's interactive mode makes it easy to test short snippets of code. There's also a bundled development
environment called IDLE.
• Is easily extended by adding new modules implemented in a compiled language such as C or C++.
• Can also be embedded into an application to provide a programmable interface.
• Runs anywhere, including Mac OS X, Windows, Linux, and Unix, with unofficial builds also available
for Android and iOS.
• Is free software in two senses. It doesn't cost anything to download or use Python, or to include it in your
application. Python can also be freely modified and re-distributed, because while the language is copyrighted
it's available under an open source license.
Vincent Claes
Python: Introductie
• Some programming-language features of Python are:
• A variety of basic data types are available: numbers (floating point, complex, and
unlimited-length long integers), strings (both ASCII and Unicode), lists, and
dictionaries.
• Python supports object-oriented programming with classes and multiple inheritance.
• Code can be grouped into modules and packages.
• The language supports raising and catching exceptions, resulting in cleaner error
handling.
• Data types are strongly and dynamically typed. Mixing incompatible types (e.g.
attempting to add a string and a number) causes an exception to be raised, so errors
are caught sooner.
• Python contains advanced programming features such as generators and list
comprehensions.
• Python's automatic memory management frees you from having to manually
allocate and free memory in your code.
Vincent Claes
Python: Introductie
• Data Types in Python
• Numbers (int, float, complex,…)
• Strings (str)
• Lists
• Dictionaries
• Booleans
• Tuples
• Sets
• Uitprinten
• Interactief werken via: Introductie_tot_Python_Syntax.ipynb
Vincent Claes
Oefeningen in Python
• Via input() kan je invoer aan je gebruiker vragen in Python, schrijf een
stukje code waar de gebruiker zijn naam invoert en print deze naam
af in hoofdletters
• Schrijf een stukje code waar je de gebruiker achter een cijfer vraagt,
en print alle cijfers uit tot dit getal
• Via int(getal) kan je de invoer string converteren naar een getalwaarde
(integer)
• Schrijf een functie waar je 2 getallen meegeeft en die het grootste
getal terugstuurt
Vincent Claes
Bibliotheken in Python
• Veel gebruikt:
• Pandas
• https://pandas.pydata.org/
• Bibliotheek voor data analyse
• Numpy
• http://www.numpy.org/
• Bibliotheek voor “scientific computing”; lineaire algebra,…
• Matplotlib
• https://matplotlib.org/
• Bibliotheek voor grafieken te maken
• Sklearn
• https://scikit-learn.org
• Machine Learning library
• Seaborn
• https://seaborn.pydata.org/
• Statistische data visualisatie bibliotheek
• OpenCV
• https://opencv.org/
• Computer Vision bibliotheek
Vincent Claes
Python: Hardware Communicatie
• Hardware: Arduino met 7-Segment Display
• Seriële Communicatie PC met Python  Arduino
• Aansturen van 7-segment display vanuit Python PC Applicatie
• Oefening Teller op 7-segment display
• Oefening Random Value op 7-segment display
Vincent Claes
Python: Hardware Communicatie
Vincent Claes
Arduino Software
• Online Arduino IDE: https://create.arduino.cc
• Install Arduino Plugin: https://create.arduino.cc/getting-
started/plugin
Vincent Claes
Arduino Software 1
Vincent Claes
Arduino Software 1
Vincent Claes
Python: Hardware Communicatie
• Python: Installatie PySerial
Vincent Claes
Python: Hardware Communicatie
• Workshop_Serial1.ipynb
Vincent Claes
Python: Hardware Communicatie
• Workshop_Serial1.ipynb
Vincent Claes
Arduino Software 2
Vincent Claes
Python: Hardware Communicatie
• Workshop_Serial2.ipynb
Vincent Claes
Arduino Code 3
Vincent Claes
Python: Hardware Communicatie
• Workshop_7Segment.ipynb
Vincent Claes
Arduino Experiments
• Schrijf Python code waar je de 7-segment display aanstuurt maar
waar je de decoder logica in Python schrijft; toon al de resultaten in
een loop op de 7-segment display
• Schrijf Python code waar je de 7-segment display aanstuurt maar
waar je de decoder logic in Python schrijft; vraag de gebruiker achter
een getal.
• Schrijf Python code waar je de schakelaar inleest van de arduino.
Vincent Claes
Python: Webserver Programming
• Pythonanywhere
• https://www.pythonanywhere.com
• Flask Python Library
• http://flask.pocoo.org
Vincent Claes
Log in or Sign up @ pythonanywhere
Vincent Claes
Open Web Apps
Vincent Claes
Add a new web app
Vincent Claes
Create a new web app
Vincent Claes
Flask Python Web Framework
Vincent Claes
Python 3.7 (Flask 1.0.2)
Vincent Claes
Select path for python file – Flask app
Vincent Claes
Overview Web Tab
Vincent Claes
Files Tab
Vincent Claes
Open mysite directory
Vincent Claes
Open flask_app.py
Vincent Claes
https://cteq.pythonanywhere.com
Vincent Claes
Example Flask App
Vincent Claes
Web Tab => reload
Vincent Claes
Webserver2.py
Vincent Claes
• webserver2.py
• map templates aanmaken
Webserver2.py – hello.html
Vincent Claes
• webserver2.py
• map templates aanmaken
• hello.html
Webserver2.py – hello.html
Vincent Claes
Oefeningen Webserver
• Schrijf code voor een webserver die een parameter verwacht “tekst”, print deze tekst in
hoofdletters op jet website
• Voeg CCS / HTML toe aan je website zodoende de site er mooier uitziet
• https://www.w3schools.com/
• Schrijf code voor een server die als parameter een e-mail adres verwacht en deze dan opsplitst in
naam – voornaam en bedrijf, toon deze informatie op je website
• Bouw een eenvoudig webserver rekenmachine
• Maak een toepassing waar je een for loop gebruikt in de html template
• Meer info :
http://interactivepython.org/runestone/static/webfundamentalsITUBIL103E2015Fall/Frameworks/templates.
html
Vincent Claes
Python: Game Programming
• Gebruik van pygame library
• https://www.pygame.org
Vincent Claes
Python: Game Programming
Vincent Claes
Python: Game Programming
Vincent Claes
Python: Game Programming: PyGame installatie –
alternatieve methode
• python3 -m pip install -U pygame –user
• python3 -m pygame.examples.aliens
Vincent Claes
Python: Game Programming
Vincent Claes
Python: Game Programming
Vincent Claes
Python: Game Programming
Vincent Claes
Python: Game Programming
Vincent Claes
Python: Game Programming
Vincent Claes
Python: Game Programming
• Beweging
Vincent Claes
Python: Game Programming
• Keys gebruiken
Vincent Claes
Python: Game Programming
• Geluid
• https://freesound.org/browse/
Vincent Claes
Python: Game Programming
• Tekst
Vincent Claes
Opdrachten
• Bouw een eigen game
• Pong
• Snake
• Eigen improvisatie
• Informatie
• https://www.pygame.org/wiki/GettingStarted
• https://www.pygame.org/docs/
• https://realpython.com/python3-object-oriented-programming/
Vincent Claes
Opdrachten
• Schrijf een applicatie die een geluid afspeelt indien iemand de “S”
toets gebruikt
• Schrijf een applicatie die “PXL” schrijft indien iemand de “T” toets
gebruikt, zorg ervoor dat de tekst terug verdwijnt indien iemand de
“O” toets gebruikt
• Schrijf een applicatie waarmee je met de muis tekent op het scherm
indien iemand eerst de “T” toets indrukt en dan met de muis over het
gamescherm gaat.
Vincent Claes
Fun Experiments with Python
• Algorithmia API
• https://algorithmia.com/
• Online API’s
• Web Scraping
• OpenCV (Vision)
• Machine Learning Experiments
Vincent Claes
Vincent Claes
• More info: vincent[at]cteq.eu
• https://www.linkedin.com/in/vincentclaes/
• You can contact me for IoT, Embedded Systems (HW, SW, FPGA,
ARM,…) and ML/AI projects (R and Python).

Weitere ähnliche Inhalte

Ähnlich wie Workshop: Introductie tot Python

Nord Toelichting Techniek
Nord Toelichting TechniekNord Toelichting Techniek
Nord Toelichting Techniektjercus
 
xxter - Pairot training 2019
xxter - Pairot training 2019xxter - Pairot training 2019
xxter - Pairot training 2019Freddy van Geel
 
Introductie robot framework
Introductie robot frameworkIntroductie robot framework
Introductie robot frameworkchristiantester
 
SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...
SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...
SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...DIWUG
 
IPv6 voor webbouwers
IPv6 voor webbouwersIPv6 voor webbouwers
IPv6 voor webbouwersFrank Louwers
 
Projectpaas drupaljam 2013 rotterdam
Projectpaas drupaljam 2013 rotterdamProjectpaas drupaljam 2013 rotterdam
Projectpaas drupaljam 2013 rotterdamBert Boerland
 
Over Naar (embedded) Linux
Over Naar (embedded) LinuxOver Naar (embedded) Linux
Over Naar (embedded) LinuxAlbert Mietus
 
Bart Lageweg - Ansible/Cobbler
Bart Lageweg - Ansible/CobblerBart Lageweg - Ansible/Cobbler
Bart Lageweg - Ansible/CobblerSplend
 
EMS Ehsal - production in a digital world 2013
EMS Ehsal - production in a digital world 2013EMS Ehsal - production in a digital world 2013
EMS Ehsal - production in a digital world 2013Hans Palmers
 
Let's Encrypt Techtalk @Openminds
Let's Encrypt Techtalk @OpenmindsLet's Encrypt Techtalk @Openminds
Let's Encrypt Techtalk @Openmindssorcix
 
Bendoo box i&i 19 nov 2014 powerpoint
Bendoo box i&i 19 nov 2014   powerpointBendoo box i&i 19 nov 2014   powerpoint
Bendoo box i&i 19 nov 2014 powerpointBendooBox
 
Correct toepassen van cryptografie - (ISC)2 NL - 10 juni 2014
Correct toepassen van cryptografie - (ISC)2 NL - 10 juni 2014Correct toepassen van cryptografie - (ISC)2 NL - 10 juni 2014
Correct toepassen van cryptografie - (ISC)2 NL - 10 juni 2014Luuk Danes
 
20170612 Presentatie over e-Depot tijdens KVAN-dagen in Dordrecht
20170612 Presentatie over e-Depot tijdens KVAN-dagen in Dordrecht20170612 Presentatie over e-Depot tijdens KVAN-dagen in Dordrecht
20170612 Presentatie over e-Depot tijdens KVAN-dagen in DordrechtRegionaal Archief Tilburg
 
Profiel thymos rudi respen
Profiel thymos   rudi respenProfiel thymos   rudi respen
Profiel thymos rudi respenRudi Respen
 
Deployment strategieën, WP Meetup Enschede, 26-02-2015
Deployment strategieën, WP Meetup Enschede, 26-02-2015Deployment strategieën, WP Meetup Enschede, 26-02-2015
Deployment strategieën, WP Meetup Enschede, 26-02-2015Arjan Snaterse
 
VIGC Live Preflight-profielen voor InDesign CS4 (2009)
VIGC Live Preflight-profielen voor InDesign CS4 (2009)VIGC Live Preflight-profielen voor InDesign CS4 (2009)
VIGC Live Preflight-profielen voor InDesign CS4 (2009)VIGCbe
 

Ähnlich wie Workshop: Introductie tot Python (20)

Nord Toelichting Techniek
Nord Toelichting TechniekNord Toelichting Techniek
Nord Toelichting Techniek
 
xxter - Pairot training 2019
xxter - Pairot training 2019xxter - Pairot training 2019
xxter - Pairot training 2019
 
Introductie robot framework
Introductie robot frameworkIntroductie robot framework
Introductie robot framework
 
Meetup ASP.NET 5 19/11/2015
Meetup ASP.NET 5 19/11/2015Meetup ASP.NET 5 19/11/2015
Meetup ASP.NET 5 19/11/2015
 
SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...
SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...
SPSNL17 - Integratie van Microsoft Teams met het Bot Framework - Michael Homp...
 
IPv6 voor webbouwers
IPv6 voor webbouwersIPv6 voor webbouwers
IPv6 voor webbouwers
 
Projectpaas drupaljam 2013 rotterdam
Projectpaas drupaljam 2013 rotterdamProjectpaas drupaljam 2013 rotterdam
Projectpaas drupaljam 2013 rotterdam
 
Over Naar (embedded) Linux
Over Naar (embedded) LinuxOver Naar (embedded) Linux
Over Naar (embedded) Linux
 
Bart Lageweg - Ansible/Cobbler
Bart Lageweg - Ansible/CobblerBart Lageweg - Ansible/Cobbler
Bart Lageweg - Ansible/Cobbler
 
EMS Ehsal - production in a digital world 2013
EMS Ehsal - production in a digital world 2013EMS Ehsal - production in a digital world 2013
EMS Ehsal - production in a digital world 2013
 
Let's Encrypt Techtalk @Openminds
Let's Encrypt Techtalk @OpenmindsLet's Encrypt Techtalk @Openminds
Let's Encrypt Techtalk @Openminds
 
Bendoo box i&i 19 nov 2014 powerpoint
Bendoo box i&i 19 nov 2014   powerpointBendoo box i&i 19 nov 2014   powerpoint
Bendoo box i&i 19 nov 2014 powerpoint
 
Correct toepassen van cryptografie - (ISC)2 NL - 10 juni 2014
Correct toepassen van cryptografie - (ISC)2 NL - 10 juni 2014Correct toepassen van cryptografie - (ISC)2 NL - 10 juni 2014
Correct toepassen van cryptografie - (ISC)2 NL - 10 juni 2014
 
Netflow Performance
Netflow PerformanceNetflow Performance
Netflow Performance
 
20170612 Presentatie over e-Depot tijdens KVAN-dagen in Dordrecht
20170612 Presentatie over e-Depot tijdens KVAN-dagen in Dordrecht20170612 Presentatie over e-Depot tijdens KVAN-dagen in Dordrecht
20170612 Presentatie over e-Depot tijdens KVAN-dagen in Dordrecht
 
Unleash the power of raven db
Unleash the power of raven dbUnleash the power of raven db
Unleash the power of raven db
 
Profiel thymos rudi respen
Profiel thymos   rudi respenProfiel thymos   rudi respen
Profiel thymos rudi respen
 
Documentatie, van last naar kracht
Documentatie, van last naar krachtDocumentatie, van last naar kracht
Documentatie, van last naar kracht
 
Deployment strategieën, WP Meetup Enschede, 26-02-2015
Deployment strategieën, WP Meetup Enschede, 26-02-2015Deployment strategieën, WP Meetup Enschede, 26-02-2015
Deployment strategieën, WP Meetup Enschede, 26-02-2015
 
VIGC Live Preflight-profielen voor InDesign CS4 (2009)
VIGC Live Preflight-profielen voor InDesign CS4 (2009)VIGC Live Preflight-profielen voor InDesign CS4 (2009)
VIGC Live Preflight-profielen voor InDesign CS4 (2009)
 

Mehr von Vincent Claes

Percepio Tracealyzer for FreeRTOS on MiniZED
Percepio Tracealyzer for FreeRTOS on MiniZEDPercepio Tracealyzer for FreeRTOS on MiniZED
Percepio Tracealyzer for FreeRTOS on MiniZEDVincent Claes
 
Xilinx Vitis FreeRTOS Hello World
Xilinx Vitis FreeRTOS Hello WorldXilinx Vitis FreeRTOS Hello World
Xilinx Vitis FreeRTOS Hello WorldVincent Claes
 
Programming STM32L432 Nucleo with Keil MDK
Programming STM32L432 Nucleo with Keil MDKProgramming STM32L432 Nucleo with Keil MDK
Programming STM32L432 Nucleo with Keil MDKVincent Claes
 
Debugging Xilinx Zynq Project using ILA Integrated Logic Analyzer IP Block
Debugging Xilinx Zynq Project using ILA Integrated Logic Analyzer IP BlockDebugging Xilinx Zynq Project using ILA Integrated Logic Analyzer IP Block
Debugging Xilinx Zynq Project using ILA Integrated Logic Analyzer IP BlockVincent Claes
 
Using Virtual IO (VIO) on Xilinx ZYNQ FPGA's
Using Virtual IO (VIO) on Xilinx ZYNQ FPGA'sUsing Virtual IO (VIO) on Xilinx ZYNQ FPGA's
Using Virtual IO (VIO) on Xilinx ZYNQ FPGA'sVincent Claes
 
Profiling Xilinx Zynq Software Applications in SDK (MiniZED board)
Profiling Xilinx Zynq Software Applications in SDK (MiniZED board)Profiling Xilinx Zynq Software Applications in SDK (MiniZED board)
Profiling Xilinx Zynq Software Applications in SDK (MiniZED board)Vincent Claes
 
ZYNQ BRAM Implementation
ZYNQ BRAM ImplementationZYNQ BRAM Implementation
ZYNQ BRAM ImplementationVincent Claes
 
Implementing a Database and API for your Cloud Service
Implementing a Database and API for your Cloud ServiceImplementing a Database and API for your Cloud Service
Implementing a Database and API for your Cloud ServiceVincent Claes
 
Launching Python Cloud Services for AI/IoT Projects
Launching Python Cloud Services for AI/IoT ProjectsLaunching Python Cloud Services for AI/IoT Projects
Launching Python Cloud Services for AI/IoT ProjectsVincent Claes
 
Real Time Filtering on Embedded ARM
Real Time Filtering on Embedded ARMReal Time Filtering on Embedded ARM
Real Time Filtering on Embedded ARMVincent Claes
 
R Markdown, Rpubs & github publishing and Shiny by Example
R Markdown, Rpubs & github publishing and Shiny by ExampleR Markdown, Rpubs & github publishing and Shiny by Example
R Markdown, Rpubs & github publishing and Shiny by ExampleVincent Claes
 
Using Texas Instruments Code Composer Studio for The CC3200XL Launchpad
Using Texas Instruments Code Composer Studio for The CC3200XL LaunchpadUsing Texas Instruments Code Composer Studio for The CC3200XL Launchpad
Using Texas Instruments Code Composer Studio for The CC3200XL LaunchpadVincent Claes
 
Hogeschool PXL Smart Mirror
Hogeschool PXL Smart MirrorHogeschool PXL Smart Mirror
Hogeschool PXL Smart MirrorVincent Claes
 
Softcore vs Hardcore processor
Softcore vs Hardcore processorSoftcore vs Hardcore processor
Softcore vs Hardcore processorVincent Claes
 
Implementing an interface in r to communicate with programmable fabric in a x...
Implementing an interface in r to communicate with programmable fabric in a x...Implementing an interface in r to communicate with programmable fabric in a x...
Implementing an interface in r to communicate with programmable fabric in a x...Vincent Claes
 
Debugging IoT Sensor Interfaces (SPI) with Digilent Analog Discovery 2
Debugging IoT Sensor Interfaces (SPI) with Digilent Analog Discovery 2Debugging IoT Sensor Interfaces (SPI) with Digilent Analog Discovery 2
Debugging IoT Sensor Interfaces (SPI) with Digilent Analog Discovery 2Vincent Claes
 

Mehr von Vincent Claes (20)

Percepio Tracealyzer for FreeRTOS on MiniZED
Percepio Tracealyzer for FreeRTOS on MiniZEDPercepio Tracealyzer for FreeRTOS on MiniZED
Percepio Tracealyzer for FreeRTOS on MiniZED
 
Xilinx Vitis FreeRTOS Hello World
Xilinx Vitis FreeRTOS Hello WorldXilinx Vitis FreeRTOS Hello World
Xilinx Vitis FreeRTOS Hello World
 
Programming STM32L432 Nucleo with Keil MDK
Programming STM32L432 Nucleo with Keil MDKProgramming STM32L432 Nucleo with Keil MDK
Programming STM32L432 Nucleo with Keil MDK
 
Debugging Xilinx Zynq Project using ILA Integrated Logic Analyzer IP Block
Debugging Xilinx Zynq Project using ILA Integrated Logic Analyzer IP BlockDebugging Xilinx Zynq Project using ILA Integrated Logic Analyzer IP Block
Debugging Xilinx Zynq Project using ILA Integrated Logic Analyzer IP Block
 
Using Virtual IO (VIO) on Xilinx ZYNQ FPGA's
Using Virtual IO (VIO) on Xilinx ZYNQ FPGA'sUsing Virtual IO (VIO) on Xilinx ZYNQ FPGA's
Using Virtual IO (VIO) on Xilinx ZYNQ FPGA's
 
Profiling Xilinx Zynq Software Applications in SDK (MiniZED board)
Profiling Xilinx Zynq Software Applications in SDK (MiniZED board)Profiling Xilinx Zynq Software Applications in SDK (MiniZED board)
Profiling Xilinx Zynq Software Applications in SDK (MiniZED board)
 
ZYNQ BRAM Implementation
ZYNQ BRAM ImplementationZYNQ BRAM Implementation
ZYNQ BRAM Implementation
 
Implementing a Database and API for your Cloud Service
Implementing a Database and API for your Cloud ServiceImplementing a Database and API for your Cloud Service
Implementing a Database and API for your Cloud Service
 
Launching Python Cloud Services for AI/IoT Projects
Launching Python Cloud Services for AI/IoT ProjectsLaunching Python Cloud Services for AI/IoT Projects
Launching Python Cloud Services for AI/IoT Projects
 
Real Time Filtering on Embedded ARM
Real Time Filtering on Embedded ARMReal Time Filtering on Embedded ARM
Real Time Filtering on Embedded ARM
 
R Markdown, Rpubs & github publishing and Shiny by Example
R Markdown, Rpubs & github publishing and Shiny by ExampleR Markdown, Rpubs & github publishing and Shiny by Example
R Markdown, Rpubs & github publishing and Shiny by Example
 
Using Texas Instruments Code Composer Studio for The CC3200XL Launchpad
Using Texas Instruments Code Composer Studio for The CC3200XL LaunchpadUsing Texas Instruments Code Composer Studio for The CC3200XL Launchpad
Using Texas Instruments Code Composer Studio for The CC3200XL Launchpad
 
Hogeschool PXL Smart Mirror
Hogeschool PXL Smart MirrorHogeschool PXL Smart Mirror
Hogeschool PXL Smart Mirror
 
Softcore vs Hardcore processor
Softcore vs Hardcore processorSoftcore vs Hardcore processor
Softcore vs Hardcore processor
 
MySQL / PHP Server
MySQL / PHP ServerMySQL / PHP Server
MySQL / PHP Server
 
Implementing an interface in r to communicate with programmable fabric in a x...
Implementing an interface in r to communicate with programmable fabric in a x...Implementing an interface in r to communicate with programmable fabric in a x...
Implementing an interface in r to communicate with programmable fabric in a x...
 
fTales workshop
fTales workshopfTales workshop
fTales workshop
 
Maker Revolution
Maker RevolutionMaker Revolution
Maker Revolution
 
Debugging IoT Sensor Interfaces (SPI) with Digilent Analog Discovery 2
Debugging IoT Sensor Interfaces (SPI) with Digilent Analog Discovery 2Debugging IoT Sensor Interfaces (SPI) with Digilent Analog Discovery 2
Debugging IoT Sensor Interfaces (SPI) with Digilent Analog Discovery 2
 
FreeRTOS API
FreeRTOS APIFreeRTOS API
FreeRTOS API
 

Workshop: Introductie tot Python

  • 2. Introductie • Python Syntax • Communiceren met Hardware • Webserver programmatie in Python • Game Programming in Python • Fun experiments • https://github.com/pxltech/Python-Workshop/ Vincent Claes
  • 3. Python: Introductie • Python is a clear and powerful object-oriented programming language, comparable to Perl, Ruby, Scheme, or Java. • Some of Python's notable features: • Uses an elegant syntax, making the programs you write easier to read. • Is an easy-to-use language that makes it simple to get your program working. This makes Python ideal for prototype development and other ad-hoc programming tasks, without compromising maintainability. • Comes with a large standard library that supports many common programming tasks such as connecting to web servers, searching text with regular expressions, reading and modifying files. • Python's interactive mode makes it easy to test short snippets of code. There's also a bundled development environment called IDLE. • Is easily extended by adding new modules implemented in a compiled language such as C or C++. • Can also be embedded into an application to provide a programmable interface. • Runs anywhere, including Mac OS X, Windows, Linux, and Unix, with unofficial builds also available for Android and iOS. • Is free software in two senses. It doesn't cost anything to download or use Python, or to include it in your application. Python can also be freely modified and re-distributed, because while the language is copyrighted it's available under an open source license. Vincent Claes
  • 4. Python: Introductie • Some programming-language features of Python are: • A variety of basic data types are available: numbers (floating point, complex, and unlimited-length long integers), strings (both ASCII and Unicode), lists, and dictionaries. • Python supports object-oriented programming with classes and multiple inheritance. • Code can be grouped into modules and packages. • The language supports raising and catching exceptions, resulting in cleaner error handling. • Data types are strongly and dynamically typed. Mixing incompatible types (e.g. attempting to add a string and a number) causes an exception to be raised, so errors are caught sooner. • Python contains advanced programming features such as generators and list comprehensions. • Python's automatic memory management frees you from having to manually allocate and free memory in your code. Vincent Claes
  • 5. Python: Introductie • Data Types in Python • Numbers (int, float, complex,…) • Strings (str) • Lists • Dictionaries • Booleans • Tuples • Sets • Uitprinten • Interactief werken via: Introductie_tot_Python_Syntax.ipynb Vincent Claes
  • 6. Oefeningen in Python • Via input() kan je invoer aan je gebruiker vragen in Python, schrijf een stukje code waar de gebruiker zijn naam invoert en print deze naam af in hoofdletters • Schrijf een stukje code waar je de gebruiker achter een cijfer vraagt, en print alle cijfers uit tot dit getal • Via int(getal) kan je de invoer string converteren naar een getalwaarde (integer) • Schrijf een functie waar je 2 getallen meegeeft en die het grootste getal terugstuurt Vincent Claes
  • 7. Bibliotheken in Python • Veel gebruikt: • Pandas • https://pandas.pydata.org/ • Bibliotheek voor data analyse • Numpy • http://www.numpy.org/ • Bibliotheek voor “scientific computing”; lineaire algebra,… • Matplotlib • https://matplotlib.org/ • Bibliotheek voor grafieken te maken • Sklearn • https://scikit-learn.org • Machine Learning library • Seaborn • https://seaborn.pydata.org/ • Statistische data visualisatie bibliotheek • OpenCV • https://opencv.org/ • Computer Vision bibliotheek Vincent Claes
  • 8. Python: Hardware Communicatie • Hardware: Arduino met 7-Segment Display • Seriële Communicatie PC met Python  Arduino • Aansturen van 7-segment display vanuit Python PC Applicatie • Oefening Teller op 7-segment display • Oefening Random Value op 7-segment display Vincent Claes
  • 10. Arduino Software • Online Arduino IDE: https://create.arduino.cc • Install Arduino Plugin: https://create.arduino.cc/getting- started/plugin Vincent Claes
  • 13. Python: Hardware Communicatie • Python: Installatie PySerial Vincent Claes
  • 14. Python: Hardware Communicatie • Workshop_Serial1.ipynb Vincent Claes
  • 15. Python: Hardware Communicatie • Workshop_Serial1.ipynb Vincent Claes
  • 17. Python: Hardware Communicatie • Workshop_Serial2.ipynb Vincent Claes
  • 19. Python: Hardware Communicatie • Workshop_7Segment.ipynb Vincent Claes
  • 20. Arduino Experiments • Schrijf Python code waar je de 7-segment display aanstuurt maar waar je de decoder logica in Python schrijft; toon al de resultaten in een loop op de 7-segment display • Schrijf Python code waar je de 7-segment display aanstuurt maar waar je de decoder logic in Python schrijft; vraag de gebruiker achter een getal. • Schrijf Python code waar je de schakelaar inleest van de arduino. Vincent Claes
  • 21. Python: Webserver Programming • Pythonanywhere • https://www.pythonanywhere.com • Flask Python Library • http://flask.pocoo.org Vincent Claes
  • 22. Log in or Sign up @ pythonanywhere Vincent Claes
  • 24. Add a new web app Vincent Claes
  • 25. Create a new web app Vincent Claes
  • 26. Flask Python Web Framework Vincent Claes
  • 27. Python 3.7 (Flask 1.0.2) Vincent Claes
  • 28. Select path for python file – Flask app Vincent Claes
  • 35. Web Tab => reload Vincent Claes
  • 37. Webserver2.py – hello.html Vincent Claes • webserver2.py • map templates aanmaken • hello.html
  • 39. Oefeningen Webserver • Schrijf code voor een webserver die een parameter verwacht “tekst”, print deze tekst in hoofdletters op jet website • Voeg CCS / HTML toe aan je website zodoende de site er mooier uitziet • https://www.w3schools.com/ • Schrijf code voor een server die als parameter een e-mail adres verwacht en deze dan opsplitst in naam – voornaam en bedrijf, toon deze informatie op je website • Bouw een eenvoudig webserver rekenmachine • Maak een toepassing waar je een for loop gebruikt in de html template • Meer info : http://interactivepython.org/runestone/static/webfundamentalsITUBIL103E2015Fall/Frameworks/templates. html Vincent Claes
  • 40. Python: Game Programming • Gebruik van pygame library • https://www.pygame.org Vincent Claes
  • 43. Python: Game Programming: PyGame installatie – alternatieve methode • python3 -m pip install -U pygame –user • python3 -m pygame.examples.aliens Vincent Claes
  • 49. Python: Game Programming • Beweging Vincent Claes
  • 50. Python: Game Programming • Keys gebruiken Vincent Claes
  • 51. Python: Game Programming • Geluid • https://freesound.org/browse/ Vincent Claes
  • 52. Python: Game Programming • Tekst Vincent Claes
  • 53. Opdrachten • Bouw een eigen game • Pong • Snake • Eigen improvisatie • Informatie • https://www.pygame.org/wiki/GettingStarted • https://www.pygame.org/docs/ • https://realpython.com/python3-object-oriented-programming/ Vincent Claes
  • 54. Opdrachten • Schrijf een applicatie die een geluid afspeelt indien iemand de “S” toets gebruikt • Schrijf een applicatie die “PXL” schrijft indien iemand de “T” toets gebruikt, zorg ervoor dat de tekst terug verdwijnt indien iemand de “O” toets gebruikt • Schrijf een applicatie waarmee je met de muis tekent op het scherm indien iemand eerst de “T” toets indrukt en dan met de muis over het gamescherm gaat. Vincent Claes
  • 55. Fun Experiments with Python • Algorithmia API • https://algorithmia.com/ • Online API’s • Web Scraping • OpenCV (Vision) • Machine Learning Experiments Vincent Claes
  • 56. Vincent Claes • More info: vincent[at]cteq.eu • https://www.linkedin.com/in/vincentclaes/ • You can contact me for IoT, Embedded Systems (HW, SW, FPGA, ARM,…) and ML/AI projects (R and Python).

Hinweis der Redaktion

  1. python3 -m pip install -U pygame –user python3 -m pygame.examples.aliens