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 9161831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:03:47+00:00 2026-06-17T14:03:47+00:00

I have some Python program that reads certain values from a file. File example:

  • 0

I have some Python program that reads certain values from a file.

File example:

0
4
5
6

The code to parse each line is as follows:

    s = f2.readline()
    p = int(s)

I am trying to pass sys.maxint in the file instead as follows:

0
sys.maxint
5
6

One of the ways to do so is to check if (s=='sys.maxint') as especial case in the code.

I wonder if there is another neat way to do so?

  • 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-17T14:03:49+00:00Added an answer on June 17, 2026 at 2:03 pm

    I am not sure why if isn’t “neat”. In my opinion it is the obvious solution. If you really want to do it without an if, you can do this (with an unnecessary string representation):

    #! /usr/bin/python2.7
    import sys
    
    for s in (s.strip () for s in open ('test', 'r') ):
        p = int (s.replace ('sys.maxint', str (sys.maxint) ) )
        print (p)
    

    I personally would keep the if:

    for s in (s.strip () for s in open ('test', 'r') ):
        p = sys.maxint if s == 'sys.maxint' else int (s)
        print (p)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some python code that I wrote to convert a python list into
I have some python code that currently performs expensive computation by performing the computation
I have an external command line program that I would like to invoke from
I have a python program that does something like this: Read a row from
there. I have some code written for Python 3.1 that is misbehaving. If it
I just beginning to program in Python. I have read in some records from
I some lines of code that read a csv file in a certain format.
Using Python 2.7 Situation: I have some piece of Python code (that the user
I currently got a program in Python that reads a text file but it
I have a Python program that uses psutil to run some various twistd ...

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.