'Python function to print two strings evenly separated

I'm wanting a python function like this:

printSeperated("leftString", "rightString", screenWidth)

That would output:

leftString                    |                        rightString

Such that the "|" delimiter is at the midpoint of the screen.

I've tried:

def printSeperated(str1, str2, w = 20):
  print(str1.ljust(w), "|".center(w), str2.rjust(w))

But this does not keep the delimiter at the center of the screen



Solution 1:[1]

print doesn't know anything about the screen/terminal width. You probably have to use something like the Curses library.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Visvamba Nathan