How can I split a file in python?

前端 未结 9 641
失恋的感觉
失恋的感觉 2020-12-03 07:29

Is it possible to split a file? For example you have huge wordlist, I want to split it so that it becomes more than one file. How is this possible?

9条回答
  •  青春惊慌失措
    2020-12-03 08:00

    Sure it's possible:

    open input file
    open output file 1
    count = 0
    for each line in file:
        write to output file
        count = count + 1
        if count > maxlines:
             close output file
             open next output file
             count = 0
    

提交回复
热议问题