Answers for "how to take input from user in python in files"

2

file input python

# import fileinput 
import fileinput 
  
# Using fileinput.input() method 
for line in fileinput.input(files ='gfg.txt'): 
    print(line)
Posted by: Guest on February-19-2021
0

how to write user input to a file in python

#Print User Input to A File
x = input("Enter blah : ")
y = open('C:UsersUSERNAMEDocumentsDoc1.txt', 'w')
y.write(x)

#Convert text to binary and then write to file
x = input("Enter blah : ")
y = open('C:UsersUSERNAMEDocumentsDoc1.txt', 'wb')
y.write(x)
Posted by: Guest on June-24-2020

Code answers related to "how to take input from user in python in files"

Python Answers by Framework

Browse Popular Code Answers by Language