Reputation: 1115
I would like to assign the following expression to a variable:
textFormat = 'soup.find("div", {"class" : "article-entry text"}).text.replace(\'\n\', "")'
I am calling this code in another file using
text = exec(textFormat)
Sadly I get the error message:
File "C:\Users\dadsad\documents\coding\dasdasd\functions.py", line 42, in loadAtom
text = exec(textFormat) File "<string>", line 1
soup.find("div", {"class" : "article-entry text"}).text.replace('
^ SyntaxError: EOL while scanning string literal
Any ideas? Thanks! :)
Edit: Tried the suggestion, getting a None:
Upvotes: 1
Views: 74
Reputation: 168876
I suspect you are suffering from backslashitis. You need one more slash before the n
:
textFormat = 'soup.find("div", {"class" : "article-entry text"}).text.replace(\'\\n\', "")'
But, instead of exec
ing code this way, you might want expose a subroutine instead:
def textFormat(soup):
return soup.find("div", {"class" : "article-entry text"}).text.replace('\n', "")
Upvotes: 5