简体   繁体   中英

CMD windows running .py scrip not writing to txt file, but running in pycharm does write to the file

print("What is this for?:")
z = input(str())
print("Username:")
x = input(str())
print("Password:")
y = input(str())

f = open("UserandPass.txt", 'a')
f.write('\n')
f.write('\n' + 'Domain:')
f.write('\n' + z)
f.write('\n' + 'Username:')
f.write('\n' + x)
f.write('\n' + 'Password:')
f.write('\n' + y)
f.close()

g = open("UserandPassbackup.txt", 'a')
g.write('\n')
g.write('\n' + 'Domain:')
g.write('\n' + z)
g.write('\n' + 'Username:')
g.write('\n' + x)
g.write('\n' + 'Password:')
g.write('\n' + y)
g.close()

print(z)
print(x)
print(y)

So I'm running a program in pycharm that can write text to a .txt file fine. The issue comes along when I run the .py script in the cmd prompt... doesn't write to the file. There are no errors, in the cmd prompt after running either. Not sure what is going on.

i run you code in a python3 interpreter under Mac OS, it worked.

maybe it's related to your system, space in the filename may be a problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM