如何在python中计算相对于给定目录的绝对路径

时间:2019-06-25 23:18:35

标签: python-3.x

例如,假设目录结构为

project
--scripts/
----script.py
--content/
----folder-a/
------a.txt
----folder-b/
------b.txt

和script.py看起来像

import argparse
import os

parser = argparse.ArgumentParser()
parser.add_argument('root', help='first arg')
parser.add_argument('path', help='second arg')

并且script.py是从projects/作为python3 script.py content content/folder-a/a.txt运行的,如何返回/folder-a/a.txt

0 个答案:

没有答案