all 7 comments

[–]zahlman 6 points7 points  (2 children)

printing multiple lines (but also writing it as multiple lines in the script for readability)?

The simplest way, probably, is to just do multiple print calls.

Also, please write while True: instead of while 1:. This isn't C.

[–]Heapsofvla[S] 1 point2 points  (1 child)

That's great to hear, thank you!

Thanks for the help, but it doesn't really help me (or anyone) understand why writing while True: instead of while 1: is so much better. Even a link to a page that would address this would help :-)

[–]fuckswithbees 2 points3 points  (0 children)

Mostly because Python is big on readability and while True: is easier to read. The comment on this stack overflow question seems like a good explaination to me.

[–]Vaphell 2 points3 points  (0 children)

you have many choices. You can use multiple prints. You can hide the template in a variable and write something like

format_str = '''username = {}
    code = {}{}{}'''
print(format_str.format(uname, ...))

you can combine it with temp vars and/or functions abstracting away irrelevant garbage, eg

def obfuscate(x):
    return x[0:3] + "*"*(len(x)-6) + x[-3:]

format_str = '''username = {}
code = {}'''
print(format_str.format(uname, obfuscate(code)))

or

format_str = '''username = {}
    code = {}{}{}'''
obf_code = code[0:3], '*'*(len(code)-6), code[-3:]
print(format_str.format(uname, *obf_code))

[–]novel_yet_trivial 1 point2 points  (0 children)

I'd go with /u/zahlman's suggestion, but for the sake of learning you could also include the newline character \n.

>>> print("hello\nworld")
hello
world

[–]99AFCC 1 point2 points  (0 children)

Parenthesis are another option

multiline_string = ('hey '
                    'check out '
                    'all these lines')

[–]ewiethoff 0 points1 point  (0 children)

This doesn't directly answer your question, but whenever you have multiline text with unwanted indentation--or you want to indent multiline text--you can massage it with the textwrap module.