What is a function parameter =[] for?

Chris Angelico rosuav at gmail.com
Tue Nov 24 09:54:45 EST 2015


On Wed, Nov 25, 2015 at 1:43 AM, BartC <bc at freeuk.com> wrote:
> It comes from the use of file handles (what you get in some languages when
> you open or create a file) which everyone can understand:
>
> * If you copy handle F to G like in an assignment, it obviously doesn't copy
> the contents of the file, just the handle.
>
> * If I compare the contents of files F and H, they might be the same, but
> they are not necessarily the same file.
>
> * If F and G are the same handle, then if I update a file via F, I will see
> the same change via handle G.
>
> The main difference is that when F and G go out of scope and the handles
> disappear, the file hopefully still exists! (And ideally the file is first
> closed via one of the handles.)

I would recommend picking a different example, actually. An open file
(the resource) is different from the file that actually exists on the
disk. You can open a file for reading three times, and barring access
conflicts etc, you'll get three distinct open-file-objects (file
handles, etc), with separate read pointers, and advancing the file
pointer of one has no effect on the other two. Plus there are other
considerations like the notion of duplicating file handles,
force-duplicating file handles (sometimes called "dup2"), files that
no longer exist on disk but only in memory, files that exist on disk
but no longer have any file names, and so on. Files are way WAY more
complicated than you want to dig into here.

ChrisA



More information about the Python-list mailing list