Python Forum
Performance options for sys.stdout.writelines
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Performance options for sys.stdout.writelines
#3
These 2 php files are are < 8kb and they only have 5 lines which are not the same.
This takes zero.something seconds to complete. About as long as it takes to press enter.
Maybe buy a new computer? I recommend Ryzen R9 processors!

path1 = '/var/www/html/20BE1cw/20BE1sW3.html.php'
path2 = '/var/www/html/20BE2cw/20BE2sW3.html.php'

with open(path1) as f1, open(path2) as f2:
    lines1 = f1.readlines()
    lines2 = f2.readlines()

# do this or you will get and index error when you get to the end of the shorter file.
if len(lines1) == len(lines2):
    data1 = lines1
    data2 = lines2
elif len(lines1) > len(lines2):
    data1 = lines1
    data2 = lines2
else:
    data1 = lines2
    data2 = lines1

diff = []

for d in range(len(data1)):
    if not data1[d] == data2[d]:
        diff.append(data2[d])
Output:
>>> len(diff) 5
Reply


Messages In This Thread
RE: Performance options for sys.stdout.writelines - by Pedroski55 - Aug-20-2022, 07:52 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  argparser not showing all options bigal 1 317 May-22-2024, 02:54 AM
Last Post: deanhystad
  [subprocess] Why stdout sent to stderr? Winfried 3 641 Jan-26-2024, 07:26 PM
Last Post: snippsat
  writelines only writes one line to file gr3yali3n 2 2,595 Dec-05-2021, 10:02 PM
Last Post: gr3yali3n
  changing stdout and stderr Skaperen 4 2,870 Dec-02-2020, 08:58 PM
Last Post: Skaperen
  print a line break in writelines() method leodavinci1990 1 6,694 Oct-12-2020, 06:36 AM
Last Post: DeaD_EyE
  Get stdout of a running process yok0 0 3,206 Aug-20-2020, 10:12 AM
Last Post: yok0
  will with sys.stdout as f: close sys.stdout? Skaperen 9 4,917 Nov-03-2019, 07:57 AM
Last Post: Gribouillis
  performance kerzol81 1 2,002 Oct-07-2019, 10:19 AM
Last Post: buran
  Help with options raiden 1 2,038 Aug-30-2019, 12:57 AM
Last Post: scidam
  Distilling strings using .writelines() and .read() tedie 1 2,131 Jun-24-2019, 09:56 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020