Sabe aquela hora que seu console do Python fica cheio de coisas, sim existe uma maneira de limpar.
Vamos lá.
Salve ele como o nome que quiser
Você pode usar ele assim:
C:\Users\Cr4t3r> python -i nomedoscript.py
pronto, ele vai criar uma variável global sendo:
cls: em caso de windows
clear: em caso de sistemas Unix.
Ao criar uma instância da classe cls e atribuir esta instância à variável global com o mesmo nome, toda vez que digitamos cls no prompt, para exibir o valor desta variável o Python executa repr(cls) e isso invoca o nosso método cls.__repr__(). Uma solução simples e inteligente, usando um pouco de conhecimento sobre o modelo de objetos da linguagem.
Greetz to Luciano Ramalho, a propósito, sou seu Fã.
Vamos lá.
Código:
class cls(object): def __repr__(self): import os os.system('cls' if os.name == 'nt' else 'clear') return '' cls = cls()
Você pode usar ele assim:
C:\Users\Cr4t3r> python -i nomedoscript.py
pronto, ele vai criar uma variável global sendo:
cls: em caso de windows
clear: em caso de sistemas Unix.
Ao criar uma instância da classe cls e atribuir esta instância à variável global com o mesmo nome, toda vez que digitamos cls no prompt, para exibir o valor desta variável o Python executa repr(cls) e isso invoca o nosso método cls.__repr__(). Uma solução simples e inteligente, usando um pouco de conhecimento sobre o modelo de objetos da linguagem.
Greetz to Luciano Ramalho, a propósito, sou seu Fã.
Comment