Using the following bit of code:
for root, dirs, files in os.walk(corpus_name): for file in files: if file.endswith(\".v4_gold_conll\"):
You'll have to join the root with the filename.
root
for root, dirs, files in os.walk(corpus_name): for file in files: if file.endswith(".v4_gold_conll"): with open(os.path.join(root, file)) as f: tokens = [ line.split()[3] for line in f if line.strip() and not line.startswith("#") ] print(tokens)