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

```
In this case you need to search the file after walking through the directories and reading the contents. 
You might consider `os.scandir()` to walk through the directories [python 3.5]. 
<https://www.python.org/dev/peps/pep-0471/>

Sample:

```
def find_file(path: str) -> str:
    for entry in scandir(path):
        if entry.is_file() and entry.name == 'token.pickle':
            return_path = f'{path}\{entry.name}'
            yield return_path
        elif entry.is_dir():
            yield from find_file(entry.path)

if __name__ == '__main__':
    for path in find_file('.'):
        with open(path, 'rb') as token:
            creds = pickle.load(token)

```