Answers for "how to read data from file in python"

41

python read file

with open("file.txt", "r") as txt_file:
  return txt_file.readlines()
Posted by: Guest on November-30-2020
0

how to read a file in python

# How to read, and print to the screen a file in python!

f = open('fileName', 'r')
print(f.read())
f.close()

# Where "fileName" is obviously the name of your file that you want to read.
Posted by: Guest on August-29-2021
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 "how to read data from file in python"

Python Answers by Framework

Browse Popular Code Answers by Language