prg –programming essentials...2 administration 2 03/12/2017 michal reinštein, czech technical...

38
PRG – PROGRAMMING ESSENTIALS 1 Lecture 5 – Modules, Namespaces https://cw.fel.cvut.cz/wiki/courses/be5b33prg/start Michal Reinštein Czech Technical University in Prague, Faculty of Electrical Engineering, Dept. of Cybernetics, Center for Machine Perception http://cmp.felk.cvut.cz/~reinsmic/ [email protected] 03/12/2017 Michal Reinštein, Czech Technical University in Prague

Upload: others

Post on 02-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

1

PRG– PROGRAMMINGESSENTIALS1

Lecture5– Modules,Namespaceshttps://cw.fel.cvut.cz/wiki/courses/be5b33prg/start

MichalReinšteinCzechTechnicalUniversityinPrague,

FacultyofElectricalEngineering,Dept.ofCybernetics,CenterforMachinePerceptionhttp://cmp.felk.cvut.cz/~reinsmic/

[email protected]

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

Page 2: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

2

ADMINISTRATION2

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttps://cw.fel.cvut.cz/wiki/help/common/plagiarism_cheating

PLAGIARISMWARNINGhttps://cw.fel.cvut.cz/wiki/help/common/plagiarism_cheating

Page 3: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

3

RECAP: MOREABOUTPYTHON3

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttps://www.youtube.com/watch?v=arxWaw-E8QQ&t=1s

• Themethodsandvariablesarecreatedonstackmemory• Theobjectsandinstancesarecreatedonheapmemory• Newstackframeiscreatedoninvocationofa

function/method• Stackframesaredestroyedassoonasthe

function/methodreturns• MechanismtocleanupthedeadobjectsisGarbagecollector• EverythinginPythonisobject• Pythonisdynamicallytypedlanguage

Page 4: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

4

RECAP: LISTS4

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/lists.html

• Listsaremutable (wecanchangetheirelements)• Stringsareimmutable (wecannotchangetheirelements)• Useslicingprinciples(indexesinbetweencharacters/items)

Page 5: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

5

RECAP:SLICING5

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/strings.html

• A substring ofastringisobtainedbytakinga slice• Slicealisttorefertosomesublist oftheitemsinthelist• Theoperator [n:m] returnsthepartofthestringfromthen’thcharactertothem’thcharacter,includingthefirstbutexcludingthelast(indicespointing between thecharacters)

• Sliceoperator [n:m] copies outthepartofthepaperbetweenthe n andm positions

• Resultof[n:m] willbeoflength(m-n)

Page 6: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

6

RECAP: STRINGSvs.LISTS6

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/lists.html

• Variables a and b refertostringobjectwithletters "banana”• Useis operatororid functiontofindoutthereference• Stringsare immutable,Pythonoptimizesresourcesbymakingtwonamesthatrefertothesamestringvaluerefertothesameobject

• Notthecaseoflists:a and b havethesamevalue(content)butdonotrefertothesameobject

Strings

Lists

Page 7: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

7

RECAP: LISTS– ALIASING,CLONING7

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/lists.html

• Ifweassignonevariabletoanother,bothvariablesrefertothesameobject

• Thesamelisthastwodifferentnames wesaythatitis aliased (changesmadewithonealiasaffecttheother)

• RECOMMENDATION:avoidaliasingwhenyouareworkingwithmutableobjects

• Ifneedtomodifyalistandkeepacopyoftheoriginalusethesliceoperator(takinganysliceof a createsanewlist)

Page 8: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

8

RECAP: LISTPARAMETERS8

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/lists.html

• Passingalistasanargumentpassesareference tothelist,notacopyorcloneofthelist

• Soparameterpassingcreatesanalias

Page 9: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

9

MODULES9

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Amodule isafilecontainingPythondefinitionsandstatementsintendedforuseinotherPythonprograms

• Modulesareoneofthemainabstractionlayersavailableandprobablythemostnaturalone

• Abstractionlayersallowseparatingcodeintopartsholdingrelateddataandfunctionality

• Themostnaturalwaytoseparatethesetwolayersistoregroupallinterfacingfunctionalityintoonefile,andalllow-leveloperationsinanotherfile

• Donewiththe import and from... import statements

Page 10: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

10

MODULES10

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

WheredoesPythonlookforimportedmodules?• Alistnamed path inmodule sys containsallthelocations(andcanbemodified)

• ThefirstitemonthelististhedirectorywiththeprogramWhathappenswhenPythonimportsamodule?• Pythonsearchesthemoduleamongalreadyimportedmodulesin sys.modules

• Ifthemoduleisnotfoundin sys.modules,Pythonsearcheslocationsin sys.path, executesthemodule onceitisfound,andrecordsthatthemodulehasalreadybeenimported

• Pythoncreatesnamesinlocalnamespace fortheimportedmodule,orforallthevariables,functions,etc.importedfromthemodule

Page 11: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

11

MODULES11

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Modulesthatcanbebothrun andimported• Specialvariablecalled __name__ insideeachmoduleitcontains:• thenameofthemodule(ofthe.py file)whenthemoduleisimported

• string "__main__" whenthe.py fileisrunasaprogram(script)

• Variable __name__ isdefinedinboththecallingnamespaceandinthenamespaceofthemodule

Page 12: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

12

MODULES12

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://docs.python-guide.org/en/latest/writing/structure/#modules

• Togainaccesstosymbolsdefinedinamodule(i.e.inadifferentnamespace)modulehastobeimported(3ways)

• Thestatementsloadamodule,createanameinthecurrentnamespace,andbindthenametotheloadedmodule

Page 13: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

13

MODULES– RANDOMNUMBERS13

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Toincluderandomdecision-makingprocess• Totakesamplesfromprobabilitydistributions• Toplayagameofchancewherethecomputerneedstothrowsomedice,pickanumber,orflipacoin…

• Toshuffleadeckofplayingcardsrandomly…• Inmodellingandsimulations:weathermodels,environmentalmodels,MonteCarlomethod

• ForencryptingbankingsessionsontheInternet

Page 14: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

14

MODULES– RANDOMNUMBERS14

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• The randommethodreturnsafloatingpointnumberintheinterval[0.0,1.0)— thesquarebracketmeans“closedintervalontheleft”andtheroundparenthesismeans“openintervalontheright” – 0.0ispossible,butallreturnednumberswillbestrictlylessthan1.0.

• Itisusualto scale theresultsaftercallingthismethodtogetthemintoanintervalsuitableforapplication.

• EXAMPLE:scalingtoanumberintheinterval[0.0,5.0)(uniformlydistributednumbers— numberscloseto0arejustaslikelytooccurasnumberscloseto0.5orcloseto1.0)

Page 15: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

15

MODULES– RANDOMNUMBERS15

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• The randrangemethodgeneratesanintegerbetweenitslower andupper argument

• Therandrangemethodsamesemanticsas range(sothelowerboundisincluded,buttheupperboundisexcluded)

• Allthevalueshaveanequalprobabilityofoccurring(i.e.theresultsare uniformly distributed).

• Randrange alsotakesanoptionalstepargument(likerange)

• EXAMPLE:Weneededarandomoddnumberlessthan100

Page 16: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

16

MODULES– RANDOMNUMBERS16

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

Thisexampleshowshowtoshuffle alist.(shuffle cannotworkdirectlywithrangeobjectsolist typeconverterfirstisnecessary)

• Randomnumbergeneratorsarebasedona deterministic algorithm— repeatable andpredictable

• Called pseudo-random generators(notgenuinelyrandom)• Eachtimeyouaskforanotherrandomnumber,you’llgetonebasedonthecurrentseedattribute,andthestateoftheseed

Page 17: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

17

MODULES– RANDOMNUMBERS17

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Repeatabilityfordebugging andforwritingunittests(programsthatdothesamethingeverytimetheyarerun)

• Forcingtherandomnumbergeneratortobeinitializedwithaknownseedeverytime(oftenthisisonlywantedduringtesting/back-testing)

• Withoutthisseedargument,thesystemprobablyusessomethingbasedontheOStime.

Page 18: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

18

MODULES– RANDOMNUMBERS18

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• EXAMPLE:generatealistcontaining n randomints betweenalowerandupperbound

• NOTE:thatwegotaduplicates intheresult(oftenthisiswanted,e.g.ifwethrowadiefivetimes,wewouldexpectsomeduplicates)

Page 19: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

19

MODULES– RANDOMNUMBERS19

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

Howtotakecareofduplicates?

• Ifyouwanted5distinctmonths,thenthisalgorithmiswrong• Inthiscaseagoodalgorithmistogeneratethelistof

possibilities,shuffle it,andsliceoff thenumberofelementsyouwant:

Page 20: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

20

MODULES– RANDOMNUMBERS20

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Allowingduplicates (usuallydescribedaspullingballsoutofabag withreplacement)

• Noduplicates (usuallydescribedaspullingballsoutofthebag withoutreplacement)

• Algorithm“shuffleandslice”isnotidealforcaseofchoosingfewelementsfromaverylargedomain

(Supposetheneedforfivenumbersbetween1and10million,withoutduplicates.Generatingalistoftenmillionitems,shufflingit,andthenslicingoffthefirstfivewouldbeaperformancedisaster.)

Page 21: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

21

MODULES– RANDOMNUMBERS21

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

Choosewiselythealgorithmbasedontheinputdata!

Page 22: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

22

MODULES– TIME22

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

Howefficientandreliableisourcode?• Onewaytoexperimentisto

timehowlongvariousoperationstakeandwhatthememoryrequirementsare(relatedtoalgorithmcomplexity:https://people.duke.edu/~ccc14/sta-663/AlgorithmicComplexity.html )

• The timemodulehasafunction clock thatisrecommended• Whenever clock iscalled,itreturnsafloatingpointnumber

representinghowmanysecondshaveelapsedsinceyourprogramstartedrunning(variesaccordingtoOS!)

Page 23: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

23

MODULES– TIME23

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• EXAMPLE:Generatingandsumminguptenmillionelementsinunderasecond

• Proprietaryfunctionruns57%slowerthanthebuilt-in one.

Page 24: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

24

MODULES– TIME24

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttps://people.duke.edu/~ccc14/sta-663/AlgorithmicComplexity.html

Page 25: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

25

MODULES– MATH25

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Themathmodulecontainsmathematicalfunctionstypicallyfoundonacalculator,includingmathematicalconstantslike pi and e

• Functions radians and degrees toconvertangles• Mathematicalfunctionsarepure anddonothaveanystate

Page 26: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

26

MODULES– CREATINGMODULES26

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Createownmodules – savescriptasafilewith .py extension• EXAMPLE:functionremove_at inascriptissavedasafilenamed seqtools.py

• Themodulemustbefirstimportedbeforeuse(.pyisthefileextensionandisnotincludedinthe importstatement)

• RECOMMENDATION:breakupverylargeprogramsintomanageablesizedpartsandkeeprelatedpartstogether

Page 27: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

27

MODULES– NAMESPACES27

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Namespaceisamapping fromnamestoobjects• Namespace isacollectionofidentifiersthatbelongtoamodule,function,oraclass

• Namespaceissetofsymbolsusedtoorganizeobjectsofvariouskindssothatwecanrefertothembyname

• Namespacespermitprogrammerstoworkonthesameprojectwithouthavingnamingcollisions(allownamereuse)

• Oftenhierarchically structured• Eachnamemustbeunique initsnamespace• NamespaceisverygeneralconceptnotlimitedtoPython• Eachmodulehasitsownnamespace – wecanusethesameidentifiernameinmultiplemoduleswithoutcausinganidentificationproblem

Page 28: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

28

MODULES– NAMESPACES28

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

HowarenamespacesdefinedinPython?• Packages(collectionsofrelatedmodules)• Modules(.pyfilescontainingdefinitionsoffunctions,classes,variables,etc.)

• Classes,Functions…Whatisthedifferencebetweenprogramsandmodules?• Botharestoredin.pyfiles.• Programs (scripts)aredesignedtoberun(executed)• Modules (libraries)aredesignedtobeimportedandusedbyotherprogramsandothermodules

• Specialcase:.pyfileisdesignedtobebothaprogramandamodule(itcanbeexecutedaswellasimportedtoprovidefunctionalityforothermodules)

Page 29: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

29

MODULES– NAMESPACES29

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

Page 30: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

30

MODULES– NAMESPACES30

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Functionsalsohaveownnamespaces• Functionscanread(read-only)variableintheouterscope• EXAMPLE:thethree n‘sabovedonotcollidesincetheyareeachinadifferentnamespace— threenamesforthreedifferentvariables

Page 31: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

31

MODULES,NAMESPACES,FILES31

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Pythonhasaconvenientandsimplifyingone-to-onemapping:onemoduleperfile – givingrisetoonenamespace

• Pythontakesthemodulenamefromthefilename,andthisbecomesthenameofthenamespace

• EXAMPLE:math.py isafilename,themoduleiscalledmath,anditsnamespaceismath (inPythontheconceptsaremoreorlessinterchangeable)

• Inotherlanguages(e.g.C#)onemodulecanspanmultiplefiles,oronefiletohavemultiplenamespaces,ormanyfilestoallsharethesamenamespace

Page 32: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

32

MODULES,NAMESPACES,FILES32

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• RECOMMENDATION:keeptheconceptsdistinctinyourmind• Filesanddirectoriesorganize where codeanddataarestored• Namespacesandmodulesareaprogrammingconcepts:helpusorganizehowwewanttogrouprelatedfunctionsandattributes.

• Namespacesarenotabout“where”tostorethings,andshouldnothavetocoincidewiththefilestructures

• Ifthefile math.py isrenamed,itsmodulenameneedstobechanged, import statementsneedtobechanged,andthecodethatreferstofunctionsorattributesinsidethatnamespacealsoneedstobechangedaccordingly

Page 33: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

33

MODULES– SCOPE33

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Ascope isatextualregionofaPythonprogramwhereanamespaceisdirectlyaccessible

Whattypesofscopescanbedefined?• Localscope referstoidentifiersdeclaredwithinafunction(theseidentifiersarekeptinthenamespacethatbelongstothefunction,andeachfunctionhasitsownnamespace)

• Globalscope referstoalltheidentifiersdeclaredwithinthecurrentmodule,orfile

• Built-inscope referstoalltheidentifiersbuiltintoPython(thoselike range and min thatcanbeusedwithouthavingtoimportanything)

Page 34: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

34

MODULES– SCOPE34

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

Whatarethescopeprecedencerules?• Thesamenamecanoccurinmorethanoneofthesescopes,buttheinnermost,orlocalscope,willalwaystakeprecedenceovertheglobalscope,andtheglobalscopealwaysgetsusedinpreferencetothebuilt-inscope

• Namescanbe“hidden”fromuseifownvariablesorfunctionsreusethosenames

• EXAMPLE:variables n andm arecreated justforthedurationoftheexecutionoff sincetheyarecreatedinthelocalnamespaceoffunction f(precedencerulesapply)

Page 35: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

35

MODULES– THEDOTOPERATOR35

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttp://openbookproject.net/thinkcs/python/english3e/modules.html

• Variablesdefinedinsideamodulearecalled attributes ofthemodule

• Attributesareaccessedusingthe dot operator (.)• Whenadottednameisuseditisoftenreferredtoitasa fullyqualifiedname

Page 36: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

36

MOTIVATION– DATASCIENCE36

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttps://www.kaggle.com/surveys/2017

Page 37: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

37

MOTIVATION– DATASCIENCE37

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

sourcehttps://www.kaggle.com/surveys/2017

Page 38: PRG –PROGRAMMING ESSENTIALS...2 ADMINISTRATION 2 03/12/2017 Michal Reinštein, Czech Technical University in Prague source

38

REFERENCES38

03/12/2017 MichalReinštein,CzechTechnicalUniversityinPrague

Thislecturere-usesselectedpartsoftheOPENBOOKPROJECTLearningwithPython3(RLE)

http://openbookproject.net/thinkcs/python/english3e/index.htmlavailableunderGNUFreeDocumentationLicense Version1.3)

• Versiondate:October2012• byPeterWentworth,JeffreyElkner,AllenB.Downey,andChrisMeyers

(basedon2ndeditionbyJeffreyElkner,AllenB.Downey,andChrisMeyers)

• Sourcerepositoryisat https://code.launchpad.net/~thinkcspy-rle-team/thinkcspy/thinkcspy3-rle

• Forofflineuse,downloadazipfileofthehtmlorapdfversionfrom http://www.ict.ru.ac.za/Resources/cspw/thinkcspy3/