Macintosh: Using TextWrangler to Develop Python Programs

Hello. Welcome to running Python
programs with TextWrangler on the Macintosh. So, I’m here on Google and
I’ve typed TextWrangler and I can just go to the
TextWrangler website. And we’re going to
download TextWrangler. and we’re playing
with usability. I guess we’ve got a nice
little download button here; download now. OK, so we’re going to download. Right there. That made that work. So here we come. OK, so now it’s downloaded
and is mounting up the image. And so I’ll come
over here and all we do is we drag the
TextWrangler into applications. And then since I’m not a
super user on this account, I have to authenticate,
which means I have to type an
account and a password. And I’ve already done
this once, and so I’m not going to bother copying it. So we’ll cancel this. But it will copy
in and then you’ll have TextWrangler installed. And I can close
all these windows. And you have TextWrangler. And I’m going to unmount
this TextWrangler drive. So I have a nice clean desktop. So I want to run TextWrangler. And the easiest way is to
start in with Spotlight and do TextWrangler and click on
TextWrangler when it comes up. And so it’s going to ask me
a few questions when we first start out. And it’s got this cool
little window here, which I’m going to close. That shows us recently
opened documents. And so I’m going to write
some Python code here. And I’m going to say
print hello world. Oops. I want to say hello world. And I’m going to save this
by saying File save as and I’m going to instead of
going straight to my desktop, you might have to push this
little button to see these, I’m going to make a
folder called assign0. And then inside
assign0 I’m going to name my file Now you’ll notice that this
assign0 appeared as soon as I made it in the
desktop, because this folder desktop under places is
the same as my desktop. So now I’m going
to save my file. And so you’ll
notice that it does what’s called syntax coloring. And shows me the fact that
it’s now got a double quoted string in Hello world. So now I’m going to run Python. Now there’s a couple
ways to do it. First I’ll show you the
built in one in TextWrangler. You go up to here,
pound exclamation and say run in terminal. And this will
start up a terminal and then run the Python
command interpreter and feed it our program. So we say run in terminal. And so there’s some stuff here. This is just sort
of cruddy overhead. But right here it basically
is my output for my program. And it says, oh, in the
file users demo desktop, we’ve got a syntax error
on line one, hello world. Invalid syntax. Now it doesn’t tell
us much about how we might fix this showing
just how not clever Python is, but it certainly knows
it we’ve made a mistake. But we know it’s in line
one so let’s go back and take a little more
closer, we meant to say print. So I forgot the t. So let’s go ahead and say t. And we’ll save it. I didn’t mean to lock it. I’ll just save it. File, save. And then I’ll run
it in Python again. Run in terminal. And then I see my
little Python output. So you’ve got to realize that
everything other than this bit here is the Python output. And I can make changes. I close each time. Hello there world. Oops. Hello there world. And I will use a shortcut. Now this command ask. There’s little apple symbol. Apple s will save it. So I’m not going to
actually save it. I’m just going to save
it with Command s. And then I’m going to run it. Oops, I didn’t mean
to run a debugger. No I do not want to do that. Close. Die. Again, I’m going to
run it in terminal. And then away we go. And you’ll see that my
program has changed. And so we can see that
I can run this program and change it over and over. Now after a while this
will get kind of tiring. I’ll hide the terminal. Get rid of it. And especially when you need
to be in a particular directory and if you’re opening
files, and so you’re going to want to run
the terminal by hand and learn a few
terminal commands. And so I’m going
to type terminal. Terminal is, we’ve
actually been using this but now I’m going to
open a separate one. And now I’m at this
command prompt where I can type commands. Let me make that a
little bit bigger. So you can see it better. And one of the commands
is ls, which stands for; I don’t know, list all
my files or something. In Windows this’d be
Derby, but in Unix it’s ls. And one of the
folders that I see is the desktop folder there. So I’m going to say cd desktop. And then I’m going to say ls. And you’ll see that I have
effectively this little folder I’ve got
there, is shown as one of the folders in
my desktop folder. So it’s a subfolder. So I’m going to go into a SS,
and zero, and do another ls. If you’re wondering
where you’re at you can always type this
command PWD, which stands for print working directory. So I’m in the main hard drive
under users, demo, desktop, assign0. And then within assign0, I’ve
got one file; If I want a little more
detail, I add minus l to my ls. And it can tell me that
it’s a file, how big it is, when it was created etc. Now if want to run this, I
simply type the command Python And Python says start
the Python interpreter and then feed it And then Python runs my little
program and gives me output. Now a couple of shortcuts. First shortcut. Hit the up arrow,
and you can hit the up arrow a couple of times. You can hit it couple times. I’m hitting up arrow,
then I’ll hit down arrow. I can run previous commands. OK? I can also type part of a
file name like Python fur and then hit Tab,
and it actually auto completes because
it knows the file name. It looks at the file
name and says oh, fur is the beginning of,
there’s only one file that begins with fur so
I’ll finish it for you. And so the command
line is pretty easy. So if you want to
make a change, you can just have the command line
sitting there in one window, and make a change. And I’m going to just
hit Command s to save it. And then I’m going to
come here and hit up arrow and I’m going to hit enter. So now I can make a mistake,
like a syntax error. I can hit Command s to save it. And I can go over here in an
up arrow and run it again. And it tells me whoa, line
two you’ve got a syntax error. And then I’ll go ahead and
fix this, print, sorry. And so now I’ve got valid
Python and if I hit up arrow, hit Enter. It says two lines; print, sorry. Now you’ll also
notice that it’s doing what’s called syntax coloring. It’s showing us what part’s
key words, what part’s not a key word. And I don’t know if
you noticed but when I had the mistake it was
black because blue means it’s a Python keyword,
print is just text so it doesn’t really know
what we meant by that. And then when I get the
syntax right turns blue. It’s not really
critical, it just helps you understand
what’s going on. Syntax coloring
gives you good clues. You can see what line you’re on. Down here in the lower left
hand corner, what line your on, what column your in. And that can actually help you
as you look at syntax errors when it tells you, ah. The syntax error is on line two. So that gives you a good
start using, downloading, and installing,
text edit and using it to do Python on Macintosh. Thank you.

25 thoughts on “Macintosh: Using TextWrangler to Develop Python Programs

  1. Thanks so much man. After 30 minutes in TextWrangler manual, I was no closer to getting my program to run. So big thanks from an old Vic-20 BASIC programmer getting back into programming with Python.
    As a side note to others. If you want to run a different version of Python, type python3.1 for example to run Python 3.1 (if installed). Otherwise it will run maybe an older version.

  2. Spent 2 hours on google trying to figure this out! With this video i just learned it in under 9 minutes,… thank you!

  3. I needed to select Python from the drop down list in the bottom right of the window for TW to understand it was python (and colour the text)

  4. It works! Thanks a lot 🙂

    Q: I tried python and got hello world and an answer to a sum OK – like yours, works fine.

    But when I tried python3.2 , I got syntax error at the closing " of "hello world" – any ideas?

    I had already downloaded 3.23 from Then when I tried python3.23 , I got bash command not found…

  5. This really is a good, simple video. Very helpful when I'm a) brushing up on coding for work and b) coding on my Mac for the first time 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *