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 a 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

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8564477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:12:35+00:00 2026-06-11T17:12:35+00:00

I have a problem with the fact that when I open a file and

  • 0

I have a problem with the fact that when I open a file and import a line with command f.readline ().I run the module then It works good. It shows the number 600 or it doesn’t matter what number it is. But how I can get that number to be used in further calculations? When I type the next calculation command, it says something like for command int it should be a string or a number. But how I turn that text file number to number that I can calculate with and Python understands?

from math import *

with open('C:\\Users\\admin\\Desktop\\terehommik.txt', 'r') as f:
    for line in f:
        s = f.readline()

and from that line comes the number, and now i need to convert string number to real number
so i could after calculate with bank rate

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:12:36+00:00Added an answer on June 11, 2026 at 5:12 pm

    Use the int function:

    x = int('600')
    
    # x is now 600, can be used in computations
    print x + 1  # No TypeError--prints 601
    

    So,

    s = f.readline()
    x = int(s)
    y = x * 5  # etc.
    

    ADDENDUM:

    OP, does your input file contain one number per line? That’s what I’ll assume for now.

    with open('myfile') as f:
        for line in f:
            x = int(line)
            print x+3
    

    If the contents of myfile are:

    600
    3
    67
    987
    

    then the above code will work, printing:

    603
    6
    70
    990
    

    N.B., for floats, use the aptly named float function instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Fact: I'm not that good with jQuery. Problem: I have a form containing dynamically
I have a problem with nodejs and connect and the fact that it's not
I have a code problem which stems from the fact that I am using
I have a problem about file open mode with fopen() . In my case,
I have some problems with Javascript. In fact, I'm just newbie in that script
We've run into an interesting situation that needs solving, and my searches have turned
I have application reads in data from text file. Recently I realized that I
I have a batch file that creates a scheduled task using schtasks like this:
I have a text file that is being written to as part of a
I have a text file that looks something like this where the first column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

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.