Skip to content
Sign upLog in
← Back to Community

How to connect and link two files together using python?

Profile icon
Matt1101

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 [earned 5 cycles]
View Answer
Voters
Profile icon
Matt1101
Comments
hotnewtop
Profile icon
ch1ck3n

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.

Profile icon
Matt1101

@ch1ck3n
Thanks

Profile icon
ch1ck3n
Profile icon
Matt1101

@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?

Profile icon
Matt1101
Profile icon
ch1ck3n

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

Profile icon
Matt1101

@ch1ck3n
Still it doesn't work

Profile icon
ch1ck3n

@Matt1101
hmmm can you invite me to the repl

Profile icon
Matt1101

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