Python study notes - os module

PHP中文网
Release: 2017-07-08 18:13:06
Original
1267 people have browsed it

Directly output system commands to the screen. The command return value obtained by this method cannot be assigned to a variable. The output result will be garbled due to encoding:

<span style="color: #0000ff">import</span><span style="color: #000000"> os

os.system(</span><span style="color: #800000">"</span><span style="color: #800000">ipconfig</span><span style="color: #800000">"</span>)
Copy after login

Store the system commands obtained by execution into the memory, and then read the results in the memory and output them to the screen without garbled characters:

<span style="color: #0000ff">import</span><span style="color: #000000"> os

com </span>= os.popen(<span style="color: #800000">"</span><span style="color: #800000">ipconfig</span><span style="color: #800000">"</span><span style="color: #000000">).read()
</span><span style="color: #0000ff">print</span>(com)
Copy after login

Create a folder in the directory where the executable file is located

<span style="color: #0000ff">import</span><span style="color: #000000"> os

os.makedirs(</span><span style="color: #800000">"</span><span style="color: #800000">makedir</span><span style="color: #800000">"</span>)
Copy after login

The above is the detailed content of Python study notes - os module. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template