Skip to content

Python playground. I built, Attack-On-Monsters in the sand-box folder and also Got started with Flask

Notifications You must be signed in to change notification settings

RashJrEdmund/py-sandbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Welcome To My Py Sandbox

  • Checkout the actual sandbox docs, where I study and also build the game "Attack On Monsters" here

    • Note I build it using the NeoVim editor
  • Or checkout my flask apps docs here

Configuring a virtual environment (v-e)

Note: you are gonna have to create a v-e in both the sand-box and flask-app(s) folders(though I haven't installed any modules in the sand-box app)

  • for this i'm using the virtualenv command

  • STEPS TO CREATE VIRTUAL ENVIRONMENT

    • in the projects directory, at top level, run

        # if using the virtualenv package
        $ virtualenv venv
      
        # if using the default venv from python
        # on linux
        $ python3 -m venv venv
    • This should create a venv folder (which is the virtual environment)

    • Next, you have to activate the virtual environment. To do so, execute

        # for linux
        $ source venv/bin/activate
      • Deactivate it by simply executing the deactivate on your terminal
    • you should see you file path look similar to this

        (venv) username@computer:~/full/path/py-sandbox/which-ever-path-you-on/$
    • You should be able to safely install packages with pip

  • Now, to install the packages in requirements.txt file of that folder, execute

      $ pip install -r requirements.txt
      # the -r means it should read from the requirements.txt file
  • ADDING YOUR OWN PACKAGES

    • After every package installation, I advice you update the requirements.txt file with

        $ pip freeze > requirements.txt
        # it's like package.json in JavaScript, but for python
    • you should even combine the installation command with the freeze command like so to execute all at once

        pip install `module_name` && pip freeze > requirements.txt
    • use pip list --local to see all locally installed modules in your virtual env

Cool new commands

  • >>

    • to use with command like echo or pip freeze to add content to the end of a file
  • Example
    • echo "some text content" >> test_file.txt to add the text "some text content" to the test_file.txt. this file will be created if not exit
  • >

    • Same as the >> pattern above but will completely replace the content of the file



Cool command combo

  • find . -type d -name "__pycache__" -exec rm -rf {} +

    • to find and delete all "pycache" folders in the current working directory
  • Explanation

    • find . : Start searching from the current directory (.)
    • -type d : Look for directories (d)
    • -name "__pycache__" : Match directories named "pycache"
    • -exec rm -rf {} + : For each found directory, execute the rm -rf command on it ({} is replaced by the found directory paths)

About

Python playground. I built, Attack-On-Monsters in the sand-box folder and also Got started with Flask

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published