iT邦幫忙

0

想詢問大神們我對 python中的 sys/os 的理解是否正確?

  • 分享至 

  • xImage

如題:
sys:於程序與python編譯器之間,針對執行環境操作之類的。
os:於程序與作業系統(windows?)之間,編輯文件檔案之類的。

我是小菜鳥,查了資料只有理解到這個程度,懇請大神補充,大感謝QAQ

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
熊熊工程師
iT邦研究生 2 級 ‧ 2022-09-28 20:29:51
最佳解答

sys 會比較像是透過 python 取得 "系統" 相關的參數,例如:作業系統種類、python 版本... 等等

os 則比較偏向於實際對作業系統下命令,像常見的 os.lsitdir() 取得該目錄下所有的檔案,基本上就等價於 windows 的 dir、linux 的 ls

看更多先前的回應...收起先前的回應...
macteng iT邦新手 5 級 ‧ 2022-09-28 21:03:58 檢舉

感謝大神~那
import sys

import os
的作用差別是什麼呢?

不就是把這兩個套件分別 import 進來做使用嗎?

macteng iT邦新手 5 級 ‧ 2022-09-28 23:19:11 檢舉

原來如此 我真是太菜了?
大感謝

許多好用的函數function,各自屬於不同的模組module。
使用函數之前,要先import導入模組。
sys和os就是模組的一種。

0
海綿寶寶
iT邦大神 1 級 ‧ 2022-09-28 21:08:31
The summary is that the OS module is responsible for interacting with the operating system, providing access to the underlying interface of the operating system, and the SYS module is responsible for the interaction between the program and the Python interpreter, providing a series of functions and variables for manipulating the Python runtime environment. 

資料來源

我要發表回答

立即登入回答