Sunday, December 13, 2020

Python sys.argv


import sys

if len(sys.argv) > 1:
print (f'\n Bilangan arguments: {len(sys.argv) - 1}')
print (f' Argument List: {str(sys.argv)}\n')
else:
print(f'\n Cuba lagi...')
print(f' Cara guna: {sys.argv[0]} <argument>\n')

Cth

Adli@CyberSec:~$ python adaketak.py

Cuba lagi...
Cara guna: adaketak.py <argument>

Adli@CyberSec:~$

Adli@CyberSec:~$ python adaketak.py saya cuba ya

Bilangan arguments: 3
Argument List: ['adaketak.py', 'saya', 'cuba', 'ya']

Adli@CyberSec:~$

No comments:

Post a Comment

Related post:

Related Posts with Thumbnails