Hi Jeremy, I am new to Python too. I find docs.python.org very helpful.
*Understanding functions:* http://docs.python.org/tutorial/controlflow.html#defining-functions *Reading and Writing Files:* http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files *File Objects:* http://docs.python.org/library/stdtypes.html#file-objects *Comments - Coding Style* http://www.python.org/dev/peps/pep-0008/#comments Hope the above links are useful. Thanks, Vignesh On Thu, May 17, 2012 at 11:45 PM, Jeremy Traurig <jeremy.trau...@gmail.com>wrote: > Hello, > > I very new to python and have been playing around with some simple code > that I would eventually use in the real word. Below is the code I have > created. I want the code to read data from a file called SIL633.txt and > then output that data into another file called test.txt. below is my code: > > #! /usr/bin/env python > # Read NRG Text File > def readNRGtxt(): > import numpy as np > f1 = open('SIL633_original.txt','r') > data = np.genfromtxt(f1,delimiter='\t',skip_header=141) > f1.close > f2 = open('test.txt','w') > np.savetxt(f2,data,fmt='%6.2f',delimiter='\t') > f2.close > > I'm running this on mac 10.5.8. When I run this script from the command > line, there is no file output. However, if I remove the "def" statement in > the script and run again from the command line, a test.txt file is output. > I guess I'm trying to understand why using the def statement changes how > the script operates and since it does, how do I correct this code so it > runs from the command line with the def statement. > > thanks for any help -- jeremy > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor