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)
...
...

```
Do a complete path, the tilda

```
~

```

specifies from where you "are right now"

to correctly specify it do the complete path. Easiest way to do this is go to file explorer, right click on the file, and press copy path. This should get you the complete path to the file which can be specified anywhere.

Please let me know if this helped!