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

  • Home
  • SEARCH
  • 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 9248841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:02:43+00:00 2026-06-18T10:02:43+00:00

In my Python books and also the Python Documents this code should be enough

  • 0

In my Python books and also the Python Documents this code should be enough to open a file:

f = open("file.txt", "r")

But if I do this I will get an error message telling me file.txt doesn’t exist. If I however use the whole path where file.txt is located it opens it:

 f = open("C:/Users/Me/Python/file.txt", "r")

Is there an explanation for this?

  • 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-18T10:02:44+00:00Added an answer on June 18, 2026 at 10:02 am

    In short – the immediate search path (the current working directory) is where Python will look… (so on Windows – possibly it’ll assume C:\Pythonxy)

    Yes, it depends on where Python/IDLE is executed… for it to use its search path:

    >>> import os
    >>> os.getcwd()
    '/home/jon'
    
    >>> open('testing.txt')
    <open file 'testing.txt', mode 'r' at 0x7f86e140edb0>
    

    And in a shell – changing directories… then launching Python/IDLE

    jon@forseti:~$ cd /srv
    jon@forseti:/srv$ idle
    
    >>> import os
    >>> os.getcwd()
    '/srv'
    >>> open('testing.txt')
    
    Traceback (most recent call last):
      File "<pyshell#2>", line 1, in <module>
        open('testing.txt')
    IOError: [Errno 2] No such file or directory: 'testing.txt'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to port an algorithm from an Excel sheet to python code but
I have always seen in python articles/books that python is simple and it has
In Django I am using two applications: python manage.py startapp books python manage.py startapp
Python 3 really complicated the whole file reading process, when you have a binary
I was reading about reflection in Python and came across this statement: Structural Reflection.
Consider this code: x = 1 # 0001 x << 2 # Shift left
I'm trying to setup a Python application that should automatically start when Linux boots.
I decided to look a bit into python. I found this book began to
I searched the site but it seems like this exercise from the book Learn
This may be a dumb question, but I'm a bit unsure if it's safe

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.