Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8033151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:36:26+00:00 2026-06-05T01:36:26+00:00

How to remove path related problems in python? For e.g. I have a module

  • 0

How to remove path related problems in python?

For e.g. I have a module test.py inside a directory TEST

**test.py**
import os
file_path = os.getcwd() + '/../abc.txt'

f = open(file_path)
lines = f.readlines()
f.close

print lines

Now, when I execute the above program outside TEST directory, it gives me error:-

Traceback (most recent call last):
  File "TEST/test.py", line 4, in ?
    f = open(file_path)
IOError: [Errno 2] No such file or directory: 'abc.txt'

how to resolve this kind of problem. Basically this is just a small example that I have given up.

I am dealing with a huge problem of this kind.

I am using existing packages, which needs to be run only from that directory where it exists, how to resolve such kind of problems, so that I can run the program from anywhere I want.

Or able to deal with the above example either running inside TEST directory or outside TEST directory.

Any help.?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:36:27+00:00Added an answer on June 5, 2026 at 1:36 am

    I think the easiest thing is to change the current working directory to the one of the script file:

    import os
    os.chdir(os.path.dirname(__file__))
    

    This may cause problems, however, if the script is also working with files in the original working directory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a path like this: parent/child/reply How do I use PHP to remove
I have been trying to track down weird problems with my mod_wsgi/Python web application.
A vaguely related question seems to be: Remove AddIn path from UDF in Excel
Using Javascript how would I remove any number of ../ from a relative path?
How can I remove the . and .. from a path in Delphi (not
I can't seem to find the function to remove a shape or path from
remove() method without any argument removes all documents inside the collection. $this->db->$collection->remove(); But how
how remove html table rows after 2nd row? if in table have 5 row,
I want to remove digits from a float to have a fixed number of
I need to get Perl to remove relative path components from a Linux path.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.