Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)
JavaScript
{
 "correct": true,
 "score": 1,
 "msg": "The code passed all tests."
}

"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:
C++
#include <stdio.h>
int main()
{
  int i;
  for(i=0;i<=10;i++)
    printf("%d\n",i);
}

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?
Posted
Updated 17-Dec-14 21:13pm
v3
Comments
Jochen Arndt 18-Dec-14 3:12am    
This is definitely not a Unicode problem.
I don't know edx/xqueue. But 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.
875ewh84 19-Dec-14 0:21am    
Hi Jochen,
The <br> tag worked. Thanks.
Jochen Arndt 19-Dec-14 2:40am    
Fine to hear that your problem is solved.
I posted a comment beacuse I was not sure if it was related to that kind of line break.
I will post a solution to get the question out of the list of unanswered ones.

1 solution

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.
 
Share this answer
 
Comments
875ewh84 20-Dec-14 3:38am    
Slight correction. What exactly worked was <br/> and not <br>.
Jochen Arndt 20-Dec-14 3:50am    
Thank you for the correction so that others having the same problem will not run into another one.
The slash is required by XML and XHTML. HTML does not require the slash but it does not harm if it is present.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900