Skip to content

Latest commit

 

History

History
99 lines (68 loc) · 1.74 KB

04-2_Python.rst

File metadata and controls

99 lines (68 loc) · 1.74 KB
/=\/=\
|====|
 \==/
  \/

Python

  • Python scheint sich als Sprache für robuste Scripts zu etablieren.
  • So wie man die Shell als Klebstreifen für's Verbinden von System-Programmen und -Dateien kategorisieren kann, so kann man Python als soliden, aber im Gebrauch aufwändigeren Zement ansehen.
  • Die Integration braucht signifikant mehr Zeit, aber das Resultat ist widerstandsfähiger.
  • viel mehr cross-platform als Shell
  • es wird erwartet, dass man ein "Hello World" Python Script schreiben und ausführen kann und an der Prüfung erklären, wie man es ausführt.

hello world

print("Hello")

REPL/Shell

$ python3
...
>>> print("Foo")
Foo

$ python3
...
Python 3.7.3 (default, Jul 25 2020, 13:03:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Type help() for interactive help, or help(object) for help about object.
>>> help()
Welcome to Python 3.7's help utility!
...
help> print
The "print" statement
*********************
...
  • ipython mit Vervollständigung, Hilfe zu Objekten etc.
  • diverse IDEs für Python

Docu

Syntax

  • sehr einfach
    • block:

      if 2>1:
        print("Wer hätte das gedacht!")
      
      def do_stuff( param1, param2 ):
         print(param1)
         return 42
      
      do_stuff( "a", "b" )
  • Achtung: Space/Indent hat syntaktischen Einfluss!
  • wie andere moderne Skript Sprachen auch objekt-orientiert, aber nicht strikt
  • Strukturierung in Module: :

    import os

ansible

  • ansible ist in Python geschrieben
  • man kann eigene ansible Module in Python schreiben
  • siehe ansible_demo/library/less dpkg_dep