Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5796581

Browse files
Upd of print func to py3 syntax in conventions section
1 parent ed755c1 commit 5796581

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

docs/writing/style.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -582,26 +582,26 @@ list of what is considered false.
582582
.. code-block:: python
583583
584584
if attr == True:
585-
print 'True!'
585+
print('True!')
586586
587587
if attr == None:
588-
print 'attr is None!'
588+
print('attr is None!')
589589
590590
**Good**:
591591

592592
.. code-block:: python
593593
594594
# Just check the value
595595
if attr:
596-
print 'attr is truthy!'
596+
print('attr is truthy!')
597597
598598
# or check for the opposite
599599
if not attr:
600-
print 'attr is falsey!'
600+
print('attr is falsey!')
601601
602602
# or, since None is considered false, explicitly check for it
603603
if attr is None:
604-
print 'attr is None!'
604+
print('attr is None!')
605605
606606
Access a Dictionary Element
607607
~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -615,22 +615,22 @@ or pass a default argument to :py:meth:`dict.get`.
615615
616616
d = {'hello': 'world'}
617617
if d.has_key('hello'):
618-
print d['hello'] # prints 'world'
618+
print(d['hello']) # prints 'world'
619619
else:
620-
print 'default_value'
620+
print('default_value')
621621
622622
**Good**:
623623

624624
.. code-block:: python
625625
626626
d = {'hello': 'world'}
627627
628-
print d.get('hello', 'default_value') # prints 'world'
629-
print d.get('thingy', 'default_value') # prints 'default_value'
628+
print(d.get('hello', 'default_value')) # prints 'world'
629+
print(d.get('thingy', 'default_value')) # prints 'default_value'
630630
631631
# Or:
632632
if 'hello' in d:
633-
print d['hello']
633+
print(d['hello'])
634634
635635
Short Ways to Manipulate Lists
636636
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -781,7 +781,7 @@ Use :py:func:`enumerate` keep a count of your place in the list.
781781
782782
a = [3, 4, 5]
783783
for i, item in enumerate(a):
784-
print i, item
784+
print(i, item)
785785
# prints
786786
# 0 3
787787
# 1 4
@@ -802,7 +802,7 @@ files for you.
802802
803803
f = open('file.txt')
804804
a = f.read()
805-
print a
805+
print(a)
806806
f.close()
807807
808808
**Good**:
@@ -811,7 +811,7 @@ files for you.
811811
812812
with open('file.txt') as f:
813813
for line in f:
814-
print line
814+
print(line)
815815
816816
The ``with`` statement is better because it will ensure you always close the
817817
file, even if an exception is raised inside the ``with`` block.

0 commit comments

Comments
 (0)