Terminal extension for python
Project description
TerminalPyth
Library that allows you to call terminal commands in python whithout discarding director changes (unlike os.system() method does).
Installation:
$ pip install terminalpyth
Usage:
import terminalpy
Create a terminalpy object. Pass True or False as argument if you want (or not) to have back the output.
trm = terminalpy.Terminal(output=True)
Only one straight-forward method: type. Pass inside it the command you want to be executed.
output = trm.type('pwd')
# in this case, returns path to the current directory,
# which in this case is stored in "output"
It works with pretty much every terminal command.
To use "sudo", if you are not in a terminal session itself, you must add the "-S" option, to read the password from IDE (e.g. Pycharm).
trm.clear()
This command clears the memory of the directory changes, returning back to the project foler.
trm.setOutput(output=False)
Changes the state of the return action. If "False", there will be no return value, otherwise there will.
The method allows to change the state during the session.
Example:
Imagine a basic directory tree:
- home
- python
- project1
- main.py
- prokect2
- main2.py
- cpp
- project3
This is the difference between TerminalPyth and os, receiving the same exact instructions:
# /home/python/project1/main.py
import terminalpy as tp
term = tp.Terminal(output=True)
path = term.type('pwd')
print(path)
# output: /home/python/project1
term.type('cd ..')
print(term.type('ls')
# output: project1
# project2
term.type('cd ..')
term.type('cd cpp')
print(term.type('pwd'))
# output: /home/cpp
term.clear()
print(term.type('pwd'))
# output: /home/python/project1
--------------------------------
# /home/python/project2/main2.py
import os
os.system('pwd')
# output: /home/python/project2
os.system('cd ..')
os.system('ls')
# output: main2.py
os.system('cd ..')
os.system('cd c++') # Error: The directory 'cpp' does not exist
os.system('pwd')
# output: /home/python/project2
The main differences between TerminalPyth and os.system():
- TerminalPyth allows multiple direcotry changes
- TerminalPyth allows to store the output in a variable
- TerminalPyth lets you chose if return the output or not
- os.system() prints its output always, in any case
- os.system() doesn't allow to store the output
- os.system() doesn't allow multiple directory change
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file terminalpyth-2.1.0.tar.gz
.
File metadata
- Download URL: terminalpyth-2.1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9f186d4f1ab842c07239b906385de8ae9e1994fa60469fff3f86354cfc1834f |
|
MD5 | d000dccfea602f62ed283543aa6e8ca6 |
|
BLAKE2b-256 | b2a45fc1d318aff343afddcc6d2d07b3ff5f74c6bec2f4b1a4b704f435d2e59b |
File details
Details for the file terminalpyth-2.1.0-py3-none-any.whl
.
File metadata
- Download URL: terminalpyth-2.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 763344f727517a31c9518f72c587eaef1cdee1e1691dd1dc9cccaa51c6b85808 |
|
MD5 | aa2787d31c31cb98051a9601e9239dcd |
|
BLAKE2b-256 | 41c4c0304d922216249ff3df5731469d8f812d75b07098369e2064f62dd10563 |