0

I'm trying to access a folder that is in the current directory in which I am writing my code. the folder I am currently in is cs113

I've tried to do

file2 = open("/cs113/studentstoires/Zorine.txt", "r)"

Would someone please tell me whey this doesn't work I've also tried to write the directory name like this:

open("/studentstories/Zorine.txt", "r")

Do I need to import sys and use sys.listdir or os.path? If so can you please give a quick little example how to do this? Thank you in advance.

1
  • Consider using os.path.join. Also, please include the errors you are getting. Commented Sep 23, 2016 at 23:00

1 Answer 1

1

If it's in the current directory, and it's the directory where you execute the script from, you should write the path without the / up front like so:

file2 = open("studentstories/Zorine.txt", "r")
Sign up to request clarification or add additional context in comments.

3 Comments

Hi @DirtyDaver, if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this.
@DirtyDaver And glad I could help :-)
I think this answer deserves more votes. Not easy to find this info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.