What is the difference between

file = open("name.txt")

and

file = open("name.txt", 'r')

?

I can still use the methods: read(n), readline(n), and readlines(n) without adding the "r" in the open method.

Recommended Answers

All 2 Replies

What is the difference between

file = open("name.txt")

and

file = open("name.txt", 'r')

?

I can still use the methods: read(n), readline(n), and readlines(n) without adding the "r" in the open method.

the parameter "mode" is optional and the default value is 'r' (read) so if you leave it out python just takes it as if there was an 'r'

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.