Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Dec 182010
 

How do I find the current module name in Python?

Answer:

The easiest way is to look at the look at the predefined global variable __main__. If it has the value "__main__", it means the program is run as a script (not as imported module).

E.g.

def main():
    print 'Running test...'


if __name__ == '__main__':
    main()
Oct 252010
 

Multi-line string in Python

Answer:

In Python, multi-line string are enclosed in triple double (or single) quotes:

E.g.

s = """Line1
Line2
Line3"""

print s

Or

s = '''Line1
Line2
Line3'''

print s

Both methods are valid.