Z77
Z77

Reputation: 1165

How to use python variable as a part of <a href = in html?

This time I need to know how can I use python variable to create a href link in html which is part of a python script.

For instance,

LinkX = "file://///server/folderX 

where folderX changes all the time and then to use this LinkX as a part of

<a href = "folderX">LinkX</a>. 

Something like this. Thank you.

Upvotes: 1

Views: 5564

Answers (2)

jonrsharpe
jonrsharpe

Reputation: 121974

If you are generating the html as text, you can use string formatting:

link = '<a href="{0}">{1}</a>'.format(destination, description)

Upvotes: 3

poke
poke

Reputation: 387527

Something like this?

>>> linkUrl = 'file://///server/folderX'
>>> linkText = '<a href="{}">{}</a>'.format(linkUrl, 'Folder X')
>>> linkText
'<a href="file://///server/folderX">Folder X</a>'

Upvotes: 1

Related Questions