0

I am currently debugging a script and i believe the issue is the configuration file not being read (jupyter notebook). I can confirm both the script and the .config file is located in the below directory

os.getcwd()

'C:\\Users\\User'
pwd

---output---
'C:\\Users\\User'

below here is the attempt to read the file

configParser = configparser.RawConfigParser()
config_path = r'C:\Users\User\cartpole.config'
configParser.read(config_path)

---output---
['C:\\Users\\User\\cartpole.config']
config = neat.Config(neat.DefaultGenome, neat.DefaultReproduction,
                    neat.DefaultSpeciesSet, neat.DefaultStagnation,
                    config_path)

population = neat.Population(config)

How would i go about printing the configuration file to confirm if its being read?

Thank you.

1 Answers1

1

If you just want to print the file:

with open('C:\\Users\\User\\cartpole.config', 'r') as f:
        for line in f:
            print(line)

EDIT: To make sure that you reference the same file:

configParser = configparser.RawConfigParser()
config_path = r'C:\Users\User\cartpole.config'

with open(config_path, 'r') as f:
    for line in f:
        print(line)
configParser.read(config_path)

If you find yourself in the situation where the config file is correct, but you still do not see your configurations, the problem is probably in your ConfigParser class.

Damiaan
  • 777
  • 4
  • 11
  • Thanks Damiaan. I will select this as the answer when it permits me – Dean Bellamy Apr 25 '22 at 09:59
  • with the suggested code, i can observe my config file. Would this confirm that my above code is reading the configuration file in the last bloc of code(4th bloc) when called upon in ```config = neat.Config....``` – Dean Bellamy Apr 25 '22 at 10:05
  • I've updated my answer to use the same variable for the path. If you can read it, you ensure you pass the same path the the parser. I don't know the class ConfigParser, so if you still have any issues on that you should create a new question on why your parser is not working. – Damiaan Apr 25 '22 at 11:52