0

I open a csv file that is an output form a windows CMD command.

I read the csv and assigne a variable, but I can find any word even I'm seeing it.

IT seems to be enconde...

content of output.txt ( Host Name: hostname

OS Name: Microsoft Windows Server 2016 Standard

OS Version: 10.0.14393 N/A Build 14393

OS Manufacturer: Microsoft Corporation)

f = open("output.txt", "rt")
f = f.read()
print(f.find("OS Name"))

OUTPUT

<class 'str'>

-1

3

1 Answer 1

0

Try this :

f = open("output.txt", "rt", encoding='utf-8')
f = f.read()
print(f.find("OS Name"))

The code above returns 21 corresponding to the position of the first occurence of the value "OS Name" while print(f.find("random_value")) returns -1 since "random_value" does not exist in the text file.

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

Comments

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.