python - 标题之前的脚本输出结束

标签 python windows python-3.x ubuntu cgi

当我在 Windows 上的编辑器(我尝试过 Netbeans、PyCharm 和 Notepad++)中创建文件 test.py(请参阅下面的代码)并将其上传到服务器 (Ubuntu) 时,我收到此错误:

标题之前的脚本输出结束:test.py

但是当我使用 vi 命令行编辑器直接在服务器上创建文件时,页面显示没有任何错误。知道如何解决这个问题吗?

这是 test.py 的代码

#!/usr/bin/python

# send content type
print("Content-Type: text/html\n\n")

print("Good")

最佳答案

我认为这是因为 Windows 回车符。

这是两个字符:

\r is carriage return;
\n is line feed.

两个字符组合起来代表 Windows 上的新行。而在 Linux 上,\n 代表新行。

Notepad++ 有一个选项可以指定您要使用的格式:

转到设置 --> 首选项并选择 linux:

enter image description here

关于python - 标题之前的脚本输出结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36962471/

相关文章:

c++ - 使用 C++ 获取 Windows 文件信息

python - @unique 装饰器在 python 中有什么作用?

python selenium webdriver 问题(selenium.common.exceptions.WebDriverException : Message: "Can' t load the profile. 配置文件目录:)

c++ - 处理创建进程的 AppCrash

python - 使用 sqlalchemy orm 从查询创建临时表

c++ - 我如何使用线程本地存储 (TLS)?

python-3.x - 为什么 PyYAML 和 ruamel.yaml 在单引号时转义特殊字符?

python-3.x - 我应该堆叠、旋转还是分组?

python - numpy 矩阵乘法 n x m * m x p = n x p

python - Django 'resolve' : get the url name instead of the view_function