Reputation: 69
I'm working with a pygame tutorial and I'm importing the pygame module on a separate file from my main.py.
pygame.py:
import pygame
class Game:
def __init__(self):
main.py:
from game import Game
def main():
I'm guessing I already have my answer, since I keep receiving the error: "NameError: name 'pygame' is not defined", but is there any way to nest modules without importing them into your main? Not a big deal, just thought I'd ask.
Upvotes: 0
Views: 75
Reputation: 36680
You might access imported modules inside imported modules following way
mymodule.py
import math
class Math:
pass
main.py
import mymodule
print(mymodule.math.cos(0.0))
then running python main.py
output
1.0
Upvotes: 1