Python中的Unicode问题 [英] Unicode issue in Python

查看:69
本文介绍了Python中的Unicode问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是由自己的分级员为Xqueue(edX)开发的。它是一个C编译器,它从Xqueue中提取json对象并将结果推回到Xqueue中。



我以预期的格式返回JSON响应(如下所示) )

I have developed by own grader for Xqueue(edX). It is a C compiler that pulls json objects from the Xqueue and pushes the results back into the Xqueue.

I am returning a JSON response in the format expected (given below)

{
 "correct": true,
 "score": 1,
 "msg": "The code passed all tests."
}



代码运行时正确为真,在这种情况下,msg是控制台上的输出。

测试我使用的是一个简单的代码:


"correct" is true when the code runs and in that case "msg" is the output on the console.
To test I am using a simple code:

#include <stdio.h>
int main()
{
  int i;
  for(i=0;i<=10;i++)
    printf("%d\n",i);
}



现在在本地计算机上,该程序会在新行中打印0到10之间的每个数字。在edX网站上,所有数字都显示在一行中,数字之间有一个空格。

由于edX Xqueue的提交对于新行提交了\\\\ n,我在将分级器响应推送到Xqueue之前,还使用\\ n替换输出中的所有\ n。问题仍然存在。

我在python中搜索了unicode问题。

我使用的是Python 2.7。



这是一个unicode问题吗?


Now in local computer this program prints each number from 0 to 10 in new line. While on the edX website, all numbers are displayed in one line with one space in between the numbers.
Since the submissions from edX Xqueue had \r\n for new line, I also replaced all \n in the output with \r\n before pushing the grader response into the Xqueue. The problem still persisted.
I googled a lot on unicode problems in python.
I am using Python 2.7.

Is it a unicode problem?

推荐答案

这绝对不是Unicode问题。



打印到控制台和网页输出之间有区别:

虽然控制台使用 \ r \\ n \\ n (Windows)或 \ n (Unix)对于新行,HTML和XML忽略这些序列。要强制换行,可以在那里使用< br> 标记。
This is definitely not a Unicode problem.

There is a difference between printing to the console and to web page output:
While the console uses \r\n (Windows) or \n (Unix) for new lines, HTML and XML ignore these sequences. To force a new line the <br> tag can be used there.


这篇关于Python中的Unicode问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆