In the code:
inF = open(input("Enter Filename: "),'r') import inF inF
Is there any way I can import the filename that the user inputs?
You actually can!
__import__("file")
read this
Another way:
import os os.system("python3 [file].py")
@Coder100 Oh, Thanks!
np :D @ANDREWVOSS
@Coder100 So if I structure it as
inF = open(input("Enter Filename: "),'r') __import__("inF") inF
How would I read the file?
@ANDREWVOSS nooo use it like import:
import
__import__(input("Enter Filename: "))
@Coder100 Sorry, let me rephrase that. How would I make it read the file that has been imported? eg:
import other.py other.py
where the other.py at the end outputs the file
other.py
@ANDREWVOSS nvm I found another way
program = input('Enter a program:') exec(program)
@ANDREWVOSS um thats really bad
@Coder100 fair enough
@ANDREWVOSS still working on it
Anyways, you should treat __import__ literally as import @ANDREWVOSS
__import__
Okay... @Coder100
@ANDREWVOSS so like
__import__("other") other.func()
will work just fine (given you defined func)
func
also
import other.py
is invalid, you mean:
import other
@ANDREWVOSS
@Coder100 Okay, I think I've got it. Thanks.
great what did you do? @ANDREWVOSS
yep that looks good @ANDREWVOSS
@Coder100 cool.
mark as correct answer? @ANDREWVOSS
@Coder100 Is there a way to remove that error message?
@Coder100 there you go
oh, type in file1 instead :) @ANDREWVOSS
file1
python is weird that way lol @ANDREWVOSS
python
sorry for the late reply I was eating a sandwich @ANDREWVOSS
@Coder100 nah you're fine
@Coder100 thanks
How can I open a file based on user input?
In the code:
Is there any way I can import the filename that the user inputs?
You actually can!
read this
Another way:
@Coder100 Oh, Thanks!
np :D @ANDREWVOSS
@Coder100 So if I structure it as
How would I read the file?
@ANDREWVOSS nooo
use it like
import
:@Coder100 Sorry, let me rephrase that. How would I make it read the file that has been imported? eg:
where the
other.py
at the end outputs the file@ANDREWVOSS nvm I found another way
@ANDREWVOSS um thats really bad
@Coder100 fair enough
@ANDREWVOSS still working on it
Anyways, you should treat
__import__
literally asimport
@ANDREWVOSSOkay... @Coder100
@ANDREWVOSS so like
will work just fine (given you defined
func
)also
is invalid, you mean:
@ANDREWVOSS
@Coder100 Okay, I think I've got it. Thanks.
great what did you do? @ANDREWVOSS
yep that looks good @ANDREWVOSS
@Coder100 cool.
mark as correct answer? @ANDREWVOSS
@Coder100

Is there a way to remove that error message?
@Coder100 there you go
oh, type in
file1
instead :) @ANDREWVOSSpython
is weird that way lol @ANDREWVOSSsorry for the late reply I was eating a sandwich @ANDREWVOSS
@Coder100 nah you're fine
@Coder100 thanks