You have following options. I use the file name myfile.xxx as placeholder for whatever file shall be opened.
Open within the folder where blender is installed:
fout = open("myfile.xxx")
However you might run into permission issues when the installation folder is write protected.
Open in the user Application folder (Appdata)
import bpy
import os
userdir = bpy.utils.resource_path('USER') # see note
mypath = os.path.join(userdir,"myfile.xxx")
fout = open(mypath)
Note: Please check also bpy.utils.user_resource(...)
Open in the same folder where the current blend file is located
import bpy
import os
blenddir = py.path.abspath('//')
mypath = os.path.join(userdir, "myfile.xxx")
fout = open(mypath)
Note: If the current session has not yet been saved to a blend file, then blenddir is returned as empty string! You might need to test for this in your script.
Open in addon folder
import bpy
import os
import myaddon
myhome = os.path.dirname(myaddon.__file__)
mypath = os.path.join(myhome, "myfile.xxx")
fout = open(mypath)
Hint: When you have installed the Addon by using the Addon Tab in User Preferences, then myhome points to Blender's scripts/addons/myaddon folder in the Appdata directory.
Open in Preset folder (where to store addon presets)
import bpy
import os
import myaddon
presets = bpy.utils.user_resource('SCRIPTS', "presets")
mypresets = os.path.join(presets, myaddon.__name__)
if not os.path.exists(mypresets):
os.makedirs(mypresets)
mypath = os.path.join(mypresets, "myfile.xxx")
fout = open(mypath)