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

  • SEARCH
  • Home
  • 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 6559775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:22:23+00:00 2026-05-25T13:22:23+00:00

I have this input file 1 2 10 2 81 3 23 6 2537857295

  • 0

I have this input file

1 2
10 2
81 3
23 6
2537857295 19
34271891003654321 1267253

I am reading the file like this

with open("powersearch.txt") as fileIn:
    for line in fileIn:
        print line

I am wondering if I want to, for every single line, have the 1st integer stored as firstNum, the 2nd stored as secondNum. With Java I can use a scanner and do nextInt() and hasNext() to get the integers, what are the equivalent in Python?

  • 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-05-25T13:22:24+00:00Added an answer on May 25, 2026 at 1:22 pm

    Well to parse an int from a string you just use int(s), where s is the string.

    I think this would be the most logic way in your example:

    with open("powersearch.txt") as fileIn:
        for line in fileIn:
            n1, n2 = (int(s) for s in line.split())
            print(n1, n2)
    

    Python is a different language than Java, and in my opinion more expressive (I can do more in one line than I can in Java and still write readable code). If you try to write Java stuff in Python you’ll find the language a lot less effective than it can be.

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

Sidebar

Related Questions

I have this use case of an xml file with input like Input: <abc
I have a checkbox in my vm file like this : <input name=ISPOperatorList[0].ISPOperatorAccessStatus id=OPERATORAccessDeny0
So basically, I have something like this - Input file with 2 integers. Code,
Hi, I have a couple of input type file elements like this : <input
I have this HTML: <form action='uploadhandle.php' method='POST' enctype=multipart/form-data> <input type='file' class='fileinput' id='photo1' name='photo1'> <input
I have this simple piece of HTML code: <div> <input type=file name=english-file /> </div>
I have created a JAR file in this way jar cf jar-file input-files .
I have this input form which goes like this: <input type=checkbox name=vehicle value=Bike />
I have a file that looks like this(have to put in code box so
I have this code.... file_parser::file_parser(string file){ txtfile.open(file.c_str(), ios::in); if (!txtfile.good()){ string error=err(0, +file+ not

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.