<jupyter_start><jupyter_text>Learning Objectives* How to read data from txt and csv files in python.* How to write/append data to a file.* How to parse through a directory using python's `os` module.<jupyter_code>with open("./sample.txt", 'r') as f:
    data = f.read()
print(data)
with open("./sample.csv", 'r') as f:
    for line in f:
        new_line = line.upper()
        print(new_line)
#     data = f.readline()
    
data
with open('sample.txt', 'w') as f:
    f.write("Hi, I am writing the data to a file for the first time.")
with open('sample.txt', 'a') as f:
    f.write("This is the second time I am writing the data")<jupyter_output><empty_output><jupyter_text>OS module<jupyter_code>import os

os.mkdir("./sample_data")
os.walk("./chesspy/")
for dirpath, dirnames, filenames in os.walk("chesspy/"):
    print(f"There are {len(dirnames)} directories and there are {len(filenames)} files in the {dirpath}\n and the filenames are {filenames}.")<jupyter_output>There are 0 directories and there are 3 files in the chesspy/
 and the filenames are ['game.py', 'players.py', 'draw.py'].
{'fraction_non_alphanumeric': 0.13985374771480805, 'fraction_numerical': 0.0018281535648994515, 'mean_word_length': 4.093023255813954, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '461445', 'license': 'MIT', 'n_tokens_mistral': 384, 'n_tokens_neox': 373, 'n_words': 130, 'path': 'module_2_programming/files_io.ipynb', 'repo_name': 'wiplane/foundations-of-datascience-ml', 'size': '1094'}