Python Adventures – 05

Following the free E-book Learning Python the Hard Way and getting down the basics of Python. In Exercise 1: A Good First Program
it’s how to write your very first Hello World! program.

 

Bring up Canopy in Ubuntu or Windows and start a new script.

 

# -*- coding: utf-8 -*-

print “Hello there world!”

print “Hello back to you!”

print “I like typing with you.”

print “Typing back is fun.”

print ‘Yay! Printing lines with Python.’

print ‘Um, I’m not touching “that!”‘

print ‘I thought you “liked” Pythons? “wink, wink, nudge nudge” ‘

print ‘The language Python and that dear Sir is definitely not a “Python”!’

 

If all goes well you should see a similar result:


 

My PowerShell acted a little funny and changed some characters:


 

However, with the assistance of a colleague with ServerCare.nl, a PowerShell Guru. I learned an important lesson. Characters might look the same but are not. For instance the < ” > I used versus what is on a website. I tried at first to type out the script but it didn’t work. I kept getting syntax errors. I copied from the exercise website, it worked in Canopy. I rewrote everything except the quote structure, it worked in Canopy. When I ran it in PowerShell, strange characters. As in real life, one sometimes must employ escape techniques around a Python. These are called escape characters so a “double quote is just a” .

 

The corrected Python:

# -*- coding: utf-8 -*-

print “Hello there world!”

print “Hello back to you!”

print “I like typing with you.”

print “Typing back is fun.”

print ‘Yay! Printing lines with Python.’

print “Um, I\’m not touching that!”

print “I thought you \”liked\” Pythons? \”wink, wink, nudge nudge\” ”

print ‘The language Python and that dear Sir is definitely not a \”Python\”!’

 

The corrected PowerShell output:


 

I had to jump ever so slightly beyond this exercise to Exercise 10: What Was That? To get a better handle on escape characters.

 

Off to the next exercise and adding in fun with data.

 

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: