I'm finally getting my robot's software off the ground!:) (Although I'm giving my "artificial learning" program a rest for later).

However, here's something I've been wondering how to do for quite some time now.

I'm using the time module to allow my robot to tell me the time upon vocal command. However, when my robot replies, the reply sounds something like this, "The time is currently Monday September eight 12 colon 46 colon 30 colon 2008." My robot vocalizes the "colon" in the time "12:46:30." So I tried to replace all colons with string.replace, like so:

import speech
import random
import sys, time, math, string

string = string.replace(":", " ")

TimeStr = [ "The time is currently " + time.asctime(), "Right now its " + time.asctime(), "It's " + time.asctime(), time.asctime() ]

if phrase == "whats the time":
    speech.say(random.choice(TimeStr))

but that gave an exception saying replace takes at least 3 arguments (2 given).
So after looking up help(replace) in the command line, I found out I had to list the string, so I rewrote the code like this:

import speech
import sys, time, math, string

string = string.replace(time.asctime(),":", " ")

TimeStr = [ "The time is currently " + time.asctime(), "Right now its " + time.asctime(), "It's " + time.asctime(), time.asctime() ]

if phrase == "whats the time":
    speech.say(random.choice(TimeStr))

After that the program runs, but my robot is still vocalizing the "colon" in time.asctime()!

I'm not sure where to go from here...

You want a separate string to hold the time

now=time.asctime()
now=now.replace(":", " ")
print now

TimeStr = [ "The time is currently " + now, "Right now its " + now, "It's " + now, now ]
 
if phrase == "whats the time":
    speech.say(random.choice(TimeStr))
#
##   you can also use datetime and access month, day, hour, etc individually
now = datetime.datetime.today()
print "\n", now
print now.year, now.hour

You could also make up your time string this way:

import time

time_str = time.strftime("%A %B %d %Y %H hours %M minutes and %S seconds",
    time.localtime())

print time_str  # Monday September 08 2008 17 hours 49 minutes and 38 seconds
This question has already been answered. Start a new discussion instead.