Skip to content

Commit bd149df

Browse files
author
Holladworld
committed
magic string
1 parent 1d50191 commit bd149df

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/python3
2+
def magic_string():
3+
magic_string.count = getattr(magic_string, 'count', 0) + 1
4+
return ("BestSchool, " * (magic_string.count -1) + "BestSchool")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/python3
2+
magic_string = __import__('100-magic_string').magic_string
3+
4+
for i in range(10):
5+
print(magic_string())
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/python3
2+
'''Module that defines locked class'''
3+
4+
5+
class LockedClass:
6+
'''
7+
A class `LockedClass` with no class or object attribute, that prevents the user from dynamically creating new instance attributes, except if the new instance attribute is called `first_name
8+
'''
9+
__slots__ = ['first_name']
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/python3
2+
LockedClass = __import__('101-locked_class').LockedClass
3+
4+
lc = LockedClass()
5+
lc.first_name = "John"
6+
try:
7+
lc.last_name = "Snow"
8+
except Exception as e:
9+
print("[{}] {}".format(e.__class__.__name__, e))

0 commit comments

Comments
 (0)