thewhitetulip / build-app-with-python-antitextbook

Aims to teach Python3 by example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: os.listdir()

vezycash opened this issue · comments

https://github.com/thewhitetulip/build-app-with-python-antitextbook/blob/master/01-intro-to-python.md#example-list-all-txt-files

import os
files = os.listdir()
for file in files:
    if file.endswith(".txt"):
        print(file)

Function os.listdir() expects an argument (a folder name)

files = os.listdir("folder")

folder = the folder which contains the text files.

OR
files=os.listdir(".")
//In this case, the files have to be in the same directly as file.py

Actually, since pytjon3 it accepts zero arguments, if there is no argument, it lists the current directory

You're right.