• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. python code to compare 2 LEF

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 125
  • Views 8191
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

python code to compare 2 LEF

san2696
san2696 over 3 years ago

Hi all,

I have 2 LEF files i want to perform these task using python

  1. get list of Pins in first LEF and compare with other LEF and report any missing pins and any extra pins

i completed this task file size of (34000 lines). When i perform different size files its giving me error(IndexError: list index out of range)

if you find anywhere wrong in a code please correct me 

please help me to solve this problem, much much much thanks in advance 

my code(python)

file1 = open('/home/script/fileabc1.lef', 'r')     #LEF1
file2 = open('/home/script/fileabc2.lef', 'r')      #LEF2


file00 = open('/home/script/o0.txt', 'r+')
file01 = open('/home/script/o1.txt', 'r+')
file02 = open('/home/script/o2.txt', 'r+')
file03 = open('/home/script/o3.txt', 'r+')
file04 = open('/home/script/o4.txt', 'r+')

for l1 in file1.readlines():
     if 'PIN' in l1:
         file00.write("%s\n" %(l1))
             for l2 in file2.readlines():
                  if 'PIN' in l2:
                       file01.write("%s\n" %(l2))


file00_1 = file00.readlines()
file01_1 = file01.readlines()

for i in range(len(file00_1)):           
       if file00_1[i] != file01_1[i]:                # error found here
             file02.write("%s" %(file00_1[i]))
       else:
             file03.write("%s\n" %(file00_1[i]))

for i in range(len(file01_1)):
       if file01_1[i] != file00_1[i]:
             file04.write("%s\n" %(file01_1[i]))

  • Cancel
Parents
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    A rather strange question to be asking in the "Custom IC Design" forum, since this is really a pure python question and the only IC aspect of the question is that you happen to be dealing with LEF files. I'd have thought stackoverflow or somewhere like that would be better (although this is a pretty basic python question).

    The error is pretty clear - on the line you indicated - if the second file has fewer lines than the first, then the array/list file01_1 will have fewer entries than file00_1 and hence it's inevitable that you'll get an index. 

    It rather depends on what you are trying to do, but maybe those range() calls should both be range(min(len(file00_1),len(file01_1))) ? It won't ever visit the lines after the length of the shortest file, but you'll have to adjust your code logic to handle that if that's what you want.

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • Andrew Beckett
    Andrew Beckett over 3 years ago

    A rather strange question to be asking in the "Custom IC Design" forum, since this is really a pure python question and the only IC aspect of the question is that you happen to be dealing with LEF files. I'd have thought stackoverflow or somewhere like that would be better (although this is a pretty basic python question).

    The error is pretty clear - on the line you indicated - if the second file has fewer lines than the first, then the array/list file01_1 will have fewer entries than file00_1 and hence it's inevitable that you'll get an index. 

    It rather depends on what you are trying to do, but maybe those range() calls should both be range(min(len(file00_1),len(file01_1))) ? It won't ever visit the lines after the length of the shortest file, but you'll have to adjust your code logic to handle that if that's what you want.

    Andrew

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Children
  • san2696
    san2696 over 3 years ago in reply to Andrew Beckett

    Thank you,  Andrew Beckett

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information