Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON FILES / CHAPTER 05 / Learn / LESSON 02
In Code Lab your code runs in a virtual folder lab (working directory). A relative path "hello.txt" is a file in that folder — not on your PC.
with open("hello.txt", encoding="utf-8") as f: line = f.readline()
readline() returns one line (with \n). strip() removes whitespace and the newline.
print(line.strip())open() as a context manager closes the file for you. encoding="utf-8" is good practice for text.
--- hello.txt ---
hello
Learn: virtual lab folder and open.
STREAM IDLE
›