Why did replit add so many files when I imported one of my scripts to main.py?

Question: Why did replit add so many files when I imported one of my scripts to main.py??

Repl link: https://replit.com/@GenericEngineer/Stronghold-Board-Game

import player

Console result:

--> poetry add player
Using version ^0.6.1 for player
Updating dependencies
Resolving dependencies...
Package operations: 15 installs, 0 updates, 0 remo vals
Writing lock file


• Installing pastedeploy (3.1.0)

• Installing plaster (1.1.2)

• Installing setuptools (69.0.3)

• Installing hupper (1.12)

• Installing markupsafe (2.1.3)

• Installing plaster-pastedeploy (1.0.1)

• Installing translationstring (1.4)

• Installing venusian (3.1.0)

• Installing webob (1.8.7)

• Installing zope-deprecation (5.0)

• Installing zope-interface (6.1)

• Installing jinja2 (3.1.3)

• Installing pyramid (2.0.2)

• Installing pyramid-jinja2 (2.10)

• Installing player (0.6.1)

That would be a package auto-guessing error, run poetry remove player in the Shell, and add this to your .replit file:

4 Likes

Thanks for the help!

that does work, but for better practice, since you aren’t exporting the modules, consider organising your file structure to avoid ambiguous imports which might collide with other packages. Also worth mentioning the less recommended: append #upm package(.) to the lines of incorrectly guessed imports.

AI: "re-organise files to prevent ambiguous imports" (edited slightly)
  1. Create distinct packages (directories) for logically grouped modules.
  2. Minimize the use of global variables in favor of passing parameters and returning values.
    Here’s an example of how you could organize your modules:
  • Root Directory
    • main.py
    • uniqueGame
      • __init__.py
      • board.py
      • dice.py
      • pieces.py
      • player.py
      • enemy.py

In Python, each directory with an __init__.py file is considered a package, and modules within that package can be imported.

Now that we have a proposed structure, let’s see how the main.py imports would be updated according to this new structure:

from termcolor import colored as c
from time import sleep as s
import re

from uniqueGame.board import init as init_board, printBoard, placePiece, movePiece, attack
from uniqueGame.pieces import piece, remCo
from uniqueGame.dice import roll
from uniqueGame.player import money, income

# ... The rest of your main.py file remains unchanged ...

In this main.py, we’ve converted broad imports like import board into more specific statements such as from uniqueGame.board import init as init_board, printBoard, placePiece, movePiece, attack. We’ve also appropriately namespaced where each function comes from, promoting better readability and maintainability.
I can’t verbatim retrieve the prompt I gave the AI


To reduce load times you might want to remove discord-haskell in the “System Dependencies” tool.
no more comments on repls so time to go a bit off-topic in help topics

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.