1

Please excuse my English

I have multiple modules within many classes and I want to create an initial file to contain a few numbers of object created from classes. I did this by importing it in another file to use the object that I created. Is there any way for me to run the code in initial.py once but import it multiple times for many files? I don't want to run the __init__ function inside the classes that I have multiple times. I found out that I can do it in a very simple way with if function like this:

import role, strategy

i = 1
if (i == 1):
   player = role.Attacker()
   player_strategy = strategy.Attacker()
   i += 1

Is there any smarter way to do it?

2
  • Modules are executed only once anyway. Just remove the if and the i. Commented Mar 29, 2018 at 14:20
  • Thanks for your comment why didn't I realize it sooner :) Commented Mar 29, 2018 at 14:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.