I have two modules:
Main:
variable1, variable2 = 800, 800
Other:
import main
variable1, variable2 = main.variable1, main.variable2
I tried to use import main to access the mains variable, however this will reinitialize the entire main class. That is contrary to what I want. I only want a single value from the variable 1 and variable two into this other file without initialization. What can I do?
When I comment out:
#from main import DISPLAY_W, DISPLAY_H
It will run the map for example.RPG Map
When I uncomment, I get this:
Traceback (most recent call last):
File "D:/Downloads/Programming/Python/Programs/Learning Basics/Program 7.12 - 2D pygame, Snow/main.py", line 7, in <module>
import Weather
File "D:\Downloads\Programming\Python\Programs\Learning Basics\Program 7.12 - 2D pygame, Snow\Weather.py", line 2, in <module>
from main import DISPLAY_W, DISPLAY_H
File "D:\Downloads\Programming\Python\Programs\Learning Basics\Program 7.12 - 2D pygame, Snow\main.py", line 143, in <module>
Weather.initialize_weather()
AttributeError: module 'Weather' has no attribute 'initialize_weather'
This implies I provided no attribute, however note this, I used dir(Weather), to find my problem:
['DISPLAY_H', 'DISPLAY_W', 'MAX_RAIN', 'MAX_SNOW', 'RAIN_SIZE', 'Rain', 'Random', 'SNOW_SIZE', 'SPEED', 'Snow', 'SystemRandom', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'betavariate', 'choice', 'choices', 'expovariate', 'gammavariate', 'gauss', 'getrandbits', 'getstate', 'initialize_rain', 'initialize_snow', 'initialize_weather', 'lognormvariate', 'normalvariate', 'paretovariate', 'pygame', 'rainfall', 'randint', 'random', 'randrange', 'sample', 'screen', 'seed', 'setstate', 'shuffle', 'snowfall', 'triangular', 'uniform', 'vonmisesvariate', 'weibullvariate']
Then again with the main uncommented:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'pygame']
Its erasing my values?
In weather
import pygame
from main import DISPLAY_W, DISPLAY_H
from random import *
DISPLAY_W, DISPLAY_H = 800, 800
screen = pygame.display.set_mode((DISPLAY_W, DISPLAY_H))
In main:
import pygame
import glob
from random import *
from pygame import mixer
import TileSheet
import Button
import Weather
# Load Window
pygame.init()
# 800x800 pixels
DISPLAY_W, DISPLAY_H = 800, 800
canvas = pygame.Surface((DISPLAY_W, DISPLAY_H))
screen = pygame.display.set_mode((DISPLAY_W, DISPLAY_H))
pygame.display.set_caption('Test Tileset')
running = True