Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 42fc183

Browse files
committedDec 20, 2023
Add changes to File IO lesson, readme and whats next section
1 parent 2914d21 commit 42fc183

File tree

12 files changed

+105
-50
lines changed

12 files changed

+105
-50
lines changed
 
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This is the entire file.
1+
outfile.txt

‎File input output/Open file/open_file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55

66
with open('input1.txt', 'r') as file:
7-
print(file.read())
7+
outfile_name = file.readline()
88

99

10-
outfile = open('outfile.txt', 'w') # Opening the file in write mode (using `w` argument)
10+
outfile = open(outfile_name, 'w') # Opening the file in write mode (using `w` argument)
1111
outfile.write('Hello World') # Writing to the file, the write() method is explained later.
1212
outfile.close()
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
type: edu
22
files:
3-
- name: open_file.py
4-
visible: true
5-
placeholders:
6-
- offset: 152
7-
length: 37
8-
placeholder_text: '# Open the file input1.txt in read mode using the with statement'
9-
- offset: 397
10-
length: 15
11-
placeholder_text: '# Close the output file!'
12-
- name: input.txt
13-
visible: true
14-
- name: input1.txt
15-
visible: true
16-
- name: tests/__init__.py
17-
visible: false
18-
- name: tests/test_task.py
19-
visible: false
20-
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=File+Input+Output+/+Open+file
3+
- name: open_file.py
4+
visible: true
5+
placeholders:
6+
- offset: 152
7+
length: 37
8+
placeholder_text: '# Open the file input1.txt in read mode using the with statement'
9+
- offset: 242
10+
length: 12
11+
placeholder_text: ???
12+
- offset: 408
13+
length: 15
14+
placeholder_text: '# Close the output file!'
15+
- name: input.txt
16+
visible: true
17+
- name: input1.txt
18+
visible: true
19+
- name: tests/__init__.py
20+
visible: false
21+
- name: tests/test_task.py
22+
visible: false
23+
feedback_link: https://docs.google.com/forms/d/e/1FAIpQLSfRlDlldKfuq-cHMNFfHMER61P1PRIan7KG6yp1GvaweDI7GA/viewform?usp=pp_url&entry.2103429047=File+Input+Output+/+Open+file

‎File input output/Open file/task.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ True
2828
**Important**: If you’re not using the `with` keyword, then you should call `f.close()` to close the file and
2929
free up any system resources used by it. You cannot use the file object after it is closed, whether by a `with` statement or by calling `f.close()`.
3030

31-
In the code editor, open the file `input1.txt` in read mode properly using the `with` statement. Check out the
32-
name that is used for the file on the next line and use it. Afterwards, close the output file `outfile` that was opened.
31+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/8691).
32+
33+
### Task
34+
- In the code editor, open the file `input1.txt` in read mode properly using the `with` statement. `input1.txt` file stores the name of the file where the string `Hello World` should to be output. Reading this name is already implemented in the `outfile_name` variable.
35+
- Open the file with `outfile_name` name in writing mode
36+
- Afterward, close the output file that was opened.
3337

3438
After running your code, check out the output file that appeared in the course view among the other files.
3539

‎File input output/Open file/tests/test_task.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ def test_out(self):
1111
from open_file import outfile
1212
output = f.getvalue().split('\n')
1313

14-
expected, actual = 8, len(output)
14+
expected, actual = 6, len(output)
1515
self.assertEqual(expected, actual, msg='Please do not remove or add any print statements.')
1616
self.assertTrue(outfile.closed, msg='The outfile file is not closed.')
17+
with open('outfile.txt', 'r') as file:
18+
hello = file.readline()
19+
self.assertEqual('Hello World', hello, msg='Please do not remove write Hello World instruction')
1720

1821
except ImportError:
1922
self.assertTrue(False, msg='Please do not rename any variables.')
2023

2124
except NameError:
2225
self.assertTrue(False, msg='You should open input1.txt as a file.')
2326

27+
except FileNotFoundError:
28+
self.assertTrue(False, msg='Output file name should be used from outfile_name variable.')

‎File input output/Read all lines/task.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
### Task
44
Read all lines from the file input.txt into the list called `lines_list`. There are at least two different ways to do it.
55

6+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/8139#readlines).
7+
68
<div class="hint">Two possible solutions are discussed in the previous task.</div>

‎File input output/Read file/task.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ Second line of the file
5050

5151
If you want to read all the lines of a file in a list, you can also use `list(f)` or `f.readlines()`.
5252

53-
5453
For more details, check out the section [Methods of File Objects](https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects) in Python Tutorial.
5554

55+
For more structured and detailed information, you can also refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/8139).
5656

57+
### Task
5758
Print the contents of "input.txt" to output by iterating over the lines of the file and printing each one.
5859
Then print only the first line of "input1.txt".
5960

‎File input output/What next/task.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
Congratulations, you made it to the end of the course! We hope you enjoyed it.
22

3+
### Feedback
4+
We would really appreciate it if you could take a few minutes to answer [our survey](https://surveys.jetbrains.com/s3/course-feedback-python-intro). Your feedback will help us improve this course and make it relevant for future students.
5+
36
If you would like to leave general feedback – write us a review on the course’s Marketplace [page](https://plugins.jetbrains.com/plugin/16630-introduction-to-python/reviews).
4-
If you want to contribute, feel free to create a pull request or an issue in the course’s [GitHub repo](https://github.com/jetbrains-academy/introduction_to_python).
57

68
### What next?
7-
89
Now that you’ve explored the basics of Python programming, you can dive deeper and polish your new skills! Here are some options for you:
910
- Learn about the most widely used Python library with our [course on NumPy](https://plugins.jetbrains.com/plugin/18302-python-libraries--numpy).
1011
- Find out how to build an [AMazing](https://plugins.jetbrains.com/plugin/17519-amazing) maze with Python.
1112
- Discover the basics of [Machine Learning](https://plugins.jetbrains.com/plugin/18392-machine-learning-101).
1213
- Check out the projects in the [Python Core](https://hyperskill.org/tracks/2) or [Python for Beginners](https://hyperskill.org/tracks/6) track at JetBrains Academy on Hyperskill.
1314

15+
You can also find a huge number of other courses in the [JetBrains Academy catalog](https://academy.jetbrains.com/)!
16+
1417
Stay tuned for new courses and updates!
18+
19+
### Several reasons to try JetBrains Academy now
20+
- At the moment, 37 Python projects and 348 topics are available for learning, and the number keeps growing.
21+
Other programming languages, such as Kotlin and Java, are also available.
22+
- Projects of varying difficulty levels provide a flexible learning experience for all.
23+
- Comprehensive learning tracks are augmented with a detailed [Knowledge Map](https://hyperskill.org/knowledge-map?utm_source=ide&utm_medium=ide&utm_campaign=ide&utm_content=last-task).
24+
- Learn anywhere: you can start learning on your tablet or mobile phone via a browser and continue on your
25+
laptop or PC; you can even build the projects [right in your IDE](https://hyperskill.org/plugin#python?utm_source=ide&utm_medium=ide&utm_campaign=ide&utm_content=last-task).
26+
27+
### Contribution
28+
If you want to contribute, feel free to create a pull request or an issue in the course’s [GitHub repo](https://github.com/jetbrains-academy/introduction_to_python).

‎File input output/Write to file/task-info.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ files:
77
placeholders:
88
- offset: 74
99
length: 3
10-
placeholder_text: add modifier
10+
placeholder_text: modifier
1111
- offset: 89
1212
length: 33
13-
placeholder_text: "# On a new line in \"output.txt\", add all elements from the\
14-
\ zoo list, joined by \" and \""
13+
placeholder_text: "# Write a new line symbol into a file and all elements from the zoo list, joined by \" and \""
1514
- offset: 127
1615
length: 27
17-
placeholder_text: '# Add the number to the output as well'
16+
placeholder_text: '# Write a new line symbol and number-variable value into a file'
1817
- name: tests/__init__.py
1918
visible: false
2019
- name: tests/test_task.py

‎File input output/Write to file/task.md

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ f.write('\n' + 'string,' + ' ' + 'another string')
3636
```
3737
This will add a new line and write `'string, another string'`.
3838

39+
For more structured and detailed information, you can refer to [this Hyperskill knowledge base page](https://hyperskill.org/learn/step/8334).
40+
41+
### Task
3942
In the code editor, **append** one new line to `output.txt` with all elements from the `zoo` list separated by `' and '`.
4043
Use the <code>' and '.join(lst)</code> syntax to join the list elements into the required string. Afterwards,
4144
append another line with the `number` to the same output file.
@@ -44,20 +47,3 @@ append another line with the `number` to the same output file.
4447
<div class='hint'>Use the <code>write()</code> method.</div>
4548
<div class='hint'>Convert <code>number</code> into a string before writing.</div>
4649
<div class="hint">Add <code>\n</code> at the beginning of each string to write so that it eds up a separate line.</div>
47-
48-
49-
50-
## What's next?
51-
52-
Now, once you have mastered the basics of Python, we bet that you’re wondering what to do next.
53-
We recommend checking out [JetBrains Academy](https://hi.hyperskill.org?utm_source=ide&utm_medium=ide&utm_campaign=ide&utm_content=last-task).
54-
Here are several reasons to try JetBrains Academy now:
55-
56-
- At the moment, 37 Python projects and 348 topics are available for learning, and the number keeps growing.
57-
Other programming languages, such as Kotlin and Java, are also available.
58-
- Projects of varying difficulty levels provide a flexible learning experience for all.
59-
- Comprehensive learning tracks are augmented with a detailed [Knowledge Map](https://hyperskill.org/knowledge-map?utm_source=ide&utm_medium=ide&utm_campaign=ide&utm_content=last-task).
60-
- Learn anywhere: you can start learning on your tablet or mobile phone via a browser and continue on your
61-
laptop or PC; you can even build the projects [right in your IDE](https://hyperskill.org/plugin#python?utm_source=ide&utm_medium=ide&utm_campaign=ide&utm_content=last-task).
62-
63-
Join JetBrains Academy [here](https://hyperskill.org/onboarding?track=python&utm_source=ide&utm_medium=ide&utm_campaign=ide&utm_content=last-task) and try it yourself!

‎README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010

1111
<p>Have fun and good luck!</p>
1212

13-
<p>P.S. Want to contribute? Feel free to send a pull request to this course’s
14-
<a href=”https://github.com/jetbrains-academy/introduction_to_python”>git repo</a>.</p>
13+
## Want to know more?
14+
If you have questions about the course or the tasks or if you find some errors,
15+
you can ask questions and participate in discussions in repository [issues](https://github.com/jetbrains-academy/introduction_to_python/issues).
16+
17+
## Contribution
18+
Please be sure to review the [project's contributing guidelines](./contributing.md) to learn how to help the project.

‎contributing.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# What this repository is
2+
This repository contains sources of the Introduction to Python course.
3+
4+
# Contributing
5+
We love contributions!
6+
We are happy to see fixes of the existing bugs and tasks and tests mistakes.
7+
The current tasks can be found in the [open issues](https://github.com/jetbrains-academy/introduction_to_python/issues) in the project.
8+
If you have some questions or find bugs or mistakes, please do not hesitate to open new ones.
9+
10+
Please, add a comment to the issue, if you're starting work on it.
11+
12+
If you add some common functionality, e.g. for the test system, it is important to add comments to describe new behaviour.
13+
This will help other developers and users to use them correctly.
14+
15+
## Submitting patches
16+
The best way to submit a patch is to [fork the project on GitHub](https://help.github.com/articles/fork-a-repo/)
17+
and then send us a [pull request](https://help.github.com/articles/creating-a-pull-request/)
18+
to the `master` branch via [GitHub Pull requests](https://github.com/jetbrains-academy/introduction_to_python/pulls).
19+
20+
If you create your own fork, it might help to enable rebase by default
21+
when you pull by executing
22+
``` bash
23+
git config --global pull.rebase true
24+
```
25+
This will avoid your local repo having too many merge commits
26+
which will help keep your pull request simple and easy to apply.
27+
28+
## Checklist
29+
Before submitting the pull request, make sure that you can say "YES" to each point in this short checklist:
30+
31+
-[ ] You provided the link to the related issue(s) from the repository;
32+
-[ ] You made a reasonable amount of changes related only to the provided issues;
33+
-[ ] You can explain changes made in the pull request;
34+
-[ ] You ran the build locally and verified new functionality/fixed bugs;
35+
-[ ] You ran related tests locally (or add new ones) and they passed;
36+
-[ ] You do not have merge conflicts in the pull request.
37+
-[ ] You've made sure that all tests in [GitHub Actions](https://github.com/jetbrains-academy/introduction_to_python/tree/master/.github/workflows) pass

0 commit comments

Comments
 (0)