# Help sending SMS with a variable in body of message

**URL:** <https://discuss.python.org/t/help-sending-sms-with-a-variable-in-body-of-message/25406>\
**Category:** Python Help\
**Created:** [April 2, 2023, 8:31pm UTC](https://discuss.python.org/t/help-sending-sms-with-a-variable-in-body-of-message/25406 "2023-04-02T20:31:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlcpy](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dlcpy](https://discuss.python.org/u/dlcpy)\
**Post date:** [April 2, 2023, 8:31pm UTC](https://discuss.python.org/t/help-sending-sms-with-a-variable-in-body-of-message/25406/1 "2023-04-02T20:31:08Z")

</div>

So I am using the code below to text me the price of a stock ticker symbol. The texting SMS message piece works fine. I also get the ticker symbol to output to the screen but I can not figure out how to add the variable to the body= section of code. If you notice I am trying to add the value of ‘market\_price’ to the body of the text message. Can someone tell me what is missing? Thank you!

```auto
import os
from twilio.rest import Client
import yfinance as yf

ticker = yf.Ticker('NLST').info
market_price = ticker['regularMarketPrice']
previous_close_price = ticker['regularMarketPreviousClose']
print('Ticker: NLST')
print('Market Price:', market_price)
print('Previous Close Price:', previous_close_price)

account_sid = os.environ['TWILIO_ACCOUNT']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
message = client.messages \
                .create(
                     body="Nestlist stock price is {'market_price'}",
                     from_='+18886103854',
                     to='6786555555'
                 )
 
print(message.sid)

```

---

<div class="post-metadata">

**Author:** ![barry-scott](https://avatars.discourse-cdn.com/v4/letter/b/e9c0ed/32.png) [@barry-scott](https://discuss.python.org/u/barry-scott)\
**Post date:** [April 2, 2023, 8:46pm UTC](https://discuss.python.org/t/help-sending-sms-with-a-variable-in-body-of-message/25406/2 "2023-04-02T20:46:28Z")

</div>

> [@dlcpy](#):
>
> `body="Nestlist stock price is {'market_price'}",`

You must put a f at the start of an string that {} is used for replacement.  
Also you do not need quotes around market\_price.

Here are examples:

```auto
:>>> market_price='$19.61'
:>>> print('The mark price {market_price}')
The mark price {market_price}
:>>> print(f'The mark price {market_price}')
The mark price $19.61
:>>> print(f"The mark price {'market_price'}")
The mark price market_price
:>>>

```

Does the create() method know what to replace the + with in the phone number?

---

<div class="post-metadata">

**Author:** ![dlcpy](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dlcpy](https://discuss.python.org/u/dlcpy)\
**Post date:** [April 3, 2023, 1:28am UTC](https://discuss.python.org/t/help-sending-sms-with-a-variable-in-body-of-message/25406/3 "2023-04-03T01:28:24Z")

</div>

> [@barry-scott](#):
>
> ```auto
> :>>> print(f'The mark price {market_price}')
> 
> ```

thank you! Yes this worked → ```  
:\>\>\> print(f’The mark price {market\_price}')

```auto

```
