Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand import sys and import shutil

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report