Luffy Posted December 4, 2017 at 10:51 PM Share Posted December 4, 2017 at 10:51 PM Pessoal, eu gostaria de saber se tem alguma forma de verificar se um determinado valor já existe dentro de um txt através do io.open? Link to comment Share on other sites More sharing options...
[Admin] tierrilopes Posted December 4, 2017 at 10:56 PM Share Posted December 4, 2017 at 10:56 PM if 'blabla' in open('example.txt').read(): print("true") ou open('file', 'r').read().find('') https://stackoverflow.com/questions/4940032/how-to-search-for-a-string-in-text-files Link to comment Share on other sites More sharing options...
Luffy Posted December 4, 2017 at 11:33 PM Author Share Posted December 4, 2017 at 11:33 PM 36 minutos atrás, Tierri Lopes disse: if 'blabla' in open('example.txt').read(): print("true") ou open('file', 'r').read().find('') https://stackoverflow.com/questions/4940032/how-to-search-for-a-string-in-text-files Muito obrigado, Tierri! E se eu quisesse obter um valor que ta dentro do aquivo txt, o que eu teria de fazer? Link to comment Share on other sites More sharing options...
[Admin] tierrilopes Posted December 4, 2017 at 11:56 PM Share Posted December 4, 2017 at 11:56 PM file = open("meu.ficheiro", "r+") if file.read() == "MOTOR=GASOLINA": PrecoGasolina() elif file.read() == "MOTOR=GASOLEO": PrecoGasoleo else: PrecoEletrico() É isto que queres? Link to comment Share on other sites More sharing options...
Luffy Posted December 7, 2017 at 01:08 AM Author Share Posted December 7, 2017 at 01:08 AM Em 04/12/2017 em 21:56, Tierri Lopes disse: file = open("meu.ficheiro", "r+") if file.read() == "MOTOR=GASOLINA": PrecoGasolina() elif file.read() == "MOTOR=GASOLEO": PrecoGasoleo else: PrecoEletrico() É isto que queres? Eu já encontrei outra solução pro meu problema. Muito Obrigado, Tierri. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now