testing content of each line in a text file in python -



testing content of each line in a text file in python -

i want write programme reads of lines given python text file , tests if line has letters and/or numbers , if not print error message

you can utilize file.readlines() iterates on lines in file. here's example.

with open("/path/to/my/file.txt") file_to_read: line in file_to_read.readlines(): # check if non-letter/number character in each line

do note readlines() include \n @ end of each line, remember remove it. simple search on google "python read file line line" have given result.

python

Comments

Popular posts from this blog

python - How to add an model instance to a django queryset? -

Using Android Volley to post an array to PHP -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -