Ask coding questions

← Back to all posts
Python not creating new file open('my_file.txt', 'w')
LordTopley (0)

I'm doing an exercise from a learning Python book and it asks me to import a paragraph from an external text file, split the paragraph into two sentences and write the sentences to two seperate text files.

No errors and everything seems to check out, but why are files now being created?

file_name = open('curiosity_shop.txt', 'r')
file_contents =

first_period = file_contents.find('.')
first_sentence = file_contents[0:first_period+1]
second_sentence = file_contents[first_period+2:]

first_sentence_file = open('first_sentence.txt', 'w')
second_sentence_file = open('second_sentence.txt', 'w')


PaoloAmoroso (122)

Can you elaborate on what's not working?

I tried your code and it works as expected, both files are created. However, the files don't show un in the filetree. To see them you have to open the shell by right-clicking anywhere in the editor window, clicking Command Palette, scrolling down a bit, and finally clicking Open Shell. Then run the ls command in the shell.

nftn (1)

I encountered same problem, and I find that sometimes maybe just refresh your webpage, then you can see the folders and files you just created, pls try, hope this can help you.