ehemalige Veranstaltungen ia3.netz + ia3.data sowie ia4.Netz im Studiengang Interaktive Medien
(c) 2020/2021 Hochschule Augsburg - Fakultät für Informatik - Prof.Dr.Nik Klever
8+9
17
a = 2*7
a
14
print(a)
14
type(a)
int
import os
getpid()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-12-c344a67d685c> in <module>() ----> 1 getpid() NameError: name 'getpid' is not defined
os.getpid()
7016
os.getcwd()
'C:\\Users\\nikkl'
x=os.getpid()
print(type(x))
<class 'int'>
if True:
print(True)
True
if True:
print(False)
File "<ipython-input-17-e69bf44c797e>", line 2 print(False) ^ IndentationError: expected an indented block
if True:
print(1)
print(4)
print("tab")
1 4 tab
help
Type help() for interactive help, or help(object) for help about object.
help()
Welcome to Python 3.7's help utility! If this is your first time using Python, you should definitely check out the tutorial on the Internet at https://docs.python.org/3.7/tutorial/. Enter the name of any module, keyword, or topic to get help on writing Python programs and using Python modules. To quit this help utility and return to the interpreter, just type "quit". To get a list of available modules, keywords, symbols, or topics, type "modules", "keywords", "symbols", or "topics". Each module also comes with a one-line summary of what it does; to list the modules whose name or summary contain a given string such as "spam", type "modules spam". help> quit You are now leaving help and returning to the Python interpreter. If you want to ask for help on a particular object directly from the interpreter, you can type "help(object)". Executing "help('string')" has the same effect as typing a particular string at the help> prompt.
dir()
['In', 'Out', '_', '_1', '_10', '_13', '_14', '_19', '_21', '_4', '_6', '__', '___', '__builtin__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '_dh', '_exit_code', '_i', '_i1', '_i10', '_i11', '_i12', '_i13', '_i14', '_i15', '_i16', '_i17', '_i18', '_i19', '_i2', '_i20', '_i21', '_i22', '_i23', '_i3', '_i4', '_i5', '_i6', '_i7', '_i8', '_i9', '_ih', '_ii', '_iii', '_oh', 'a', 'exit', 'get_ipython', 'os', 'quit', 'x']
dir(a)
['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes']
a.bit_length()
4
dir(os)
['DirEntry', 'F_OK', 'MutableMapping', 'O_APPEND', 'O_BINARY', 'O_CREAT', 'O_EXCL', 'O_NOINHERIT', 'O_RANDOM', 'O_RDONLY', 'O_RDWR', 'O_SEQUENTIAL', 'O_SHORT_LIVED', 'O_TEMPORARY', 'O_TEXT', 'O_TRUNC', 'O_WRONLY', 'P_DETACH', 'P_NOWAIT', 'P_NOWAITO', 'P_OVERLAY', 'P_WAIT', 'PathLike', 'R_OK', 'SEEK_CUR', 'SEEK_END', 'SEEK_SET', 'TMP_MAX', 'W_OK', 'X_OK', '_Environ', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_execvpe', '_exists', '_exit', '_fspath', '_get_exports_list', '_putenv', '_unsetenv', '_wrap_close', 'abc', 'abort', 'access', 'altsep', 'chdir', 'chmod', 'close', 'closerange', 'cpu_count', 'curdir', 'defpath', 'device_encoding', 'devnull', 'dup', 'dup2', 'environ', 'error', 'execl', 'execle', 'execlp', 'execlpe', 'execv', 'execve', 'execvp', 'execvpe', 'extsep', 'fdopen', 'fsdecode', 'fsencode', 'fspath', 'fstat', 'fsync', 'ftruncate', 'get_exec_path', 'get_handle_inheritable', 'get_inheritable', 'get_terminal_size', 'getcwd', 'getcwdb', 'getenv', 'getlogin', 'getpid', 'getppid', 'isatty', 'kill', 'linesep', 'link', 'listdir', 'lseek', 'lstat', 'makedirs', 'mkdir', 'name', 'open', 'pardir', 'path', 'pathsep', 'pipe', 'popen', 'putenv', 'read', 'readlink', 'remove', 'removedirs', 'rename', 'renames', 'replace', 'rmdir', 'scandir', 'sep', 'set_handle_inheritable', 'set_inheritable', 'spawnl', 'spawnle', 'spawnv', 'spawnve', 'st', 'startfile', 'stat', 'stat_result', 'statvfs_result', 'strerror', 'supports_bytes_environ', 'supports_dir_fd', 'supports_effective_ids', 'supports_fd', 'supports_follow_symlinks', 'symlink', 'sys', 'system', 'terminal_size', 'times', 'times_result', 'truncate', 'umask', 'uname_result', 'unlink', 'urandom', 'utime', 'waitpid', 'walk', 'write']
help(os.getcwd)
Help on built-in function getcwd in module nt: getcwd() Return a unicode string representing the current working directory.
dir(os.getcwd)
['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__text_signature__']
text = "Dies" + " ist " + " ein " + "Satz"
text.find("ist")
5
text[5:]
'ist ein Satz'
text.replace("ist","war")
'Dies war ein Satz'
text
'Dies ist ein Satz'
text = text.replace("ist","war")
text
'Dies war ein Satz'
textliste = text.split()
textliste
['Dies', 'war', 'ein', 'Satz']
"-".join(textliste)
'Dies-war-ein-Satz'
"Dies ist ein Satz"
'Dies ist ein Satz'
'Dies ist ein Satz'
'Dies ist ein Satz'
"Nik's Text"
"Nik's Text"
'Nik\'s Text'
"Nik's Text"
langertext = """Dies ist ein
Text über mehrere
Zeilen
"""
str(langertext)
'Dies ist ein\nText über mehrere\nZeilen\n'
print(langertext)
Dies ist ein Text über mehrere Zeilen
repr(langertext)
"'Dies ist ein\\nText über mehrere\\nZeilen\\n'"
print(str(langertext))
Dies ist ein Text über mehrere Zeilen
print(repr(langertext))
'Dies ist ein\nText über mehrere\nZeilen\n'
datei = open("test.txt","w")
datei.write(langertext)
datei.close()
datei = open("test.txt","r")
gesamterInhalt = datei.read()
datei.close()
print(gesamterInhalt)
Dies ist ein Text über mehrere Zeilen
a = 4*3.5
type(a)
float
try:
dateiname = "irgendeinName.irgendwas"
datei = open(dateiname,"r")
except IOError, e:
print(dateiname,"nicht verfügbar")
File "<ipython-input-55-692b18f84830>", line 4 except IOError, e: ^ SyntaxError: invalid syntax
try:
dateiname = "irgendeinName.irgendwas"
datei = open(dateiname,"r")
except IOError as e:
print(e.errno,e.strerror)
print(dateiname,"nicht verfügbar")
2 No such file or directory irgendeinName.irgendwas nicht verfügbar
a = int(3.141)
a
3
a = int(3.6789)
a
3
a = float("3.141")
a
3.141
a = float("3.45€")
a
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-63-bc731ef2a1a1> in <module>() ----> 1 a = float("3.45€") 2 a ValueError: could not convert string to float: '3.45€'