io - How to create a .txt file in Python? (Pycharm) -
in previous post, asked how create new file written in if didn't exist. however, i've tried in pycharm, , it's not working. don't see sign of file lookhere.txt
my_list = [i**2 in range(1,11)] openfile = open('lookhere.txt', 'w') item in my_list: openfile.write(str(item) + "\n") openfile.close()
what doing wrong? have pycharm's use of projects?
the text file created in pycharm project folder, suggested. if want go elsewhere, desktop instance, this:
f = open('path_to_desktop/file.txt', 'w')
note: tested on own system. able project path right-clicking folder in project window(on right), , clicking 'copy path' menu pops up.
edit: assume since accepted answer, worked out eventually(though please, other questions, comment). wanted add, @thaneplummer mentioned, it's better practice use statement when opening files. 1 reason being files auto-closed you! google ;)
Comments
Post a Comment