I have a very rookie question to ask. I am using Pyraf, Python, Sextractor, & a sextractor wrapper to do some automatic photometry on celestial images.
The following code I have written is used to extract info from a sextractor catalog such as image positions, image magnitudes, etc:
catalog_f=sextractor.open('Z2.cat') catalog=catalog_f.readlines() filename="Z2X.txt" sys.stdout=open(filename, 'w') for star in catalog: print star['X_IMAGE'] sys.stdout=sys.__stdout__
Now, I am still learning python and I am still unclear on how to create functions (i.e. def etc). I have to use the above code many times in a single script to extract various fields from different catalogs.
So my question is this: is there a way to turn this bit of code into a function that I can call upon at a later time, where I specify the catalog (eg. 'Z2.cat'), the file name to write to (eg. 'Z2X.txt) and the field(s) to extract (eg. 'X_IMAGE').
Many thanks in advance,