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

```
well, if you do not know the complete path, this is much more difficult IMHO. I don't have any good, pythonic idea to do that!

To search for the file within your whole PC, use subprocess module and execute "find" command on linux (you're on linux, right?), catch the output, and ask if your file is there:

```
import subprocess

file_name = "test.txt"

sp = subprocess.Popen(["find", '/', "-name", file_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = sp.communicate()

found = False
for line in output:
    if file_name.encode() in line:
        found = True

print("Found:", found)

```

NOTE: to delimit the search replace "/" by the parent folder you expect the file to be in.

EDIT: On windows, though I could not test it, the command would be: "dir /s /p hello.txt", so the subprocess call would look like this: `sp = subprocess.Popen(["cmd", "/c", 'dir', '/s', '/p', 'Links'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)`