'How to send the same word to each number using Twilio. I am importing random word from a text file to send to recipients

I am wanting to send the same random word from my text file to each recipient. Right now it sends a different random word to each phone number and I need it to be the same to all. I am using Twilio to send texts to numbers. Here is what I have tried below:

import os
from twilio.rest import Client
import random

# Open the file in read mode
with open("5words.txt", "r") as file:
    allText = file.read()
    word = list(map(str, allText.split()))

account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
family = {'+123456789', '+123456789','123456789','123456789','123456987','123456789'}
for number in family:
    client.messages.create(
         body=('Your word of the day is ' + random.choice(word)),
         from_='+12345678',
         to=(number)
     )


Solution 1:[1]

Set random.choice(word) to a variable before entering the for loop and use that variable name in the body of the text when calling the Twilio API.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alan