Len P
Len P

Reputation: 21

trying to put a line break (carriage return?) through tweepy

I have created a python script for sending a tweet out to twitter. I am having an issue with sending a carriage return / line break. Normally I would like the command \n in python but this doesn't work with tweepy and it send the text to twitter including the \n.

The end of my script looks like this:

phrase = "Hello World! \n I am sending a tweet from a bot!"    
api.update_status(phrase)

and the result on twitter is:

Hello World! \n I am sending a tweet from a bot!

and what I want is:

Hello World!    
I am sending a tweet from a bot!

How can I do this with my script?

Upvotes: 2

Views: 791

Answers (2)

Lucas Schneider
Lucas Schneider

Reputation: 1

I'm sorry for the late response, but I was struggling with this until I figured out the solution:

create_tweet(text=message.replace("\\n", "\n"))

That replaces the escaped newline with a true newline character. I haven't tested it out with api.update_status, but it still should work nevertheless.

Upvotes: 0

pigeonburger
pigeonburger

Reputation: 736

That's unusual, what you tried should be working.

For whatever reason, it doesn't seem to be. This should work instead:

phrase = """
Hello World!

I am sending a tweet from a bot!
"""    
api.update_status(phrase)

Upvotes: 2

Related Questions