Uwujonga njani umxholo weModyuli kwiPython

NguJohn Paul Mueller

IPython ikunika iindlela ngeendlela ezahlukeneyo zokujonga umxholo wemodyuli. Indlela esetyenziswa ngabaphuhlisi abaninzi kukusebenza kunyeeya kuwe()function, ekuxelela malunga neempawu ezibonelelwa yimodyuli.



Iimpawu zomsebenzi zenziwe ngokuzenzekelayo yiPython kuwe. Ezi mpawu zenza le misebenzi ilandelayo okanye ziqulathe olu lwazi lulandelayo:

  • __izakhiwo__Inoluhlu lwazo zonke izinto ezakhelweyo ezifikelelekayo kwimodyuli. IPython yongeza ezi mpawu ngokuzenzekelayo kuwe.

    jp ukucoca amanzi
  • __cached__Ikuxelela igama kunye nendawo ekuyo kwifayile egciniweyo enxulumene nemodyuli. Ulwazi lwendawo (umendo) luhambelana nolawulo lwangoku lwePython.



  • __doc__: Iziphumo zinceda ulwazi kwimodyuli, ucinga ukuba uyizalisile. Umzekelo, ukuba uyachwetheza os .__ doc__ kwaye ucinezela u-Enter, Python) uya kukhupha ulwazi ngoncedo olunxulumene nefayile ye-wenaIthala leencwadi.

  • __ifayile__: Ukuxelela igama kunye nendawo yemodyuli. Ulwazi lwendawo (umendo) luhambelana nolawulo lwangoku lwePython.

  • __ukuqalisa__Ichonga ukuba ngaba imodyuli ikwinkqubo yokuziqalela ngokwayo. Ngokwesiqhelo olu phawu lubuyisela ixabisoUbuxoki. Olu phawu luluncedo xa ufuna ukulinda de imodyuli enye yenziwe ngaphambi kokuba ungenise enye imodyuli exhomekeke kuyo.



    naphcon iliso liyehla
  • __khuphela__Imveliso yolwazi lomlayishi kule modyuli. Inkqubo ye- umlayishi sisiqwengana sesoftware efumana imodyuli kwaye siyibeka kwimemori ukuze iPython ikwazi ukuyisebenzisa. Olu luphawu olunye kunqabile ukuba ulusebenzise.

  • __igama__: Ikuxelela nje igama lemodyuli.

  • __pakethi__Olu phawu lusetyenziswa ngaphakathi ngenkqubo yokungenisa ukwenza kube lula ukulayisha kunye nokulawula iimodyuli. Awudingi ukuba nexhala malunga nolu phawu.

Unokumangaliswa kukufumanisa ukuba ungaziphonononga nangakumbi kwiimpawu. Chwetheza Ungasebenzisi (MyLibrary.SayHello) kwaye ucinezela u-Enter.

Ngaba yi-albuterol steroid

umfanekiso0.jpg

Olunye lolu ngeniso, njenge__igama__, ikwavela kuluhlu lwemodyuli. Nangona kunjalo, unokuba nomdla malunga nolunye ungeniso. Umzekelo, unokufuna ukwazi ukuba yintoni__sizeof__konke malunga. Enye indlela yokufumana ulwazi olongezelelweyo kukuchwetheza Uncedo (__ ubukhuluof__) kwaye ucinezela u-Enter. Uyabona ulwazi oluncinci (kodwa oluluncedo) lolwazi.

umfanekiso1.jpg

IPython ayizukuqhushumba ukuba uzama uphawu. Nokuba iqokobhe linengxaki, ungahlala uqala entsha. Ke enye indlela yokujonga imodyuli kukuzama nje iimpawu. Umzekelo, ukuba uchwetheza MyLibrary.SayHello .__ sizeof __ () kwaye ucinezela u-Enter, ubona ubungakanani beYithi Molo()sebenza kwii-byte.

umfanekiso2.jpg

Ngokungafaniyo nezinye iilwimi ezininzi zokuprinta, iPython yenza ikhowudi yemvelaphi yeelayibrari zayo zeelwimi ezikhoyo. Umzekelo, xa ujonga kwifayile ye-IPython33Libulawulo, ubona uluhlu lwe.pyiifayile onokuzivula nge-IDLE ngaphandle kwengxaki kwaphela.

Ngaba i-acetaminophen ibangela ukuqhina

umfanekiso3.jpg

Ukujonga umxholo ngokuthe ngqo kunokukunceda ufumane iindlela ezintsha zenkqubo kunye nokuqonda ngcono ukuba isebenza njani ilayibrari. Ixesha elingakumbi olichitha usebenza nePython, kokukhona uya kuba ngcono ekuyisebenziseni ukwakha usetyenziso olunomdla.

Qiniseka ukuba ujonga nje ikhowudi yelayibrari kwaye ungayitshintshi ngengozi. Ukuba ngempazamo uyitshintshe ikhowudi, usetyenziso lwakho lunokuyeka ukusebenza. Okubi nangakumbi kukuba ungazisa ii-bugs ezifihlakeleyo kwisicelo sakho eziza kuvela kuphela kwinkqubo yakho kwaye ayikho kwenye indawo. Soloko usebenzisa ukhathalelo xa usebenza nekhowudi yethala leencwadi.