Skip to content

Commit a428f5b

Browse files
realDuYuanChaogithub-actions
andauthored
development (#21)
* add logging * Formatted with psf/black * sets example * call external command * contains * Formatted with psf/black * to integer Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent d376ba1 commit a428f5b

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

basics/call_external_command.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def main() -> None:
2+
"""
3+
>>> import subprocess
4+
>>> _ = subprocess.run(["ls", "-l"])
5+
"""
6+
7+
8+
if __name__ == "__main__":
9+
from doctest import testmod
10+
11+
testmod()

basics/log_example.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def main() -> None:
2+
import logging
3+
4+
logging.debug("Debugging information")
5+
logging.info("Informational message")
6+
logging.warning("Warning:config file %s not found", "server.conf")
7+
logging.error("Error occurred")
8+
logging.critical("Critical error -- shutting down")
9+
10+
11+
if __name__ == "__main__":
12+
main()

basics/sets_example.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def main() -> None:
2+
"""
3+
>>> languages = {"Python", "Java", "C", "JavaScript", "Python", "C"}
4+
>>> len(languages)
5+
4
6+
>>> "Java" in languages
7+
True
8+
>>> "Python" in languages
9+
True
10+
>>> "c" in languages
11+
False
12+
"""
13+
14+
15+
if __name__ == "__main__":
16+
from doctest import testmod
17+
18+
testmod()

maths/to_integer.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def to_integer(number_str: str) -> int:
2+
"""
3+
>>> to_integer("123")
4+
123
5+
>>> to_integer("3.14")
6+
3
7+
>>> to_integer("-123")
8+
-123
9+
>>> to_integer("-3.14")
10+
-3
11+
>>> to_integer("123a")
12+
Traceback (most recent call last):
13+
...
14+
ValueError: could not convert string to float: '123a'
15+
"""
16+
return int(float(number_str))
17+
18+
19+
if __name__ == "__main__":
20+
from doctest import testmod
21+
22+
testmod()

strings/contains.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def contains(main_str: str, sub_str: str) -> bool:
2+
"""
3+
>>> "a" in "abc"
4+
True
5+
>>> "bc" in "abc"
6+
True
7+
>>> "ac" in "abc"
8+
False
9+
>>> "" in "abc"
10+
True
11+
>>> "" in ""
12+
True
13+
"""
14+
return sub_str in main_str
15+
16+
17+
if __name__ == "__main__":
18+
from doctest import testmod
19+
20+
testmod()

0 commit comments

Comments
 (0)