Help to convert Number to String
Ben Finney
ben+python at benfinney.id.au
Fri Aug 13 23:04:34 EDT 2010
Vamsi <vamsikrishna.bandlamudi at gmail.com> writes:
> fileopen = open('C:/MPython/test.txt', 'r')
> str = fileopen.read()
The above statement clobbers the existing binding of ‘str’ to the
built-in string type. From that point on, the built-in string type is no
longer accessible by the name ‘str’; that name accesses a different
object.
Choose a better name for the return value; make it describe what the
value is for in the context of the program.
in_file = open('C:/MPython/test.txt', 'r')
in_file_content = in_file.read()
print in_file_content
in_file.close()
# …
It also has the advantage of making your code more readable, since the
names help indicate *why* the code is written the way it is.
--
\ “Creativity can be a social contribution, but only in so far as |
`\ society is free to use the results.” —Richard Stallman |
_o__) |
Ben Finney
More information about the Python-list
mailing list