Thursday, September 23, 2010

Cool stuff for Mac

Hey guys,

Recently, I got a Mac. This means I'll be able to help a lot more with Mac problems on our author forums and on this blog. In related news, here's a cool trick for Macs only. You can make your program talk to you! Start by importing os. OS is a module that lets you interact with your computer's operating system. Then, type the following:

os.system("say Hello World!")

This will send a command to Mac OS telling it to, well, say, "Hello World!" You can put whatever you want after say. However, apostrophes (') don't seem to work. If you have one in your string, it won't say anything at all. Here's an example program:

import os
os.system("say Whats your name?")
#For some reason, apostrophes don't work.

name = raw_input("What's your name?")
# It's good to put it on the screen as well,
# in case users don't have their speakers on.

print "Hi, "+name+", hows it going?"
os.system("say Hi, "+name+", hows it going?")

I hope this brings a whole new level of interaction to all your future programs!

Carter Sande

5 comments:

  1. My nine year old son is having trouble running a couple of the modules. He keeps getting error messages. He's very frustrated. Is there somewhere where he can get help or contact you? Please help. He's working really hard and checking that all the input is added correctly. Awaiting your response. Thank you.

    ReplyDelete
  2. If you're having trouble, you can e-mail us at cp4khelp@yahoo.com or go to our author forum here .

    ReplyDelete
  3. The os.system() function interacts with the internal system,on Mac OS X it interacts with the kernel(Darwin/UNIX) and the terminal(/applications/utilities)lets you interact easily

    ReplyDelete
  4. is there any way that this can work on windows?
    email me at eliandkatie@acsalaska.net
    also... i'd like some help with PythonCard. Thanks!

    ReplyDelete

Note: Only a member of this blog may post a comment.