Skip to content

Commit a5bdd20

Browse files
committed
updates
1 parent 2f1dac0 commit a5bdd20

File tree

10 files changed

+37
-38
lines changed

10 files changed

+37
-38
lines changed

labs/coding-204-reading-a-file/2.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,21 @@ Let's look at what is going on in the code.
2828
### Give it a try!
2929

3030
To run this code sample:
31-
1. Open a text editor.
31+
1. Create a folder for this lab.
32+
* *On a DevNet Learning Lab PC*, create a folder in "C:\Coding-204\{yourname}". Enter command: **mkdir Coding-204\{yourname}**
33+
* where {yourname} is replaced by your first name.
34+
2. Open a text editor.
3235
* *On a DevNet Learning Lab PC*, open Notepad++ (Start Menu -> Notepad++)
33-
2. Create a new text file.
36+
3. Create a new text file.
3437
* Enter some text.
35-
3. Create a folder for this lab.
36-
* *On a DevNet Learning Lab PC*, create a folder in "C:\Coding-101\yourname"
3738
4. Save your new text file in your folder.
3839
5. Create another new text file.
3940
6. Copy paste the code above into the file.
4041
7. Save the file with the extension **.py** in the your new directory. For example, **read-file.py**.
4142
8. Open a command prompt.
4243
* *On a DevNet Learning Lab PC*, (Start --> Command Prompt)
4344
9. At the command line, go to the directory where you saved the **read-file.py** file.
44-
* *On a DevNet Learning Lab PC*, **cd C:\Coding-101\yourname**
45+
* *On a DevNet Learning Lab PC*, **cd C:\Coding-204\{yourname}**
4546
10. Type the python command and then the filename at the command prompt, and hit return.
4647
* *On Windows*, **py -3 read-file.py**
4748
* *On Mac OS or Linux*, **python3 read-file.py**
@@ -61,4 +62,3 @@ You should see a result like this:
6162

6263
### Things to Try
6364
* What happens if you have a typo in the name of the file?
64-

labs/coding-204-reading-a-file/3.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Step 3. Read one line at a time
22
Sometimes, it is useful to read the data from a file one line at a time.
3-
3+
44
We can use the **.readline()** method to read one line at a time.
55

66
Here is some code that reads only the first line of the text file.
@@ -26,15 +26,15 @@ Let's look at what is going on in the code.
2626
### Give it a try!
2727

2828
To run this code sample:
29-
1. Open a text editor.
29+
1. Open a text editor.
3030
* *On a DevNet Learning Lab PC*, open Notepad++ (Start Menu -> Notepad++)
3131
2. Open your **read-file.py** file that you created in step 2.
3232
3. Modify your code to use **.readline()** instead of **.read()**.
3333
4. Save your file.
3434
5. Open a command prompt.
3535
* *On a DevNet Learning Lab PC*, (Start --> Command Prompt)
3636
6. At the command line, go to the directory where you saved the **read-file.py** file.
37-
* *On a DevNet Learning Lab PC*, **cd C:\Coding-101\yourname**
37+
* *On a DevNet Learning Lab PC*, **cd C:\Coding-204\yourname**
3838
7. Type the python command and then the filename at the command prompt, and hit return.
3939
* *On Windows*, **py -3 read-file.py**
4040
* *On Mac OS or Linux*, **python3 read-file.py**

labs/coding-204-reading-a-file/4.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Step 4. Read the file one line at a time using a loop
22
Sometimes, it is useful to read the data from a file one line at a time and use a loop to keep repeating the operation until you have read the entire file.
3-
3+
44
We can use a file object and a **for** loop to move through the file.
55

66
```python
@@ -12,7 +12,7 @@ x=1
1212
for line in my_file_object:
1313
print ("Line " + str(x) + ": " + line)
1414
x += 1
15-
15+
1616
my_file_object.close()
1717

1818
```
@@ -28,15 +28,15 @@ Let's look at what is going on in the code.
2828
### Give it a try!
2929

3030
To run this code sample:
31-
1. Open a text editor.
31+
1. Open a text editor.
3232
* *On a DevNet Learning Lab PC*, open Notepad++ (Start Menu -> Notepad++)
3333
2. Open your **read-file.py** file that you created in step 2.
3434
3. Modify your code to use the loop above.
3535
4. Save your file.
3636
5. Open a command prompt.
3737
* *On a DevNet Learning Lab PC*, (Start --> Command Prompt)
3838
6. At the command line, go to the directory where you saved the **read-file.py** file.
39-
* *On a DevNet Learning Lab PC*, **cd C:\Coding-101\yourname**
39+
* *On a DevNet Learning Lab PC*, **cd C:\Coding-204\yourname**
4040
7. Type the python command and then the filename at the command prompt, and hit return.
4141
* *On Windows*, **py -3 read-file.py**
4242
* *On Mac OS or Linux*, **python3 read-file.py**

labs/coding-204-reading-a-file/5.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ Let's look at what is going on in the code.
3333
### Give it a try!
3434

3535
To run this code sample:
36-
1. Open a text editor.
36+
1. Open a text editor.
3737
* *On a DevNet Learning Lab PC*, open Notepad++ (Start Menu -> Notepad++)
3838
2. Open your **read-file.py** file that you created in step 2.
3939
3. Modify your code to use the with statement and loop above.
4040
4. Save your file.
4141
5. Open a command prompt.
4242
* *On a DevNet Learning Lab PC*, (Start --> Command Prompt)
4343
6. At the command line, go to the directory where you saved the **read-file.py** file.
44-
* *On a DevNet Learning Lab PC*, **cd C:\Coding-101\yourname**
44+
* *On a DevNet Learning Lab PC*, **cd C:\Coding-204\yourname**
4545
7. Type the python command and then the filename at the command prompt, and hit return.
4646
* *On Windows*, **py -3 read-file.py**
4747
* *On Mac OS or Linux*, **python3 read-file.py**
@@ -58,4 +58,3 @@ This is the second line. Yep, this is the second line.
5858
You should see a result like this:
5959

6060
![](/posts/files/coding-204-reading-a-file/step5-results.jpg)
61-

labs/coding-204-reading-a-file/6.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Step 6. Read JSON from a file
1+
## Step 6. Read JSON from a file
22
If you are using REST APIs, see [Coding 101: Rest Basics Learning Lab](/#/labs/coding-101-rest-basics/step/1) for more info, you often have the need to load some JSON from a file.
33

44
We can use the same techniques that we used in the previous steps to help us read JSON from a file.
@@ -65,11 +65,11 @@ Let's look at what is going on in the code.
6565
* Use **json.loads()** to load the contents of the file into a json object
6666
* Now, you have the contents of the file in memory in a json object and you can loop through and manipulate the JSON as usual.
6767
* See [Coding 202 Parsing JSON](/#/labs/coding-202-parsing-json/step/1) for more information on how to parse JSON.
68-
68+
6969
### Give it a try!
7070

7171
To run this code sample:
72-
1. Open a text editor.
72+
1. Open a text editor.
7373
* *On a DevNet Learning Lab PC*, open Notepad++ (Start Menu -> Notepad++)
7474
2. Create a new text file.
7575
* Copy/paste the JSON from above into the file.
@@ -81,7 +81,7 @@ To run this code sample:
8181
7. Open a command prompt.
8282
* *On a DevNet Learning Lab PC*, (Start --> Command Prompt)
8383
8. At the command line, go to the directory where you saved the **read-file-json.py** file.
84-
* *On a DevNet Learning Lab PC*, **cd C:\Coding-101\yourname**
84+
* *On a DevNet Learning Lab PC*, **cd C:\Coding-204\yourname**
8585
9. Type the python command and then the filename at the command prompt, and hit return.
8686
* *On Windows*, **py -3 read-file-json.py**
8787
* *On Mac OS or Linux*, **python3 read-file-json.py**
@@ -91,8 +91,7 @@ Using the example JSON file above:
9191

9292
You should see a result like this:
9393

94-
![](/posts/files/coding-201-reading-a-file/step6-results.jpg)
94+
![](/posts/files/coding-204-reading-a-file/step6-results.jpg)
9595

9696
### Things to Try
9797
* Can you display the tags for each device?
98-

labs/coding-205-writing-file-ga/2.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ To run this code sample:
2828
1. Open a text editor.
2929
* *On a DevNet Learning Lab PC*, open Notepad++ (Start Menu -> Notepad++)
3030
3. Create a folder for this lab.
31-
* *On a DevNet Learning Lab PC*, create a folder in "C:\Coding-205\yourname".
31+
* *On a DevNet Learning Lab PC*, create a folder in "C:\Coding-205\yourname". Enter command: `mkdir Coding-205\{yourname}`
32+
* where {yourname} is replaced by your first name.
3233
6. Copy/paste the code above into your new file.
3334
7. Save the file with the extension **.py** in your new directory. For example, **write-file.py**.
3435
8. Open a command prompt.
3536
* *On a DevNet Learning Lab PC*, (Start --> Command Prompt)
3637
9. At the command line, go to the directory where you saved the **write-file.py** file.
37-
* *On a DevNet Learning Lab PC*, **cd C:\Coding-205\yourname**
38+
* *On a DevNet Learning Lab PC*, `cd Coding-205\{yourname}`
3839
10. Type the python command and then the filename at the command prompt, and hit return.
3940
* *On Windows*, **py -3 write-file.py** or type: **python write-file.py**
4041
* *On Mac OS or Linux*, **python3 write-file.py**

labs/coding-205-writing-file-ga/5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ To run this code sample:
8282
3. Save the file. If encoding type is an option select **UTF-8**.
8383
4. Type the python command and then the filename at the command prompt, and press the return key.
8484
* *On Windows type*: **py -3 write-json-to-file.py**. Or type: **python write-json-to-file.py**
85-
* *On Mac OS or Linux type*: **python3 create-device-list.py**
85+
* *On Mac OS or Linux type*: **python3 write-json-to-file.py**
8686
5. The program should execute or display an error message.
8787

8888

labs/coding-206-logging/2.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ The default level is **WARNING**, which means that only events of this level and
3434
### Give it a try!
3535

3636
To run this code sample:
37-
1. Open a text editor.
37+
1. Open a text editor.
3838
* *On a DevNet Learning Lab PC*, open Notepad++ (Start Menu -> Notepad++)
3939
3. Create a folder for this lab.
40-
* *On a DevNet Learning Lab PC*, create a folder in "C:\Coding-101\yourname".
40+
* *On a DevNet Learning Lab PC*, create a folder in "C:\Coding-206\yourname".
4141
6. Copy/paste the code above into your new file.
4242
7. Save the file with the extension **.py** in your new directory. For example, **simple-logging.py**.
4343
8. Open a command prompt.
4444
* *On a DevNet Learning Lab PC*, (Start --> Command Prompt)
4545
9. At the command line, go to the directory where you saved the **simple-logging.py** file.
46-
* *On a DevNet Learning Lab PC*, **cd C:\Coding-101\yourname**
46+
* *On a DevNet Learning Lab PC*, **cd C:\Coding-206\yourname**
4747
10. Type the python command and then the filename at the command prompt, and hit return.
4848
* *On Windows*, **py -3 simple-logging.py**
4949
* *On Mac OS or Linux*, **python3 simple-logging.py**
@@ -58,4 +58,4 @@ With the logging level set to 'info', you should see a result like this:
5858
![](/posts/files/coding-206-logging/step2b-results.jpg)
5959

6060
### Things to Try
61-
* Experiment with using the different levels to log and display messages
61+
* Experiment with using the different levels to log and display messages

labs/coding-206-logging/3.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ Let's look at what is going on in the code.
2222
### Give it a try!
2323

2424
To run this code sample:
25-
1. Open a text editor.
25+
1. Open a text editor.
2626
* *On a DevNet Learning Lab PC*, open Notepad++ (Start Menu -> Notepad++)
2727
3. Create a folder for this lab.
28-
* *On a DevNet Learning Lab PC*, create a folder in "C:\Coding-101\yourname".
28+
* *On a DevNet Learning Lab PC*, create a folder in "C:\Coding-206\yourname".
2929
6. Copy/paste the code above into your new file.
3030
7. Save the file with the extension **.py** in your new directory. For example, **logging-step3.py**.
3131
8. Open a command prompt.
3232
* *On a DevNet Learning Lab PC*, (Start --> Command Prompt)
3333
9. At the command line, go to the directory where you saved the **logging-step3.py** file.
34-
* *On a DevNet Learning Lab PC*, **cd C:\Coding-101\yourname**
34+
* *On a DevNet Learning Lab PC*, **cd C:\Coding-206\yourname**
3535
10. Type the python command and then the filename at the command prompt, and hit return.
3636
* *On Windows*, **py -3 logging-step3.py**
3737
* *On Mac OS or Linux*, **python3 logging-step3.py**
@@ -45,4 +45,4 @@ Now open the file **mylog.log**. You should see a result like the following:
4545

4646
### Things to Try
4747
* Experiment with using the different levels to log and display messages
48-
* Try running the program multiple times. Is the log file overwritten or appended to?
48+
* Try running the program multiple times. Is the log file overwritten or appended to?

labs/coding-206-logging/4.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ Let's look at what is going on in the code.
2525
* We've add some new things to the **logging.basicConfig** statement.
2626
* **format='%(asctime)s %(levelname)s:** adds the time and level name to the front of each message
2727
* **datefmt='%m/%d/%Y %I:%M:%S %p'** specifies the date/time format to use when displaying the date.
28-
28+
2929
### Give it a try!
3030

3131
To run this code sample:
32-
1. Open a text editor.
32+
1. Open a text editor.
3333
* *On a DevNet Learning Lab PC*, open Notepad++ (Start Menu -> Notepad++)
3434
3. Create a folder for this lab.
35-
* *On a DevNet Learning Lab PC*, create a folder in "C:\Coding-101\yourname".
35+
* *On a DevNet Learning Lab PC*, create a folder in "C:\Coding-206\yourname".
3636
6. Copy/paste the code above into your new file.
3737
7. Save the file with the extension **.py** in your new directory. For example, **logging-step4.py**.
3838
8. Delete the **mylog.log** file that you created in the previous step.
3939
9. Open a command prompt.
4040
* *On a DevNet Learning Lab PC*, (Start --> Command Prompt)
4141
10. At the command line, go to the directory where you saved the **logging-step4.py** file.
42-
* *On a DevNet Learning Lab PC*, **cd C:\Coding-101\yourname**
42+
* *On a DevNet Learning Lab PC*, **cd C:\Coding-206\yourname**
4343
11. Type the python command and then the filename at the command prompt, and hit return.
4444
* *On Windows*, **py -3 logging-step4.py**
4545
* *On Mac OS or Linux*, **python3 logging-step4.py**
@@ -50,4 +50,4 @@ Now open the file **mylog.log**. You should see a result like the following:
5050
![](/posts/files/coding-206-logging/step4-results.jpg)
5151

5252
### Things to Try
53-
* Experiment with different format options - you can read more about the format options [here](https://docs.python.org/3/howto/logging.html#changing-the-format-of-displayed-messages).
53+
* Experiment with different format options - you can read more about the format options [here](https://docs.python.org/3/howto/logging.html#changing-the-format-of-displayed-messages).

0 commit comments

Comments
 (0)