Skip to content

Commit 966cc18

Browse files
committed
stepic ex
1 parent 8b61c9c commit 966cc18

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

stepic/config.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[DEFAULT]
2+
UseTheForce = True
3+
UseTheLightSaber = True
4+
ForceReFill = 30
5+
LightSaberPower = 20
6+
7+
[Section 1]
8+
Title = "How to use the Force"
9+
10+
[Section 2]
11+
Title = "How to use the light saber"

stepic/config_files.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import configparser
2+
3+
parser = configparser.ConfigParser()
4+
5+
parser.read("config.cfg")
6+
7+
print(parser.sections())
8+
print(parser.has_section("Section 2"))
9+
10+
UseTheLightSaber = bool(parser['DEFAULT']['UseTheLightSaber'])
11+
print(UseTheLightSaber)
12+
print(type(UseTheLightSaber))
13+
14+
use_the_force = parser['DEFAULT'].getboolean('UseTheForce')
15+
print(use_the_force)
16+
# light_saber_power = parser['DEFAULT'].getfloat('LightSaberPower')
17+
# print(light_saber_power)
18+
19+
light_saber_power = parser['DEFAULT'].getint('LightSaberPower')
20+
print(light_saber_power)
21+
22+
try:
23+
title = parser['Section 3']['Title']
24+
print(title)
25+
except KeyError as err:
26+
print("No such thing as ", err)

stepic/file_op.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
fp = open("test.txt", "w")
3+
fp.write("test test test\n")
4+
fp.close()
5+
6+
with open("test.txt", "r") as fp:
7+
data = fp.read()
8+
print(data)
9+
10+
with open("test.txt", "a+") as fp:
11+
fp.write("added more tests\n")
12+
fp.seek(0)
13+
data = fp.read()
14+
print(data)

stepic/test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test test test
2+
added more tests

0 commit comments

Comments
 (0)