推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
will2k
V2EX  ›  Python

GitHub Action 使用 Python 创建目录

  •  1
     
  •   will2k · Aug 16, 2023 · 1656 views
    This topic created in 1143 days ago, the information mentioned may be changed or developed.

    想用 GitHub Action 自动执行一个 python 文件,但是实际执行的和我在本地执行的结果不一样。

    我要根据路径创建文件夹,但是创建出来的是命名为路径的一个文件夹?

    比如:我要创建一个路径为./archives/key/month的文件夹,如果其中任何一个不存在就自动创建,也就是三个文件夹。

    但是却只生成了一个名称为archives/key/month的文件夹。

    代码是这么写的

    path = os.path.join('./archives',key,year,month)
    os.makedirs(path, exist_ok=True)
    

    所以大佬们这问题咋解决,第一次遇到这个奇怪的问题

    2 replies  •  2023-08-16 18:41:45 +08:00
    AoEiuV020JP
        1
    AoEiuV020JP  
       Aug 16, 2023
    不可能,绝对不可能,
    文件名就不允许有斜杠/,
    linux 下文件名 archives/key/month 和路径 archives/key 中的文件 month ,是一个概念,
    will2k
        2
    will2k  
    OP
       Aug 16, 2023
    解决了,是因为如果 GitHub 仓库中某个文件夹只有一个子文件夹,那么这个文件夹的名称后面就会加个`/`,表示目录分级关系。和 vscode 一样。我没仔细看,以为是文件夹的名称。![image]( https://images.nice2cu.cc/i/2023/08/16/uexsv8.webp)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2324 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 02:11 · PVG 10:11 · LAX 19:11 · JFK 22:11
    ♥ Do have faith in what you're doing.