Python Forum
[cx_Freeze] Build .exe they get more .py files, help needed !
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[cx_Freeze] Build .exe they get more .py files, help needed !
#2
A little basic.
1 python file that's imported is  called a module.
More than 1 file working together is often called a package.
Using __init__.py as glue to navigate the file tree.

So a game can have many files,and often a main python file that start the game.
Can look a silly setup where more than one file work together.

Folder setup:
my_game/
 |-- __init__.py
 |-- start_game.py
 sub_folder/
   |-- __init__.py
   |-- game_module_1.py
   |-- game_module_2.py
start_game.py:
import random
import time
from sub_folder import game_module_1, game_module_2

def game():
    time.sleep(5)
    return random.choice([game_module_1.motor_1(), game_module_2.motor_2()])

print('Dos the motor start???')
if game() == 'start motor':
    print('The motor did start')
else:
    print('The motor did not start')
__init__.py:
from .sub_folder import motor_1
from .sub_folder import motor_2
game_module_1.py:
def motor_1():
    return 'start motor'
game_module_2.py:
def motor_2():
    return 'Stop motor'
The __init__.py in sub folder is empty.

Running this game:
Output:
C:\1\my_game λ python start_game.py Dos the motor start??? The motor did not start C:\1\my_game λ python start_game.py Dos the motor start??? The motor did start C:\1\my_game λ python start_game.py Dos the motor start??? The motor did not start
Reply


Messages In This Thread
RE: [cx_Freeze] Build .exe they get more .py files, help needed ! - by snippsat - Oct-01-2017, 09:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Failed tkinter Compile In Custom 3.7.2 Build Using Custom Tcl/Tk Build gwc 0 2,668 Jan-25-2019, 01:56 PM
Last Post: gwc
  [cx_Freeze] CMD Prompt can't find my setup.py, help needed ! JamieVanCadsand 1 3,833 Sep-30-2017, 10:10 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020