Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    40
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Add Command to Python

    I noticed that python has no clear() function.
    So I made one:
    Code:
    def clear():
       import os
       os.system("clear")
    Where can I put this (in a .py file) so that python recognizes it as a command without me having to def it every time?

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Location
    Brasília, Brazil
    Posts
    153
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Save it as a .py file like myfile.py then import it in your program:

    Code:
    from myfile import clear
    
    clear()

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    40
    Thanks
    4
    Thanked 0 Times in 0 Posts
    No, I mean in the interpreter. It works, but when you quit() you have to run from clear import clear again.

  • #4
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Location
    Pilipinas
    Posts
    169
    Thanks
    4
    Thanked 18 Times in 18 Posts
    But when you quit(), you can now use the `clear` command to clear your command line. And yeah, when you restart the interpreter, you pretty much have to import the modules you want to use, like sys, os, or clear.clear.
    I am a Man of Truth. I am a Free Human Person. I am a Peacemaker.
    ** Independent Multimedia Artist in Pasig **


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •