Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing module error
#6
I don't know what's going on. I don't have your full code (I don't even have Pygame), so I can't run all of it. But if I eliminate the imports I don't have, char imports and Char instantiates. You might have another variable char that is confusing things. You might have another file named char.py that is confusing things.

The way that you are importing things looks odd, and could cause other problems down the line. This is how I would recommend doing things. Have a separate file for each class, it's sub-classes, and any constants they need. None of them should have top level variables that are going to change, and none of the classes should have instances. If there is anything that two of those files need, but it into another file. Instances of the classes should only be made in other classes, or in a main program file responsible for running the overall code. These instances should be passed from class to class as attributes when needed.

For example, in my t_games project, there is a file for the Interface class. An instance of that is created in the main program file. The interface instance loads all of the game classes from their .py files, and creates an instance of the Human class from the player.py file. The interface instance creates an instance of the current game, passes the human instance to the game instance. The game instance creates instances of any AI players. These are defined in the game file, inheriting from the base classes in the player.py file. The human and the AI player instances are all passed a copy of the game instance so that they can interact with it.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Importing module error - by walernor - Feb-01-2019, 04:16 PM
RE: Importing module error - by ichabod801 - Feb-01-2019, 04:21 PM
RE: Importing module error - by walernor - Feb-01-2019, 04:56 PM
RE: Importing module error - by ichabod801 - Feb-01-2019, 06:18 PM
RE: Importing module error - by walernor - Feb-02-2019, 08:50 AM
RE: Importing module error - by ichabod801 - Feb-02-2019, 04:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  importing variables from module 8376459 1 349 Feb-18-2024, 02:24 PM
Last Post: deanhystad
  no module named 'docx' when importing docx MaartenRo 1 1,159 Dec-31-2023, 11:21 AM
Last Post: deanhystad
  pyarrow error when importing pandas sravva 1 1,040 Jun-06-2023, 05:09 PM
Last Post: snippsat
  My code displays too much output when importing class from a module lil_e 4 1,282 Oct-22-2022, 12:56 AM
Last Post: Larz60+
  Importing module in jupyter Noteboook ajitnayak1987 0 1,796 Jun-04-2021, 12:26 PM
Last Post: ajitnayak1987
  ERROR: importing desired module mbgamer28 0 1,729 Apr-05-2021, 07:46 PM
Last Post: mbgamer28
Bug Error while importing numpy Erfan 3 3,373 Nov-28-2020, 07:49 AM
Last Post: bowlofred
  importing module - not working jdhamblett 3 3,125 Jun-22-2020, 07:33 PM
Last Post: jdhamblett
  importing same python library in multiple custom module escape_freedom13 6 3,976 May-10-2020, 07:01 PM
Last Post: escape_freedom13
  vlc module error pythonprogrammer 1 2,944 Apr-23-2020, 04:16 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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