Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand import sys and import shutil

Shulou Source: shulou.com Published: 2022-06-02 11:05:51 10月05日 Update

This article introduces you how to understand import sys and import shutil, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Import sys

Sys.argv # running script is the parameter after reading the command

Sys.exit () # exit the program

Print (sys.version) # get the current version of the python interpreter

Sys.maxint () # maximum int value

Sys.path # returns the search path of the module

Sys.platform # returns the name of the operating system platform

Sys.stdout.write ("please") # output on the screen

Print (os.path.abspath ("name.tar")) # View file path

Import shutil # read a file and write to another file

F1=open ("text.txt")

F2=open ("Note 1", "w")

Shutil.copyfileobj (F1 and f2)

Shutil.copyfile (Note1, Note2) # copy file

Shutil.copystat ("text.txt", "Note 2") # copy permission does not create a new file

Shutil.copy () # copy files and permissions

Shutil.copy2 () # copy files and status information

Shutil.copytree ("time_test", "new_test") # copy file directory

Shutil.rmtree ("new_test") # Delete file directory

Shutil.make_archive ("D:/timetttttt_tp", "zip", "C:\ Users\ arce.PyCharmCE2017.2") # need to be compressed, compressed format, where to put compressed files

Make_archive (base_name, format, root_dir=None, base_dir=None, verbose=0, dry_run=0, owner=None, group=None, logger=None)

Import zipfile

Z=zipfile.ZipFile ("os_txt.zip", "w") # compress files separately (create a package and put the files in)

Z.write ("os.txt.py")

Print ("- -")

Z.write ("Notes 2")

Z.close ()

Z=zipfile.ZipFile ("os_txt.zip", "r") # decompress

Z.extractall ()

Z.close ()

#

Import tarfile

Tar=tarfile.open ("name.tar", "w")

Tar.add (r "E:\ 2018.4.9\ Test", arcname= "Test")

Tar.add (r "E:\ 2018.4.9\ Module 3", arcname= "Module 3")

Tar.close ()

Tar=tarfile.open ("name.tar", "r")

Tar.extractall () # fill in the parentheses here where to decompress (path)

Tar.close ()

Import os

Print (os.path.abspath ("name.tar")) # View file path

On how to understand import sys and import shutil to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Files notes paths copies modules content more permissions directories help tests yes maximum operating system information interests parameters names commands places Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information Huawei MariaDB Linux