0

if param[0:4]<>'ini=':
print ' %s ini='%sys.argv[0]
sys.exit(1)
inifile=param[4:]

Hi All,

Can u explain wht actually above code work?

Thanks in Advance.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by jlm699
1

First of all, you should use code tags like such:
[code=python] # Code goes in here

[/code]
Which would've given you the following:

if param[0:4]<>'ini=':
    print ' %s ini='%sys.argv[0]
    sys.exit(1)
inifile=param[4:]

Now, to answer your question:
First we check that the first 4 characters of param are "not equal" to ini= ... <> is the obsoleted form of != So, as long as the first four characters of param are not 'ini=' then we execute the code block within the if statement, which is printing the name of our program ( sys.argv[0] is always the name of the running program), and then we exit with a return of 1...

If the first four characters of param WERE 'ini=', then we would execute the line of code immediately after the if block, which declares the variable inifile to be equal to the remainder of param.. here's an example of that slicing:

>>> param = 'ini=myinifile.txt'
>>> param[0:4]
'ini='
>>> param[:4]
'ini='
>>> param[4:]
'myinifile.txt'
>>>
Votes + Comments
very nice
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.