Are there python commands to achieve the following :

1. Create new text files

2. Write certain text to these file (similar to DOS Echo> command ???)

Recommended Answers

All 4 Replies

Yes.

Generally ...

text = "just a sample text"
# open the file for writing
fout = open('test.txt', 'w')
# write the text string to the file
fout.write(text)
# close the file
fout.close()

don't know about creating a .txt but you can write in one, read one, and several other things i normally go about writing in one similar to vegaseat:

yourface = 1
f = open('randomfile.txt', 'w')
write = ' if you have integers in your code you want to write in you do this: ' + repr(yourface)
f.write(write)

#or you can do this

f.write('meow/n')
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.