Aktuelles zu Python (Aktuelles zu Python), Information, Seite 724192
https://www.purl.org/stefan_ram/pub/aktuelles_python (Permalink) ist die kanonische URI dieser Seite.
Stefan Ram
Python-Kurs

Aktuelles zu Python 

apxp.inxfexrkixt.cxom/dxemxo

2020-10-09 chat

yoxpaxd.xeu

2020-09-18 Planung

ungefähre Planung für heute (Freitag):
– 09.00 Abschluß des Kapitels „Weitere Arten von Zeichenfolgenliteralen“
– 10.00 Anweisungsfolgen und Skripte
– 11.00 Erstellen von Graphiken
– 12.00 Mittagspause
– 13.00 def
– 14.00 if und while
– 15.00 Fragestunde

2020-09-15 Lambda-Funktionen

https://towardsdatascience.com/what-are-lambda-functions-in-python-and-why-you-should-start-using-them-right-now-75ab85655dc6
You can see that this definition is much simpler than the normal python function definition you are used to.
It is simple, concise, and can be written in a single line of code.
As a Data Scientist, you will work a lot with pandas library and this is a place where you will be using lambda notation often.
Übersetzung (autom.), Unterstreichungen und Anmerkungen in Klammern von Stefan Ram
(Zum Thema der Lambda-Funktionen:)
Sie sehen, dass diese Definition viel einfacher ist als die normale Pythonfunktionsdefinition (= Definition mit "def"), an die Sie (vielleicht) gewöhnt sind.
Sie ist einfach, prägnant und kann in einer einzigen Codezeile geschrieben werden.
Als Datenwissenschaftler werden Sie viel mit der Pandabibliothek arbeiten, und dies ist ein Ort, an dem Sie häufig die Lambda-Notation verwenden werden.

2020-03-13

Kursprogramm, falls am Ende noch Zeit ist

2019-06-12

Informationen über die verschiedenen Adressen des Rechners ausgeben

main.py

import socket

print( f"{socket.gethostbyname_ex( socket.gethostname() ) = }" )

Einzelnen Anschluß prüfen

socket ” = wörtlich: „Steckdose“

Die Adresse ist ein Paar. Die erste Komponente ist entweder eine Domäne (wie »example.com«) oder eine IPv4-Adresse wie »192.0.2.1«. Die zweite Komponente ist die Kennzahl des Anschlusses (des sockets, auch “port ” genannt).

main.py

import socket as socket_module

socket_module.setdefaulttimeout( 1 )

socket_module.socket().connect( ( '127.0.0.1', 445 ) )

Protokoll
(keine Ausgabe.)
main.py

import socket as socket_module

socket_module.setdefaulttimeout( 1 )

socket_module.socket().connect( ( '127.0.0.1', 444 ) )

Protokoll
socket.timeout: timed out

Das erste Skript verwendete den Anschluß 445 und erhielt eine Antwort, das zweite verwendete den Anschluß 444 und erhielt keine  Antwort innerhalb der festgelegten Zeit von einer Sekunde.

Mehrere Anschlüsse prüfen

main.py

import socket as socket_module

socket_module.setdefaulttimeout( 0.01 )

for port in range( 1, 65535 ):

try:

socket = socket_module.socket()

socket.connect( ( '127.0.0.1', port ) )

print( '\n', port, ' connected', sep='' )

socket.send( b'Hello\r\n' )

print( port, 'sent' )

reply = socket.recv( 4096 )

print( port, 'reply:', str( reply ))

except socket_module.timeout:

pass

except OSError:

pass

except ConnectionRefusedError:

print( port, "ConnectionRefusedError" )

except ConnectionResetError:

print( port, "ConnectionResetError" )

finally:

socket.close()

Protokoll

135 connected

135 sent

139 connected

139 sent

300 connected

300 sent

300 reply: b'Ready.'

445 connected

445 sent

445 ConnectionResetError

Anschlüsse bedienen

main.py

import socket as socket_module

server = socket_module.socket()
server.bind( ( "0.0.0.0", 3306 ))
server.listen()
print( "Listening." )

while True:
client, address = server.accept()
print( "accepted from: ", client, address[ 0 ], address[ 1 ])
request = client.recv( 1024 )
print( "Received: ", request )
client.send( b"Ready." )
client.close()

Protokoll

Listening.

accepted from: ...

Windows
netstat -a
elevated Windows
netstat -a -b

Mehrere Anschlüsse gleichzeitig bedienen

main.py

import socket as socket_module
import select as select_module

ports = [ 21, 23, 25, 80, 110, 139, 445, 1433, 1521, 1723, 3389, 5900, 8080 ]
servers = []

for port in ports:
try:
print( port )
server = socket_module.socket()
server.setsockopt( socket_module.SOL_SOCKET, socket_module.SO_REUSEADDR, 1 )
server.bind( ( "0.0.0.0", port ))
server.listen()
servers.append( server )
except OSError:
print( "Can't bind to", port )

while True:
readable, _ ,_ = select_module.select( servers, [], [] )
ready_server = readable[ 0 ]
client, address = ready_server.accept()
try:
print( "accepted from: ", address[ 0 ], address[ 1 ])
request = client.recv( 1024 )
print( "Received: ", request )
client.send( b"Ready." )
finally:
client.close()

Anschlüsse
  21 FTP
23 telnet
25 smtp
80 HTTP
110 pop3
139 netbios
445 file sharing
1433 SQL Server
1521 Oracle
1723 VPN
3389 remote desktop
5900 VNC
8080 proxy

Webscraping

(siehe Extralektion zu diesem Thema)

Whois-Abfrage

main.py
import socket as socket_module
socket_module.setdefaulttimeout( 5 )

socket = socket_module.socket()
try:
socket.connect( ( "whois.internic.net" ,43 ))
print( 'connected' )
socket.send( b'example.com\r\n' )
print( 'sent' )
bytes = socket.recv( 8192 )
print( 'reply:\n', bytes.decode( 'iso8859-1' ), sep='' )
except socket_module.timeout:
print( "timeout" )
except ConnectionRefusedError:
print( "ConnectionRefusedError" )
except ConnectionResetError:
print( "ConnectionResetError" )
finally:
socket.close()
Protokoll

connected

sent

reply:

Domain Name: EXAMPLE.COM ...

Abfrage der eigenen IP-Adressen

Ein Rechner kann mehrere IP-Adressen haben. Das folgende Programm liefert bei einem Rechner hinter einem Router die lokale Adresse des Rechners.

main.py

import socket as socket_module

socket = socket_module.socket( socket_module.AF_INET, socket_module.SOCK_DGRAM )

try:

socket.connect(( '10.255.255.255', 1 ))

print( socket.getsockname()[0] )

finally:

socket.close()

Protokoll
10.36.142.37

Notizen

socket = socket_module.socket( family=sockets.AF_INET, type=sockets.SOCK_STREAM )

Es gibt verschiedene Adreßfamilien.

AF_INET: internet address family: Internet Protocol v4 addresses (default)

SOCK_STREAM (TCP) a connection-based protocol. The connection is established and the two parties have a conversation until the connection is terminated by one of the parties or by a network error. Ggs: SOCK_DGRAM (UDP) a datagram-based protocol. You send one datagram and get one reply and then the connection terminates.

2019-06-03

Woher kommen Urkommandos?
Einzelne Bitmuster entfalten Ihre Wirkung aufgrund elektronischer Schaltkreise, welche sich aufgrund physikalischer Gesetzmäßigkeiten verhalten.
Spielcomputer Logikus, Digital-Elektronik 8700.
Welches Bitmuster entspricht der Funktion »random«?
Da Python -Programme interpretiert werden, gibt es kein Bitmuster.
Wenn man ein C -Programm für »random« kompiliert erhält man jedoch ein Muster mit zirka 1000 Bit.
Wie werden Programmiersprachen erschaffen?
Praktisch, indem man eine Implementation programmiert.
Theoretisch, indem man Syntax und Semantik spezifiziert.
Literatur:
Niklaus Wirth: Grundlagen und Techniken des Compilerbaus. ISBN 3486243748
Aho, Sethi, Ullman: Compilerbau, Tl. 1. Oldenbourg 1999 ISBN 3486252941
Aho, Sethi, Ullman: Compilerbau, Tl. 2. Oldenbourg 1999 ISBN 3486252666
www.flipcode.com/articles/scripting_issue01.shtml
staff.polito.it/silvano.rivoira/HowToWriteYourOwnCompiler.htm
Ein PL/0-Übersetzer in Pascal: http://www.246.dk/pl0.html
Zu PL/0 (mit PL/0-Synax [sic!]): http://www.inf.hs-zigr.de/~wagenkn/TI/Berechenbarkeit/rekabstieg.html
Einführung mit PL/0: http://www.htw-dresden.de/~s2536/Compiler/Vorlesung_CI.pdf
www.htw-dresden.de/~s2536/Compiler/Vorlesung_CI.pdf
Guide to the PL/0 Compiler, http://www.cs.rochester.edu/courses/254/PLzero/guide.pdf
Beispiel mit Schildkröten: LRFB.
Wie kann man Module in Python  anlegen?
Wurde gestern schon gezeigt.
Wie kann man Python -Programme in exe-Programm umwandeln?
Ist nicht nötig, aber möglich, zum Beispiel mit PyInstaller oder py2exe.
Suchmaschine: [Python deployment]
Wie kann man Python -Programme in anderen Sprachen nutzen?
Das geht in C, C++  und indirekt in weiteren Sprachen.
www.boost.org/doc/libs/1_44_0/libs/python/doc/tutorial/doc/html/python/embedding.html
docs.python.org/extending/embedding.html
Wo ist Python  erkennbar langsamer als C ?
benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/go-python3.html
Wie kann man den Quellcode von Python-Programmen wie the GIMP  oder LibreOffice  lesen?
Diese Programme sind zum größten Teil nicht  in Python geschrieben.
Suchmaschine: [GIMP source code]
Suchmaschine: [LibreOffice source code]
IDLE ist beispielsweise in Python geschrieben. Quellcode: Suchmaschine: [Python IDLE source code]

2018-11-21

Die Funktion ›prmonth‹ ist ein weiteres Beispiel eines reinen Wirkfunktors.

Protokoll

from calendar import prmonth

prmonth( 2038, 1 )

    January 2038
Mo Tu We Th Fr Sa Su
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
x = prmonth( 2038, 1 )
    January 2038
Mo Tu We Th Fr Sa Su
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
print( x )
None

Hingegen ist ›month‹ ein reiner Wertfunktor.

Protokoll

from calendar import month

x = month( 2038, 1 )

print( x )

January 2038

Mo Tu We Th Fr Sa Su

1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30 31

 

Seiteninformationen und Impressum   |   Mitteilungsformular  |   "ram@zedat.fu-berlin.de" (ohne die Anführungszeichen) ist die Netzpostadresse von Stefan Ram.   |   Eine Verbindung zur Stefan-Ram-Startseite befindet sich oben auf dieser Seite hinter dem Text "Stefan Ram".)  |   Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram. Schlüsselwörter zu dieser Seite/relevant keywords describing this page: Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram724192 stefan_ram:724192 Aktuelles zu Python Stefan Ram, Berlin, and, or, near, uni, online, slrprd, slrprdqxx, slrprddoc, slrprd724192, slrprddef724192, PbclevtugFgrsnaEnz Erklärung, Beschreibung, Info, Information, Hinweis,

Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram.
https://www.purl.org/stefan_ram/pub/aktuelles_python