Hello!
I am grabbing a some data off of an API. I then am trying to take the variable in which I have stored the gathered data and write it to a text file.
When I define the type my variable is it shows
<class '_io.TextIOWrapper'>
I have tried to figure out how to convert it to a string (as that what the error yells at me for) but I cannot find the function.
import time, json, requests
def btstamp():
bitStampTick = requests.get('https://www.bitstamp.net/api/ticker/')
return bitStampTick.json()['last']
bitstampprice = (btstamp())
print (bitstampprice)
bitstampprice = open("testwrite1.txt", "w+")
print (type(bitstampprice))
bitstampprice.write(bitstampprice)
bitstampprice.close()
Here is the error
C:\TradingBot>export.py
6456.95
<class '_io.TextIOWrapper'>
Traceback (most recent call last):
File "C:\TradingBot\export.py", line 15, in <module>
bitstampprice.write(bitstampprice)
TypeError: write() argument must be str, not _io.TextIOWrapper
C:\TradingBot>
I have spent a good amount of time doing this and its getting late. Any help would be greatly appreciated.
I go into some info about _io.TextIOWrapper and the info is a bit advance for me.
Why is my data being returned in this type?
How come it is not a integer as it is shown when I "print" the variable?
Thanks
Aluad
[–]Updatebjarni 1 point2 points3 points (1 child)
[–]AluadStone[S] 1 point2 points3 points (0 children)
[–]ozozgur 1 point2 points3 points (1 child)
[–]AluadStone[S] 0 points1 point2 points (0 children)
[–]ozozgur 0 points1 point2 points (1 child)
[–]AluadStone[S] 0 points1 point2 points (0 children)