thewhitetulip / build-app-with-python-antitextbook

Aims to teach Python3 by example
GNU General Public License v3.0
559 stars 69 forks source link

Error: os.listdir() #17

Closed vezycash closed 7 years ago

vezycash commented 7 years ago

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

thewhitetulip commented 7 years ago

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

vezycash commented 7 years ago

You're right.