-4

understandable versions of Question:

  • How to detect and get strings inside of parenthesis?
  • How to detect and get datatypes inside of parenthesis?
  • How to detect and get strings inside of parenthesis using If?
  • How to detect and get datatypes inside of parenthesis using if?

example:

x = input("send command(only allow 1 digits of character and only allow A,B<C<D<E<and F)")
if x == "$C A":
    print(x)
elif x == "$C B":
    print(x)
...

6 possibilities(if and elif statements)

tried: using rfind method, rpartition method translate method(translate from parenthesis to curly brackets), used format() method, used str() function

my code(with if statements):

def commandLine():
    c = input()
    if c = "$CR -f a"
        print("you made a file named a")
    elif c = "$CR -f A"
        print("you made a file named A")
...

possibilites: 15,000 or 7,000

lazy code:

def commandLine():
    c = input()
    if c = "$CR -f"
        f = input("filename: ")
        print(f)

possibilites with short code: Infinity(infinite characters can be typed in the f=input() variable)

7
  • You should learn about regular expressions. Commented Apr 21, 2023 at 20:01
  • Your code is hard to read with only 1 space for indentation. Please use the standard 4 spaces. Commented Apr 21, 2023 at 20:02
  • 1
    You can also use the argparse module to parse strings that look like command line arguments. Commented Apr 21, 2023 at 20:03
  • Your code has many syntax errors that you should fix before addressing the real question: = that should be ==, missing : at the end of if, Commented Apr 21, 2023 at 20:16
  • @Barmar argparse gets arguments from the commandline. im getting arguments from the c=input() variable Commented Apr 21, 2023 at 20:23

1 Answer 1

0

You can split your input and make if/else statement with every parameter:

def commandLine():
    c = input()
    c = c.split(" ")
    if c[0] == "$CR":
      if c[1] == "-f":
        if c[2]:
          print("you made a file named {}".format(c[2]))
commandLine()

I'm not sure if this is what you were asking but it's what i understood. I hope it helps

Output:

$CR -f A
you made a file named A
Sign up to request clarification or add additional context in comments.

4 Comments

i have a problem. so when i made a command that writes inside files, it only wrote the "hello," instead of "hello, world"
It this text is at the end of the command line you can use something like this: " ".join(c[2:]) it will get all the text from the number of command that you put to the end of your command line
where do i put it?
in this example if you want a multi word name you should put it like this: print("you made a file named {}".format(" ".join(c[2:]))) i can´t really tell you where to put it whitout looking at your code, but i think this example could help you

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.