Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Overload of constructor
#1
Hello, I have for files AllOnesGA.py with the main(), GeneticAlgorithm.py,Population.py and Individual.py

The cuestion is that pycharm mark as an error the overloading of the constructor
thanks
class Population:
    def __init__(self,populationSize):
        self.populationSize=individual_file[populationSize]
    def __init__(self,populationSize,chromosomeLength):
        self.population = individual_file.Individual[populationSize]
        for individualCount in range (0,populationSize):
            individual = individual_file(chromosomeLength)
            self.population[individualCount]= individual
        ...
what I'm doing wrong

ps:the error is
Error:
File "/home/psm/PycharmProjects/AllOnesGA/genetic_algorithm.py", line 12, in initPopulation population = population_file.Population(self.populationSize, chromosomeLength) File "/home/psm/PycharmProjects/AllOnesGA/population_file.py", line 7, in __init__ self.population = individual_file.Individual[populationSize] TypeError: 'type' object is not subscriptable
Reply


Messages In This Thread
Overload of constructor - by psosmol - Apr-16-2019, 10:07 AM
RE: Overload of constructor - by buran - Apr-16-2019, 10:14 AM
RE: Overload of constructor - by psosmol - Apr-17-2019, 05:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 1,047 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Not including a constructor __init__ in the class definition... bytecrunch 3 12,393 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  syntaxerror when entering a constructor MaartenRo 2 2,056 Aug-03-2020, 02:09 PM
Last Post: MaartenRo
  error in constructor overriding in python3 srm 1 1,876 Jul-18-2019, 12:21 PM
Last Post: ichabod801
  This constructor takes no arguments Friend 2 5,423 Jun-26-2019, 02:54 PM
Last Post: Friend
  class constructor with dataframe UGuntupalli 2 2,378 Jun-11-2019, 10:50 PM
Last Post: UGuntupalli
  How I can overload operator [] ? AlekseyPython 3 3,236 Feb-20-2019, 05:38 AM
Last Post: AlekseyPython
  Constructor Rajesh1978 2 3,267 May-22-2018, 05:18 PM
Last Post: micseydel
  I'm trying to make a constructor without hardcoding all of the values RedSkeleton007 7 4,585 Apr-05-2018, 11:12 AM
Last Post: buran
  Author class, with constructor validations nexusfactor 3 2,959 Oct-12-2017, 11:00 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020