Forum Archive

Creating a textfile from within the program

karthikmaiya

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?

JadedTuna

@karthikmaiya, not sure what you are asking about, but try:

with open("hi.txt", "w"): pass
karthikmaiya

Basically i want to dynamically generate an output .txt file using python

ccc
my_text = 'Basically I want to dynamically generate an output .txt file using python.'
with open('hi.txt', 'w') as out_file:
    out_file.write(my_text)