Relative path to script folder using text view I'm completely new to scripting, just started watching my first tutorial on this matter and the tutor in the video uses the built-in python scripting view, but has to copy and paste lines of code into the console to add the folder, that contains both the script and all associated files, and another line of code every time he updates the script outside of blender and also every time he restarts blender.
I've found it more convenient to load the script into Text View, where I can even edit and update it more easily, but I can't seem to get Blender to load and save files, that are in the same folder as the script itself just by specifying their name, it only seems to work, when I specify the whole path.
The instructor uses the command bpy.data.filepath to specify the filepath, but every time I try this, I get an error both in Intellij and in blender's text view, telling me, that bpy couldn't be found, in blender's python console, the command works just fine.

Any help or pointers in the right direction will be much appreciated.
If you are editing a script in the text editor and clicking the Run Script button then you need to have import bpy at the top of your script to use anything in the bpy module.

Blender's python console automatically imports the bpy module for you, it also gives you some shortcuts like D = bpy.data so you can simply use D.filepath in the python console. The console also imports math and mathutils items so you can simply use radians() in the console but will need to import it if you use it in a script.


  Convenience Imports: from mathutils import *; from math import *
  Convenience Variables: C = bpy.context, D = bpy.data


It is also possible to run text from the text editor in the console. I use the addon mentioned in the previous link to run scripts in the console to make debugging easier.