Write Python Code to Create file to Write The contents to file at the Run Time

 

Write Python Code to Create file to Write The contents to file at the Run Time


filename = input("Enter name of file: ")

contents = input("Enter contents of file: ")

 

with open(filename, 'w') as f:

    f.write(contents)

print("File created successfully.")

print("This is your file")

print(contents)

Output:

Enter name of file: myfile

Enter contents of file: This is file handling class. Python programming

File created successfully.

This is your file

This is file handling class. Python programming

टिप्पणी पोस्ट करा

0 टिप्पण्या