python 3 error i know the file works in python 2.6

garywood pythonsky at sky.com
Thu Feb 5 07:55:42 EST 2009


can someone help me please 


#open file and read last names
filename = input('name file')
file = open(filename, 'r')
names_list = file.readlines()
file.close()
#open a file for saving passwords
outfile_name = input('Save passwords')
outfile = open(outfile_name, 'a')


#create a password for each name in list
import random, string
name = ('')
for name in names_list:
    name_prefix = name[0:2]
    number = random.randrange(100,999)
    name_prefix = str.upper(name_prefix)
    password = name_prefix + str(number)
    whole_line = (password)
    print (password)
    outfile_name.write(whole_line)
    outfile_name.close()
    
    print (password)

error
Traceback (most recent call last):
  File "C:\Documents and Settings\Gary\Desktop\python\bembry\pa2.i.py", line 21, in <module>
    outfile_name.write(whole_line)
AttributeError: 'str' object has no attribute 'write'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090205/1174611f/attachment.html>


More information about the Python-list mailing list