0
對於輸出,我想要一個列表,每個索引都包含一個數字和一個由兩個不同文件(如B2)組成的字母。相反,當我運行我的程序時,我得到的輸出列出了不同行上的每個文件值。其中一個輸入文件是一個簡單的數字列表,另一個是字母列表。根據我的代碼,我希望能得到一些幫助。提前致謝!合併文件時奇怪的輸出
def combine():
mylist = []
galaxy = open("galaxies.rtf","r")
print("Reading from galaxies.txt...")
for line in galaxy:
gline = galaxy.read()
cycle = open("cycles.rtf","r")
print("Reading from cycle.txt...")
for line in cycle:
cline = cycle.read()
print("Combining values...")
string = gline + cline
mylist.append(string)
galaxy.close()
cycle.close()
return mylist
combine()
# the main function calls combine() to read the data from files
# then displays a formatted table with the combined values
def main():
#Print a header at start of main() function
print("Report of BOOYA Radio Galaxy Observations\n")
# Call the combine() function, returned list saved as radioData
radioData = combine()
# Loop through the radioData list printing 5 columns of values
for j in range(0,len(radioData),5):
for k in range(0,5):
print(radioData[j+k],end="\t")
print()
main()
請編輯您的問題,使python縮進是正確的。輸入文件的一些內容是什麼? – barny
如果您希望我們可以幫助您,請向我們展示您的輸入文件和預期輸出的示例。 –
修正了縮進。其中一個輸入文件是數字列表,另一個是字母列表。該計劃的目的是將兩者結合起來,例如B5。 –