Selection sequence works in python window but not as stand alone script.

Discussion created by chpolyzo on Feb 23, 2014
I was wondering why a selection chain consisted by a "Selected by attributes" followed by a "selected by location" command provides an empty fc as a stand alone script, while it works fine in the python window.

here's my piece of code which provides the desirable selection in the python window but produces empty feature classes as a stand alone script:

aree_layer = "aree_2HA_" + input_file[-8:-4]
punti_layer = "punti_2HA_" + input_file[-8:-4]
arcpy.MakeFeatureLayer_management(input_directory + "\\" + input_file, aree_layer)
arcpy.MakeFeatureLayer_management(output_directory + "\\" + "p_" + input_file[-8:-4] + ".shp", punti_layer)

selection_aree = arcpy.SelectLayerByAttribute_management(aree_layer, 'NEW_SELECTION', ' "NumPoints" = 1 ' )
#select points which are completely within >2HA polygons
selection_punti = arcpy.SelectLayerByLocation_management(punti_layer, 'COMPLETELY_WITHIN', aree_layer)
arcpy.CopyFeatures_management(selection_punti, output_directory + "\\" + "selection_punti_" + input_file[-8:-4] + ".shp")

arcpy.SelectLayerByAttribute_management (aree_layer, "CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management (punti_layer, "CLEAR_SELECTION")

I would appreciate any kind of help