In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail about Python shell script commonly used in the preparation of files is how, the content of the article is of high quality, so the editor to share to you to do a reference, I hope you have a certain understanding of the relevant knowledge after reading this article.
In Python writing shell scripts, we often use some related regular expressions and some temporary text), as well as manipulating / etc/passwd files and other related files.
Sys.argv is a list that holds the command-line arguments of the python program. Where sys.argv [0] is the name of the program itself.
Instead of talking without practice, let's write a simple script to copy files. The colleague who asked me to write the script the other day has a directory of tens of thousands of files. He wants to copy these files to other directories, but he can't copy the directory itself directly. He tried "cp src/* dest/" and reported an error that the command line was too long and asked me to write a script for Python. Fuck python:
Import sys,os.path,shutil
For f in os.listdir (sys.argv [1]):
Shutil.copy (os.path.join (sys.argv [1], f)
Sys.argv [2])
Try the post in the linuxapp version again-rename all the files in a folder to 1000110999. You can write like this:
Import os.path,sys dirname=sys.argv [1] iTunes 10001 for f in os.listdir (dirname): src=os.path.join (dirname,f) if os.path.isdir (src): continue os.rename (src,str (I)) iComplete1 about how the files commonly used in Python shell scripts are shared here. I hope the above content can be of some help to you and 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: 246
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.