Gabriel's method is pretty standard. You can refer to more details about sam format here. However, if you have to use Python, try something like the following:
samFile="/yourDir/test.sam"
chr1Output="/yourDir/test_chr1.sam"
with open(samFile,"r") as i, \
open(chr1Output,"w") as o:
for line in i:
if line[0]=="@": #avoid processing the first few lines start with @
continue
else:
item=line.split("\t")
chr=item[2]
#your REF column may only use numbers, without "chr", so you may need to edit this line below
if chr=="chr1":
o.write(line)
Note that this python code should be able to output all chr1 reads for you, but it does not sort the positions on chr1. If you would like to do that in python, one way I can think of is to use python dictionary. Use positions as the key for each line, and then sort via key.
Perhaps this post would help.