0

I am a beginner in writing Python scripts and I need help on the following:

Threads::num,47141,47146,47151,47156,47161,47166,47171,47176

How can I get and display the last value '47176'

The following is the part of the code I have written:

elif sys.argv[1] == "-c":
    b = sys.argv[2]
    with open(b) as f:
        for line in f:
            if 'Threads::num' in line:
                print line.strip(',').split(',')[-1]
                print line

The output of this code is that it displays all the values as follows Threads::num,47141,47146,47151,47156,47161,47166,47171,47176

0

1 Answer 1

1

I think your post got re-formatted, because the Python interpreter definitely won't execute it, but take a look at this:

print line.strip(',').split(',')[-1] 
print line

The phrase line.strip(',').split(',')[-1] ends up as '47116', but then you do a print line which just outputs the whole of the contents of line again.

Sign up to request clarification or add additional context in comments.

2 Comments

is there any problem in the logic ?
what should I do next Bruce ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.