[Tutor] writing HTML code to a variable/file
Alan Gauld
alan.gauld at btinternet.com
Tue May 26 19:34:33 CEST 2009
"Dayo Adewunmi" <contactdayo at gmail.com> wrote
> subsequently written to the file. How do I save this
>
> <a href=\"http://users.example.com/~" + userName + ">" + lastName + ", "
> + firstName + "</a>
>
> to a variable, then?
aVar = '<a href=\"http://users.example.com/~' + userName + ">" + lastName +
", " + firstName + "</a>"
But IMHO its much easier to use string formatting:
aVar = '<a href="http://users.example.com/~%s>%s,%s</a>' %(
userName,lastName,firstName)
Its also more efficient.
However in practice you don;t need to store it as a variable before writing
it,
you can just write the string directly.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list