diff --git a/deva_iast_comp/data.txt b/deva_iast_comp/data.txt new file mode 100644 index 0000000..c720817 --- /dev/null +++ b/deva_iast_comp/data.txt @@ -0,0 +1,461 @@ +a:abnormal +aMSaprakalpanA:aṃśa-kalpanā +aGnya:ághnya ({%also%} {@-yá@}) +adfpita:á-dṛp-ita {%or%} {@-ta +adya:a-dyá (ā́) {%ad.%} to-day +aDarozWa,°rOzWa:adhara‡oṣṭha +aDaHsTa:adhaḥ-stha +aDipuruza:adhi-pŭruṣa +aDirukmamandiragavAkzam:abnormal +aDIk:abnormal +anirhARarca:a-nirhāṇa‡ṛca +anUpa:anūpá [anu+ap-a] +antaHsaMjYa:antaḥ-saṃ-jña +anvavekzA:anu‡avekṣ-ā {%f.%} regard +aparAvfttaBAgaDeya:abnormal +apartu:apa‡ṛtu +aprOQa:a-pra‡ūḍha +arDarca:ardha‡ṛcá +arvAkkAlikatA:arvāk‡kālika-tā +arvAcIna:arvācī́na ({%or%} á) +alomaka:a-lómaka ({%or%} áka) +alohita:a-lóhita ({%or%} tá) +avarti:áva‡ṛti +aviBUzaRaparicCada:abnormal +aSanAyA:aśanā́yā ({%or%} ā́) +asaNga:á-saṅga ({%or%} á) +asma:á-sma ({%or%} á) +asmattas:asmat-tas (= {%ab.%} asmát) +asyavAmIya:‘asya-vām’-īya +ahar:áhar ({%used as the middle base of%} áhan) +ahas:áhas = áhar: {@-kara +A:abnormal +Agama:ā́-gama {%a.%} coming up; {%m.%} arrival +AN:abnormal +AcArya:ā-cāryâ [{%fp.%} to be gone to] +AtiraScIna:ā-tira{%s-k-%}īna +AtmecCA:abnormal +AtmOpamya:ātma‡aupamya +Aruj:ā-ruj (-°) +AruRa:āruṇ-a ({@ī@}) +Arta:ā’‡ṛta +Arti:ā’‡ṛti +Asana:ā́s-ana ({%or%} á) +AsapiRqakriyAkarma:abnormal +iq:íḍ {%f.%} comfort; oblation +itara:í-tara ({%n.%} {@-d@}; {%V. also%} {@-m@}) +iti:í-ti {%or%} i-tí +indrApUzan:índrā-pū́ṣan ({%or%} indrā-pūṣán) +ihAmutraPalaBogavirAga:abnormal +Ij:ĪJ I.Ā. ī́j{@a-te +Idfkza:īdṛkṣa ({@ā@}) +ISAna:ī́ś-āna ({%or%} {@á@}) +ujjfmBa:uj-ṛmbha +ujJ:UJJH [ud + hā] +ujJa:ujjh-a {%a.%} abandoning +uttamarRa:uttama‡ṛṇa +uttarozWa,°rOzWa:uttara‡oṣṭha +udIcya:abnormal +upayAcana:upa-yā{%c%}-ana +upasti:úpa-sti ({%or%} -stí) +upozaRa:upa‡oṣaṇa +uzwf:úṣ-ṭṛ ({%or -trí%}) +U:abnormal +U~:ūm̐ +Uh:ŪH ({%often ŭh%}) +fDak:ṛ́dh-ak ({%or%} ák) +ekaka:eka-ká ({@akā +ekayazwi:eka-yaṣṭi* +ekESvarya:eka‡aiśvarya +etaSa:éta-śa ({%sts. -s%}á) +enap:abnormal +E:*ai +o:abnormal +kakudruma:kaku[d]-druma +kakzyA:kakṣyā̂ +kacawatapagajaqadaba:abnormal +kanizWa:kán-iṣṭh-a ({%or%} -á) +kam:KAM ({%no pres. base%}) +karizya:kariṣya [ḥ] +kASmIrika:abnormal +kila:kíla ({%V. sts.%} {@ā@}) {%ad. quidem%} +kIdfS:kī-dríś +kuRW:KUṆṬ +kutra:kú-tra (-trā +kf:KṚ (skṛ after upa +kfpanILa:kṛpá-nīḷa +kxptakeSanaKaSmaSru:abnormal +kxpti:k{%lí%}p-ti ({%also%}-tí) {%f.%} coming about +kruYc:krúñc ({%nm.%} {@kruṅ@}) +kzA:abnormal +KA°:abnormal +KUra:abnormal +gamBIra:gambh-īrá = gabhīra: {@ā +gavezaRa:gava‡eṣaṇa +gavya:gáv-ya ({%or%} -yá) +guRW:GUṆṬ +gutsa:*gutsa +gup:GUP ({%no pr. st.%}) guard +gur:gur = gus +glapsa:abnormal +glAna:glā-na ({%pp.%} √ glai) +cakreSa:cakra-īśa +cawacaw:caṭa-ca{%t +catasf:cátasṛ {%or%} catasṛ́ +cana:ca-ná ({%SV.%} caná) +candrodaya:abnormal +cala:cal-a {%a.%} moving +cArcikya:*cārcik-ya +citkAra:abnormal +cuRwI:abnormal +Canda:chánd-a {%or%} chand-á +CucCUndara:chucchundara +ja:ja (-°) +jakz:abnormal +jakz:JAKṢ [{%redupl. of%} has] +jakzivAn:*jakṣ-i-vān +jagat:já-g-at ({%pr. pt. redupl. fr.%} √ gā) +jaNgala:*jaṅ-gal-a +jani:ján-i ({%or%} {@ī@}) +janitf:ján-i-tṛ ({%or%} -tṛ́) +janmarkza:janma‡ṛkṣa +jAyaka:*jāya-ka +juzwa:júṣ-ṭa ({%or%} -ṭá) +jF:{%GRĪ%} +jenya:jén-ia +joNga:*joṅga +jYAnecCAkriyASaktimat:abnormal +jyezWa:jyā’‡iṣṭha ({%or%} {@á +Qakkana:ḍhakka-na {%or%} {#°ma#} -ma +tatra:tá-tra ({%V. also%} {@ā +tAmrozWa:tāmra‡oṣṭha +tittiri:tittíri ({%or%} í) +tilodana:tila‡odana +turAzAh:turā-ṣā́h ({%nm.%} {@-ṣā́ṭ; -sāh +turIya:tur-īya ({%also%} tú- {%and%} -yá +tedani:tedani ({%or%} {@î@}) +tyaj:TYAJ [(a)ti‡aj] +trayodaSan:tráyo-daśan ({%or s%}án) +trayodaSarca:trayodaśa‡ṛcá +tripad:tri-pád ({%or%} trí-: {%strong st.%} {@-pād@}) +dakziRa:dákṣ-iṇa ({%also%} á) +damBoli:abnormal +daridra:dár-i-dra ({%also-í-dra%}) +darvi:dárvi ({%also%} {@ī@}) +darSa:dárś-a ({%or%} -á) +dAruRa:dārú-ṇa ({%or%} á) +dfkza:dṛk-ṣa (-°) +dfS:dṛ́ś ({%nm.%} {@dṛk@}) +devatAgAra:devatā‡ā̆gāra +dyotana:dyót-ana ({%or%} á) +dramma:dramma (δραχμή) +dravat:drav-át ({%pr. pt. of%} √ dru) +dvAdaSan:dvā́-daśan ({%or%} án) +dvApara:dvā-pára ({%or%} á) +dvipad:dví-pad ({%or%} -pád: {%strong base%} {@-pād@}) +Danvadurga:abnormal +DAnyAMSa:*dhānya‡aṃśa +Di:dhi = adhi ({%in%} dhi-ṣṭhita +Dyuzita:[a]dhy-uṣita +na:abnormal +nak:nák ({%only nm.%}) +napAt:ná-pāt ({%V. only in strong cases%}) +navadaSan:náva-daśan ({%or%} án) +navan:návan ({%or%} án) +nazwa:~naṣ-ṭa +nazwi:~naṣ-ṭi +nAgarI:*nāgarī +nArada:nā́rada ({%or%} á) +nAva:nāva = nau +nid:abnormal +nir:abnormal +nirgatAKilakalmaza:abnormal +nizpanda:niṣ-[s]panda +nILa:nīḷá +nyakta:ni‡âkta +nyaYc:ni‡âñc +nyarbuda:ni‡ârbuda +nvE:n[ú]vaí +paYcan:páñc-an ({%or%} {@-án@}) +paT:páth ({%weak base%}; {@pánthān +panu:pan-ú ({%or%} -ū́) +payozRI:paya[ḥ]‡uṣṇī +paramarzi:parama‡ṛṣi +paraHsahasra:páraḥ-sahasra ({%or%} rá) +parAk:parāk (or {@ṅ@}) +parAyaRa:parā’‡ayaṇa +parudvAra:*parud-vāra +paro'kza:paró-[a]kṣa +paro'varam:paro-(a)varám +parozRih:para[ḥ]‡uṣṇih +parmAqi:parmāḍi ({%or -nd%}i) +paryARa:pari-[y]āṇa +parzad:par-ṣad = pari-ṣad +paSu:páś-u ({%or%} -ú +paSca:*paś-cá +pAkyA:pākyā̂ +pAna:pā’‡ana +pASa:pā́ś-a {%m.%} [√ paś +pAScAttya:pāścāt-tya ({%or%} -ya +piMS:PIṂŚ {%and%} {#piMz#} PIṂṢ +pibd:pibd [pi-p(a)d +pIq:PĪḌ [pi-s(a)d +puMScalI:pu{%ms-k%}al-ī́ +pumAMs:púmāṃs ({%strg. base%}; {%wk. base%} +purauzRih:pura(ḥ)-uṣṇih +puro'nuvAkyA:puro-(a)nuvākyā̂ +puz:puṣ (-°) +puzwi:púṣ-ṭi ({%or -t%}í: {%RV.%}) +pftanAzah:pṛtanā-ṣáh ({%str. st.%} -ṣā́h) +pfTak:abnormal +potf:pó-tṛ ({%or%} -tṛ́) +prauga:prá-üga +praRava:pra-ṇáva ({%or%} á) +pratIka:prátī-ka [prati‡ak-a +praTama:pra-thamá [= pra-tama +prapitAmaha:prá-pitāmaha ({%or%} á) +prAcya:prāc-yâ ({%or%} yá) +prADva:pra‡adhva [fore-journey] +pruzvA:prúṣ-vā ({%or%} {@ā́@}) +prOQa:pra‡ūḍha +prOQi:pra‡ūḍhi +psaras:ps-ar-as [bh(a)s-ar-as] +psu:psu [bh(a)s-u] +psu:psu [bh(a)s-u] +psuras:ps-úr-as [bh(a)s-ur-as] +Par:PHAR [= SPHAR] +PARwa:phāṇṭa [phāṇ(i)ta] +PeRwa:pheṇṭa : {@-ka +baD:abnormal +barAsI:barāsī’ +barhizad:barhi[ḥ]-ṣád +barhiHzad:barhiḥ-ṣad = barhi-ṣad; {@-ṣṭha@} +bAlya:bā́l-ya ({%or%} -yâ) +bAhya:bā́hya [{%fr.%} bahi(s)] +buSa:buśa {%and%} {#buza#} buṣa +bfhawwika:bṛha{%t-t%}ika +brahmaRaspati:abnormal +brahmaRvat:bráhmaṇ-vat ({%or%} -vát) +brahmarzi:brahma‡ṛṣi +brAhmaRAcCaMsin:brāhmaṇāt-śaṃs-ín +BagIraTa:bhagī-ratha [bhagi-ratha +BaNgi:bhaṅg-i ({%or%} {@ī@}) {%f.%} breaking; bend +Bas:bhas = bhasman +BA:BHĀ II.P. {@bhā́-ti +BAwa:bhāṭa : {#°ka#} -ka +BAm:BHĀM [{%dialectic form of%} bhram] +Bikzu:bhikṣu ({%des. a.%}) +Bizaj:BHIṢAJ [(a)bhi-saj +BUti:bhū́-ti ({%or%} -tí) +BUma:abnormal +BUmi:bhū́-mi ({%sts.%} {@ī@}) +Bfti:bhṛ-tí (ŚB. {%also%} bhṛ́-) +Bo:abnormal +macCarIra:mat-śarīra +maYjari:mañj-ar-i ({%or%} ī) +mawaka:maṭa-ka [{%Prākritic for%} mṛta-ka] +maTan:math-an ({%only in.%} {@mathnā@}) +manotf:manó-tṛ ({%or%} -tṛ́) +mantavya:man-távya ({%or%} yâ) +mayUrI:mayū’r-ī +mayoBu:mayo-bhú ({%or%} -bhū́) +mazi:maṣ-i ({%or%} ī) +mas:mas = mās +masi:masi ({%or%} ī) +mahacCabda:mahat-śabda +mahartvij:mahā’‡ṛtvij ({%or%} íj) +maharzi:mahā‡ṛṣi +mahEtareya:mahā‡aitareya +mAtura:mātur-a = mātṛ +mAna:mā’‡ana +mAnita:mAn-i-ta +mAnuza:mā́nuṣ-a ({%or%} á) +mAruta:mā́rut-a ({%or%} á: {%Br.%}) +mAlatI:mālatī ({%rarely%} i) +mAsopavAsa:māsa‡upavāsa : {@-ka +mikz:MIKṢ [{%des. of%} √ miś {%in%} miś-ra +miTu:míth-u ({%or%} ū) +mizwa:miṣ-ṭa [{%pp.%} = mṛṣṭa] +mI:mī {%occurs in some forms of%} √ mā +muhu:múh-u ({%or%} -ú) +mUrti:mū’r-ti +mUla:mū́l-a [= mū́r-a +mfkaRqa:mṛkaṇḍa ({%also%} u) +mfkz:MṚK-Ṣ [{%der. of%} √ mṛj] +mfcCakawika:mṛd-śakaṭ-ika +mfR:MṚṆ [{%fr.%} mṛ-ṇā +meDapati:médha-pati ({%or%} medhá-) +meLi:meḷí +yakan:abnormal +yakft:yák-ṛt ({%nm. &%} °-) +yajYa:ya{%g-ñ%}á +yatra:yá-tra ({%V. sts.%} ā́) +yaTarcam:yathā‡ṛcam +yadi:yád-i ({%V. also%} {@ī@} {%metr.%}) +yayi:ya-y-í ({%or%} ī́) +yavanAnI:*yavan-ānī +yazwf:yáṣ-ṭṛ́ ({%or -trí%}) +yAcYA:yā{%k-ñ%}ā́ +yAtayAma:yātá-yāma : {#°n#} -n +yAna:yā’‡ana +yAvacCaktitas:yāvat-śakti-tas +yuC:YU-CH [{%pr. base of%} √ ¤2.¤ yu] +yup:YUP ({%V. +yuvati:yuva-tí ({%or%} ī) +yUTa:yū-thá [union: √ ¤1.¤ yu] +raMh:RAṂH [= RAÑGH] +rakz:RAK-Ṣ [{%der. of%} √ rak +raGu:ragh-ú [√ raṅgh = raṃh] +rasAsvAda:rasa‡āvāda +rA:abnormal +rAmyA:rā́m-yā ({%or%} ā̂) +rip:RIP ({%RV.%}; {%rare +rizwi:ṛ́ṣ-ṭi +ruci:rúc-i ({%or%} í) +ruD:RUDH [= ¤2.¤ RUH] +[ruh:RUH = {#ruD#} RUDH +rOdra:raúdra ({%or%} á) +lam:LAM [= √ ram] +lamb:LAMB [{%later form of%} √ ramb] +lip:LIP VI. {@limpá@} [{%later form of%} √ rip] +lih:LIH [{%later form of%} √ rih] +luRW:LUṆṬ +lohita:lóh-ita [{%later form of%} rohita] +vajrivas:abnormal +vataMsa:[a]va-taṃsa +vadAnya:[a]va-dān-ya +vaDU:vadh-ū’ +van:van (= vana +varayuvati:vara-yuvati ({%or%} {@ī@}) +varzya:várṣ-ya ({%yv. +valaBi:valabhi ({%or more commonly%} {@ī@}) +vali:val-i ({%or%} ī) +vallari:vallari ({%or%} {@ī@}) +valli:valli ({%rare%}) +vas:VAS ({%RV. +vasantA:vasántā ({%or%} ā́) +vah:vah ({%only%} -° +vARArasI:vāṇārasī = vārāṇasī +vAta:vā́-ta [{%pp.%} √ ¤1.¤ vā +vAma:vā-má [√ ¤3.¤ vā] +vidAna:vid-āna ({%or%} á) +vidyeSa:vidyā‡īśa {%m.%} lord of knowledge +viD:vidh (√ vyadh) +viBaktf:ví-bhaktṛ ({%w. ac.%}) {%or%} tṛ́ ({%w. g.%}) +viSAKa:ví-śākha ({%AV. also-s%}ā́kha) +viSvaha:viśvá-ha ({%or%} ā) +vizuvat:viṣŭ-vat +vizw:VIṢ-Ṭ [{%prob. der. of%} √ viś] +vfzala:vṛṣa-lá ({%or%} vṛ́ṣa-la +vfzwi:vṛṣ-ṭí ({%RV. +vfzRi:vṛ́ṣ-ṇi ({%or n%}í) +vfh:VṚH {%or%} BṚH +veNgi:veṅgi ({%or%} ī) +veRu:véṇu ({%or%} ú) +veditf:véd-i-tṛ ({%or%} -tṛ́ +vezaRa:véṣ-aṇa ({%or%} á) +vEkakzika:vaikakṣ-ika ({%or%} -ya) +vEkaNkata:vaikaṅkata ({%or%} á) +vEjayanta:abnormal +voQf:vóḍhṛ ({%or ri%}) +vopadeva:abnormal +vo|um:voḷhum +vyaj:VI‡AJ = {#vIj#} VĪJ +vyazwi:vi‡âṣṭi +vyAqi:vyāḍ-i ({%or%} ḷi) +vyUQa:vi‡ūḍha ({%V.%} {@-ūṭhá@}) +vratati:vratáti ({%sts.%} ī) +vraSc:abnormal +Sakan:śák-an ({%or%} -án) +SanEs:śánais ({%RV.%} +Sama:abnormal +SaMBu:śaṃ-bhú ({%or%} ū́) +SaravyA:śaravyā̂ +Salpa:śalpa : {#°ka#} -ka +Sazkuli:śaṣkuli ({%or%} {@ī@}) +SA:ŚĀ III. ({%RV.%}) {@śiśā@} +SAkapArTiva:*śāka-pārthiva +SAKowa:śākhoṭa : {#°ka#} {@-ka +Simbi:śimbi ({%or%} {@ī@}) +Sir:ŚIR (= √ ¤2.¤ śṛ) +SiSvi:abnormal +Sis:ŚIS ({#Siz#} ŚIṢ) +SudDodana:śuddha‡odana +SevfDa:śé[va]-vṛdha ({%or%}á¹) +Scar:ŚCAR (= CAR) +Srat:śrát {%or%} {#Srad#} śrád +SraTAya:śrathā-ya ({%RV.%}) +SraddaDAnatA:śrad-dadhāna-tā {%f.%} faith; {@-vat +SrI:ŚRĪ (= ŚRĀ) +SrI:ŚRĪ (= ŚRI) +Sru:ŚRU = {#sru#} SRU +Sruz:abnormal +Sruzwi:śrúṣ-ṭi ({%AV.%}; {@-ṭí@} +Sreyo'BikANkzin:śreyo-(a)bhikāṅkṣin +Srotf:śró-tṛ ({%w. ac.%}) {%or%} {@-tṛ@} ({%w. g.%}) +SlizwaparaMparitarUpaka:abnormal +SvA:ŚVĀ {%or%} {#Svi#} ŚVI +za:abnormal +zaLUnA:ṣaḷ-ūnā +zWu:ṢṬHU (= √ ṣṭhīv) +saG:SAGH [= SAH] +saccandrikA:sat-candrikā +sacCAstra:sat-śāstra +sawAlu:saṭālu = śalāṭu +saMqIvin:sa{%m-d%}īvin +sat:[a]s-át +satrAYc:satrā’‡añc +sadAnanda:sadā-ānanda +sannamusala:abnormal +saptarca:sapta‡ṛcá +saB:SABH = {#sah#} SAH +samAna:samāná [{%fr.%} sama] +saMBava:saṃ-bhavá ({%VS.%} +saraw:saráṭ ({%or%} h ?) +saropAnta:sara[ḥ]‡upānta +saSc:SAŚC [{%contracted fr.%} sa-s(a)c: √ sac] +sANga:sá‡aṅga ({%or%} á) +sAraNga:sāráṅga ({%or%} á +sAh:sāh (-°) +su:SU (= √ ¤1.¤ sū) +su:SU (= √ ¤2.¤ sū) +su:sú ({%in V. also%} sū́) +suganDi:su-gándh-i ({%or%} {@í@}) +suzvaya:suṣvaya [{%den. fr.%} súṣvi +sUr:sū́r = {#svar#} su‡â{@r@} +sUrta:sū’r-ta +sf:ŚṚ +sfj:ŚṚJ VI. {@sṛjá@} +sfRI:sṛ́ṇī ({%or%} ī́) +sfp:ŚṚP +so:abnormal +sOparRa:saúparṇa ({%sts. also%} á) +sOmya:saum-yá ({%AV. also%} saúm-) +sTAna:sthā’‡ana +snAvan:snā́-van ({%or%}) -ván) +snIhiti:snī’h-iti +spUrD:SPŪRDH [{%collateral form of%} spṛdh +spfh:SPṚH [{%collateral of%} SPṚDH] +srA:SRĀ ({%cp.%} √ śrā) +svar:svâr ({%in YV. also%} {#suvar#} súvar) +svaraMkfta:abnormal +svAti:svātí ({%or%} ī́) +svEra:sva‡īra +svErin:sva‡īr-in +haragalagaralatamAla:abnormal +hasa:hás-a ({%or%} á) +hArd:abnormal +hiMs:HIṂS [{%anomolous des. of%} √ han] +huhu:huhŭ +hUrC:HŪR-CH [{%prob. der. of%} √ hvṛ] +hfcCaya:hṛd-śaya +asOnAman:abnormal +UrDvANguli:abnormal +kAryavinimaya:abnormal +kAlidAsa:abnormal +nyAyAropitavikrama:abnormal +prakz:PRAK-Ṣ = {#praC#} PRACH +praBaNga:pra-bhaṅgá : {%line%} ¤8¤ +pravidvas:abnormal +barh:abnormal +yajYArTam:abnormal diff --git a/deva_iast_comp/readme.txt b/deva_iast_comp/readme.txt new file mode 100644 index 0000000..afb72dc --- /dev/null +++ b/deva_iast_comp/readme.txt @@ -0,0 +1,12 @@ +deva_iast_comp + +This directory contains programs to analyze the data in +https://github.com/sanskrit-lexicon/csl-orig/issues/628. + +It is intended also as a tutorial on Python programming. + +data.txt This is a text file containing the data in the first comment of +the issue 628. + +step0 Contains first program, to read the data.txt file, and write + the lines therin to another file. See step0/readme.txt for more info. diff --git a/deva_iast_comp/step0/readme.txt b/deva_iast_comp/step0/readme.txt new file mode 100644 index 0000000..a34e5c2 --- /dev/null +++ b/deva_iast_comp/step0/readme.txt @@ -0,0 +1,39 @@ +step0/readme.txt + +This readme.txt file is just a text file, written as a guide to what is in the +step0 directory. + +# ------------------------------------ +readwrite.py First python program, designed to read the lines of data.txt + and write the upper-cased lines to another file. + Usage: +python readwrite.py ../data.txt readwrite.txt + +Suggestions for study: +1. Study the program - start at the bottom (at 'if __name__=="__main__":'). + Pay particular attention to the indentation, as it is an important + detail peculiar to Python. + When you get to 'lines = read_lines(filein)', go back up to 'def read_lines' + to see what the read_lines 'function' is doing. + Similarly review the rest of the 'main' part. +2. Run the program, as indicated in the 'usage' comment above. + Look at 'readwrite.txt' - is it as you expected? +3. Make another program (you choose the name), which reads 'readwrite.txt' + and changes all letters to lower case. Then run the program. +4. When you're done, push the directory. + +#------------------------------------------- +'temp' files. +Look at the .gitignore file in the MD directory top level. +The 'temp*' line means that any file (or directory) whose name starts with +'temp' will NOT be tracked by git. Such files will be available on your +machine, but will be ignored when you push. +This is a good way to make small experiments that are meaningful for you +but that might not be useful to other repository users. + +Conversely, files which you +do want to share with others should have names that do not start with 'temp'. + +You can always do a 'git status' after 'git add' but before 'git commit' to +see which files git is tracking. + diff --git a/deva_iast_comp/step0/readwrite.py b/deva_iast_comp/step0/readwrite.py new file mode 100644 index 0000000..5aa4bc5 --- /dev/null +++ b/deva_iast_comp/step0/readwrite.py @@ -0,0 +1,74 @@ +# coding=utf-8 +"""readwrite.py + +""" +from __future__ import print_function +import sys,re,codecs + +# def f(x,y,z): that's the way Python function definitions start +def read_lines(filein): + # Notice the indentation + # there's a lot packed into the next line. + # We could say: + # open file named filein for reading. The file is encoded as utf-8. + # Use the variable 'f' for reading from the file. 'f' could be + # called the 'file handle'. + with codecs.open(filein,"r","utf-8") as f: + # Notice the further indentation + # Read every line in the file, and strip from the end of each + # line the line-ending characters '\r\n' + # And, add each stripped line into the Python list named 'lines' + lines = [line.rstrip('\r\n') for line in f] + # Notice we have gone back to 1 character of indentation (same as 'with') + # print to the 'console' a message indicating how many lines were read + print(len(lines),"lines read from",filein) + # the function returns the list of lines + return lines + +# this adjustlines function capitalizes each line +def adjustlines(lines): + newlines = [] # start with an empty list, in which the new lines will be put + # adjust each line in a python 'for loop' + + for line in lines: + # we know, from the way read_lines was constructed, that each element + # in lines represents a line of the text file used as input ('filein') + # As such, it is a python 'str' (for 'string'). There is a builtin way to + # convert strings to upper case + newline = line.upper() + # We want to add the new line to our list of new lines. + # 'append' is the way to do that + newlines.append(newline) + # we're done with the for loop, so we go back one level of indentation + # We need to return the newlines object that this function computed + return newlines + +def write_lines(fileout,lines): + # Note we call this function as 'write_lines(fileout,newlines)'. + # In this function, the function parameter 'lines' will, when + # called, have the value newlines. + # open the file, but this time for 'writing' + with codecs.open(fileout,"w","utf-8") as f: + # write each line using a for loop + for line in lines: + # we will add the 'newline' line break character at the end of the line + f.write(line+'\n') + print(len(lines),"lines written to",fileout) + # This function doesn't explicitly return anything. + +if __name__=="__main__": + # First input argument: path to input text file + filein = sys.argv[1] + # Second input argument: path to output text file + fileout = sys.argv[2] # word frequency + # Call function read_lines to get all the input lines into + # a python list 'lines' + lines = read_lines(filein) + # Call function adjustlines to do something to each line + # Result is the list newlines + newlines = adjustlines(lines) + # write the list of new lines to fileout + write_lines(fileout,newlines) + # That's all this little program does + +