+ 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 .)

17th Jul 2019, 12:57 PM
parag sahu
parag sahu - avatar
5 odpowiedzi
+ 2
myfile = open("myfile.txt", "r") print(myfile.read())
17th Jul 2019, 1:09 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar
+ 2
Oops 😅😅 sorry . My mistake while writing content and "myfile.txt" Wedad Saleh . Actually after doing that also it's not working.
17th Jul 2019, 2:01 PM
parag sahu
parag sahu - avatar
+ 1
Thnx Wedad Saleh but can u plzz explain me why that didn't worked?
17th Jul 2019, 1:41 PM
parag sahu
parag sahu - avatar
+ 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().
17th Jul 2019, 1:58 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar
+ 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")
17th Jul 2019, 2:49 PM
**🇦🇪|🇦🇪**
**🇦🇪|🇦🇪** - avatar