Python Forum
replace html string with python variable !
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
replace html string with python variable !
#3
(Aug-30-2018, 11:12 AM)Axel_Erfurt Wrote: better use popen

import os

process = os.popen('whoami')
myname = process.read()
process.close()
 
html_str = """
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
 
<h1>test</h1>
<p>My first paragraph.</p>
 
</body>
</html>
"""
 
html_str = html_str.replace("test", myname)

Html_file= open(r"/tmp/q.html","w")
Html_file.write(html_str)
Html_file.close()

works thank u :)
can u explain why u used myname = process.read() ?
Reply


Messages In This Thread
RE: replace html string with python variable ! - by evilcode1 - Aug-30-2018, 11:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] [Beautiful Soup] Replace tag.string from another file? Winfried 2 347 May-01-2025, 03:43 PM
Last Post: Winfried
Question [SOLVED] How to replace characters in a string? Winfried 2 1,094 Sep-04-2024, 01:41 PM
Last Post: Winfried
  Replace a text/word in docx file using Python Devan 4 23,377 Oct-17-2023, 06:03 PM
Last Post: Devan
  Need to replace a string with a file (HTML file) tester_V 1 1,973 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Replacing String Variable with a new String Name kevv11 2 1,691 Jul-29-2023, 12:03 PM
Last Post: snippsat
  why doesn't it replace all html tags? Melcu54 3 1,949 Jul-05-2023, 04:47 AM
Last Post: Melcu54
  Replace string in a nested Dictianory. SpongeB0B 2 2,460 Mar-24-2023, 05:09 PM
Last Post: SpongeB0B
  Replace with upper(string) WJSwan 7 2,889 Feb-10-2023, 10:28 AM
Last Post: WJSwan
  Need help on how to include single quotes on data of variable string hani_hms 5 7,452 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 1,902 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020