Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to reference a file in python

with open("filename.txt","r") as f:
    contents = f.read()
Comment

how to write a file in python

with open(file_path+file_name*, 'wb') as a:
    a.write(content)
    
# *example: r"C:UsersuserDesktophello_world.docx".
# 'hello_world' DOENT EXIST at the moment, python will automatically create it for us
Comment

how to file in python

Simple way to get a directory of a file and open it:
  
from tkinter.filedialog import askopenfilename

filename = askopenfilename()
Comment

write a file python

# read, write, close a file
# catch error if raise
try:
    file = open("tryCatchFile.txt","w") 
    file.write("Hello World")

    file = open("tryCatchFile.txt", "r")
    print(file.read())
except Exception as e:
    print(e)
finally:
    file.close()
Comment

PREVIOUS NEXT
Code Example
Python :: matplotlib increase tick frequency 
Python :: find the time of our execution in vscode 
Python :: plot second y axis matplotlib 
Python :: string formatting in python 
Python :: thread with args python 
Python :: python return min length of list 
Python :: mss python install 
Python :: plot using matplotlib 
Python :: python find in list 
Python :: convert list of list to list python 
Python :: print current line number python 
Python :: python code to print prime numbers 
Python :: the list of prime number in a given range python 
Python :: non-integer arg 1 for randrange() 
Python :: linspace python 
Python :: how to make a list using lambda function in python 
Python :: python get parent directory 
Python :: how to create a python script to automate software installation? 
Python :: how to find if the numpy array contains negative values 
Python :: make white image numpy 
Python :: Randint Random Library 
Python :: get number of zero is a row pandas 
Python :: how to display printed values without scientific notation python 
Python :: calculate distance in python 
Python :: settings urls 
Python :: pdf to csv 
Python :: remove tuple from list python 
Python :: kill python process with bash 
Python :: distance between numpy arrays 
Python :: get the last element from the list 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =