こんばんは、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))
はそれを解決するだろう。このようなものを使用して期待していた:http://stackoverflow.com/questions/20350305/python-read-crlf-text-file -as-is-with-crlf – geostocker
crlf行終端文字は、文字列の中の '\ r \ n 'ではありません。文字通り、それを含むテキストファイルの行のターミネータです。例えばあなたはこのコードをWindowsシステムに書きました。 –
私はそれほど多くを考えました...それは悪名高いくぼみです、それで? – geostocker