Question: This is how i made my CSV file:

```
with open('Mail_Txt.csv', 'w', encoding='utf-8', newline='') as csvfile:
    fieldnames= ['Sender', 'Subject', 'Snippet']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames , delimiter=',')
    for val in final_list:
        writer.writerow(val)

```

I try many methods to print the Sender column of the CSV file. But I fail all the time. so, help me to print the first or `'Sender'` column of the CSV file

Answer: 
I have stored device configuration in device\_config.cfg file. using ciscoconfparse and regex module I am able to do this.

```
from ciscoconfparse import CiscoConfParse
import re

final_list = []
cisco_file = 'device_config.cfg'

cisco_cfg = CiscoConfParse(cisco_file)
parent_child_line = cisco_cfg.find_objects_w_child(parentspec=r"", childspec=r"10.10.10.10")
parsed_data = cisco_cfg.find_objects(r"10.10.10.10")

# print(parent_child_line)
# print(parsed_data)

for p_line in parent_child_line:
    # print(p_line.text)
    final_list.append(p_line.text)
    for child in p_line.children:
        if re.search(r'10.10.10.10', child.text):
            # print(child.text)
            final_list.append(child.text)

print('\n#############################################\n')

for i in parsed_data:
    if not re.search(r'^\s\w', i.text):
        # print(i.text)
        final_list.append(i.text)
        print(final_list)

```
As far as I can see, we can do it without regex assuming that by `parent line` you mean the line starting with `ip access-list`.

```py
parent_line = None

# data being the input string
for line in data.splitlines():
    if line.startswith('ip access-list'):
        parent_line = line
    elif '10.10.10.1' in line:
        print(parent_line)
        print(line)

```

It prints:

```py
ip access-list extended test2
permit ip host 10.10.10.1 any log

```

---

This code will need very minor changes if the parent and child lines need to be identified based on whitespace at the beginning.