Forum Archive

Creating a textfile from within the program ?.

alexsunny123

Hello,

In pythonista is it possible to create an output textfile from within the code itself. Meaning say i want to create a text file called hi.txt and it doesnt already exist. Is there a functions that will allow me to create from within the program without creating it myself?
https://ometv.onl https://chatroulette.top https://omegle.wtf https://bazoocam.cam
thanks
alexsunny

cvp

@alexsunny123 this is what you want

my_text = 'this is my text'
with open('hi.txt', mode='wt', encoding='utf-8') as fil:
    fil.write(my_text)