import ast
str_number = '58'
print(ast.literal_eval(str_number))
# output: 58 - <type 'int'>
str_dict = '{"name": "vasya", "age": 30}'
print(type(ast.literal_eval(str_dict)))
# output: {"name": "vasya", "age": 30} - <type 'dict'>
w2 = "космодром"
with open("base.txt") as bh:
lines = [line for line in bh]
with open("base.txt", "w") as bh, open("deleted.txt", "w") as dh:
handler = {True: dh, False: bh}
for line in lines:
handler[w2 in line].write(line)
w3 = None if dh.tell() else w2