how to read a specific line which starts in "#" from file in python -


how can read specific line starts in "#" file in python , set line key in dictionary (without "#") , set lines after line until next "#" value dictionary please me
here file :

01

please me :(

from collections import defaultdict  key = 'nokey' d = defaultdict(list)  open('thefile.txt', 'r') f:     line in f:         if line.startswith('#'):             key = line.replace('#', '')             continue         d[key].append(line) 

your dictionary have list of lines under each key. lines come before first line starting '#' stored under key 'nokey'.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -