From the course: Learning Python

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Files

Solution: Files - Python Tutorial

From the course: Learning Python

Solution: Files

- [Instructor] All right, so for this challenge, we needed to add up all of the byte sizes of the text files in the Deps Directory and we had to ignore any files that were not text files. So in my code, I have to import the OS module and I gave this as a bit of a hint in the instructions was to look at the OS and OS Path modules. So I import OS because I'm going to make use of the code in that module. And then in my code, I have a variable that keeps track of the total byte count so far and that is initialized to zero. Then I have a variable that contains the name of the Deps Directory, and I made it a variable because I'm going to use it several times. So to get a list of the contents of the directory, I can use the listdr function, which is contained within the OS module, which is part of the Python Standard Library. That will give me a list of file names, but those file names don't have the directory path in them.…

Contents