-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathTopLevelPrint.qhelp
More file actions
33 lines (23 loc) · 1.09 KB
/
TopLevelPrint.qhelp
File metadata and controls
33 lines (23 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>Using <code>print</code> statements in level scope may result in surprising output at import time.
This in turn means that other code cannot safely import the module in question if the program may only write
real output to standard out.
</p>
</overview>
<recommendation>
<p>Replace the <code>print</code> statements with calls to some form of logging function or use the <code>warnings</code> module.</p>
</recommendation>
<example>
<p>In the example, importing the module may cause a message to be printed, which may interfere with the operation of the program.</p>
<sample src="TopLevelPrint.py" />
</example>
<references>
<li>Python Language Reference: <a href="http://docs.python.org/2/reference/simple_stmts.html#the-print-statement">The print statement</a>.</li>
<li>Python Standard Library: <a href="http://docs.python.org/3/library/functions.html#print">The print function</a>.</li>
<li>Python tutorial: <a href="http://docs.python.org/2/tutorial/modules.html">Modules</a>.</li>
</references>
</qhelp>