1

I wanted to learn command line programming using Python. I saw a to-do challenge on the internet and started to work on it by learning from the web. The challenge is to create a command line interface of a to-do app.

The challenge is titled CoronaSafe Engineering Fellowship Test Problem. Here is the challenge material on Google Drive: https://drive.google.com/drive/folders/1SyLcxnEBNRecIyFAuL5kZqSg8Dw4xnTG?usp=sharing and there is a GitHub project at https://github.com/nseadlc-2020/package-todo-cli-task/

In the README.md I was instructed to create symbolic link for the batch file todo.bat with the name todo. Now, my first condition is that, when the symbolic link is called from the command prompt without any arguments, it must print some usage tips for the program. Finally, I have to use the npm test command to test the execution.

At the very beginning I got this trouble, whenever I use a print statement, I see a dot • at the end of every string which ends with a new line. For instance,

import sys
import random

args = sys.argv[1:]

if len(args) == 0:
    print('Usage :-', end='\n')
    print('$ ./todo help             # Show usage', end='')

The above statements when executed without arguments gives the output,

Usage :-.
$ ./todo help             # Show usage

Here, I noticed that for the first print statement ends with a newline, the string ends with what looks like a middle dot (•). Whereas, for the second print statement since I override the end parameter with an empty string, no newline character was output, and so the dot is not printed. See the screen shot:

Screenshot of command window with the error message and details

What's wrong, and how can I pass the test? My program does not print a middle dot at all.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • working as expected. no `.` at the end of line – Nitin Goyal Dec 21 '20 at 04:34
  • it is working fine on my device can you please share the OS information also ```end='\n'``` is default in print function so remove that. – Rohit Chauhan Dec 21 '20 at 04:37
  • Actually the execution was instructed to be npm test, and on testing that I got error and the reason for the error was the `.` . Let me add the snips to the question – Gomathi Sankar Dec 21 '20 at 06:02
  • @Rj_Innocent_Coder I knew that one but I was just testing with various end parameters and pasted that one here Also I am using Windows 10 currently updating to version 20H2 – Gomathi Sankar Dec 21 '20 at 06:09
  • I'm also using windows 10 latest patch, works like a charm. :) – Rohit Chauhan Dec 22 '20 at 05:51
  • Another duplicate: https://stackoverflow.com/questions/65454092/unwanted-dot-at-the-end-of-print-statements-in-python-print-function – tripleee Dec 26 '20 at 08:57

4 Answers4

1

The problem seems to be squarely inside the todo.test.js file.

In brief, Windows and Unix-like platforms have different line ending conventions (printing a line in Windows adds two control characters at the end, whilst on Unix-like systems only one is printed) and it looks like the test suite is only prepared to cope with results from Unix-like systems.

Try forcing your Python to only print Unix line feeds, or switch to a free Unix-like system for running the tests.

Alternatively, rename todo.test.js and replace it with a copy with DOS line feeds. In many Windows text editors, you should be able to simply open the file as a Unix text file, then "Save As..." and select Windows text file (maybe select "ANSI" if it offers that, though the term is horribly wrong and they should know better); see e.g. Windows command to convert Unix line endings? for many alternative solutions (many of which vividly illustrate some of the other issues with Windows; proceed with caution).

This seems to be a known issue, as noted in the README.md you shared: https://github.com/nseadlc-2020/package-todo-cli-task/issues/12 (though it imprecisely labels this as "newline UTF encoding issues"; the problem has nothing to do with UTF-8 or UTF-16).

See also the proposed duplicate Line endings (also known as Newlines) in JS strings

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Using `npm test` for Python code is decidedly odd anyway. There are several popular Python test frameworks which would probably be better suited for this. – tripleee Dec 21 '20 at 08:28
  • Thanks for your response...It was not a part of academics. It was a challenge like stuff in our country for student internship selection for UG students. Also, I thought of sharing the entire directory but there are over 7000 files in the npm_modules sub directory despite only less 50 mb in size. If you can take a look let me share the directory link in the question as well... – Gomathi Sankar Dec 21 '20 at 08:39
  • UG means Under Graduate, Bachelors degree. And, the drive link for the directory... https://drive.google.com/drive/folders/1SyLcxnEBNRecIyFAuL5kZqSg8Dw4xnTG?usp=sharing – Gomathi Sankar Dec 21 '20 at 13:39
  • The fact is that the deadline for the challenge had passed. But I wish to complete it for self satisfaction and also I can learn something. Anyways thanks for your response and kindness... – Gomathi Sankar Dec 22 '20 at 01:21
0

I had exactly the same problem.

I replaced:

    print(variable_name)                                      # Or print("Your text here")

With:

    sys.stdout.buffer.write(variable_name.encode('utf-8'))    # To sys.stdout.buffer.write("Your text here".encode('utf-8'))

Now it worked fine in windows.

Gokul Raam
  • 31
  • 6
0

First write your help string like this

help_string='Usage :-\n$ ./task add 2 hello world    # Add a new item with priority 2 and text "hello world" to the list\n$ ./task ls                   # Show incomplete priority list items sorted by priority in ascending order\n$ ./task del INDEX            # Delete the incomplete item with the given index\n$ ./task done INDEX           # Mark the incomplete item with the given index as complete\n$ ./task help                 # Show usage\n$ ./task report               # Statistics'

Then print it on the console using

sys.stdout.buffer.write(help_string.encode('utf8'))

This problem occurs due to differences in encoding type of windows and npm tests. Also make sure to avoid any spaces after or before "\n".

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
-1

Why have multiple prints,when python prints can incorporate new line without having to declare separately, follow example below:

print("Usage :- \n$ ./todo help    #Show usage")  

Output:

Usage :- 
$ ./todo help    #Show usage
tsamridh86
  • 1,480
  • 11
  • 23
  • Thanks for the response I tried nearly every kind of the python print statement but never worked and i believe from the earlier comments of the question, the problem is with either the JS or npm – Gomathi Sankar Dec 21 '20 at 08:49