When is del useful in python?

前端 未结 21 2401
野趣味
野趣味 2020-11-22 11:58

I can\'t really think of any reason why python needs the del keyword (and most languages seem to not have a similar keyword). For instance, rather than deletin

21条回答
  •  醉话见心
    2020-11-22 12:16

    Force closing a file after using numpy.load:

    A niche usage perhaps but I found it useful when using numpy.load to read a file. Every once in a while I would update the file and need to copy a file with the same name to the directory.

    I used del to release the file and allow me to copy in the new file.

    Note I want to avoid the with context manager as I was playing around with plots on the command line and didn't want to be pressing tab a lot!

    See this question.

提交回复
热议问题