0

so, i have a bit of a problem here. (it might be confusing, i'll explain it) whenever i try to run my program, game.py, i run into an error telling me that "maptile" cannot be imported, however it exists as a class and said class is what i'm trying to import. can anyone help me?

this part might make it a bit hard: there are multiple files, and the error is coming from actions.py, which is where i'm trying to import "maptile". however, in tiles.py, which is where maptile is defined, it's defined on the third line. to combat this error, i moved the import of maptile (in actions.py) down to line 10 or 13. this would mean the import is happening after maptile is defined. i still got the error.

the import (that i think is where the error is coming from):

from tiles import MapTile

the error:

 Traceback (most recent call last):
        File "C:\Users\littl\OneDrive\Documents\Python 
     Programs\adventuregame\game.py", line 1, in <module>
     import world, tiles, actions, enemies
        File "C:\Users\littl\OneDrive\Documents\Python 
     Programs\adventuregame\tiles.py", line 1, in <module>
     import items, enemies, actions, world
        File "C:\Users\littl\OneDrive\Documents\Python 
     Programs\adventuregame\actions.py", line 13, in <module>
     from tiles import MapTile
    ImportError: cannot import name 'MapTile'

if you need any more information, i can give it to you.

Ivam
  • 379
  • 3
  • 12
  • Can you give us a [mcve], as in `actions.py` and `tiles.py` files with all the extraneous stuff removed, just enough code to reproduce the error? Without that, all we can really do is guess. – abarnert Jul 14 '18 at 03:48
  • As a guess, though, you probably have a circular import. If so, it's probably a dup of [this question](https://stackoverflow.com/questions/22187279/). – abarnert Jul 14 '18 at 03:48
  • @abarnert sure! [actions.py](https://pastebin.com/tp2tBrNk) [tiles.py](https://pastebin.com/kBk9rFTg) – InsertUsernameSTO Jul 15 '18 at 03:06
  • No, post the relevant parts of those files as part of the question, don't give us links to the entire files on some external site in a comment. And make sure they're enough to reproduce the error (and tell us what command to use—e.g., does `python3 tiles.py` do it?). Please read the MCVE link I gave in my first comment. – abarnert Jul 15 '18 at 19:34
  • Also, if your problem is a circular import, did you read the question I linked above? You need to read at least the top two answers (and maybe skim the top comments underneath them), but between them, they should cover what's happening, why it's happening, and the various ways can you fix it. If that solves your problem, just say so and we can close your question as a dup. If not, explain why it doesn't. (If your problem isn't a circular important, of course, ignore all of this.) – abarnert Jul 15 '18 at 19:40

0 Answers0