简体   繁体   中英

Python file is not reading contents of a text file

My Python file, which is just a very small file, will not read the contents of a.txt file in the same folder as the python file. The (very simple) code is below:

file = open("contents.txt", "r")

print(file.read())

file.close()

Even this will not work. The contents:txt file contains:

random data that the python file should read

Can anyone help?

PS No errors are produced, and the command prompt app just moves on.

Never mind, it works. The file was located in a different folder, and once i brought it to the folder with the python file, it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM