coolair
V2EX  ›  问与答

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

  •  
  •   coolair · Dec 20, 2016 · 1945 views
    This topic created in 3630 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   ·   1001 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 18:55 · PVG 02:55 · LAX 10:55 · JFK 13:55
    ♥ Do have faith in what you're doing.