Answers for "how to input file in python"

19

python write to file

with open(filename,"w") as f:
  f.write('Hello World')
Posted by: Guest on March-30-2020
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
5

python write to file

path = "guide/README.txt" # The path of your file should go here
with open(path, "w") as fil: # Opens the file using 'w' method. See below for list of methods.
  fil.write("This is the README. It is reccomended that you read it.") # Writes to the file used .write() method
  fil.close() # Closes file
'''
List of methods:
w* - replace everything with needed text
r^ - read the file
a* - adds to file
x - creates file

* Creates file if the file at that path does not exist
^ Throws error if file does not exist
'''
Posted by: Guest on October-18-2020
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 input file in python"

Python Answers by Framework

Browse Popular Code Answers by Language