icode
icode

Reputation: 57

How to build a new kind of syntax for an object in python

How to build a new kind of syntax which when has been called run it's value in os.system

while True:
    a=input('enter your direction: ')
    if a!='':
        !dir !+Shell(a)
    else:
        print('the dir can not be None')

Upvotes: 1

Views: 45

Answers (1)

temp123
temp123

Reputation: 382

Based on your clarification, maybe this would work for you:

import subprocess

while True:

    cmd = input("Enter a command: ")

    if cmd != "":
        cmd = cmd.split("!")[1]
        subprocess.call(cmd, shell=True)

    else:
        print("Input cannot be None")

Upvotes: 1

Related Questions