-3

これが私が持っているものです。

"""

Author: Michael Wellman (wellmanm)
Title: pa10.py
Description: Deciphering a document using pennymath.

"""

def decode(inputfile,outputfile):
    **inputfile = open("superDuperTopSecretStudyGuide.txt","rU").read()
    outputfile = open("translatedguide.txt","w")**
    count = 0
    aList = []
    for words in inputfile:
        aList.append(words)
        charCount = len(aList)
        **outpufile.write(aList)**
        while count<charCount:
            print aList[count],
            if (aList[count].isalpha()):            
               if (ord(aList[count])>90):           
                   count = count + ord(aList[count])-95     
               else:                                
                   count = count + ord(aList[count])-63     
            else:
                if (aList[count].isdigit()):       
                   count = count + ord(aList[count])-46             
                else:
                   count = count + 6                        
    **inputfile.close()
    outputfile.close()**

txtファイルは私の教授からのものです:P

太字の部分が最も重要だと思います。

何かご意見は?

4

1 に答える 1

2

コードを実行してみましたか?

行に関するエラーメッセージが表示されると思います

outpufile.write(aList)

メソッドのドキュメント文字列には、次のfile.write()ように明確に記載されています。

write(str) -> なし。文字列 str をファイルに書き込みます。

バッファリングのため、書き込まれたデータがディスク上のファイルに反映される前に、flush() または close() が必要になる場合があることに注意してください。

listの代わりに を提供していstrます。に変更してみてください

outpufile.write(''.join(aList))

また

outputfile.write(aList[-1])

またはあなたのニーズに合ったもの。また、リストをクリアすることはないため、 を反復処理するときinputfileに、最初の文字、次に最初と 2 番目、次に最初の 3 文字、というように書きます。それは意図したものですか?

最後に、メソッドinputfileが.strfile.read()str

inputfilePS 変数が文字列でwords、単一の文字である場合は、絶対に変数を呼び出さないでください。それは決して誰の助けにもなりません。

于 2012-04-25T21:53:17.227 に答える