Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用makedirs将文件夹转换为csv文件_Python - Fatal编程技术网

Python 使用makedirs将文件夹转换为csv文件

Python 使用makedirs将文件夹转换为csv文件,python,Python,我试图以.csv文件的形式获取最后一个文件,但我得到了一个名为.csv字符串的文件夹 a = 'ICIC' type = '.csv' os.makedirs('D:/PMS/{}/Master/{}'.format(a, a,type)) format()中有三个参数,但只有两个占位符 os.makedirs('D:/PMS/{}/Master/{}{}'.format(a, a, type)) 如果您使用的是Python 3,则使用f字符串 os.makedirs(f'D:/PMS/{a

我试图以.csv文件的形式获取最后一个文件,但我得到了一个名为.csv字符串的文件夹

a = 'ICIC'
type = '.csv'
os.makedirs('D:/PMS/{}/Master/{}'.format(a, a,type))

format()
中有三个参数,但只有两个占位符

os.makedirs('D:/PMS/{}/Master/{}{}'.format(a, a, type))
如果您使用的是Python 3,则使用f字符串

os.makedirs(f'D:/PMS/{a}/Master/{a}{type}')
请注意,不能使用
os.makedirs
创建文件。要做到这一点,您可以使用

folder = 'ICIC'
file_type = '.csv' # type is built-in name, don't use it as a variable
file_name = f'D:/PMS/{a}/Master/{a}{type}'

with open(file_name, 'w') as empty_csv:
    pass

format()
中有三个参数,但只有两个占位符

os.makedirs('D:/PMS/{}/Master/{}{}'.format(a, a, type))
如果您使用的是Python 3,则使用f字符串

os.makedirs(f'D:/PMS/{a}/Master/{a}{type}')
请注意,不能使用
os.makedirs
创建文件。要做到这一点,您可以使用

folder = 'ICIC'
file_type = '.csv' # type is built-in name, don't use it as a variable
file_name = f'D:/PMS/{a}/Master/{a}{type}'

with open(file_name, 'w') as empty_csv:
    pass

这仍然会创建一个文件夹,作为.csv的字符串值,因此该文件夹是在ICIC中创建的。csv@Mihir更新了我的回答我无法理解你的代码@Guy它说首先创建一个目录,然后将a.csv文件夹转换为.csv文件,对吗?@Mihir你不能将文件夹转换为文件。最后一个代码片段将在指定位置创建一个csv文件。我使用这个代码`os.makedirs(f'D:/PMS/{a}/Master/{a}')`
file\u name=f'D:/PMS/{a}/Master/{a}{type}'
打开(文件名,'w',encoding='utf-8')作为empty_csv:pass
但它也会创建一个名为ICIC的文件夹和一个ICIC.csv文件,如何删除ICIC文件夹这仍然会创建一个文件夹,该文件夹作为.csv的字符串值,因此,在ICIC中创建的文件夹。csv@Mihir更新了我的回答我无法理解你的代码@Guy它说首先创建一个目录,然后将a.csv文件夹转换为.csv文件,对吗?@Mihir你不能将文件夹转换为文件。最后一个代码片段将在指定位置创建一个csv文件。我使用这个代码`os.makedirs(f'D:/PMS/{a}/Master/{a}')`
file\u name=f'D:/PMS/{a}/Master/{a}{type}'
打开(文件名,'w',encoding='utf-8')作为空的_csv:pass
,但它也会创建一个名为ICIC的文件夹和一个ICIC.csv文件,如何删除ICIC文件夹