Reading a File

Write a program that reads and parses files like this (download):

1910420003;Corinna;Baumgartner
1910420002;Anzhelika;Chernykh
1910420005;Simon;Hu
1910420006;Matthias;Kappel
1810420009;Peter;Kolter
1920420033;Jan;Kornberger
1910420007;Luis;Kraker
1810420010;Leonid;Kudriaschov
1910420008;Michael;Lang
1910420010;Sonja;Lukas
1910420013;Behnaz;Mehrabadi
1910420014;Leo;Moser
1910420015;Moritz;Nagelschmied
1910420018;Bianca;Reimer
1910420020;Tim;Schmid
1910420021;Lukas;Schüttler
1910420022;Michael;Schweiger
1910420024;Paul;Sinabell
1910420025;Jan;Slovik
1910420026;Daniel;Söls
1910420027;Michael;Stangl
1910420028;Felix;Themessl
1920420035;Astrid;Vogel
1810420029;Florian;Zwittnigg
666;Jörg;Faschingbauer

The program parses each line as a student record, consisting of

  • Matriculation number

  • First name

  • Last name

Commandline

The program is invoked with the student database file name as its only parameter,

$ path/to/repo/root/exercises/lastname.firstname/studentdb students.txt

Output

The program writes to standard output one line per student record,

Note

Please take care that the output is exactly as shown (spaces are spaces, not tabs, for example). This greatly helps a future checker script.

$ path/to/repo/root/exercises/lastname.firstname/studentdb students.txt
...
MatNr: 1810420029, Last name: Zwittnigg, First name: Florian
MatNr: 666, Last name: Faschingbauer, First name: Jörg
$

Further Information

  • Note that a line, when read from a file, still comes with a newline (”\n”) at the end. You should rid of trailing newline, otherwise the last name will have a trailing newline. See str.rstrip() (documentation here)

  • Use str.split() on each line (documentation here).

Dependencies

cluster_python Python Programming cluster_python_basics Python: The Language Fundamentals cluster_python_misc Python: Miscellaneous Topics cluster_ece19 ECE19: Exercises and Custom Topics python_basics_python_0500_files File I/O python_basics_python_0220_for for Loops python_basics_python_0500_files->python_basics_python_0220_for python_misc_encoding Encoding python_basics_python_0500_files->python_misc_encoding python_basics_python_0120_helloworld Hello World python_basics_python_0110_blahblah Blahblah python_basics_python_0120_helloworld->python_basics_python_0110_blahblah python_basics_python_0160_boolean Boolean python_basics_python_0150_datatypes_overview Datatypes python_basics_python_0160_boolean->python_basics_python_0150_datatypes_overview python_basics_python_0193_while while Loops python_basics_python_0193_while->python_basics_python_0160_boolean python_basics_python_0170_if The if Statement python_basics_python_0193_while->python_basics_python_0170_if python_basics_python_0250_refs_flat_deep_copy References, (Im)mutability python_basics_python_0250_refs_flat_deep_copy->python_basics_python_0150_datatypes_overview python_basics_python_0140_variables Variables python_basics_python_0250_refs_flat_deep_copy->python_basics_python_0140_variables python_basics_python_0150_datatypes_overview_compound Compound Datatypes python_basics_python_0250_refs_flat_deep_copy->python_basics_python_0150_datatypes_overview_compound python_basics_python_0170_if->python_basics_python_0160_boolean python_basics_python_0200_sequential_types Sequential Datatypes python_basics_python_0200_sequential_types->python_basics_python_0150_datatypes_overview_compound python_basics_python_0150_datatypes_overview->python_basics_python_0140_variables python_basics_python_0300_strings More About Strings python_basics_python_0300_strings->python_basics_python_0250_refs_flat_deep_copy python_basics_python_0300_strings->python_basics_python_0200_sequential_types python_basics_python_0300_strings->python_basics_python_0150_datatypes_overview python_basics_python_0130_syntax_etc Syntax etc. python_basics_python_0130_syntax_etc->python_basics_python_0120_helloworld python_basics_python_0320_strings_methods Miscellaneous String Methods python_basics_python_0320_strings_methods->python_basics_python_0300_strings python_basics_python_0140_variables->python_basics_python_0130_syntax_etc python_basics_python_0220_for->python_basics_python_0193_while python_basics_python_0220_for->python_basics_python_0200_sequential_types python_basics_python_0150_datatypes_overview_compound->python_basics_python_0150_datatypes_overview python_misc_encoding->python_basics_python_0150_datatypes_overview python_misc_encoding->python_basics_python_0320_strings_methods ece19_file_read Reading a File ece19_file_read->python_basics_python_0500_files