I would like to write a function to build a bytes type string that need to use f-string with different value. the only way I can think about is like following code. anyone have better suggestion? In code, I have string like I have level but in my actual code the string is about 600 charactors
def get_level_string(x):
size = dict(v1=1, v2= 200, v3= 30000)
s = size.get('v1')
name = lambda x: f"I have level value as {x} in the house"
return {
'level1': b'%a' % (name(size['v1'])),
'level2': b'%a' % (name(size['v2'])),
'level3': b'%a' % (name(size['v3'])),
}[x]
a = get_level_string('level1')
b = get_level_string('level2')
c = get_level_string('level3')
print(a, type(a))
print(b, type(b))
print(c, type(c))
=> #b"'I have level value as 1 in the house'" <class 'bytes'>
=> #b"'I have level value as 200 in the house'" <class 'bytes'>
=> #b"'I have level value as 30000 in the house'" <class 'bytes'>