0

A function is returning me the below list of named tuples:

[popenfile(path='/home/giampaolo/monit.py', fd=3, position=0, mode='r', flags=32768), popenfile(path='/var/log/monit.log', fd=4, position=235542, mode='a', flags=33793)]

I want to print the value of 'path' in the tuple. How to do this? Please help dear community.

I tried to follow online articles but no solve.

1 Answers1

1

To make it clear see below code:

from collections import namedtuple

popenfile = namedtuple('popenfile', 'path fd position mode flags')

tuple_list = [popenfile(path='/home/giampaolo/monit.py', fd=3, position=0, mode='r', flags=32768), popenfile(path='/var/log/monit.log', fd=4, position=235542, mode='a', flags=33793)]

for ntup in tuple_list:
    print(ntup.path)

which prints

/home/giampaolo/monit.py
/var/log/monit.log
user19077881
  • 3,643
  • 2
  • 3
  • 14