The main problem is that the py file may not be in the current directory.
There is no need to make a py file open in the current directory. Python will automatically open the file in the current directory.
This line of code is telling the Python interpreter to open a file called “myfile.txt” that is located in the current directory.
What is a .py file
?
A .py file is a Python script.
How to create a .py file
To create a .py file in Python, you first need to open a new file in your text editor of choice. Once the file is open, you will need to create a new module. To do this, type the following code into your editor:
from __future__ import print_function
Next, you will need to import the module that you just created. To do this, type the following code into your editor:
from mymodule import *
Now that the module is imported, you will need to create a function inside of it. To do this, type the following code into your editor:
def myfunc(): print(“Inside myfunc”)
Finally, you will need to call the function that you just created. To do this, type the following code into your editor:
The result of running this code should be a .py file that contains the myfunc function.