Home > other >  IDLE load. TXT file appears RESTART how to solve
IDLE load. TXT file appears RESTART how to solve

Time:09-30

Being read the file on the desktop, but always a RESTART of the program, how to solve this problem

CodePudding user response:

The file name you write the full path

CodePudding user response:

Do you use to open open the file:
 open (yourFilePath, "r") 

To ensure that:
Open to find your files yourFilePath

How to find:
Either: relative path
And when you run the code with directory

Either: the absolute path
Give the complete path

Here, you are clearly:
In IDLE running, the program of the current directory, not your python code directory, namely:
C:/Users/dd/AppData/Local/designed/Python/Python37/6.1 py
The corresponding directory:
C:/Users/dd/AppData/Local/designed/Python/Python37/

But:
I don't know, but you can use the
 
The import OS
Print (OS) getcwd ())

Can print out

Here, it is best to the absolute path
Such as your 1. TXT in
C:/Users/dd/AppData/Local/designed/Python/Python37/
Here, the absolute path=full path is:
C:/Users/dd/AppData/Local/designed/Python/Python37/1. TXT
Then the code written
 open (" C:/Users/dd/AppData/Local/designed/Python/Python37/1. TXT ", "r") 

Can open,

CodePudding user response:

In addition, it is strongly recommended that you switch to a better editor VSCode, convenient for debugging the Python code,

Don't know about VSCode may refer to my tutorial:
History's most easy-to-use editor: VSCode

About to debug with VSCode Python:

Mac:
Debugging, Python in history, had better use the editor: VSCode

Windows:
[resolved] Windows installation VSCode
[record] Windows VSCode new Python project
[record] using VSCode to debug Windows Python project code file


CodePudding user response:

refer to the second floor crifan response:
do you use to open open the file:
 open (yourFilePath, "r") 

To ensure that:
Open to find your files yourFilePath

How to find:
Either: relative path
And when you run the code with directory

Either: the absolute path
Give the complete path

Here, you are clearly:
In IDLE running, the program of the current directory, not your python code directory, namely:
C:/Users/dd/AppData/Local/designed/Python/Python37/6.1 py
The corresponding directory:
C:/Users/dd/AppData/Local/designed/Python/Python37/

But:
I don't know, but you can use the
 
The import OS
Print (OS) getcwd ())

Can print out

Here, it is best to the absolute path
Such as your 1. TXT in
C:/Users/dd/AppData/Local/designed/Python/Python37/
Here, the absolute path=full path is:
C:/Users/dd/AppData/Local/designed/Python/Python37/1. TXT
Then the code written
 open (" C:/Users/dd/AppData/Local/designed/Python/Python37/1. TXT ", "r") 

Can open,

Why put Chinese characters in the notepad to open it

CodePudding user response:

refer to the second floor crifan response:
do you use to open open the file:
 open (yourFilePath, "r") 

To ensure that:
Open to find your files yourFilePath

How to find:
Either: relative path
And when you run the code with directory

Either: the absolute path
Give the complete path

Here, you are clearly:
In IDLE running, the program of the current directory, not your python code directory, namely:
C:/Users/dd/AppData/Local/designed/Python/Python37/6.1 py
The corresponding directory:
C:/Users/dd/AppData/Local/designed/Python/Python37/

But:
I don't know, but you can use the
 
The import OS
Print (OS) getcwd ())

Can print out

Here, it is best to the absolute path
Such as your 1. TXT in
C:/Users/dd/AppData/Local/designed/Python/Python37/
Here, the absolute path=full path is:
C:/Users/dd/AppData/Local/designed/Python/Python37/1. TXT
Then the code written
 open (" C:/Users/dd/AppData/Local/designed/Python/Python37/1. TXT ", "r") 

Can open,

Followed by encoding='document coding can be opened
  • Related