Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get data from .dat file with python

I need to read a .dat file in python, i need to read two value from dat file

[Registration information]
Name=nikam
Key=**KDWOE**

need to get nilkam from name and KDWOE from key

    datContent = [i.strip().split() for i in open("./license.dat").readlines()]
        print (datContent)       

i got this result
[[‘[Registration’, ‘information]’], [‘Name=nilkam’], [‘Key=KZOiX=BFcjLKqJr6HwYxYU+NHN8+MP7VO0YA5+O1PwX0C3twCmum=BLfBI95NQw’]]
and from second

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    with open("./license.dat", 'r') as f :
              f = (f.read())
        print (f)

i got this

[Registration information]
Name=nikam
Key=KDWOE

i need result need to get nilkam from name and KDWOE from key

>Solution :

I’m not sure what a .dat file is, and you don’t specify, but given your example it looks like the configparser library might work for you.

import configparser

config = configparser.ConfigParser()
config.read('./license.dat')

print(config['Registration information']['Name'])
print(config['Registration information']['Key'])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading