Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 1715
Alex Hales
  • 0
Alex HalesTeacher
Asked: May 31, 20222022-05-31T00:20:01+00:00 2022-05-31T00:20:01+00:00

python – How to take text from file?

  • 0

[ad_1]

I’m a beginner in Python, and I don’t get how to take a text from a file.

I’ve tried a lot of codes that I found on this forum, but it seems that no one tried to do what I’m trying to do.

It’s been 3 days I’m trying to do that and I feel like It’s impossible.

Here is the code, I have a file named 1.txt and I’m wondering how to get the content of 1.txt right here : “””Text from my file here”””

Is there a way to do that?

Thanks in advance!



def analyze_text_sentiment(text):
   client = language.LanguageServiceClient()
   document = language.Document(content=text, type_=language.Document.Type.PLAIN_TEXT)

   response = client.analyze_sentiment(document=document)

   sentiment = response.document_sentiment
   results = dict(
       text=text,
       score=f"{sentiment.score:.1%}",
       magnitude=f"{sentiment.magnitude:.1%}",
   )
   for k, v in results.items():
       print(f"{k:10}: {v}")

from google.cloud import language


def analyze_text_entities(text):
   client = language.LanguageServiceClient()
   document = language.Document(content=text, type_=language.Document.Type.PLAIN_TEXT)

   response = client.analyze_entities(document=document)

   for entity in response.entities:
       print("=" * 80)
       results = dict(
           name=entity.name,
           type=entity.type_.name,
           salience=f"{entity.salience:.1%}",
           wikipedia_url=entity.metadata.get("wikipedia_url", "-"),
           mid=entity.metadata.get("mid", "-"),
       )
       for k, v in results.items():
           print(f"{k:15}: {v}")
           

text = """Text from my file here"""
analyze_text_sentiment(text)
analyze_text_entities(text)

[ad_2]

  • 0 0 Answers
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 4778 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1063 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1009 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.