Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # <Gabrielle Byczek>
- # <GEOG656>
- # Purpose: <To effectively read and write text files using Python scripting>
- # Collect imports
- import math
- import os
- def main():
- # The main function
- in_file, out_file, chi_table_file = findPath()
- z_score_list = calculateZscore(in_file, out_file)
- print z_score_list
- def findPath():
- direcName = raw_input("What is the working directory? ")
- fileName = raw_input("What is the name of the input file? ")
- chiSquare = raw_input("The name of the chi-squared table? ")
- outputFile = raw_input("What is the output filename? ")
- # Assemble the paths
- inputPath = os.path.join(direcName,fileName)
- chiTable = os.path.join(direcName, chiSquare)
- finalOutput = os.path.join(direcName, outputFile)
- # Return them
- return inputPath, outputFile, chiTable
- def calculateZscore(inFile,outFile):
- inputFile = open(inFile,"r")
- zscoreList = []
- # Opening outFile
- outFile= open(outFile, 'w')
- # Read the lines of the file
- for line in inputFile.readline():
- line = line.strip()
- line = line.replace(" ","")
- line = line.split(",")
- Zscore = float(int(line[3])-int(line[4]))/(int(line[4])**(0.5))
- zscoreList.append(Zscore)
- line= ',' .join(line)
- line = line + "," + str(Zscore) + "\n"
- print('outFile = %s (type %s)' % (outFile, type(outFile).__name__))
- outFile.writeline(line)
- outFile.close()
- return zscoreList
- if __name__ == '__main__':
- # Call the main() function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement