python脚本中的IndentationError用于组织音乐 - python

我过去制作过此脚本,现在想使用它,但是尝试运行它时发生错误。这个脚本是关于组织我的音乐的。我有一个按标签组织的目录,想从label和year目录中的目录名称中获取歌手的名字,并在artist和year目录中创建新目录。

标签内的目录名称是这样的

LabelName_ [Artist-AlbumName] _2015-08-09

并想要像这样在艺术家目录和年份目录(按日期)内创建符号链接

2015-08-09_ [Artist-AlbumName] _LabelName

import os
basedir = "/home/zab/Music/#01.Label"
artist_parent_dir = "/home/zab/Music/#03.Artist"
date_parent_dir = "/home/zab/Music/#04.ReleaseDate"
for fn in os.listdir(basedir):
    label_path = os.path.join( basedir, fn)
    for album in os.listdir(label_path):
        i = 1
        words = album.split("_")
        for word in words:
            if i == 1:
                label = word
            elif i == 2:
                name = word
            else:
                date = word
            i = i + 1
        artist_album = name.split("-")
        j = 1
        for part in artist_album:
            if j == 1:
                artist = part.replace("[","")
            j = j + 1
        date_parts = date.split("-")
        z =  1
        for part_two in date_parts:
            if z == 1:
                year = part_two
            z = z + 1
        if not os.path.isdir(os.path.join(artist_parent_dir,artist)):
            os.mkdir(os.path.join(artist_parent_dir,artist))
        if not os.path.isdir(os.path.join(date_parent_dir,year)):
            os.mkdir(os.path.join(date_parent_dir,year))
        src = os.path.join(label_path,album)
        artist_dst = os.path.join(artist_parent_dir, artist, name + "_" + label + "_" + date)
        year_dst = os.path.join(date_parent_dir,year, date + "_" + name + "_" + label)
        if not os.path.exists(artist_dst):
            os.symlink(src, artist_dst)
        if not os.path.exists(year_dst):
            os.symlink(src, year_dst)

File "/home/zab/Music/_Scripts/OrganizeByArtist.py", line 22
    artist = part.replace("[","")
                                ^
IndentationError: expected an indented block

怎么了? part.replace是过时的还是什么?
任何改进此脚本的建议将不胜感激。

参考方案

您可能会混合使用空格和制表符,这使得很难弄清楚Python如何看待缩进。

Python-crontab模块 - python

我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…

Python Pandas导出数据 - python

我正在使用python pandas处理一些数据。我已使用以下代码将数据导出到excel文件。writer = pd.ExcelWriter('Data.xlsx'); wrong_data.to_excel(writer,"Names which are wrong", index = False); writer.…

Python GPU资源利用 - python

我有一个Python脚本在某些深度学习模型上运行推理。有什么办法可以找出GPU资源的利用率水平?例如,使用着色器,float16乘法器等。我似乎在网上找不到太多有关这些GPU资源的文档。谢谢! 参考方案 您可以尝试在像Renderdoc这样的GPU分析器中运行pyxthon应用程序。它将分析您的跑步情况。您将能够获得有关已使用资源,已用缓冲区,不同渲染状态上…

Python:在不更改段落顺序的情况下在文件的每个段落中反向单词? - python

我想通过反转text_in.txt文件中的单词来生成text_out.txt文件,如下所示:text_in.txt具有两段,如下所示:Hello world, I am Here. I am eighteen years old. text_out.txt应该是这样的:Here. am I world, Hello old. years eighteen a…

用大写字母拆分字符串,但忽略AAA Python Regex - python

我的正则表达式:vendor = "MyNameIsJoe. I'mWorkerInAAAinc." ven = re.split(r'(?<=[a-z])[A-Z]|[A-Z](?=[a-z])', vendor) 以大写字母分割字符串,例如:'我的名字是乔。 I'mWorkerInAAAinc”变成…