0

I just started learning python in order to do some stuff for the company I work for. I want to add a command line option like -doc but Ì somehow struggle with adding color or any other custom text format to my documentation (to be printed in cmd).

I have following problems:

1. Ansi escaping doesn't work as I expect when reading tutorials on the internet:

This code: print('\033[31m' + 'Hello' + '\033[0m') doesn't escape at all so I end up with this output: [31mHello[0m

2. I can't import colorama because my users have a plain python installation and I can't just add libraries to it. So my plan would be to add colorama to my project structure.

To 1: Do I misunderstand something important or has someone an idea what I`m doing wrong?

To 2: Is there a way to install colarama into my project without any changes to the plain python installation or dependencies to the outside of my project?

... I would accept any other solution to my problem.

Georgy
  • 12,464
  • 7
  • 65
  • 73
MsFinster
  • 1
  • 4
  • And what is your platform and terminal type? If you are on Windows, generally speaking, you have to use Windows API calls (see https://stackoverflow.com/questions/287871/print-in-terminal-with-colors/3332860#comment3901803_3332860) – aparpara Apr 05 '19 at 13:38
  • Possible duplicate of [Print in terminal with colors?](https://stackoverflow.com/questions/287871/print-in-terminal-with-colors) – aparpara Apr 05 '19 at 13:56
  • OK, looks like https://stackoverflow.com/questions/287871/print-in-terminal-with-colors is a comprehensive guide on color terminal printing in Python, including Windows cmd without Colorama (https://stackoverflow.com/a/288556/11255447) – aparpara Apr 05 '19 at 13:58
  • My target environment is standard cmd from windows. Wait ill go through your links, maybe it is helping me already. – MsFinster Apr 05 '19 at 14:07
  • Ok, I know some of the pages you send me. For some reason I cant get my Console not to print out the explizit ansi code. Other guides are refering to non-windows consoles so ill ignore them. I feel like https://stackoverflow.com/questions/287871/print-in-terminal-with-colors/3332860#comment3901803_3332860 ist the right answer to my question. I need to find out how to use windows calls. Ill write a solution as soon as i found out. Thanks for your help so far, – MsFinster Apr 05 '19 at 14:51

1 Answers1

0

Just use batch to do that.

Code: @echo ^[[31mHello^[[0m (^ is ctrl)

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 04 '22 at 18:32