<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Python獲取當前路徑

      如下的代碼列出了Python中獲取當前路徑的一些方法:

      import os
      import sys
      
      def test():
          path1 = '/dir1/dir2/file.txt'
          path2 = '/dir1/dir2/file.txt/'
      
          print('__file__ =', __file__)
          print('path1 =', path1)
          print('path2 =', path2)
      
          # Return the directory name of pathname path.
          # This is the first element of the pair returned
          # by passing path to the function split().
          print('os.path.dirname(__file__) =', os.path.dirname(__file__))
          print('os.path.dirname(path1) =', os.path.dirname(path1))
          print('os.path.dirname(path2) =', os.path.dirname(path2))
      
          # Return the base name of pathname path. This is the second element
          # of the pair returned by passing path to the function split().
          # Note that the result of this function is different from the
          # Unix basename program; where basename for '/foo/bar/' returns
          # 'bar', the basename() function returns an empty string ('').
          print('os.path.basename(__file__) =', os.path.basename(__file__))
          print('os.path.basename(path1) =', os.path.basename(path1))
          print('os.path.basename(path2) =', os.path.basename(path2))
      
          # Return a string representing the current working directory.
          print('os.getcwd() =', os.getcwd())
      
          # Return a normalized absolutized version of the pathname path.
          # On most platforms, this is equivalent to calling the function
          # normpath() as follows: normpath(join(os.getcwd(), path)).
          print('os.path.abspath(__file__) =', os.path.abspath(__file__))
          print('os.path.abspath(path1) =', os.path.abspath(path1))
      
          # Return the canonical path of the specified filename, eliminating
          # any symbolic links encountered in the path (if they are supported
          # by the operating system).
          print('os.path.realpath(__file__) =', os.path.realpath(__file__))
          print('os.path.realpath(path1) =', os.path.realpath(path1))
      
          # Split the pathname path into a pair, (head, tail) where tail is the
          # last pathname component and head is everything leading up to that.
          # The tail part will never contain a slash; if path ends in a slash,
          # tail will be empty. If there is no slash in path, head will be empty.
          # If path is empty, both head and tail are empty. Trailing slashes are
          # stripped from head unless it is the root (one or more slashes only).
          # In all cases, join(head, tail) returns a path to the same location
          # as path (but the strings may differ). Also see the functions dirname()
          # and basename().
          print('os.path.split(__file__) =', os.path.split(__file__))
          print('os.path.split(path1) =', os.path.split(path1))
      
          # A list of strings that specifies the search path for modules.
          # Initialized from the environment variable PYTHONPATH, plus an
          # installation-dependent default.
          #
          # As initialized upon program startup, the first item of this list,
          # path[0], is the directory containing the script that was used to
          # invoke the Python interpreter. If the script directory is not
          # available (e.g. if the interpreter is invoked interactively or if
          # the script is read from standard input), path[0] is the empty string,
          # which directs Python to search modules in the current directory first.
          # Notice that the script directory is inserted before the entries
          # inserted as a result of PYTHONPATH.
          #
          # A program is free to modify this list for its own purposes.
          # Only strings and bytes should be added to sys.path; all
          # other data types are ignored during import.
          print('sys.path[0] =', sys.path[0])
          sys.path.insert(0, path1)
          print('sys.path[0] =', sys.path[0])
      
          # The list of command line arguments passed to a Python script.
          # argv[0] is the script name (it is operating system dependent
          # whether this is a full pathname or not). If the command was
          # executed using the -c command line option to the interpreter,
          # argv[0] is set to the string '-c'. If no script name was passed
          # to the Python interpreter, argv[0] is the empty string.
          print('sys.argv[0] =', sys.argv[0])
      test()

      代碼腳本所在的絕對路徑為:

      /home/hyg/code/pytorch-study/vehicle-reid/some_test.py

      執行如下命令:

      cd /home/hyg/code/pytorch-study/vehicle-reid
      python /home/hyg/code/pytorch-study/vehicle-reid/some_test.py

      輸出為:

      __file__ = /home/hyg/code/pytorch-study/vehicle-reid/some_test.py
      path1 = /dir1/dir2/file.txt
      path2 = /dir1/dir2/file.txt/
      os.path.dirname(__file__) = /home/hyg/code/pytorch-study/vehicle-reid
      os.path.dirname(path1) = /dir1/dir2
      os.path.dirname(path2) = /dir1/dir2/file.txt
      os.path.basename(__file__) = some_test.py
      os.path.basename(path1) = file.txt
      os.path.basename(path2) = 
      os.getcwd() = /home/hyg/code/pytorch-study/vehicle-reid
      os.path.abspath(__file__) = /home/hyg/code/pytorch-study/vehicle-reid/some_test.py
      os.path.abspath(path1) = /dir1/dir2/file.txt
      os.path.realpath(__file__) = /home/hyg/code/pytorch-study/vehicle-reid/some_test.py
      os.path.realpath(path1) = /dir1/dir2/file.txt
      os.path.split(__file__) = ('/home/hyg/code/pytorch-study/vehicle-reid', 'some_test.py')
      os.path.split(path1) = ('/dir1/dir2', 'file.txt')
      sys.path[0] = /home/hyg/code/pytorch-study/vehicle-reid
      sys.path[0] = /dir1/dir2/file.txt
      sys.argv[0] = /home/hyg/code/pytorch-study/vehicle-reid/some_test.py

      執行如下命令:

      cd /home/hyg/code/pytorch-study/vehicle-reid
      python ./some_test.py

      輸出為:

      __file__ = ./some_test.py
      path1 = /dir1/dir2/file.txt
      path2 = /dir1/dir2/file.txt/
      os.path.dirname(__file__) = .
      os.path.dirname(path1) = /dir1/dir2
      os.path.dirname(path2) = /dir1/dir2/file.txt
      os.path.basename(__file__) = some_test.py
      os.path.basename(path1) = file.txt
      os.path.basename(path2) = 
      os.getcwd() = /home/hyg/code/pytorch-study/vehicle-reid
      os.path.abspath(__file__) = /home/hyg/code/pytorch-study/vehicle-reid/some_test.py
      os.path.abspath(path1) = /dir1/dir2/file.txt
      os.path.realpath(__file__) = /home/hyg/code/pytorch-study/vehicle-reid/some_test.py
      os.path.realpath(path1) = /dir1/dir2/file.txt
      os.path.split(__file__) = ('.', 'some_test.py')
      os.path.split(path1) = ('/dir1/dir2', 'file.txt')
      sys.path[0] = /home/hyg/code/pytorch-study/vehicle-reid
      sys.path[0] = /dir1/dir2/file.txt
      sys.argv[0] = ./some_test.py

      執行如下命令:

      cd /home/hyg/code/pytorch-study/vehicle-reid
      python some_test.py

      輸出為:

      __file__ = some_test.py
      path1 = /dir1/dir2/file.txt
      path2 = /dir1/dir2/file.txt/
      os.path.dirname(__file__) = 
      os.path.dirname(path1) = /dir1/dir2
      os.path.dirname(path2) = /dir1/dir2/file.txt
      os.path.basename(__file__) = some_test.py
      os.path.basename(path1) = file.txt
      os.path.basename(path2) = 
      os.getcwd() = /home/hyg/code/pytorch-study/vehicle-reid
      os.path.abspath(__file__) = /home/hyg/code/pytorch-study/vehicle-reid/some_test.py
      os.path.abspath(path1) = /dir1/dir2/file.txt
      os.path.realpath(__file__) = /home/hyg/code/pytorch-study/vehicle-reid/some_test.py
      os.path.realpath(path1) = /dir1/dir2/file.txt
      os.path.split(__file__) = ('', 'some_test.py')
      os.path.split(path1) = ('/dir1/dir2', 'file.txt')
      sys.path[0] = /home/hyg/code/pytorch-study/vehicle-reid
      sys.path[0] = /dir1/dir2/file.txt
      sys.argv[0] = some_test.py

      執行如下命令:

      cd /home/hyg/code
      python ./pytorch-study/vehicle-reid/some_test.py

      輸出為:

      __file__ = ./pytorch-study/vehicle-reid/some_test.py
      path1 = /dir1/dir2/file.txt
      path2 = /dir1/dir2/file.txt/
      os.path.dirname(__file__) = ./pytorch-study/vehicle-reid
      os.path.dirname(path1) = /dir1/dir2
      os.path.dirname(path2) = /dir1/dir2/file.txt
      os.path.basename(__file__) = some_test.py
      os.path.basename(path1) = file.txt
      os.path.basename(path2) = 
      os.getcwd() = /home/hyg/code
      os.path.abspath(__file__) = /home/hyg/code/pytorch-study/vehicle-reid/some_test.py
      os.path.abspath(path1) = /dir1/dir2/file.txt
      os.path.realpath(__file__) = /home/hyg/code/pytorch-study/vehicle-reid/some_test.py
      os.path.realpath(path1) = /dir1/dir2/file.txt
      os.path.split(__file__) = ('./pytorch-study/vehicle-reid', 'some_test.py')
      os.path.split(path1) = ('/dir1/dir2', 'file.txt')
      sys.path[0] = /home/hyg/code/pytorch-study/vehicle-reid
      sys.path[0] = /dir1/dir2/file.txt
      sys.argv[0] = ./pytorch-study/vehicle-reid/some_test.py

      posted @ 2019-10-04 19:59  洗盞更酌  Views(2176)  Comments(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲小说乱欧美另类| 色综合色狠狠天天综合网| 国产成人av免费网址| 久爱无码精品免费视频在线观看| 无码熟妇人妻av在线电影| 久久久精品94久久精品| 日本免费一区二区三区| 日韩中文字幕在线不卡一区| 中国CHINA体内裑精亚洲日本| 中文丰满岳乱妇在线观看| 人妻av无码系列一区二区三区| 亚洲www永久成人网站| 亚洲av无码牛牛影视在线二区| 在线日韩日本国产亚洲| 亚洲成片在线看一区二区| 成人国产乱对白在线观看| 97精品尹人久久大香线蕉| 妺妺窝人体色www婷婷| 日本激情久久精品人妻热| 无码人妻丰满熟妇区96| 久草热大美女黄色片免费看| 国产成人av电影在线观看第一页| 亚洲av日韩av永久无码电影| 亚洲人成网站在线播放动漫| 免费观看的AV毛片的网站不卡| 亚洲另类激情专区小说图片| 成人免费无码视频在线网站 | 久久99精品久久久久麻豆| 免费人成视频在线视频电影| 免费AV片在线观看网址| 麻豆亚洲精品一区二区| 久久精品国产99久久6| 午夜DY888国产精品影院| 亚洲人成网站在线播放2019| 欧美国产激情18| 久久精品国产高潮国产夫妻 | 人妻丰满熟妇av无码区| 精品国产国语对白主播野战 | 国产丝袜肉丝视频在线| 久久久无码一区二区三区| 亚洲天堂男人天堂女人天堂|