Adding filename variable into HTML string in Python -


I have searched and can not find any solution on this. I am trying to loop the Python code through a directory for .mht files. After searching the files, it will write an IFrame HTML code in the file pointing to .ht. I am having trouble writing the iframe code and include the file name variable in src

  htmlframe = '' '& lt; Iframe src = "'% s.mht'" class = "iframe" scrolling = "no" frameborder = "0" style = "width: 100%" & gt; & Lt; / Iframe & gt; & Lt; Br> ''% Os.path.basename  

The error I get is below:

  traceback (most recent Call final): File "move.py", line 52,  gt; ''% Os.path.basename TypeError: Not enough arguments for format string  

Thanks in advance for any help

But for complex string replacement tasks, you should look at the template engine to keep an overview with this kind of engine and then make modifications later It is usually very easy to make a very simple standard library:

Most of the time Switch to is enough!

example:

  template from string import s = "" Iframe src = "$ filename" class = "iframe" scrolling = "no" & gt; & lt ; / Iframe & gt; " "" T = Template (s) Print t.substitute (filename = "foobar.mht")  

Test:

  Python template.py & lt ; Iframe src = "foobar.mht" class = "iframe" scrolling = "no" & gt; & Lt; / Iframe & gt;  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -