Relative path to script folder using text view
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.