Python 脚本不一致地打印变量值

Python 脚本不一致地打印变量值,python,python-3.x,Python,Python 3.x,我有一个Python3脚本,它扫描文件夹中的某个文件类型,然后获取扩展名为和不带扩展名的文件名 出于某种原因,它没有打印出没有扩展名的文件名 以下是脚本: for file in os.listdir("."): if file.endswith(".rew"): astroFileName = file astroFileTitle = print(os.path.splitext(file)[0]) print(astroFileNam

我有一个Python3脚本,它扫描文件夹中的某个文件类型,然后获取扩展名为和不带扩展名的文件名

出于某种原因,它没有打印出没有扩展名的文件名

以下是脚本:

for file in os.listdir("."):
    if file.endswith(".rew"):
        astroFileName = file
        astroFileTitle = print(os.path.splitext(file)[0])
        print(astroFileName)
        print(astroFileTitle)

        data = dict(
            Astro_Name=file,
            Astro_Title=astroFileTitle,

        commands = """\
            max_copy cp {Astro_Name} {Astro_Title}
            reginto_f /r /w {Astro_Title}
        """

        for command in commands.splitlines():
            command = command.format(**data) 
            print(command)
例如,如果文件名为“modern_star_chart.rew”,它将打印出:

modern_star_chart.rew
modern_star_chart
modern_star_chart.rew None
None
如您所见,它将打印astroFileTitle一次,但不是第二次,它只打印一次

这可能是什么原因造成的


谢谢

函数的
print
不返回任何值,它返回
None

替换:

    astroFileTitle = print(os.path.splitext(file)[0])
与:


print
函数不返回任何值,它返回
None

替换:

    astroFileTitle = print(os.path.splitext(file)[0])
与:


我们有所有的密码吗?对于数据字典,我没有看到右括号。我们有所有的代码吗?对于数据字典,我看不到右括号。