Weekly Notes - Interpreter - 3 PDF

Title Weekly Notes - Interpreter - 3
Course Python Programming
Institution City College of San Francisco
Pages 1
File Size 35.4 KB
File Type PDF
Total Downloads 61
Total Views 130

Summary

Aaron Brick...


Description

CS131A

3

Weekly notes

2017

Interpreter

Key terms: python3 >>> .py # import Reading: Severance 1 Exercise: Write a program that prints out the address of a restaurant you dislike. The more common implementation of the Python language is itself written in C and thus more specifically called CPython. On hills it is installed at /usr/local/bin/python3. The interpreter can be invoked in either an interactive, shell mode, or a batch, program mode. Expect to use both. The former, whose prompt is >>>, is good for manual testing and quick checks. There is a taxonomy of packages with useful content which we can access by importing those packages. [abrick@hills cs131a]$ python3 Python 3.4.1 (default, Aug 4 2014, 13:12:43) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.localtime().tm_year 2016 >>> exit Use exit() or Ctrl-D (i.e. EOF) to exit >>>

The batch mode runs whole programs at once. Your program must have a name different from all the language keywords and modules you are using, or the interpreter may favor your definition over its own, breaking everything. Program names should end in .py. In the simple case the interpreter is invoked by name (the shell knows where it’s located). For ultimate convenience, a program beginning with a hashbang, #!, line, and being set as executable can be run without any other name. The ./ fragment of the pathnames explicitly locates these programs in the current directory, rather than anywhere else a program might have that name. [abrick@hills cs131a]$ python3 ./estimate_earth_mass.py According to my calculations, earth mass is about 6 x 10ˆ27 grams [abrick@hills cs131a]$ head -n 1 ./estimate_earth_mass.py #!/usr/local/bin/python [abrick@hills cs131a]$ chmod u+x ./estimate_earth_mass.py [abrick@hills cs131a]$ ./estimate_earth_mass.py According to my calculations, earth mass is about 6 x 10ˆ27 grams [abrick@hills cs131a]$

Next, we will address the basic object types.

Brick...


Similar Free PDFs