2016-09-02 5 views
1

こんばんは、ASCIIテキスト、実行可能、

私は現在のpythonに導入コースに在籍していると私は解決することができていない問題に遭遇してきました。私はそれが私のコードのどこかで単純なエラーだと確信していますが、私は私の問題を解決したので、何か質問を見つけることができませんでした。それがコンパイルされ、cygwinのからそれを実行するときに正常に動作不思議な

...

(私はへのアクセスを持っていないこと)、サードパーティのテストを通じて検証中に、私はこのエラーを取得してい

CRLFラインターミネータとPythonスクリプト、ASCIIテキスト実行可能ファイルは、

これは私のコードです:

height = float(input("What is the plane's elevation in metres? \r\n")) 
    height = format(height * 3.28084, '.2f') 

    speed = float(input("What is the plane's speed in km/h? \r\n")) 
    speed = format(speed * 0.62137, '.2f') 

    temperature = float(input("Finally, what is the temperature (in celsius) outside? \r\n")) 
    temperature = format(temperature * (9/5) + 32, '.2f') 

    print("""\n########### OUTPUT ###########\n\nThe elevation is {feet} above the sea level, \n 
you are going {miles} miles/h, \n 
finally the temperature outside is {temp} degrees fahrenheit \n 
########### OUTPUT ###########""".format(feet=height, miles=speed, temp=temperature)) 

そして、これはそれに基づいて、CGI(両方が同じエラーを投げている)である:あなたは、このコマンドを実行することができますそうすることを、LFにCRLFを変換する必要が

#!/usr/bin/env python3 
# -*- coding: utf-8 -*- 


# To write pagecontent to sys.stdout as bytes instead of string 
import sys 
import codecs 


#Enable debugging of cgi-.scripts 
import cgitb 
cgitb.enable() 


# Send the HTTP header 
#print("Content-Type: text/plain;charset=utf-8") 
print("Content-Type: text/html;charset=utf-8") 
print("") 


height = format(1100 * 3.28084, '.2f') 

speed = format(1000 * 0.62137, '.2f') 

temperature = format(-50 * (9/5) + 32, '.2f') 


toPrint = """\n########### OUTPUT ###########\n\nThe elevation is {feet} above the sea level, \n 
you are going {miles} miles/h, \n 
finally the temperature outside is {temp} degrees fahrenheit \n 
########### OUTPUT ###########""" 

toPrint.format(feet=height, miles=speed, temp=temperature) 

# Here comes the content of the webpage 
content = """<!doctype html> 
<meta charset="utf-8"> 
<title>Min redovisnings-sida</title> 
<pre> 
<h1>Min Redovisnings-sida </h1> 




</pre> 

<body> 
{printer} 
</body> 

""" 


# Write page content 
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach()) 
sys.stdout.write(content.format(printer=toPrint)) 
+0

はそれを解決するだろう。このようなものを使用して期待していた:http://stackoverflow.com/questions/20350305/python-read-crlf-text-file -as-is-with-crlf – geostocker

+1

crlf行終端文字は、文字列の中の '\ r \ n 'ではありません。文字通り、それを含むテキストファイルの行のターミネータです。例えばあなたはこのコードをWindowsシステムに書きました。 –

+0

私はそれほど多くを考えました...それは悪名高いくぼみです、それで? – geostocker

答えて

1

dos2unix your_file 

あなたのフォルダ内に以下のコマンドを使用して、特定のフォルダの内容にそれを適用する必要がある場合:

find . -type f -exec dos2unix {} \; 
あなたが最初の DOS2UNIXパッケージをインストールする必要があります0

sudo apt-get install dos2unix 
+0

これは興味深いテストかもしれません。 dos2unixを実行してコードを提出すると、Pythonスクリプト、ASCIIテキスト実行可能と言う「エラー」が出る可能性があります。これを行うと、 '\ r \ n'とは何の関係もなく、テスターの問題か、それをどのように使用しているのかが分かります。 –

+0

これは通常、私がWindowsからUbuntuにファイルをコピーするときに私がこの問題に遭遇したときに行うことです。これらのコマンドを実行し、Gitを使用してコードをリモートサーバーにプッシュします。 – ettanany

関連する問題