0

I'm just starting to learn basic python coding at the moment and I'm using a video tutorial to do so, I'm running IDLE Python 2.7.12 Shell and following along with the instructor using IDLE 3.5.0 Shell. So the issue I've come across is when I'm trying to use the split method this is coming up

>>> numbers = input("Enter your numbers, separated by commas: ")
Enter your numbers, separated by commas: 1,2,3
>>> numbers.split(",")

Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
    numbers.split(",")
AttributeError: 'tuple' object has no attribute 'split'

I can't really figure out why that is. When he runs it the numbers come back ['1','2','3']. I'm sure this is really basic but I would greatly appreciate any help or advice you can offer. Thanks.

buran
  • 13,682
  • 10
  • 36
  • 61
mikey730
  • 3
  • 1
  • You're using Python 3 code in Python 2. Change `input` to `raw_input`, or upgrade to Python 3. – Carcigenicate Nov 05 '20 at 19:34
  • 2
    Does this answer your question? [Differences between \`input\` and \`raw\_input\`](https://stackoverflow.com/questions/3800846/differences-between-input-and-raw-input) – Random Davis Nov 05 '20 at 19:34
  • That is because the `input` function in Python 2 was also `eval`uating the input. Why are you doing a Python 3 tutorial and running Python 2??? Wouldn't it be easier to just upgrade? – Tomerikoo Nov 05 '20 at 19:35
  • He said we would be good to use the older version and he would let us know when we would have an issue. I appreciate the info! – mikey730 Nov 05 '20 at 19:46

2 Answers2

1

You are using python2 and in this case input() evaluates the user input. In python2 you should use raw_input() instead of input() That said, you should really be using python 3 (that is what your instructor is using)

buran
  • 13,682
  • 10
  • 36
  • 61
0
word=raw_input("Test")
word.split()
print(word)

Use raw_input() for Python 2.X. It has been deprecated in Python 3.X.