Ask coding questions

← Back to all posts
How to connect and link two files together using python?
Matt1101 (0)

I'm trying to create a game but I do not know how to link two files together. Example: if I have two files, one named main.py and the other named test.py, how can I link the two files together by using both piles to get the result from main.py and test.py?

Answered by ch1ck3n (2335) [earned 5 cycles]
View Answer
Comments
hotnewtop
ch1ck3n (2335)

main.py:

import test

print(mylittletest)

and test.py:

mylittletest = "hello"

when I do import test it imports test.py and every function and variable!

and yes it does run both files so if I put print("bababooey") on both files it would print bababooey twice.

Matt1101 (0)

@ch1ck3n wait for some reason on a replit file I created named help, when I connect the two files together, it doesn't connect the functions or the imports such as import pygame?

ch1ck3n (2335)

@Matt1101 try renaming the file imported.py to something random

Matt1101 (0)

@ch1ck3n Still it doesn't work

ch1ck3n (2335)

@Matt1101 hmmm can you invite me to the repl

Matt1101 (0)

@ch1ck3n Actually someone commented on the help file and the code worked, Thanks for helping.