more newbie list questions
googleboy
mynews44 at yahoo.com
Thu Jul 14 13:52:24 EDT 2005
Thanks for this. It ahs been very helpful.
I realised that my problem using getattr were because I was trying to
use it over the list of lists, instead of each book. I have written up
a for loop now, and I think I am a lot closer:
for book in all_books:
author1 = getattr(book, 'author1')
sTemplate.replace('author1', author1)
found = sTemplate.find('%author1%')
print '\n.\n.\n'
print author1
print '\n'
print found
print sTemplate
You will notice that I print out various things. I am having some
troubles.
The resulting output of this loop is as follows:
andy humber
47
The title is %title%. <br><br>
The author is %author1% %author2% <br><br>
The Publisher is %publisher1% %publisher2% <br><br>
The ISBN is %ISBN% <br><br>
This is obviously correctly assigning the author's name to the author1
variable, which I was my problem.
It is finding my search string at teh 47th character of the sTemplate
string, which is great.
But it doesn't seem to want to replace the search string with the value
of the author1 variable.
Is there something else I am missing here?
Thanks for the advice.
regards,
googleboy
More information about the Python-list
mailing list