split python file into different data types code example
Example: split python file into different data types
f = open('MixedFile.txt','w')
while True :
user = input("Enter Any Data Type Element :: ")
if user == 'end':
print('!!!!!!!! EXIT !!!!!!!!!!!!')
break
else :
f.write(user + '\n')
f.close()
f = open('MixedFile.txt')
a = []
a = f.read().split()
f.close()
fs = open ('StringFile.txt','w')
ff = open ('FloatFile.txt','w')
fn = open ('NumberFile.txt','w')
for i in a :
try:
int(i)
fn.write(i + '\n')
except:
try:
float(i)
ff.write(i + '\n')
except:
fs.write(i + '\n')
f.close()
fs.close()
fn.close()
ff.close()
print("reading................")
fs = open ('StringFile.txt','r')
ff = open ('FloatFile.txt','r')
fn = open ('NumberFile.txt','r')
print(fs.read())
print(fn.read())
print(ff.read())