0
我想將我在子函數中創建的列表調用到另一個子函數中。使用參數和調用函數是我的致命弱點,因爲它涉及到python。我想將我在calculateZscore函數中創建的newList調用到mu globalChi函數中。如何將返回的值傳遞到另一個函數
我當前的代碼:
import os
import math
'''
c:/Scripts/Lab2Data
NCSIDS_ObsExp.txt
chisquare.txt
output.txt
'''
def main():
directory = raw_input ("What is the working directory? ")
input_file = raw_input ("What is the name of the input file? ")
chiTable = raw_input ("What is the name of the chi-squared table? ")
outPut = raw_input ("What is the name of the output file? ")
path = os.path.join(directory,input_file)
path_1 = os.path.join(directory, chiTable)
path_2 = os.path.join(directory, outPut)
if __name__ == "__main__":
main()
def calculateZscore(inFileName, outFileName):
inputFile = open(inFileName,"r")
txtfile = open(outFileName, 'w')
for line in inputFile:
newList = line.strip().split(',')
obsExp = newList[-2:]
obsExp = list(map(int, obsExp))
obs = obsExp[0]
exp = obsExp[1]
zScore = (obs - exp)/math.sqrt(exp)
zScore = map(str, [zScore])
newList.extend(zScore)
txtfile = open(outFileName, 'w')
txtfile.writelines(newList)
inputFile.close() #close the files
txtfile.close()
return newList #return the list containing z scores
def globalChi(zscoreList):
print newList
你能否創建一個更簡單的例子來說明你正在做什麼? –
另外,您的縮進在您在此處發佈的代碼中顯示爲關閉。請將其編輯爲與您實際運行的相同。請注意,對於本網站的正確格式,除了實際縮進的空格外,還必須在每行的開頭添加四個空格。 –