<> preface

OS Although the module has been learned in the basic time , But who let me belong to the kind of people who don't need to forget immediately , So when I'm crawling down a website that some indescribable man likes , When the crawled data needs to be saved , You need to use it OS The module is ready

<>OS Review of module foundation

Let's review the basics first
OS The module is used to manipulate the folder ( Based on my understanding )
import os os.mkdir("path") # Create the path
then , The foundation is gone , That's right , I want to learn the basics OS When you use the module , I learned this , At that time , It's enough

<>OS Module application

This is what I use when I write the crawler applet

<>1. When saving the file, an error is reported when the folder already exists
import os path = " File path " if not os.path.exists(path): os.mkdir(path)
If path non-existent , Just create it , If there is , You don't create it

<>2. View the path of the current file
import os print(os.getcwd())
This one is very useful , Before using mobile phone to write crawler , This is the current path , To save the data , As for what data is climbing , Well , Of course, it's the kind that men love to watch O(∩_∩)O ha-ha ~

<>3. Copy file , Rename copy
import os # The first method os.rename(" The name of the file to copy ", " File renaming after copying ") # The second method os.system("copy
The name of the file to copy File renaming after copying ") # The way to do this is to turn it on cmd rename , Is equivalent to the code to help you open cmd, And he made the order , Note that the file name needs to be an absolute path
<> epilogue

I use it for the time being os That's all , Maybe it's not good enough

©2019-2020 Toolsou All rights reserved,
【Java8 New features 1】Lambda Expression summary What is a process , Concept of process ?hdfs dfs Common basic commands java When creating objects, you must _Java Basic test questions Generation of random numbers + Figure guessing game When will we enter the old generation ?HDFS Common commands ( summary ) It is never recommended to spend a lot of time studying for employment pythonmacOS Big Sur The installation could not be completed Big Sur Why can't I install it ?Python pyttsx3| Text reading ( Various languages )