Examples

Let’s take a look at some code examples, and how you’d create them with voice.

Requests

Here’s a function that makes a GET request using the requests module:

import requests


def get(url):
    r = requests.get(url)
    return r.text

To code this with voice, you can say:

add import requests
add function get
add parameter url
add r equals requests dot get of url
add return r dot text

Flask

Here’s Flask’s hello world example:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return 'hello world'

To code this with voice, you can say:

add from flask import capital flask
add app equals capital flask of double underscores name
add function hello
add return in quotes hello world
add decorator app dot route of in quotes slash

Django Model

Here’s an example Django model:

from django.db import models

class MyModelName(models.Model):
    my_field_name = models.CharField(max_length=20)

To code this with voice, you can say:

add from django dot db import models
add class my model name
add parent models dot capital model
add my field name equals models dot pascal case char field of max length equals twenty

Fizzbuzz

Here’s a simple fizzbuzz implementation:

for number in range(5):
    if number % 3 == 0 and number % 5 == 0:
        print('fizzbuzz')
    elif number % 3 == 0:
        print('fizz')
    elif number % 5 == 0:
        print('buzz')
    else:
        print(number)

To code this with voice, you can say:

add for number in range of five
add if number mod three double equals zero and number mod five double equals zero
add print in quotes fizzbuzz
add else if number mod three double equals zero
add print in quotes fizz
add else if number mod five double equals zero
add print in quotes buzz
add else print number

Editing

Let’s start with the following code.

def test():
    print('hello')
    return 5

You can use the change command to replace code. For instance, if you put your cursor on the word test and say:

change word to get

That should produce:

def get():
    print('hello')
    return 5

If you want this function to return 10 instead, you can say:

change return value to ten

That should produce:

def get(value):
    print(value)
    return 10

If you want to have this function take a parameter called value, you can say:

add parameter value

That should produce:

def get(value):
    print('hello')
    return 10

If you want to change this code to print value instead of hello, you can say:

change argument to value

That should produce:

def get(value):
    print(value)
    return 10

If you want to add another argument to the call to print, you can say:

add argument in double quotes test

That should produce:

def get(value):
    print(value, "test")
    return 10

To delete the last line of this function, you could say:

delete line 3

That should produce:

def get(value):
    print(value, "test")

To copy the print call, you could say:

copy line

Followed by:

paste

To produce:

def get(value):
    print(value, "test")
    print(value, "test")