+ 1
Why this doesn't works?
Suppose i have a file and something is written in it. myfile=open("myfile.txt") content=myfile.read() print(content) (May be this doubt looks silly but i m just a beginner in python . So i hope u will help me in these silly doubts .)
5 ответов
+ 2
myfile = open("myfile.txt", "r")
print(myfile.read())
+ 2
Oops 😅😅 sorry . My mistake while writing content and "myfile.txt" Wedad Saleh . Actually after doing that also it's not working.
+ 1
Thnx Wedad Saleh but can u plzz explain me why that didn't worked?
+ 1
1: Python is a case sensitive programming language. Thus, Content and content are two different variable names in Python.
2: myfile.txt should be inside '' " .
3: As a note You should always close your files .close().
+ 1
that's mean u don't have the file -myfile-
OK
Write this line first to create the file :
myfile = open("myfile.txt", "x")