私は一般的にPythonでJavascriptコードのビルダーを作ろうとしています。私は考えることができるすべてを試しましたが、私はまだ構文エラーがあります。 エラーは次のとおりです。Python javascript builder
ファイル "test.py"、行12 exploit =( "var word = prompt" "単語を与える"; function pal(){if(word === reverse()。join( '')+ word.split( '')。reverse()。join( '')){document.write( "こんにちはこれは回文文字列です
" + word.split( '') "+ word)と同じです} else {document.write("エラー504(回文ではない)...こんにちはこれは回文ではありません "" + word.split( '')。reverse()。join( '')+ +言葉)}}パル()」と同じではありません ";") ^ にSyntaxError:無効な構文
私は変換するためのものだった( "文字列にJavaScriptコード")ではなく働くアドバイス?おかげで申し訳ありませんもし私の質問の波平明らか
マイコード:あなたはexploit
に割り当てるJavaScriptの文字列内の引用符をエスケープする必要があります一つには
import time as t
from os import path
def createFile(dest):
date=t.localtime(t.time())
##Filename=month+date+year
name="%d_%d_%d.js"%(date[1],date[2],(date[0]%100))
exploit = ("var word=prompt("Give a word","");function pal(){if(word===word.split('').reverse().join('')){document.write("hello this is a palindrome<br>"+word.split('').reverse().join('')+" is the same as "+word)}else{document.write("Error 504(Not a palindrome)...hello this is not a palindrome<br>"+word.split('').reverse().join('')+" is not the same as "+word)}}pal();")
s = str(exploit)
if not(path.isfile(dest+name)):
f=open(dest+name,'w')
f.write(s)
f.close()
if __name__=='__main__':
createFile("lol")
raw_input("done!!!")
あなたが尋ねていることはまったく明確ではありません。 –
'exploit ='で始まる行の構文ハイライトを見てください。 – Xufox
私はこのすべてを含むfile.jsを作成したい: – javscripters