Don't shadow file built-in | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

29th Jul 2016, 5:43 PM
trueneu
trueneu - avatar
2 Answers
+ 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)
6th Aug 2016, 12:02 PM
trueneu
trueneu - avatar
- 2
file is not a built-in in python 3. trying to print it gives not defined exception.
29th Jul 2016, 8:15 PM
RedAnt
RedAnt - avatar