0

I've made a code where python reads from a file and then proceeds to print a specific line:

with open('crypto.txt') as f:
    lines = f.readlines(1)
crypto = str(lines)
print(crypto)

But the output is for example: ['bitcoin\n'] how do i remove ['\n'] to only get bitcoin as an output ?

I know that with f.read() there is no brackets and \n but I can't choose a specific line to read - or can I?

here is the txt file:

bitcoin
ethereum
cardano
sandbox
xtekky
  • 572
  • 1
  • 4
  • 13

1 Answers1

0

Foud the answer!

f = open('crypto.txt')
lines = f.readlines()
line = lines[0]
print(line)

output ex: bitcoin

xtekky
  • 572
  • 1
  • 4
  • 13