How to run a python script external to Blender to run bpy commands in Blender'spython console Platform = Ubuntu Linux 64 bit, Blender 2.77a

When creating models using bpy-based python scripting, there many times I need to type in the same code in Blender's python console; every time I invoke a new blender session.

For example if something is wrong with objects, I type the following:

for object in bpy.data.object:
    print(object.name + " is at location " + str(object.location)) 


I would like to put this in an xxx.py file I create in a documents folder so when I need to execute it in the Blender python console at each Blender session, all I would need to do is run the .py file ; this will save a lot of repetitive typing.

How do I do this?

Sam
This is the equivalent to running the script directly, referencing a scripts path from a 2 line text-block.

filename = "/full/path/to/myscript.py"
exec(compile(open(filename).read(), filename, 'exec'))


You might want to reference a script relative to the blend file.

import bpy
filepath = bpy.path.abspath("//myscript.py")
exec(compile(open(filepath).read(), filepath, 'exec'))