python 3.x - Same for loop, giving out two different results using .write() -


this first time asking question let me know if doing wrong (post wise)

i trying create function writes .txt seem 2 different results between calling within module, , writing same loop in shell directly. code follows:

def function(para1, para2): #para1 string searching within para2. para2 list of strings     open("str" + para1 +".txt", 'a'. encoding = 'utf-8') file:     #opens file naming convention          n = 0         word in para2:             if word == para1:                 file.write(para2[n-1]+'\n')                 print(para2[n-1]) #intentionally included part of debugging             n+=1  function("targetstr". targettext)  #target str phrase looking for, targettext tokenized text #looking through. in form of list of strings, output of #another function, , has been 'declared' variable  

when define function in shell, correct words appearing. however, when call same function through module(in shell), nothing appears in shell, , text file shows bunch of numbers (eg: 's93161), , no new lines.

i have gone extent of including print statement right after declaration of function in module, , commented print statement, , yet nothing appears in shell when call it. however, numbers still appear in text file.

i guessing there problem how have defined parameters or how cam inputting parameters when call function.

as reference, here desired output:

‘she

ashley

there

kitty

coates

‘let

let

that

ps: sorry if not clear have limited knowledge on speaking python

i have found solution issue. turns out need close shell , restart before compiler recognizes changes made function in module. took @ issue, , tried help.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -