def 小児科医():

かけだし小児科医が仕事の合間にプログラミングを勉強するブログです。

退屈なことはPythonにやらせよう 第2版 読んでみた⑩

previous article↓

 

defpediatric.hatenablog.com

Recently, I've realized that I should be using English in various situations, such as programming, working, or participating in Kaggle competitions.

Starting with this article, I'll attempt to write this blog in English (as long as I don't find it too tedious!).

After drafting, I'll revise the article using ChatGPT.

In doing so, I can reap the dual benefits of automation and improving my English.

 

Today, I delved into 'Automate the Boring Stuff with Python'.

The topic of discussion is file management.

 

 

 

shutil module:

The shutil module provides functions to copy, move, rename, and delete files.

  • shutil.copy(src, dst): This function copies a file (src) to a directory (dst).
  • If you wish to copy all files or directories within a specified directory, you should utilize 'shutil.copytree()'.
  • shutil.move(src, dst): This function moves a file (src) to a directory (dst).
  • While 'shutil.rmtree' can be used to delete all files in a chosen directory, it's a risky approach. It's safer to use the 'send2trash' module.

 

 

zipfile module:

Using zip files (.zip), you can compress multiple files to reduce their overall size.

  • zipfile.ZipFile(): This is used for reading zip files.
  • The 'extractall()' method allows you to decompress a zip file.
  • If you aim to create a zip file, pass 'w' as the second argument to 'zipfile.ZipFile()'.
  • The 'write()' method lets you add files to the zip archive.

 

This session has concluded.
The next session will be on 'debugging'.