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 adding
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()