+ 1

why this python file not run by python but by other method ?

here i code a python file which includes opening and writing of files and i code it by using visual studio code and when i try to run it by navigating file by cmd commands i run properly but if i select the file and open with python i cant run why is this ? this is happen with one python file which includes open file syntex a example of such file 1 file = open("file.txt", "w") 2 file.write("helo this is a sample writing") 3 file.close()

18th Sep 2020, 6:09 PM
Jiten
Jiten - avatar
3 Answers
+ 3
Instruction in line 1 will create a file in the some python file directory if it does not exist.So you have to see the file manually in this directory.But you can read from this file yo check if it
18th Sep 2020, 7:19 PM
HBhZ_C
HBhZ_C - avatar
+ 3
With w option yes the file will be created but you can read from file with r mode.
19th Sep 2020, 7:42 AM
HBhZ_C
HBhZ_C - avatar
+ 1
Thanks for answering HBhZ_C But as I know if directory is not exit python will create it.
19th Sep 2020, 2:06 AM
Jiten
Jiten - avatar