Skip to content

Commit ce44f8d

Browse files
committed
Merge branch 'modern-python'
2 parents 7c8dcbf + 3584071 commit ce44f8d

File tree

9 files changed

+79
-80
lines changed

9 files changed

+79
-80
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ A simple function that calculates the square of a number:
1515

1616
~~~~~ python
1717
def square(num):
18-
return num**2
18+
return num ** 2
1919
~~~~~
2020

2121
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' % num
36+
print("found the square of {:d}".format(num))
3737
return num * num
3838
~~~~~

programming/sr/index.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +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:"
84-
f = open(os.path.join(R.usbkey, "my-file.txt"), "r")
85-
print f.read()
86-
f.close()
82+
print("The path to the USB key is:", R.usbkey)
83+
print("My file on the USB contains:")
84+
with open(os.path.join(R.usbkey, 'my-file.txt'), 'r') as f:
85+
print(f.read())
8786
~~~~~
8887

8988
[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/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Check the log file for errors
4242
see any error reports.
4343

4444
Print all the things
45-
: Adding [`print` statements](/docs/python/tutorial/inputoutput.html)
45+
: Adding `print` statements
4646
into the code you're working on allows you to track the progress of
4747
the system while it is running. When working on non-software systems
4848
other mechanisms are used to achieve the same goal — LEDs

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)