Using arguments in a function from another function

I have a text document with the following format:

word_1 word_2 word_3
word_4 word_5 word_6

For each line of this text document:

  • first: I want to save the words and add "_info"to each word;
  • Second: the arguments I want to use in the next function (which repeats for each row) are:

    def my_function 
    ("word_1","word_2","word_3","word_1_info","word_2_info","word_3_info")
    

After the first calculations with the arguments of the first line, the following arguments will be:

def my_function ("word_4","word_5","word_6","word_4_info","word_5_info","word_6_info")

The most next I've been was reading (because I'm having trouble adding "_info" to each word), the text file information as follows:

f = open("test.txt","r")
array=[]

for line in f:
    x = re.findall(r"[a-zA-Z]+_+\d",line)
    array.append(x)


def my_function("array[0][0]","array[0][1]","array[0][2]")

How can I improve my code to do what I need?

Author: hkotsubo, 2020-06-01

1 answers

Hello, I will try to help you:)

For python this "array= [ ]" is actually a list

>>> type([]) ===:> class list

When you enter a file, you can pass it directly into a loop.

I imagine this file internally would look like this:

Word_4

Word_5

Word_6

Word_4

Word_5

New_list = list ()

For lines in open ("test.txt'):

# lines .... The reading of the txt but nevertheless there was a \n

Lines.strip() # this way an empty line

Ref = f ' {lines.strip ()} _info ' # using f string

New_list.append (ref) # add list

If in this file there are more than 10 contents.

Will you write everyone ?

Could use a decompressor

Def my_function (*nova_list)

Loop.....

If you really want to access each one by function

Def my_function (exem1, exem2, exem3, exem4 ,exem5)

Print (exem1)

Print (exem2)

Just call the function by passing the list

My_function (*nova_list)

 0
Author: jeferson.cardoso, 2020-06-02 18:42:34