python中filenotfounderror_python - FileNotFoundError: [Errno 2] No such file or directory:

count = 0

answer = ""

pass_pool={"CSRP":"","pos":"","erp":"","comverse":"","miki":"","citrix":""}

name = ""

def program_start():

answer = input('Do you want to make some TXT with the same passwords? y\\n :')

count = int(input('How many TXT files do you want to make?'))

name = input('Enter the hot user id:')

name = name+".TXT"

password_collector() # collect password to pass_pool dictionary

create_file() #create TXT file. it has to be in capital "TXT"

#for the safe program.

def create_file():

newTXT = open(name, "w")

newTXT.write(name + "\n \n" )

for system , password in pass_pool.items():

newTXT.write(system + ":" + password )

newTXT.close()

I get:

File "C:\Python33\mypy\txt creator.py", line 16, in create_file

newTXT = open(name, "w")

FileNotFoundError: [Errno 2] No such file or directory:

From what I look on google this error mean wrong path or file not found. But I check with sys.path and saw that "C:\Python33\mypy" in my paths, and I create the file with "w" so it should work with no problems.

When I used only the create_file() function in the shell it works with no problem.

python

file

createfile

|

this question

edited Feb 15 at 10:33

rrao 137 1 11 asked Sep 9 '13 at 6:04

Or Halimi 176 1 3 14 Use raw strings or escape the '\\', otherwise '\t' is treated as tab character:

r"C:\Python33\mypy\txt creator.py" –

Ashwini Chaudhary Sep 9 '13 at 6:08

|

1 Answers

1

---Accepted---Accepted---Accepted---

When you set the value of name in program_start, Python creates a variable name local to that function's scope, which masks the global name, so the global value remains unchanged. In create_file you use the unchanged global name, which equals to "", and opening a file with the name "" gives you an error.

The quick-and-dirty fix would be addingwith open('C:\\Users\\Ben.Brittany-PC\\Documents\\stats.txt', 'rb') as csvfile: reader = csv.reader(csvfile, delimiter=' ', quotechar='|') for row in reader: print(row) and the error: FileNotFoundError: [Errno 2] No such f

global name

in the beginning of program_start. But it is much clearer to write

count = 0

answer = ""

pass_pool={"CSRP":"","pos":"","erp":"","comverse":"","miki":"","citrix":""}

def program_start():

answer = input('Do you want to make some TXT with the same passwords? y\\n :')

count = int(input('How many TXT files do you want to make?'))

name = input('Enter the hot user id:')

name = name+".TXT"

password_colector() # collect password to pass_pool dic

create_file(name) #create TXT file. it has to be in capital "TXT"

#for the safe pogram.

def create_file(name):

newTXT = open(name, "w")

newTXT.write(name + "\n \n" )

for system , password in pass_pool.items():

newTXT.write(system + ":" + password )

newTXT.close()

|

this answer answered Sep 9 '13 at 6:16

fjarri 6,808 17 34 ho thats right! i totaly miss that. so i will get problem with count and answer to.. thx alot! –

Or Halimi Sep 9 '13 at 6:25

|

de (it's just a simple code but I cannot solve the problem): import csvwith open('address.csv','r') as f: reader = csv.reader(f) for row in reader: print row python file find share edited Mar 9 '14 at 13:28 embert 3,337 3

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值