There is actually a nice shortcut if you need a relative path and you won't necessarily use the same computer (Or just useful to know nonetheless):

from os.path import dirname

folder_name = dirname(__file__)

In folder_name you will have the path of the folder that your current code is in.

You can instead import the entire os package, though it is a waste of resources unless you need more functions from it:

import os

folder_name = os.path.dirname(__file__)

To that you can add the relative path of the file that you want to open.

file = open(folder_name + 'readme.txt') #As Otto said, 'r' after the file path is for reading, but it is also the default value so can be skipped

After this you will have to close the file in the end of the use.

A different way to use files in Python is using the command "with". This command leaves the file (Or url) connection open until you are out of the indentation for it and then it closes it (Similar to function use).

Example:

with open(os.path.dirname(__file__)+r"\file.txt") as f: lines = list(f) #This actually reads the entire file into a list that is split based on lines in the file, # useful for small size of text files.#Here the file is already closed but "lines" is still an active list variable.