0% found this document useful (0 votes)
104 views

Make Python Tutorial

This document provides an introduction to Make and Python. It discusses what Make is and how it works, including how to write Makefiles and some key features of Make. It also discusses what Python is, some of its key features like simple syntax and extensive libraries, and covers basic Python concepts like variables, numbers, strings, lists, and dictionaries. The document provides examples of using these basic Python constructs.

Uploaded by

Ah-Ram Kim
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

Make Python Tutorial

This document provides an introduction to Make and Python. It discusses what Make is and how it works, including how to write Makefiles and some key features of Make. It also discusses what Python is, some of its key features like simple syntax and extensive libraries, and covers basic Python concepts like variables, numbers, strings, lists, and dictionaries. The document provides examples of using these basic Python constructs.

Uploaded by

Ah-Ram Kim
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

2009.1.

16

Make&Python

Make&PythonTutorial
AhRamKim ReinitzLab

Make&Python

WhatsMake?
Makeisacommandgenerator.Usingadescriptionfile(defaultname=makefile orMakefile),itcreatesasequenceofcommandsforexecutionbythe UNIX/LINUXshell.

WhyMake?
Evenrelativelysmallprojectstypicallyinvolveanumberoffilesthatdependupon eachotherinvariousways.e.g.Cprogramming:Ifyoumodifyoneormore sourcefiles,youmustrelinktheprogramafterrecompilingsomebutnot necessarilyallofthesources.Itisthisprocessthatmakegreatlysimplifies. Yourecordonceandforalltherelationshipsamongasetoffilesandthenlet makeautomaticallyperformallupdatingtaskveryeasily.

e.g.maketransc

Make&Python

Background:Asimplecompilation

Imagefromhttp://www.eng.hawaii.edu/Tutor/Make

1.Compilerstage:.cfileisconvertedintoalowerlevellanguagecalledAssembly language;making.sfiles. 2.Assemblerstage:.sfileisthenconvertedintoobjectcode(.o)whichare fragmentsofcodewhichthecomputerunderstandsdirectly. 3.Linkerstage:Linkingthe.ofiletocodelibrarieswhichcontaincertain"builtin" functions,suchasprintf.Thisstageproducesanexecutableprogram,herea.out

Command:cc/gcc/iccfile.c

Make&Python

Background:Compilingwithseveralfiles

Thethreedifferenttasksrequiredtoproducetheexecutableprogram: cccgreen.c cccblue.c ccgreen.oblue.o


Make&Python

Background:Dependencies
e.g.main.odependson data.h main.c io.h 4differenttasksrequired cccmain.c cccdata.c cccio.c ccoproject1data.omain.oio.o Ifyouusemake,thensimply

makeproject1

Make&Python

Background:Dependencies
e.g.main.odependson data.h main.c io.h Ifmain.cisedited,youshould cccmain.c ccoproject1data.omain.oio.o

Make&Python

Background:Dependencies
e.g.main.odependson data.h main.c io.h Ifmain.cisedited,youshould cccmain.c ccoproject1data.omain.oio.o Ifyouusemake,then makeproject1

Make&Python

HowtowriteMakefile(ormakefile)?
target:sourcefile(s) command(mustbeprecededbyatab) project1:data.omain.oio.o ccoproject1data.omain.oio.o data.o:data.cdata.h cccdata.c main.o:data.hio.hmain.c cccmain.c io.o:io.hio.c cccio.c Tip:Touseotherfilesuchasxfile, e.g.makefxfileproject1

Determining dependencies

Make&Python

Features
Macro(byyourself) OBJECTS=data.omain.oio.o project1:$(OBJECTS) ccoproject1$(OBJECTS) sameas $@:fullnameofthecurrenttarget project1:data.omain.oio.o ccoproject1data.omain.oio.o Tip:Macroonthecommandline e.g.makeCC=gccproject1 $<:sourcefileofthecurrent dependency

Builtinmacro CC:containscurrentCcompiler CFLAGS:additionaloptionstobuiltin Crule

$?:alistofprerequisitesnewerthan currenttarget

Make&Python

Predefinedrules
SuffixRule: Inordertocreateaxxx.ofile,use$(CC)$(CFLAGS)conthecorrespondingxxx.c file. e.g.data.o:data.h sameas data.o:data.cdata.h $(CC)$(CFLAGS)cdata.c

Make&Python

Fullvs.Simplifieddescription
POBJ=data.omain.oio.o project1:$(POBJ) cco$@$(POBJ) data.o:data.h main.o:data.hio.h io.o:io.h

project1:data.omain.oio.o ccoproject1data.omain.oio.o data.o:data.cdata.h cccdata.c main.o:data.hio.hmain.c cccmain.c io.o:io.hio.c cccio.c POBJ=data.omain.oio.o project1:$(POBJ) cco$@$(POBJ) project1:data.hio.h

POBJ=data.omain.oio.o project1:$(POBJ) cco$@$(POBJ) data.omain.oio.o:data.hio.h

Make&Python

Realexample:Makefilefortransc

Make&Python

WhatsPython?(wasbornin1989Christmas)

Pythonisainterpretedprogramminglanguage.Ithasvariousbuiltindatastructures anditisobjectoriented.Python'selegantsyntaxanddynamictyping,togetherwith itsinterpretednature,makeitagoodlanguageforscriptingandrapidapplication developmentinmanyareasonmostplatforms.

Make&Python

Howdiditworkforme?

TSV/TXPLOTandsoon..

Make&Python

Keyfeatures
1.Simpleandreadablesyntax 2.Interpretedlanguage 3.Platformindependent(Linux,Unix,Windows,MacOS,Dos,Amiga) 4.Designedforrapiddevelopment 5.Supportsbothprocedureorientedandobjectorientedprogramming 6.Extensible:e.g.UseofCmodulesinpythonscriptforfastrun 7.Embeddable:pythonscriptinC/C++programs 8.Extensivelibraries:forDB,CGI,ftp,XML,GUIandsoon 9.Automaticmemorymanagementbyreferencecounting 10.SupportsCstylebitwiseshifting&masking:<<,>>,&,|,^,~

Make&Python

Basicgrammar

1. No semi-colon 2. No declaration, No data type definition 3. Grouping of statements by indentation, NOT by curly braces { } 4. # for single line comments, for multiline comments 5. \ for explicit line joining 6. Variable only refers to the object and does not represent the object itself! 7. Five data types: - Numbers - Strings - Lists - Tuples e.g. 123, 12345L, 1.43, 5+4j e.g. ham, egg, milk e.g. [ham,egg,3] e.g (ham,egg,3) e.g. {ham:4,egg:5}

- Dictionaries

8. import libraries and your own modules using import

Make&Python

Referencesinpython
a 1 2 3

Assignment manipulates references x = y does not make a copy of y x = y makes x reference the object y references Example: >>> a = [1, 2, 3] >>> b = a >>> a.append(4) >>> print b [1, 2, 3, 4] >>> c = b[:]

a 1 b a 1 b c 1 2 3 4 2 3 4 2 3

Make&Python

Numbers

1. int object (4 byte == long type in C) 2. long object (unlimited) 3. float object (8 byte == double type in C) 4. complex object (real = 8 byte, imaj = 8 byte) e.g >>a = 12345678L >>b = 4+5j >> b.real 4.0 >> b.imag 5.0

Make&Python

Strings
Result "helloworld" "hellohellohello" "h" "o" "ell" 5 1 1 1 # concatenation # repetition # indexing # (from end) # slicing # size # comparison # search # type

Operation "hello"+"world" "hello" * 3 "hello"[0] "hello"[-1] "hello"[1:4] len("hello") "hello" < "jello" "e" in "hello" "1235".isdigit()

Make&Python

Lists

Mutable and flexible arrays (Tuples are exactly same as Lists but immutable) a = [99, "bottles of beer", ["on", "the", "wall"]] Same operators as for strings a+b, a*3, a[0], a[-1], a[1:], len(a) Operation a[0] a[1:2] = ["bottles", "of", "beer"] del a[-1] a = range(5) a.append(5) a.pop() a.insert(0, 42) a.pop(0) a.reverse() a.sort() Result 98 [98, "bottles", "of", "beer", ["on", "the", "wall"]] [98, "bottles", "of", "beer"] [0,1,2,3,4] [0,1,2,3,4,5] [0,1,2,3,4] and returns 5 [42,0,1,2,3,4] [0,1,2,3,4] and returns 42 [4,3,2,1,0] [0,1,2,3,4]

Make&Python

Dictionaries

Hash tables, "associative arrays" dic = {key1:value1,key2:value2,...} d = {"duck": "eend", "water": "water"} Operation d["duck"] d["back"] del d["water"] d["back"] = "rug" d["duck"] = "duik" Result "eend" # raises KeyError exception {"duck": "eend"} {"duck": "eend", "back": "rug"} {"duck": "duik", "back": "rug"} # delete # insert # overwrite

Make&Python

Cvs.Python

Make&Python

Cvs.Python

e.g.test(10,3)returnsreferenceto[0,3,6,9] 0,1,2,3,4,5,6,7,8,9

You might also like