Search code examples
pythonsyntaxbatch-fileequivalent

comparing batch to python commands?


Ok i have these commands used in batch and i wanted to know the commands in python that would have a similar affect, just to be clear i dont want to just use os.system("command here") for each of them. For example in batch if you wanted a list of commands you would type help but in python you would type help() and then modules... I am not trying to use batch in a python script, i just wanna know the similarities in both languages. Like in english you say " Hello" but in french you say "Bonjour" not mix the two languages. (heres the list of commands/functions id like to know:

  1. change the current directory
  2. clear the screen in the console
  3. change the prompt to something other than >>>
  4. how to make a loop function
  5. redirections/pipes
  6. start an exteral program (like notepad or paint) from within a script
  7. how to call or import another python script
  8. how to get help with a specific module without having to type help()

@8: (in batch it would be command /?)

EDITED COMPLETELY

Thanks in Adnvance!


Solution

  • You can't just mechanically translate batch script to Python and hope that it works. It's a different language, with different idioms and ways of doing things, not to mention the different purpose.

    I've listed some functions related to what you want below, but there's no substitute for just going and learning Python!


    1. os.chdir

    2. os.system("cls") is probably the simplest solution

    3. Change sys.ps1 and sys.ps2.

    4. Nope, there are no gotos in Python. Use for and while loops instead.

    5. Doesn't make sense, use Python's IO instead.

    6. subprocess.Popen

    7. Doesn't make sense, use import or subprocess.Popen instead.

    8. help