builtin function or method is not subscriptable code example

Example 1: not builtin_function_or_method

# Imports
import speech_recognition as sr
import os
import time
import datetime
import warnings
import calendar
import subprocess
import sys
import random
import wikipedia
from gtts import gTTS

#Information
yourname = "Jimmy"
preferedname = "Boss"
myname = "vox"
datecreated = "28th November 2020"
timecreated = "15:53"

# Ignore warnings
warnings.filterwarnings('ignore')

# Get Audio Input
def getAudio():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...\n")
        audio = r.listen(source)

    data = ''

    try:
        data = r.recognize_google(audio)
        print('You said: ' +data)
    except sr.UnknownValueError:
        print("Speech Recognition failed to identify audio, Unknown Error.")
    except sr.RequestError as e:
        print("Request for results error: " +e)
    return data

# VOX Response
def voxResponse(text):
    print(text)

    voice = gTTS(text=text, lang='en', slow=False)
    voice.save('response.mp3')

    os.system('start response.mp3')

# Wake word
def wakeWord(text):
    WAKE_WORDS = ['hey vox', 'okay vox', 'vox'] # List of wake words

    text = text.lower()
    for phrase in WAKE_WORDS:
        if phrase in text:
            return True

    return False

# Get Date
def getDate():
    now = datetime.datetime.now()
    my_date = datetime.datetime.today()
    weekday = calendar.day_name[my_date.weekday]
    monthNum = now.month
    dayNum = now.day

    months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
    ordinalNumbers = ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th', '11th', '12th', '13th', '14th', '15th', '16th', '17th', '18th', '19th', '20th', '21st', '22nd', '23rd', '24th', '25th', '26th', '27th', '28th', '29th', '30th', '31st']

    return ('Todays date is '+weekday+' '+months[monthNum -1]+' the '+ordinalNumbers[dayNum -1]+'.')

print(getDate())

Example 2: 'builtin_function_or_method' object is not subscriptable

listb.pop()[0]

Tags:

Misc Example