I have created two files. The first one called EA contains variables and calls to functions. The second file called EA_Functions contains all the functions used in EA.
This is EA:
from EA_Functions import *
HIGHEST_NUMBER = 10
LOWEST_NUMBER = 1
SET_SIZE = 5
NUMBER_OF_PARENTS = 2
NUMBER_OF_CHILDREN = 2
MUTATION_STEP_SIZE = 0.5
warms = {}
# Create an initial random sets of warms
for i in range(SET_SIZE):
warms[i] = np.random.randint(low=LOWEST_NUMBER, high=HIGHEST_NUMBER + 1, size=SET_SIZE, dtype=int)
# Order the set of warms based on the error
warms_sorted = sort(warms)
This is EA_Functions:
import numpy as np
from random import randint
def calculate_error(lst):
return (SET_SIZE - np.mean(lst)) ** 2
def sort(dictionary):
return sorted(dictionary.items(), key=lambda item: calculate_error(item[1]))
I want to use SET_SIZE variable contained in the first file, EA.
If in EA_Functions I try to import EA:
from EA import *
I get errors during the execution of the "main" code, the file EA