DiffSK / configobj

Python 3+ compatible port of the configobj library
https://configobj.readthedocs.org
Other
322 stars 76 forks source link

Referencing ConfigObj Question + Weird Use Case #200

Closed zig13 closed 1 year ago

zig13 commented 4 years ago

Hi I have a project heavily based on ConfigObj called Scenzig. Haven't worked on it for years but want to get 'back on the horse' Is there a proper way of correctly incorporating the v5.0.6 release of ConfigObj in my repository in a way that links back here? It's written to just use ConfigObj.py and Six.py from the route directory (yes my code is probably horrendous from a readability perspective and definitely not PEP 8 compliant - that's what happens when you learn-as-you-go) but in the ConfigObj repository there is no ConfigObj.py file instead mostly being contained in init.py.

Also way back in the day a limitation of ConfigObj had me stumped for ages. I don't know if it's worth doing a full issue write-up for as it might be considered bad practice.

The issue is with ConfigObj editing and saving an explicit dictionary in unrepr mode.

An early version of my character template was nice and compact and looked like this:

Items = [4, 5]
Abilities = [1, 2]
Currencies = {1: 0, 2: 0}
Vitals = {1: 0, 2: 0}
Attributes = {1: 0, 2: 0}
['Scenes']
Current = 1
Previous = None
States ={}
[Labels]
1 = "Joe"

Whenever ConfigObj was asked to change one of the dictionaries and save it would crash and as I recall the output was not particularly helpful in determining what was at fault. It took me some time to see the pattern.

So I ended up having to expand the dictionaries out into headings and lists. My character templates now look more like this with each ID on a new line:

active = [1,2]
1 = [1]
2 = [1]
[Attributes]
vital = [1,2]
active = [1,2,3,4]
1 = [3]
2 = [4]
3 = [5]
4 = [5]
[AttributeVals]
1 = [1000, 1000]
2 = [1000, 1000]
3 = [50, 100]
4 = [50, 100]
[Currencies]
1 = 0
2 = 0

Seeing as IDs are used, it is no more human readable but much less succinct.

I still use explicit dictionaries in other 'config' files as there is no issue with reading the dictionary e.g. :

commands = ['Inventory','I']
description = 'Look at what items you are carrying'
evaluators = ['n1'] #n1 equals the number of items in inventory 1
    [[1]]
    evaluations = {0:True} #Any non-zero number of items will equate to True and validate this outcome
    text = "You are carrying:"
    effects = {'ListInventory':[1]}
    [[2]]
    evaluations = {0:0} #This outcome will occur only if n1 returns 0
    text = "You're not carrying anything."

For the record all the Config files are intended to be written/edited by Adventure writers who would not be the typical end user. My intention is for people to be able to write interactive fiction/an adventure game without having to learn one of the impenetrable and often propriety languages designed for the purpose.

Thanks for maintaining this incredibly useful Library!

robdennis commented 1 year ago

I'm declaring bankruptcy on this issue, but if you're stilling wondering this after 2.5 years ( :grimacing: ) then please re-open before 5.1.0 releases and I'll see what I can do