Help with AlphaVangtage output (removing page breaks in csv output)

I am trying to learn python on my own to program some stock screeners. At the moment I am stumped. I am using output from AlphaVantage to get data on stock options. The problem is I keep getting page breaks in the output because the output is so, “wide.” Here is what I am getting (headers only, data omitted as it is not the problem)

contractID symbol expiration strike type last mark
bid bid_size ask ask_size volume open_interest date
implied_volatility delta gamma theta vega rho

I need it to look like this:
(Picture the headers all on one line as the screen here is not wide enough!)

contractID symbol expiration strike type last mark bid bid_size ask ask_size volume open_interest date implied_volatility delta gamma theta vega rho

I have tried:

data.replace(“\r”, " ")

but get “SyntaxError: unterminated string literal”

Thus I am assuming the "" is causing a carriage rerturn and needs to be removed but cannot seem to remove it!

What am I missing here? Am I just missing some syntax? Or am I using the wrong approach totally? Thanks in advance.

That snippet of code looks OK, but you haven’t shown it in context, so it might be something near there.

When you read a file in Python, the line endings get converted to '\n', so maybe you should be replacing '\n' instead of '\r'.

Try printing ascii(data) to see more clearly what the characters are.

Hello,

just note that

is not changing the value of the variable “data”. If you reassign it to itself, then it will be. The following highlights two scenarios (the first one is just printing the original value).

g = '\rglkjlgj'
print(g)             # print original

# Replace with '5' (note that the result is unchanged)
g.replace('\r', '5')
print(g)             # print after replacement to verify if changes were made

# Make replacement but reassign it to itself to make change
g = g.replace('\r', '5')
print(g)
1 Like