import tempfile with tempfile.NamedTemporaryFile(mode='w+') as temp_file: temp_file.write('First line\\nSecond line\\nThird line\\nFourth line\\n') temp_file.seek(0) lines = temp_file.readlines() for line in lines[1:]: print(line.strip())
Second line Third line Fourth line
import tempfile with tempfile.NamedTemporaryFile(mode='w+') as temp_file: temp_file.write('The quick brown fox jumps over the lazy dog') temp_file.seek(16) temp_file.write('red ') temp_file.seek(0) print(temp_file.read())
The quick brown red jumps over the lazy dogPackage Library: The tempfile library is a built-in package and does not require any external installation.