split python file into different data types

##Write a Python program to create a file of elements of any data type (mixed data type, i.e. some  elements maybe of type int, some elements of type float and some elements of type string). Split  this file into three file containing elements of same data type (i.e. 1st file of integers only, 2nd file of float only and 3rd file of strings only). Take input from the user to create the file.  
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())

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source