Home  >  Article  >  Backend Development  >  Python study notes - os module

Python study notes - os module

PHP中文网
PHP中文网Original
2017-07-08 18:13:061266browse

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>)

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)

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>)

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!

Statement:
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