coolair
V2EX  ›  问与答

获取/usr/test/中的/usr 或/usr/有什么更好的方式吗?

  •  
  •   coolair · Dec 20, 2016 · 1921 views
    This topic created in 3613 days ago, the information mentioned may be changed or developed.
    我是这样弄的
    str='/usr/test/'
    '/{0}'.format(str.split('/')[1])
    '/{0}/'.format(str.split('/')[1])

    感觉有点繁琐啊
    2 replies  •  2016-12-21 08:56:24 +08:00
    264768502
    264768502
    Dec 20, 2016 via Android
    1
    看上去是 python, 不去看看 os.path?

    shell 的话 dirname
    lln133208
    lln133208
    Dec 21, 2016
    2
    os.path.dirname
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1883 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 15:44 · PVG 23:44 · LAX 07:44 · JFK 10:44
    ♥ Do have faith in what you're doing.