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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:03:11+00:00 2026-05-12T12:03:11+00:00

I want to read from stdin five numbers entered as follows: 3, 4, 5,

  • 0

I want to read from stdin five numbers entered as follows:

3, 4, 5, 1, 8

into seperate variables a,b,c,d & e.

How do I do this in python?

I tried this:

import string
a=input()
b=a.split(', ')

for two integers, but it does not work. I get:

Traceback (most recent call last):
  File "C:\Users\Desktop\comb.py", line 3, in <module>
    b=a.split(', ')
AttributeError: 'tuple' object has no attribute 'split'

How to do this? and suppose I have not a fixed but a variable number n integers. Then?

  • 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-12T12:03:11+00:00Added an answer on May 12, 2026 at 12:03 pm

    Use raw_input() instead of input().

    # Python 2.5.4
    >>> a = raw_input()
    3, 4, 5
    >>> a
    '3, 4, 5'
    >>> b = a.split(', ')
    >>> b
    ['3', '4', '5']
    >>> [s.strip() for s in raw_input().split(",")] # one liner
    3, 4, 5
    ['3', '4', '5']
    

    The misleadingly names input function does not do what you’d expect it to. It actually evaluates the input from stdin as python code.

    In your case it turns out that what you then have is a tuple of numbers in a, all parsed and ready for work, but generally you don’t really want to use this curious side effect. Other inputs can cause any number of things to happen.

    Incidentally, in Python 3 they fixed this, and now the input function does what you’d expect.

    Two more things:

    1. You don’t need to import string to do simple string manipulations.
    2. Like mjv said, to split a tuple or a list into several variables, you can ‘unpack’ it. This will not be feasible if you don’t know how long the list will be, though.

    Unpacking:

    >>> l = (1,2,3,4,5)
    >>> a,b,c,d,e = l
    >>> e
    5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read user input from STDIN and process the preliminary input while
I would like to read asynchronously from stdin with Qt. I don't want to
Let say i want to read the integers a, b and c from stdin
I want to read lines from a file into a Set or List. Is
i want to read an xml from stdin. For parsing the xml I would
I want to read a number from stdin. I don't understand why scanf requires
I want to read input from STDIN, and just read what it is: if
I am writing my first clojure program, and want to read lines from stdin.
I am writing a short python script to read line from stdin, but when
i want to read from a text file in C#. But I want all

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.