G
G
George1232016-08-30 20:54:56
Python
George123, 2016-08-30 20:54:56

How to open txt files in python program?

Hello!
Help me please. I am trying to figure out how to open files through Python. I tried the options that were suggested on the Internet, but they did not work. (for example)
f = open('text.txt')
f.read()
Explain me how open at least text files. I would be very grateful.
PS
I'm very sorry for the stupid questions, but, alas, I have nowhere else to turn. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Vladimir Martyanov, 2016-08-30
@vilgeforce

Did not work - how is it?

A
Alexey Cheremisin, 2016-08-30
@leahch

What might not work here?
Move to the directory where the file is

with open("Sante-1.csv") as f:
    r = f.read()
    print(r)

Or, whatever you like. And yes, you can specify the full path
f= open("/Users/leah/Documents/Sante-1.csv")
r = f.read()
print(r)

R
Rou1997, 2016-08-30
@Rou1997

Search for your version of Python, they vary.

D
Dimonchik, 2016-08-30
@dimonchik2013

https://pythonworld.ru/tipy-dannyx-v-python/fajly-...

K
Kirill Romanov, 2016-08-30
@Djaler

Perhaps the author expects the specified file to open in some text editor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question