Answers for "how to use file in python"

1

how to reference a file in python

with open("filename.txt","r") as f:
    contents = f.read()
Posted by: Guest on August-11-2020
1

how to open a file with python

x = open("filename.txt", "r")
print(x.read()) #if file is a txt file this will print the text
#Make sure the file is in the same directory as were your python file is opened in.
#you can also make a var out of your text by doing:
var = x.read() #or 
var = open("filename.txt", "r").read()
Posted by: Guest on December-03-2021

Code answers related to "how to use file in python"

Python Answers by Framework

Browse Popular Code Answers by Language