[Tutor] help with exercise 15 of zed shaw's LPTHW

Michael Selik michael.selik at gmail.com
Wed Jul 6 11:23:04 EDT 2016


On Wed, Jul 6, 2016 at 10:59 AM <lohecn at tuta.io> wrote:

> why do I have to create a variable txt_again to assign it to the open
> function and them print the file?
> why is it that I can't only write something like open(file_again).read()?
>

Good insight. In fact you don't need to create the variable. The code ``data
= open('filename').read()`` will open the file named "filename" in the
current working directory, read it, and assign the data to a variable.

However, many programmers use variables not because they must, but because
good variable names can make code easier to read. Also, doing less stuff on
a line of code can make that code easier to read.


More information about the Tutor mailing list