How to select (command A) an object in the scene I am writing a python script to export a 3D model as .stl from blender. 
here is my code 

import bpy
import time
start_time=time.time
from mathutils import *
from math import *
import random
D = bpy.data
C = bpy.context
#Clean the scene
bpy.ops.object.select_by_type(type='MESH')
bpy.ops.object.delete()
bpy.ops.object.select_by_type(type='CAMERA')
bpy.ops.object.delete()
bpy.ops.object.select_by_type(type='LAMP') 
bpy.ops.object.delete()
#Import the model .mhx in the scene
bpy.ops.import_scene.makehuman_mhx(filepath="model.mhx")
bpy.ops.object.mode_set(mode='POSE');
# modify this model and export it as .stl
#----under construction------
#select the layer 1 and after that select all object in the layer 1.
bpy.context.scene.layers[0] = True
bpy.context.scene.layers[1] = False
#I used this command to select the object in the layer but it did not work.
bpy.ops.outliner.object_operation('SELECT')
bpy.ops.export_mesh.stl("/model.stl")
To select objects that are currently visible in the 3dview, which means they are on any visible layers, you can set the select property of visible objects.

for obj in bpy.context.visible_objects:
    obj.select = True


If you want to check every object on layer[0] and still catch ones that may be hidden you can test the layer value of each object.

for obj in bpy.data.objects:
    if obj.layers[0]:
        obj.select = True


After deleting and deselecting objects you may also want to ensure that the active object is valid.

bpy.context.scene.objects.active = bpy.context.selected_objects[0]