Python Forum
Read txt files in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read txt files in python
#1
Hi, my teacher just gave me this assignment and i already wrote smt, but it doesn't work... Can anyone help me,please?
---------------------------------------------------------------------------------------------------------------
Forum posts are collected in some files that have the following format.
A file contains one or more posts, the beginning of a post is marked by a line that contains it
sequentially the two substrates "<POST>" and "N" (without quotation marks)
interspersed, preceded, and / or followed by 0.1 or more spaces.
"N" is the post ID (a positive number).
The content of the post is in the next lines up to the line that marks the next post
or the end of the file.
It is assured that the string "<POST>" is not contained in any posts.

In the following, we mean, as usual, any sequence of characters
alphabetically of maximum length. The alphabet characters are the ones for which
True is the isalpha () method.

Write a post function (fposts, set) that takes the input:
- the path of a file (fposts)
- and a set of words (together)
and returns a set (result).

The returned set (result) should contain the post identifiers (IDs)
which contain at least one word of the input element.
Two words are considered equal even if some alphabetic characters appear in one
uppercase and the other in lower case.
---------------------------------------------------------------------------------------------------------------
def post(fposts,set):
fposts=open('file01.txt')
for p in set:
if p.isalpha()==True:
fposts.readline
if p not in fposts:
print("no world in set found in post")
else:
print(fposts(n))
return(p)

---It's the first time for me doing programmation so i don't really know what i am doing and i'm freaking desperate.---
Reply


Messages In This Thread
Read txt files - by rii - Oct-26-2017, 03:18 PM
RE: Read txt files in python - by Larz60+ - Oct-26-2017, 04:18 PM
RE: Read txt files - by Larz60+ - Oct-26-2017, 04:01 PM
RE: Read txt files - by rii - Oct-26-2017, 04:09 PM
Read txt files in python - by rii - Oct-26-2017, 04:13 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020