Don't shadow file built-in | SoloLearn: Learn to code for FREE!

0

Don't shadow file built-in

Don't shadow file built-in as you do it in file exercises! Don't shadow any built-ins, it's a bad practice, leads to strange errors and behavior is sometimes hard to predict.

7/29/2016 5:43:54 PM

trueneu

2 Answers

New Answer

+1

Sir, even if it is not builtin in py3, it is in py2, and I really doubt that beginners are ready to study all the differences between python versions. Furthermore, from this tutorial standpoint py3 & py2 are practically equal (except for print function and dict comprehensions). So I think it's possible for people to use knowledge they gained here in py2 without knowing details ; even though file() isn't even used that much in py2, it's still bad to teach people to shadow builtins (even former ones. Confusion is no good anyway)

-2

file is not a built-in in python 3. trying to print it gives not defined exception.