I am using os.listdir(path), However, I want to skip the first few files available in the path.
JavaScript
x
4
1
for file in os.listdir(local_path):
2
with open(os.path.join(local_path, file)) as myfile:
3
# This will open all the files
4
ALL THE FILES IN PATH ARE NAMED AND SORTED. For example, file0000, file0001, file0002 ..etc What I can use to skip say first 5 files and use the rest of other files.
Advertisement
Answer
os.listdir
doesn’t guarantee order, so you should sort first to make sure, then you can just slice:
JavaScript
1
3
1
for file in sorted(os.listdir(local_path))[5:]:
2
# rest of the code goes here
3