I was working on a script which reading a folder of files(each of size ranging from 20 MB to 100 MB), modifies some data in each line, and writes back to a copy of the file.
'write(arg)' method expects string as its argument. So once it calls, it will directly writes. this is the reason it is much faster.
where as if you are using writelines() method, it expects list of string as iterator. so even if you are sending data to writelines, it assumes that it got iterator and it tries to iterate over it. so since it is an iterator it will take some time to iterate over and write it.
Is that clear ?