为什么python文件无法保存,python为什么创建不了包

大家好,小编来为大家解答以下问题,python为什么不能保存新建文件了,python为什么不能保存新建文件夹,现在让我们一起来看看吧!

我试图重命名文件,然后打开它并修改数据,但我观察到以下错误

[错误183]当文件已存在时,无法创建该文件

我的代码在这里:def copy_and_replace_new_files(path, list_of_dictionary):

''' get to working directory'''

os.chdir(path)

''' get each dictionary

get all key values

start moving files to new destination

this will be with new name'''

for item in iter(list_of_dictionary):

''' join path and source file

copy to destination and rename'''

src_dir = os.curdir

dst_dir = (os.curdir, "new")

src_file = (src_dir, item['filename'])

(src_file, dst_dir)

dst_file = (dst_dir, item['filename']) # old file name

new_file_name = .splitext(item['filename'])[0]

new_file_name = new_file_name + '_new' + '.txt'

os.rename(dst_file, new_file_name)

''' Find and Replace with Pattern'''

for newline in fileinput.FileInput(new_file_name, inplace=1):

pattern = item['table']

pattern = str(pattern).rstrip()

newline = newline.replace(str(pattern), str(pattern+'_new'))

print(newline.rstrip())

你能告诉我哪里出错了吗。在

  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值