<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 問題 你想測試一個文件或目錄是否存在。 ## 解決方案 使用 `os.path` 模塊來測試一個文件或目錄是否存在。比如: >>> import os >>> os.path.exists('/etc/passwd') True >>> os.path.exists('/tmp/spam') False >>> 你還能進一步測試這個文件時什么類型的。在下面這些測試中,如果測試的文件不存在的時候,結果都會返回False: >>> # Is a regular file >>> os.path.isfile('/etc/passwd') True >>> # Is a directory >>> os.path.isdir('/etc/passwd') False >>> # Is a symbolic link >>> os.path.islink('/usr/local/bin/python3') True >>> # Get the file linked to >>> os.path.realpath('/usr/local/bin/python3') '/usr/local/bin/python3.3' >>> 如果你還想獲取元數據(比如文件大小或者是修改日期),也可以使用 `os.path` 模塊來解決: >>> os.path.getsize('/etc/passwd') 3669 >>> os.path.getmtime('/etc/passwd') 1272478234.0 >>> import time >>> time.ctime(os.path.getmtime('/etc/passwd')) 'Wed Apr 28 13:10:34 2010' >>> ## 討論 使用 `os.path` 來進行文件測試是很簡單的。在寫這些腳本時,可能唯一需要注意的就是你需要考慮文件權限的問題,特別是在獲取元數據時候。比如: >>> os.path.getsize('/Users/guido/Desktop/foo.txt') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.3/genericpath.py", line 49, in getsize return os.stat(filename).st_size PermissionError: [Errno 13] Permission denied: '/Users/guido/Desktop/foo.txt' >>>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看