1
[Python] Assigning the Open Function to a Variable with Exec Returns "Syntax error"
Post Flair (click to view more posts with a particular flair)
Author Summary
bubster20 is
in
PYTHON
Post Body
Yes the extra long variable name is there for a reason: I thought openFile (the original name) was a built in function. Here's the code:
extralongvariablenamethatisntafunction = "genericstring"
name1 = open("name.txt")
name = name1.read()
name1.close()
#the whole ton of websites in the list folder
number = 1;
evalstring = "n"
def genericloopname():
eval("extralongvariablethatisntafunction=open(\"WebsiteList/w" str(number) ".txt\")")
eval(evalstring str(number) " = extralongvariablethatisntafunction.read()")
eval("extralongvariablethatisntafunction.close()")
if (number < 9):
genericloopname()
genericloopname()
#write to the JS file
openjs = open("loadingscript.js", "w ")
towrite = "document.getElementById('user').innerHTML = '" name "';"
openjs.write(towrite)
openjs.close()
In case the indentations don't come out right, they are correct, the syntax error is pointing to the equal sign of "extralongvariablethatisntafunction=open("WebsiteList/w1") Thanks!
[Edit] To be exact, here's the error itself extralongvariablethatisntafunction=open("WebsiteList/w1.txt") ^ SyntaxError: invalid syntax
Author
Account Strength
100%
Account Age
8 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,442
Link Karma
903
Comment Karma
440
Profile updated: 6 hours ago
Posts updated: 9 months ago
Subreddit
Post Details
Location
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 8 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnprogra...