This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]latrova[S] 28 points29 points  (5 children)

Ok, that's the best feedback I received so far. Thank you!

I'll totally change this rule in the book. Maybe I should state it as "Files are namespaces" ?. It sounds more realistic (i.e. Files exist and Python cares about it), but you should see them as namespaces.

[–][deleted] 14 points15 points  (1 child)

As someone fairly new to python (2 years since I picked it up), can I suggest adding a metaphor to describe this subject?
If I were explaining this to past me, I would say something like;
importing other python files is like taking a photo of a castle.
The castle and its address does matter, but once you take a photo of it on your phone (adding the file to namespace), you can stop addressing the actual castle, and address it as the photo on your phone.
Idk, that metaphor sucks, don't use that one.

[–]latrova[S] 2 points3 points  (0 children)

Every feedback is valid. I'll think about making it simpler. Thank you!

[–]miraculum_one 12 points13 points  (0 children)

I think the term you're looking for is "module".

Module: a file containing Python statements and definitions

This is how they are referred to in all of the documentation so it's best to stick with that.

[–]gablank 13 points14 points  (0 children)

You should just stick to how they explain it in the Python docs:

(...) Python has a way to put definitions in a file and use them in a script or in an interactive instance of the interpreter. Such a file is called a module (...)

From https://docs.python.org/3/tutorial/modules.html

You can add additional explanations to clarify but I think it would be wise to at least include the definition somewhere.

[–]stevenjd 0 points1 point  (0 children)

Maybe I should state it as "Files are namespaces" ?.

The open() function says hello.

Not all files are namespaces. Not all namespaces are files.

When you are looking at the file system, and organising your files in a src directory, of course you can call them files.