[prog] Problem with objects in Python3

David Sumbler david at aeolia.co.uk
Wed Mar 30 18:45:00 UTC 2022


I have used Python quite a bit for odd projects in the past, but I am
certainly nowhere near being an expert (nor ever likely to be).

The problem I am struggling with at the moment is this: the program I
am working on reads a file which contains data about a number of
people.  Each line has data about just one person (including her/his
name), and normally there will be a number of other lines with
different data about that same person.

What I want to do is to use the person's name (with spaces removed) as
a variable name, and create a Person object using that name.

My problem is that I can't hard code the variable name because it is
derived from data in the input file.  With a hard-coded name I can
easily check whether the object exists, and create it if it doesn't;
but I can't figure out how to do this with names that are derived from
data in a file.

Can somebody point me in the right direction?

David


More information about the Programming mailing list