Python 2.7 运行此脚本删除文件时没有属性错误,但什么也没有发生

Python 2.7 运行此脚本删除文件时没有属性错误,但什么也没有发生,python-2.7,Python 2.7,此代码未打印任何属性错误,也未打印任何内容。我试图找到打印错误,这样我就可以知道为什么它没有在我的目录中的文件上循环并删除它们 import os import glob def Test(): path = ('/home/Jack/Python.files/') # Shows the path for all python files directories = os.listdir(path) # Finds the directory name v = p

此代码未打印任何属性错误,也未打印任何内容。我试图找到打印错误,这样我就可以知道为什么它没有在我的目录中的文件上循环并删除它们

import os
import glob

def Test():

    path = ('/home/Jack/Python.files/') # Shows the path for all python files
    directories = os.listdir(path) # Finds the directory name

    v = path + directories[0] + ('/*.py~') 
    a = path + directories[1] + ('/*.py~')
    z = path + directories[2] + ('/*.py~')
    w = path + directories[3] + ('/*.py~')
    s = path + directories[4] + ('/*.py~')
    x = path + directories[5] + ('/*.py~')
    # Cocatinates path, directories, and files that end in .py~ together

    numbers = (v, a, z, w, s, x) 
    # Puts the file variables in a tupple

    for i in numbers: 
        if i in path: 
        # Iterates over the tupple for each string file   

            os.remove(i)
            print os.remove(glob.glob(i))
            # Places that string in os.remove and deletes the file

Test()

你输入了代码> GOLB,但是你有没有考虑过实际使用它?这就是我所拥有的,我在最后一行得到了Test()调用的无效语法。
glob.glob()
返回什么?
os.remove()
可以接受吗?它需要字符串,但是当我将列表转换为字符串@IgnacioVazquez Abrams时,它也不起作用。为什么您认为将列表转换为字符串会产生有效的文件名?