- 论坛徽章:
- 0
|
Below code snippet got choked in pyhton3.0 while it does job in python2.5
I highlighted the line that caused the breaking in red color and the compiler says
Traceback (most recent call last):
File "ph.py", line 312, in <module>
key = string.strip( key )
AttributeError: 'module' object has no attribute 'strip'
I'm quite new to Python. please tell me what is wrong and how to fix it.
Thanks in advance.
Regards,
if __name__ == '__main__':
if len(sys.argv) == 1:
sys.stdout = sys.stderr
print ('Usage: %s <input filename>' % sys.argv[0])
print (' The input file contains pairs of lines. The first line')
print (' each pair is a string containing a key. The second line')
print (' is an integer which is the desired hash code.')
sys.exit()
input = open(sys.argv[1], 'r')
keys = []
while 1:
key = input.readline()
if key == "": break
hashcode = input.readline()
if hashcode == "":
sys.stderr.write('Odd number of lines in file\n')
sys.exit()
key = string.strip( key )
hashcode = int(hashcode)
keys.append( (key,hashcode) )
input.close()
sys.stderr.write('%i key/hash pairs read\n' % len(keys) )
generate_hash( keys ) |
|