0

So i have been fiddling around with python and league of legends. And i found out you can make notes in game. So i thought about making python code read a line of text from the note i made in game, like "Lux no flash", but it doesn't seems to be able to read it at all, it only works when i do it manually with the exact same code. Here is my code:

import os import time def main(): os.chdir('C:\\Riot Games\\League of Legends\\RADS\\solutions\\lol_game_client_sln\\releases\\0.0.1.237') f=open("MyNotes.txt", "r") if f.mode == 'r': lines=f.readlines() text = lines[4] time.sleep(0.1) if text == 'Lux no flash': print('Done') else: print('Something went wrong') f.close() if __name__== "__main__": main() 

The output is "something went wrong", but when i do it manually it says "done". I feel like python cant read league code. Maybe you guys know how to do this... This is the .txt file im trying to access:

################################################## 2018-09-13_18-57-33_ ################################################## Lux no flash 
9
  • Lux with big or small L is what makes your code not work I think Commented Sep 15, 2018 at 17:26
  • I found that its the hashes but i'm not certain, the code doesn't care about case and if it is the hashes i need a fix xD Commented Sep 15, 2018 at 17:29
  • 1
    1) with .readlines(), the line separator is preserved in the resulting strings, so you need to look for 'Lux no flash\n'; 2) lists are zero-indexed, so this line is at position 3, not 4 Commented Sep 15, 2018 at 17:30
  • @JohnClarkson I agree this should not retrieve the line if cases do not match and not using any .lower() to compare Commented Sep 15, 2018 at 17:31
  • 1
    What do you mean "the code doesn't care about case"? == certaintly is case-sensitive. Commented Sep 15, 2018 at 17:34

2 Answers 2

2

Using lux.txt:

################################################## 2018-09-13_18-57-33_ ################################################## Lux no flash 

Code:

content = [] with open('lux.txt', 'r') as f: for line in f: content.append(line.strip('\n')) for i in content: if 'Lux no flash' == i: print("Done") else: pass 

Better @pygo

with open('lux.txt', 'r') as f: content = f.read() if 'Lux no flash' in content: print("Done") else: print("No else, this works :)") 

Output:

(xenial)vash@localhost:~/python/stack_overflow$ python3.7 lux.py Done 
Sign up to request clarification or add additional context in comments.

Comments

2

I'm Just taking a file on an assumption basis:

# cat MyNotes.txt there is Lux no flash in line there is Something went wrong There is nothing lux no flash this is all test 

So, just looking for the word 'Lux no flash' you are searching into your file, we can simply do as below.. but its case sensitive.

It's always best practice to use with open() method to read a file.

import os import time def main(): with open("MyNotes.txt") as f: for line in f.readlines(): if 'Lux no flash' in line: print('Done') else: print('Something went wrong') if __name__== "__main__": main() 

Output result will be :

Done Something went wrong Something went wrong Something went wrong 

Even tried using the lux.txt , it works as expected with my code.

import os import time def main(): with open("lux.txt") as f: for line in f.readlines(): #line = line.strip() # use can use the strip() or strip("\n") #line = line.strip("\n") # if you see white spaces in the file if 'Lux no flash' in line: print('Done') else: pass if __name__== "__main__": main() 

Resulted outout is:

# test.py Done 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.