Sublime Forum

Files are not being made (.txt, .csv) when I try to create them in python

#1

Hi,
I have a problem when I try to create a basic .txt file in sublime text. The basic code is below. The text file never shows up in the directory where my python file is. I should note that I am able to create this .txt file in other IDE (such as IDLE), so this issue seems to be with Sublime Text. I’m new to Sublime so I don’t know why this happens.

f = open('test1.txt', 'w')
f.write('test text')
f.close()
0 Likes

#2

Seems to work just fine for me.

0 Likes

#3

Are you getting some form of error when you do it? If yes, you may be running into a permission problem. If no, are you looking in the right place for the created files?

0 Likes

#4

I’m not getting any error message. The files just don’t show up in the directory I’m in. I’ve also checked the directory where Sublime was installed via Appdata\Roaming

0 Likes

#5

The files will be placed in the current working directory that you tell the build to run in, which is the working_dir key in the sublime-build file. If you didn’t specify that, the default is the location where the file being built is stored.

1 Like

#6

Thanks for the help. It seems like I was in the correct directory. The real issue was that I was running the python file via command prompt and that did not create the file. However, running the python file via “build” (ctrl + B) in the program did create the file. It’s been resolved, thanks again.

0 Likes

#7

man i was having the same exact issue. i was saving my python file after writing

filename = ‘programming.txt’

with open(filename, ‘w’) as file_object:
file_object.write(“I love daddy programming”)

and it would not produce a new .txt file, it was only when i BUILT the file then saved it did the txt file come up. i was stumped for a good hour. frustrating times lol

0 Likes

#8

Try ctrl+shift+b and select Python.

0 Likes

#9

Which is natural. Saving a file doesn’t run the code. You need to of course run the program to make it do what you defined it to do :slight_smile:

0 Likes