Answers for "user input and files python"

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

Python Answers by Framework

Browse Popular Code Answers by Language