On 29 October 2012 13:32, Oscar Benjamin wrote:
>
> def main(x, y='default'):
> print(x)
> print(y)
>
> if __name__ == "__main__":
> main(sys.argv[1:])
A quick correction. That should be (note the *):
if __name__ == "__main__":
main(*sys.argv[1:])
Oscar
On 29 October 2012 06:06, Saad Javed wrote:
> Hi,
>
> #!/usr/bin/env python
>
> import sys
>
> x = 'Saad is a boy'
>
> def main(x):
> a = []
> b = x.split(' ')
> for item in b:
> a.append(item)
> print a
> if __name__ == '__main__':
> x = sys.argv[1]
> main(x)
>
>
> How can I make this program run
On 29 Oct 2012 02:30, "Saad Javed" wrote:
>
> I've come up with this:
>
> try:
> sys.argv[1]
> x = sys.argv[1]
> main(x)
> except IndexError:
> main(x)
>
> It works but seems hackish.
>
> Saad
Saad,
The first sys.argv is not needed.
Notice how i have replied below the text i am quoting? That is
Saad Javed wrote:
> Hi,
>
> #!/usr/bin/env python
>
> import sys
>
> x = 'Saad is a boy'
>
> def main(x):
> a = []
> b = x.split(' ')
> for item in b:
> a.append(item)
> print a
> if __name__ == '__main__':
> x = sys.argv[1]
> main(x)
>
>
> How can I make this program run with the default va
On Mon, Oct 29, 2012 at 11:28:05AM +0500, Saad Javed wrote:
> I've come up with this:
>
> try:
> sys.argv[1]
> x = sys.argv[1]
> main(x)
> except IndexError:
> main(x)
>
> It works but seems hackish.
There's no need to look up sys.argv[1] twice, nor any need to write
main(x) in both blocks. You
Saad, please don't send HTML emails, as it destroys the essential
formatting of your code.
On Mon, Oct 29, 2012 at 11:06:14AM +0500, Saad Javed wrote:
> How can I make this program run with the default value of x if I don't
> specify an argument at the command line?
arguments = sys.argv[1:] #
I've come up with this:
try:
sys.argv[1]
x = sys.argv[1]
main(x)
except IndexError:
main(x)
It works but seems hackish.
Saad
On Monday, October 29, 2012, Saad Javed wrote:
> Hi,
>
> #!/usr/bin/env python
>
> import sys
>
> x = 'Saad is a boy'
>
> def main(x):
> a = []
> b = x.split(' ')
> for
Hi,
#!/usr/bin/env python
import sys
x = 'Saad is a boy'
def main(x):
a = []
b = x.split(' ')
for item in b:
a.append(item)
print a
if __name__ == '__main__':
x = sys.argv[1]
main(x)
How can I make this program run with the default value of x if I don't
specify an argument at the command line