Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

Commonmark migration
Source Link

I'm trying to create variable names such as:

event1
event2
event3

to name different instances of the same class.

I searched online, and a lot of people are suggesting dictionary. But as far as I know, dictionary only works for pairs. I want to name different instances of the same class, for example:

class Event:
 def __init__(self, description):
 self.__description = description
event1 = Event('This is event 1')
event2 = Event('This is event 2')
event3 = Event('This is event 3')

Does anyone know how I can do that? Thanks in advance.

Edit 1:

#Edit 1: ItIt appears my question was not clear enough. I do not know how many instances are needed. I will read the length of a file (the number of lines in the file), and then create instances of the class.

Edit 2:

#Edit 2: II have multiple pieces of information to fill in the class. For example:

class Event:
 def __init__(self, name, description, value):
 self.__name = name
 self.__description = description
 self.__value = value
event1 = Event('This is event 1', 'Tom eats apple', '20')
event2 = Event('This is event 2', 'Jerry eats pie', '10')
#......
#(maybe 20 or more)

I'm trying to create variable names such as:

event1
event2
event3

to name different instances of the same class.

I searched online, and a lot of people are suggesting dictionary. But as far as I know, dictionary only works for pairs. I want to name different instances of the same class, for example:

class Event:
 def __init__(self, description):
 self.__description = description
event1 = Event('This is event 1')
event2 = Event('This is event 2')
event3 = Event('This is event 3')

Does anyone know how I can do that? Thanks in advance.

#Edit 1: It appears my question was not clear enough. I do not know how many instances are needed. I will read the length of a file (the number of lines in the file), and then create instances of the class.

#Edit 2: I have multiple pieces of information to fill in the class. For example:

class Event:
 def __init__(self, name, description, value):
 self.__name = name
 self.__description = description
 self.__value = value
event1 = Event('This is event 1', 'Tom eats apple', '20')
event2 = Event('This is event 2', 'Jerry eats pie', '10')
#......
#(maybe 20 or more)

I'm trying to create variable names such as:

event1
event2
event3

to name different instances of the same class.

I searched online, and a lot of people are suggesting dictionary. But as far as I know, dictionary only works for pairs. I want to name different instances of the same class, for example:

class Event:
 def __init__(self, description):
 self.__description = description
event1 = Event('This is event 1')
event2 = Event('This is event 2')
event3 = Event('This is event 3')

Does anyone know how I can do that? Thanks in advance.

Edit 1:

It appears my question was not clear enough. I do not know how many instances are needed. I will read the length of a file (the number of lines in the file), and then create instances of the class.

Edit 2:

I have multiple pieces of information to fill in the class. For example:

class Event:
 def __init__(self, name, description, value):
 self.__name = name
 self.__description = description
 self.__value = value
event1 = Event('This is event 1', 'Tom eats apple', '20')
event2 = Event('This is event 2', 'Jerry eats pie', '10')
#......
#(maybe 20 or more)
added 390 characters in body
Source Link
SamTulster
  • 79
  • 1
  • 10

I'm trying to create variable names such as:

event1
event2
event3

to name different instances of the same class.

I searched online, and a lot of people are suggesting dictionary. But as far as I know, dictionary only works for pairs. I want to name different instances of the same class, for example:

class Event:
 def __init__(self, description):
 self.__description = description
event1 = Event('This is event 1')
event2 = Event('This is event 2')
event3 = Event('This is event 3')

Does anyone know how I can do that? Thanks in advance.

#Edit 1: It appears my question was not clear enough. I do not know how many instances are needed. I will read the length of a file (the number of lines in the file), and then create instances of the class.

#Edit 2: I have multiple pieces of information to fill in the class. For example:

class Event:
 def __init__(self, name, description, value):
 self.__name = name
 self.__description = description
 self.__value = value
event1 = Event('This is event 1', 'Tom eats apple', '20')
event2 = Event('This is event 2', 'Jerry eats pie', '10')
#......
#(maybe 20 or more)

I'm trying to create variable names such as:

event1
event2
event3

to name different instances of the same class.

I searched online, and a lot of people are suggesting dictionary. But as far as I know, dictionary only works for pairs. I want to name different instances of the same class, for example:

class Event:
 def __init__(self, description):
 self.__description = description
event1 = Event('This is event 1')
event2 = Event('This is event 2')
event3 = Event('This is event 3')

Does anyone know how I can do that? Thanks in advance.

#Edit 1: It appears my question was not clear enough. I do not know how many instances are needed. I will read the length of a file (the number of lines in the file), and then create instances of the class.

I'm trying to create variable names such as:

event1
event2
event3

to name different instances of the same class.

I searched online, and a lot of people are suggesting dictionary. But as far as I know, dictionary only works for pairs. I want to name different instances of the same class, for example:

class Event:
 def __init__(self, description):
 self.__description = description
event1 = Event('This is event 1')
event2 = Event('This is event 2')
event3 = Event('This is event 3')

Does anyone know how I can do that? Thanks in advance.

#Edit 1: It appears my question was not clear enough. I do not know how many instances are needed. I will read the length of a file (the number of lines in the file), and then create instances of the class.

#Edit 2: I have multiple pieces of information to fill in the class. For example:

class Event:
 def __init__(self, name, description, value):
 self.__name = name
 self.__description = description
 self.__value = value
event1 = Event('This is event 1', 'Tom eats apple', '20')
event2 = Event('This is event 2', 'Jerry eats pie', '10')
#......
#(maybe 20 or more)
added 212 characters in body
Source Link
SamTulster
  • 79
  • 1
  • 10

I'm trying to create variable names such as:

event1
event2
event3

to name different instances of the same class.

I searched online, and a lot of people are suggesting dictionary. But as far as I know, dictionary only works for pairs. I want to name different instances of the same class, for example:

class Event:
 def __init__(self, description):
 self.__description = description
event1 = Event('This is event 1')
event2 = Event('This is event 2')
event3 = Event('This is event 3')

Does anyone know how I can do that? Thanks in advance.

#Edit 1: It appears my question was not clear enough. I do not know how many instances are needed. I will read the length of a file (the number of lines in the file), and then create instances of the class.

I'm trying to create variable names such as:

event1
event2
event3

to name different instances of the same class.

I searched online, and a lot of people are suggesting dictionary. But as far as I know, dictionary only works for pairs. I want to name different instances of the same class, for example:

class Event:
 def __init__(self, description):
 self.__description = description
event1 = Event('This is event 1')
event2 = Event('This is event 2')
event3 = Event('This is event 3')

Does anyone know how I can do that? Thanks in advance.

I'm trying to create variable names such as:

event1
event2
event3

to name different instances of the same class.

I searched online, and a lot of people are suggesting dictionary. But as far as I know, dictionary only works for pairs. I want to name different instances of the same class, for example:

class Event:
 def __init__(self, description):
 self.__description = description
event1 = Event('This is event 1')
event2 = Event('This is event 2')
event3 = Event('This is event 3')

Does anyone know how I can do that? Thanks in advance.

#Edit 1: It appears my question was not clear enough. I do not know how many instances are needed. I will read the length of a file (the number of lines in the file), and then create instances of the class.

Source Link
SamTulster
  • 79
  • 1
  • 10
Loading
lang-py

AltStyle によって変換されたページ (->オリジナル) /