string = "Deepika Padukone, Esha Gupta or Yami Gautam - Who's looks hotter and sexier? Vote! - It's ... Deepika Padukone, Esha Gupta or Yami Gautam…. Deepika Padukone, Esha Gupta or Yami Gautam ... Tag: Deepika Padukone, Esha Gupta, Kalki Koechlin, Rang De Basanti, Soha Ali Khan, Yami ... Amitabh Bachchan and Deepika Padukone to be seen in Shoojit Sircar's Piku ..."
fp = open("test.txt", "w+");
fp.write("%s" %string);
Run Code Online (Sandbox Code Playgroud)
运行上面的代码后,我得到以下错误.
File "encode_error.py", line 1
SyntaxError: Non-ASCII character '\xe2' in file encode_error.py …Run Code Online (Sandbox Code Playgroud) 我试图替换字符串的出现次数"blue"与"red"使用DOM方法在文档中。但是,我没有得到想要的结果。
这是我试过的代码:
<html>
<body>
<p>Click the button to replace "blue" with "red" in the paragraph below:</p>
<div id="main">
<p>Mr Blue has a blue house and a blue car.</p>
<p>Mr Blue has a blue house and a blue car.</p>
</div>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var str = document.getElementById("main");
var x = str.document.getElementsByTagName("p");
var res = x.innerHTML.replace(/blue/gi, "red");
document.getElementsByTagName("p").innerHTML = res;
}
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)