Extracting spectra of individual stellar objects When you look through a telescope into the heavens you see an entire patch of the sky in which there are many light sources. If I attach a spectrometer, with a diffraction (or prism), to the eye pieces the components of light from the eye pieces will disperse according to their wavelength irrespective of where it is coming from. 
My question is: How do you separate the spectra of individual stars/galaxies from the midst of all the light sources? 
From what I gathered from looking this topic up on the internet, this is done computationally using a large variety of algorithms. I have not looked into how these algorithms work but I understood that this is indeed done computationally rather than instrumentally. 
Is this correct? Is this the only way to do it? I am trying to understand how to separate the spectrum from a single object (star, galaxy etc.) so that its composition can be studied. 
 A: When light enters your telescope, light from all sources visible in the field of view is present in all parts of your lens or your mirror. But what the optics does is that it sorts light based on angle of incidence, such that all light from one particular angle also is projected in a particular angle. That is why you can see an image there, and not just a gray smeared mix of light waves. On the focal plane - in the image - the light is already sorted for you: When you see an image of a star, it is because all the light from that particular star has been directed to one point on your image plane. 
From there, it is a matter of simply isolating light from different areas of the image plane. You do not lose any light from that object, because all light from the object is where you want it already (this is only an idealized approximation, in real life you do lose a bit because of diffraction and atmospheric blurring etc, but it's close enough). 
There are several different ways of doing this. The classic method is to cover the majority of the image plane (where you would normally have the photographic paper or your CCD) with a screen with a small aperture or slit, blocking out all other light than that of the object of interest. This light can then, with additional optics, be redirected into your dispersion unit (prism, grating, or grism). 
One variation of this method which is particularly popular with stars in crowded star fields, is to use movable optical fibers. This has the advantage that you can extract light from a lot of stars at the same time, avoiding loss of information and still keep the quality of each spectrum as high as you would have with just a single aperture.
For extended sources like e.g. nearby galaxies, Integral Field Units are very popular (but expensive!). There, you slice the entire image up in pixels with e.g. a big array of tiny lenses, and direct the light from each pixel into its own separate dispersion unit. This is not a good idea for star fields, where the images of individual stars may overlap 4 or more pixels, but for large nebulae of gas, it is extremely useful.
Finally, there is also the primitive but cheap and efficient slitless spectroscopy. In this, you just place a dispersion unit directly at the image plane of your telescope, and let all the objects there draw out into wide stripes, each a 2D spectrum. The downside to this is that spectra may often overlap. The advantage is that it is cheap and simple, and because of the simplicity, you lose much less light in the optics, so you can see faint objects with relatively short exposure times. 

EDIT: I just found this picture on Neill Reid's homepage at STScI and thought I'd add it here. It's what slitless spectroscopy looks like. The ring is the remnant of Supernova 1987A; blue is a normal image of the field around it, orange is the slitless spectrum. The multiple images of the NS remnant represent various emission lines; there is almost no emission from the ring in other wavelengths. 

