Guten Abend,ASCII-Text ausführbare Datei, mit CRLF Linienbegrenzer
Ich bin derzeit in einer Einleitung-Kurs Python eingeschrieben und sind dabei auf ein Problem gekommen, dass ich nicht in der Lage zu lösen. Ich bin sicher, dass es irgendwo in meinem Code ein einfacher Fehler ist, aber ich konnte keine Fragen zu SO finden, die mein Problem gelöst haben.
Merkwürdiger es kompiliert und läuft gut, wenn es von Cygwin Ausführung ...
ich diesen Fehler, während er durch 3rd-Party-Tests validieren (dass ich keinen Zugang zu):
Python-Skript, ASCII-Text ausführbare Datei, mit CRLF Linienbegrenzer
Dies ist mein Code:
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))
Und das ist ein cgi darauf basierenden (beide den gleichen Fehler werfen):
#!/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))
hoffte etwas mit, wie diese es lösen würde: http://stackoverflow.com/questions/20350305/python-read-crlf-text-file -as-is-with-crlf – geostocker
Die crlf-Zeilenabschlüsse sind nicht die Zeichen in den Strings. Sie sind buchstäblich die Terminatoren der Zeilen in der enthaltenen Textdatei. z.B. Sie haben diesen Code auf einem Windows-System geschrieben. –
Ich dachte mir so viel ... Es ist der berüchtigte Einschnitt, dann? – geostocker