HomeОбразованиеRelated VideosMore From: Dominique Thiebaut

Parsing Text Files in Python

326 ratings | 94148 views
A short program to read lines from a text file and extract information, patterns, from each line.
Html code for embedding videos on your blog
Text Comments (21)
Jovan Djordjevic (2 months ago)
line.find(' NO '), i think you are complicating it a lil bit
Gatya (6 months ago)
if 'yes' in line : countYes += 1 if 'no' in line: countNo += 1
M.Ammar Nasim (9 months ago)
how did you make demoFileRead.py???
José R (1 year ago)
and for read paragraph?
You can see a paragraph like a big line
Muhamed Kasim (1 year ago)
how can calculate line with out (for)
Dominique Thiebaut (1 year ago)
If you do not want a for loop, you could put the contents of the file into a single string using the read() function, and then you can search the whole contents with the index() function.
Malav Soni (1 year ago)
every time i try it i get this "syntax error" and that it is not apprehended in this piece of code that is given please help!! unfortunately i cannot upload a image ("print screen") of that otherwise i would. thank you any way. peace
Rud Dog (1 year ago)
Where would I learn what features are available in the form of imported modules. It was not till recently that I discovered "OS". What modules are available that can recover information about files size, type, etc? Also how does one find out if the modules are cross platform, Mac, PC and Unix? Thank you for your clear and to the point videos on Python 3. My search continues for same type videos but on tkinter.
Mustafa Uçar (1 year ago)
ağzını şıplatma hoca
nuradin abdi (2 years ago)
keyboard noises make ME CRINGE
Jesus Covarrubias (1 year ago)
Thanks for pointing that out.
Jordan Taylor (1 year ago)
i hammer keys too, probably still habituated from old consoles in the 80's. it'll get better when we all die off in 30 years.
Ali Alghamdi (1 year ago)
The "te" sounds
nuradin abdi (2 years ago)
bumbaclat
shane butler (2 years ago)
thank you sir
Malik Rumi (2 years ago)
WAIT A MINUTE! You're not going to deal with or explain the two YES on one line? What if someone wants all the YES, not just a count of lines with YES in them?!
Gatya (6 months ago)
well you see its counting per line, it checks per line if there is a yes or a no, if it does find one in a line, the code below will execute and increment the count for yes or no, because it checks per lines not per words
Mark Walle (1 year ago)
You could use count instead of find, so like: countYes += line.count("YES") According to help(str.find) and help(str.count): Find will Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Count will return the number of non-overlapping occurrences of substring sub in string S[start:end].
confidential303 (2 years ago)
Need help on python I want to access a media box harddisk (which has an internal address like 169.10.1.40 ) and list the files within the directory ..All my recorded video is listed in the map /media/movies I want to create a script that can list all the files. is this possible ? or should you turn to other languages ??
the flavabomb (2 years ago)
exactly what I was thinking...the whole time I was like...HE. MUST SEE THERE IS 4! 😂

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.