Answers for "get data from file python"

73

python write to file

file = open(“testfile.txt”,”w”) 
 
file.write(“Hello World”) 
file.write(“This is our new text file”) 
file.write(“and this is another line.”) 
file.write(“Why? Because we can.”) 
 
file.close() 
Posted by: Guest on December-09-2019
1

how to write a python variable to a file

#use pickle

import pickle
dict = {'one': 1, 'two': 2}
file = open('dump.txt', 'w')
pickle.dump(dict, file)
file.close()

#and to read it again
file = open('dump.txt', 'r')
dict = pickle.load(file)
Posted by: Guest on May-04-2020
0

read a data file in python

import pandas as pd

df = pd.read_csv('data.csv')

print(df.to_string())
Posted by: Guest on April-21-2021

Code answers related to "get data from file python"

Python Answers by Framework

Browse Popular Code Answers by Language