Question: I have two file in directory `abc`

```
test.py
hello.txt

```

File `test.py`:

```
import os.path

if os.path.exists('hello.txt'):
  print('yes')
else:
  print('no')

```

when execute test.py in same directory, the output is, as I'd expect, 'yes'

```
abc > python test.py

output: yes

```

but when try to execute form other directory 

```
~ > python ~/Desktop/abc/test.py

output: no

```

how to correct this

```
# the real case
if os.path.exists('token.pickle'):
    with open('token.pickle', 'rb') as token:
        creds = pickle.load(token)

```

it works when executing within directory `abc` but fails form outside.

Answer: 
thanks, everyone, finally I found the solution, never thought that would be easy.... just change the working directory and voila its work　　　

```
import os
...
script_path = os.path.dirname(os.path.realpath(__file__))
os.chdir(script_path)
...
...

```
I see you already post an [answer to your own question here](https://stackoverflow.com/a/59423881/1078556)

Anyway, I wanted to advice you there's no need to use `os.chdir()` for the purpose here really, simply do it like this:

```
# the real case

path_to_your_file = os.path.join(os.path.dirname(os.path.realpath(__file__)),"token.pickle")

if os.path.exists(path_to_your_file):
    with open(path_to_your_file, 'rb') as token:
        ...

```

P.S.
If you're wondering, there's several good reason to [prefer using `os.path.join()` over manual string concatenation](https://stackoverflow.com/a/13944874/1078556), the main one being it [makes your coding platform independent](https://stackoverflow.com/questions/10918682/platform-independent-path-concatenation-using) in the first place