First page Back Continue Last page Overview Image

Die Systemshell aufrufen

Will man ein Systemkommando ausführen, so kann man dem Systembefehl ein „!“ voranstellen:

In [1]: !wc ulysses.txt

33025 267887 1572565 ulysses.txt

Die Ausgabe des Systembefehls kann auch ganz einfach einer Variablen zugewiesen werden:

In [2]: x = !wc ulysses.txt

In [3]: first5lines = ! head -n 5 ulysses.txt

In [4]: first5lines

Out[4]: ['ULYSSES', '', 'by James Joyce', '', '']

In [5]: filename = "ulysses.txt"

In [6]: !wc {filename}

33025 267887 1572565 ulysses.txt