+ 4

How can i format my print statement to the center without using the generic center() method or the os module?

Originally, I used the os module and it works really fine on my pydroid. But for a reason which I don't know about, it keeps raising OS MODULE ERROR when the same program was run on a laptop with different IDE Who could help give me reason(s) for this? Thee center() method has not been really helpful. I want a method that can AUTOMATICALLY CENTRALISED the print statement without specifying the width parameter. The os module would have been perfect if it was not raising an error when used with other IDE. I'll deeply appreciate your contributions. Thanks

30th Apr 2020, 8:50 AM
Mujeeb Adeyanju Sunmola
Mujeeb Adeyanju Sunmola - avatar
1 Odpowiedź
+ 4
Thanks for the reply Mirielle || GOAT. I was actually after formatting the print statement to the center of ANY console IRRESPECTIVE of the IDE AUTOMATICALLY Many thanks to the humble tutelage from Lothar and David Nierman. Lothar walked me through this challenge by simply importing the shutil module Below is a sample code: import shutil as sh console_size=sh.get_terminal_size().columns print("AdeHumble".center(console_size))
8th May 2020, 9:38 AM
Mujeeb Adeyanju Sunmola
Mujeeb Adeyanju Sunmola - avatar