oliveiracarlos Posted June 12, 2012 at 03:22 AM Report Share #462094 Posted June 12, 2012 at 03:22 AM Boa noite, Tenho um ficheiro "Exercicio.py" que tem como função abrir um ficheiro cujo nome está contido no script, neste caso "Texto.txt". Gostava de saber se é possivél chamar esta função pela shell de comandos da seguinte forma: abre trabalho.txt, em vez de python Exercicio.py? Tenho pesquisado bastante e não consegui nenhuma resposta a esta duvida. mais uma vez obrigado pela vossa ajuda. Link to comment Share on other sites More sharing options...
brunoais Posted June 12, 2012 at 10:19 AM Report Share #462127 Posted June 12, 2012 at 10:19 AM em que OS? "[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31 Life is a genetically transmitted disease, induced by sex, with death rate of 100%. Link to comment Share on other sites More sharing options...
oliveiracarlos Posted June 12, 2012 at 06:09 PM Author Report Share #462333 Posted June 12, 2012 at 06:09 PM Estou a usar o Ubuntu numa maquina virtual Link to comment Share on other sites More sharing options...
Th3Alchemist Posted June 13, 2012 at 09:16 AM Report Share #462417 Posted June 13, 2012 at 09:16 AM (edited) nao, mas podes abrir o script com argumentos como por exemplo; ~$ python Exercicio.py abre ficheiro.txt para tal, utilizas o sys.argv Edited June 13, 2012 at 09:18 AM by Th3Alchemist Link to comment Share on other sites More sharing options...
brunoais Posted June 13, 2012 at 02:56 PM Report Share #462511 Posted June 13, 2012 at 02:56 PM Dá aqui uma vista de olhos: http://linux.about.com/od/commands/a/Example-Uses-Of-The-Command-Alias.htm "[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31 Life is a genetically transmitted disease, induced by sex, with death rate of 100%. Link to comment Share on other sites More sharing options...
bsccara Posted June 14, 2012 at 12:03 AM Report Share #462601 Posted June 14, 2012 at 12:03 AM Podes fazer Exercicio.py <nome do ficheiro> (sem o 'python' antes), se é isso que queres. Para isso mete esta linha no topo do ficheiro .py: #!/usr/bin/python e marca-o como executável com 'chmod a+x Exercicio.py'. Já agora a extensão 'py' não é necessária (recomendável mas não necessária). Link to comment Share on other sites More sharing options...
oliveiracarlos Posted June 14, 2012 at 06:56 AM Author Report Share #462613 Posted June 14, 2012 at 06:56 AM Obrigado pela ajuda resultou Link to comment Share on other sites More sharing options...
tiagogala Posted July 8, 2012 at 06:08 PM Report Share #467935 Posted July 8, 2012 at 06:08 PM Uma alternativa é adicionares o header #! /usr/bin/python marcar o ficheiro como executável chmod +x exercício.py , mudar-lhe o nome para "abre" e colocá-lo em em /usr/bin (acho eu). Assim, a partir da linha de comandos basta escrever $ abre <ficheiro.txt> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now