Dec-20-2016, 08:42 AM
Quote:Why don't you use a full path but relative?
My apologies, I'm quite new to programming. I've just been following tutorials with a certain YouTuber (who seems to know what he's doing) And I couldn't find out why, when I copied his exact code, I did not get the same result (it just flat out didn't work). Which led me to believe that perhaps, something was wrong with my path.
Now when you use
file_obj = open('file_name.txt', 'a')
From what I understand from your post, this allows you to open files from anywhere within the working directory? It seems like when I go to actually write the file (there is no file created yet) it does not create it, with the code that I am using in the original post.
Perhaps I should take a step back from trying to understand this, but when I delve into trying to learn, it's always in the back of my head that I don't understand directories or how to navigate to files within python.
For example: With my current python install directory, a few sources say that from within CMD, I should be able to just type
python example.py
, no matter where the current directory is that I'm currently inside of (within cmd). This is not the case. It always gives me C:\Users\Aaron>python test1.py
python: can't open file 'test1.py': [Errno 2] No such file or directory
when in fact, test1.py exists inside my scripts subfolder of Python35-32 (Main directory) . Do I have a fundamental misunderstanding about how this concept works? The help that I read on this specifically stated that I should be able to run any .py file, regardless of where I have it, as long as the main "Python35-32" directory is above everything else.
Thank you for your response, by the way. I really want to understand this.