Python Code Examples

Growing collection of Python programming examples

Tag: read file

    1. from the directory, where the script is executed,
    2. the file called “filename.txt” is opened, just for reading purposes,
    3. all lines of the file are interpeted as objects in a list
    4. in a loop, every object of this list is printed to the main output.
    f = open("filename.txt", "r")
    lines = f.readlines()
    
    for line in lines:
        print(line, end="")
    + ,