User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 423,546 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,026 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums

Setting directory for opening files

Join Date: Dec 2006
Posts: 21
Reputation: trihaitran is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
trihaitran trihaitran is offline Offline
Newbie Poster

Re: Setting directory for opening files

  #5  
Jan 1st, 2007
Somehow my current working directory is set to my home directory by default. I found a solution to this problem though.

__dir__ = os.path.dirname(os.path.abspath(__file__))
filepath = os.path.join(__dir__, 'test.txt')
file = open(filepath, 'rU')

This will get the absolute path to the directory of the *.py file and then I can add the name of my test.txt to it.
Last edited by trihaitran : Jan 1st, 2007 at 8:15 pm.
Reply With Quote  
All times are GMT -4. The time now is 5:55 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC