O
O
Onkel_Ron2020-07-27 15:29:49
Python
Onkel_Ron, 2020-07-27 15:29:49

Python. How to create a list with 100 lines?

Good afternoon!
Tell me how to create a list of 100 lines?

import os
dest = 'O:\\OPO\\PFR\\'
filelist = open('filelist.lst', 'w')
os.chdir(dest)
for root, dirs, files in os.walk("."):
    for filenames in files:
        if filenames.endswith(".xml"):
            filelist.write(dest + filenames + '\n')
filelist.close()

The code reads the filenames from the directory and writes all the values ​​(2111), with the path, to filelist.lst
There is no way to write the first 100 lines from the list of values.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2020-07-27
@Onkel_Ron

It can be like this: or like this:
for filenames in files[0:100]:
for filenames in files[:100]:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question