Search code examples
pythonslackslack-api

Message sent to slack channel using python script is not properly aligned


I am trying to send a message to a Slack channel using a python script. The message gets delivered to the slack channel however I see the formatting of the next is not correct.

Given below is my Dataframe but when this get sent to the slack channel the text is not properly aligned.

name, sales_prct,return_prct
product_id_1234567, 45%, 2%
product_id_45764333, 65%, 12%
product_id_675335, 42%, 7%

Solution

  • To format the text in slack we are supposed to use triple backquotes "```" before and after the text. So you can format your string in python as follows:

    message = f"Hello, given below is the summary ```{df}```"