Start Using Python on Mac

Start IDLE from the terminal

To open IDLE:

  1. Open a terminal window.
  2. In the terminal window, issue the command idleX.Y (for example: idle2.7) to launch IDLE*.
  3. Click Python-> Preferences… Menu item.
  4. Click General
  5. In startup Preferences part, click Open Edit Window radio button.
  6. Click Ok

Then can see the edit window and edit your Python code in the edit window.

*Note: IDLE (Integrated Development Environment or Integrated Development and Learning Environment) is an integrated development environment for Python.

Create a folder for your own Python program file

To create a folder to save your Python program file:

  1. Go to Macintosh HD (your hard drive name. your hard drive might have a different volume name)
  2. Click Users folder
  3. Create a folder named python_code (you can use a different name for this folder).

The extension name for Python is .py.

Enter Python interpreter

  1. Click the edit window to activate editing window for Python
  2. Click Run-> Python Shell Menu item

Now you can see the windows of Python interpreter, and it is called Python version_nember Shell.

Try Some Simple Python command

You can try some command in the Python Shell window, and have a feeling how Python interpreter works.

For example:

Type:

>>> print (‘Hello’)

And type enter.

You will see:

Hello!

Type:

>>> print(‘Good Morning!’)

and enter.

You will see

Good Morning!

Create a python program file

Click the edit window to activate it. Type the following code:

print(‘Hello, morning!’)

x = 2

print(‘x = 2’)

y = 3

print (‘y = 3’)

z = x+y

print(‘Please tell me the result of s+y’)

print(‘The result of x+y is: ‘)

print(z)

Save the code into a file named mypython1.py into the folder python_code taht you created earlier.

Run a python program inside Python interpreter

Open your python interpreter. Type:

>>> execfile(‘/Users/python_code/mypython1.py’)

Then press enter.

You can see the result of your scripts like this:

>>> execfile(‘/Users/faqing/hello/mypython1.py’)

Hello, morning!

x = 2

y = 3

Please tell me the result of x+y

The result of x+y is:

5

>>>

Now you are able to open Python interpreter, writer a small Python program, run your Python program inside Python interpreter, and you can also run simple command inside Python interpreter.

Advertisements

About zephyr9000

Happy sailer
This entry was posted in Programming, Python and tagged , . Bookmark the permalink.

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