WA SENDER
WA SENDER

Reputation: 15

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

    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

Upvotes: 0

Views: 547

Answers (1)

brunns
brunns

Reputation: 2764

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'])

Upvotes: 1

Related Questions