To automate a process outside of QGIS why don't use pure Python geospatial modules instead of working with PyQGIS ? It is easier and faster if you want to work in the Python shell.
This task is very easy to do with Fiona and Shapely, for example.
Original polylines
from shapely.geometry import Point, LineString, mapping
import fiona
def pair(list):
'''Iterate over pairs in a list '''
for i in range(1, len(list)):
yield list[i-1], list[i]
with fiona.open('original_lines.shp') as input:
# get the crs, driver, and schema
meta = input.meta
# explode lines
with fiona.open('ligne_splited'lines_splitted.shp', 'w',**meta) as output:
for line in input:
# use pair function to extract the line segments
for seg_start, seg_end in pair(line['geometry']['coordinates']):
segment = LineString([Point(seg_start),Point(seg_end)])
output.write({'geometry':mapping(segment),'properties':line['properties']})
Result