Skip to content

Commit 3584071

Browse files
committed
Move to Print functions
This is the main visual difference in Python 3. These are all still valid in Python 2, though hopefully we won't go back there. I've left in place the terminology of "print statements" because: a) it's teechnically still correct -- `print(x)` _is_ a statement b) this is easy to change later (at no additional effort) if we decide we really want to c) I think "print statement" sounds nicer than "print funtion call"
1 parent a76e387 commit 3584071

File tree

8 files changed

+76
-76
lines changed

8 files changed

+76
-76
lines changed

IDE/code_checking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ So an error on the second line of a file,
3232

3333
~~~~~ python
3434
import sr.robot
35-
print bacon
35+
print(bacon)
3636
~~~~~
3737

3838
Would show up as:

programming/python/functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This would be used by some other code as follows:
2222

2323
~~~~~ python
2424
sq = square(5)
25-
print sq # prints: 25
25+
print(sq) # prints: 25
2626
~~~~~
2727

2828
Another advantage of grouping your code like this is that if you decide you change the way that it works slightly,
@@ -33,6 +33,6 @@ The same function modified & printing a log message:
3333

3434
~~~~~ python
3535
def square(num):
36-
print "found the square of {:d}".format(num)
36+
print("found the square of {:d}".format(num))
3737
return num * num
3838
~~~~~

programming/sr/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ usbkey
7979
import os
8080

8181
R = Robot()
82-
print "The path to the USB key is:", R.usbkey
83-
print "My file on the USB contains:"
82+
print("The path to the USB key is:", R.usbkey)
83+
print("My file on the USB contains:")
8484
with open(os.path.join(R.usbkey, 'my-file.txt'), 'r') as f:
85-
print f.read()
85+
print(f.read())
8686
~~~~~
8787

8888
[Custom Robot Object Initialisation](#CustomRobotInit) {#CustomRobotInit}

programming/sr/power/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ You can access these values like so:
2121

2222
~~~~~ python
2323
# Print the battery voltage and current to the log
24-
print R.power.battery.voltage, R.power.battery.current
24+
print(R.power.battery.voltage, R.power.battery.current)
2525
~~~~~
2626

2727
A fully charged battery will measure 12.6V.

programming/sr/vision/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ R = Robot()
3636

3737
while True:
3838
markers = R.see()
39-
print "I can see", len(markers), "markers:"
39+
print("I can see", len(markers), "markers:")
4040

4141
for m in markers:
4242
if m.info.marker_type == MARKER_ARENA:
43-
print " - Marker #{0} is {1} metres away".format(m.info.code, m.dist)
43+
print(" - Marker #{0} is {1} metres away".format(m.info.code, m.dist))
4444
~~~~~
4545

4646
[Choosing Resolution](#ChoosingResolution) {#ChoosingResolution}
@@ -217,9 +217,9 @@ polar
217217
For example, the following code displays the polar coordinate of a `Point` object `p`:
218218

219219
~~~~~ python
220-
print "length", p.polar.length
221-
print "rot_x", p.polar.rot_x
222-
print "rot_y", p.polar.rot_y
220+
print("length", p.polar.length)
221+
print("rot_x", p.polar.rot_x)
222+
print("rot_y", p.polar.rot_y)
223223
~~~~~
224224

225225
[`Orientation`](#Orientation) {#Orientation}

troubleshooting/python.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ For example:
2121

2222
~~~~~ python
2323
def foo(s):
24-
print s
24+
print(s)
2525

2626
foo "Hello World!" # should be foo("Hello World!")
2727
~~~~~
@@ -51,7 +51,7 @@ Other causes of syntax errors to look out for are:
5151

5252
~~~~~ python
5353
x = 5
54-
print X # wrong case
54+
print(X) # wrong case
5555
~~~~~
5656

5757
Error:
@@ -75,8 +75,8 @@ For example:
7575

7676
~~~~~ python
7777
a = ["Molly", "Polly", "Dolly"]
78-
print a[0]
79-
print a[3]
78+
print(a[0])
79+
print(a[3])
8080
~~~~~
8181

8282
Error:

tutorials/basic_motor_control.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ Here's an example:
223223

224224
~~~~~ python
225225
for i in [1, 2, 3]:
226-
print i
226+
print(i)
227227
~~~~~
228228

229229
The above would output:

0 commit comments

Comments
 (0)