Skip to content

Commit b482072

Browse files
committed
Added syntax highlighting to README
1 parent 46f99ca commit b482072

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

README.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ the project directory and run
4343
### Connecting
4444
Constructing a new `Scratch` object will automatically connect to Scratch
4545

46-
```
46+
```python
4747
import scratch
4848
s = scratch.Scratch()
4949
```
@@ -52,27 +52,27 @@ This will create a connection on `localhost` port 42001 and set `s.connected`
5252
to `True`. If you want to change the host or port, you can provide them to the
5353
constructor
5454

55-
```
55+
```python
5656
s = scratch.Scratch(host='0.0.0.0', port=40000)
5757
```
5858

5959
If you are disconnected, you can reconnect using the `connect` method
6060

61-
```
61+
```python
6262
s.connect()
6363
```
6464

6565
### Broadcasting
6666
Broadcasting messages to Scratch will function like a broadcast block in
6767
Scratch. You can broadcast either a single message
6868

69-
```
69+
```python
7070
s.broadcast('Hello, Scratch!')
7171
```
7272

7373
Or a list of messages
7474

75-
```
75+
```python
7676
s.broadcast(['Hello, Scratch!', 'How are you doing?'])
7777
```
7878

@@ -84,14 +84,14 @@ Sending sensor updates to Scratch will create new sensors in the Sensing
8484
category, or update sensors with new values. The `sensorupdate` method accepts
8585
a dict whose keys are sensor names, and values are sensor values.
8686

87-
```
87+
```python
8888
s.sensorupdate({'temperature' : 75})
8989
```
9090

9191
### Receiving
9292
Use the `receive` method to receive messages from Scratch
9393

94-
```
94+
```python
9595
msg = s.receive()
9696
```
9797

@@ -111,7 +111,7 @@ Broadcast messages are received anytime a broadcast block is executed in
111111
Scratch. The message data is a string of the message that was broadcast. An
112112
example broadcast message returned from `receive` looks like this:
113113

114-
```
114+
```python
115115
('broadcast', 'Hello, Python!')
116116
```
117117

@@ -122,7 +122,7 @@ dict that maps global variable names to their values. Suppose you created two
122122
variables, `foo` and `bar`. Upon their creation, `receive` would return a
123123
message that looks like this:
124124

125-
```
125+
```python
126126
('sensor-update', {'foo': 0, 'bar': 0})
127127
```
128128

@@ -133,23 +133,23 @@ receive all the messages from Scratch you must repeatedly call `receive`. A
133133
nice way to handle this is to have a generator function that yields a message
134134
everytime it receives, and exits on error.
135135

136-
```
136+
```python
137137
def listen():
138138
while True:
139-
try:
140-
yield s.receive()
141-
except scratch.ScratchError:
142-
raise StopIteration
139+
try:
140+
yield s.receive()
141+
except scratch.ScratchError:
142+
raise StopIteration
143143
```
144144

145145
Now you can iterate over all the messages from Scratch
146146

147-
```
147+
```python
148148
for msg in listen():
149149
if msg[0] == 'broadcast':
150-
# code to handle broadcasts
150+
# code to handle broadcasts
151151
elif msg[0] == 'sensor-update':
152-
# code to handle sensor updates
152+
# code to handle sensor updates
153153
```
154154

155155
If an error occurs or the connection to Scratch is closed, Python simply exits
@@ -158,7 +158,7 @@ the loop.
158158
### Disconnecting
159159
To close a connection to Scratch
160160

161-
```
161+
```python
162162
s.disconnect()
163163
```
164164

0 commit comments

Comments
 (0)