[issue39641] concatenation of Tuples

2020-02-16 Thread bruce blosser


bruce blosser  added the comment:

ok -  well sorry, I am obviously in way over my head, and now very confused...  

I was just going by what was being said on a number of python web sites, 
including one where I am taking a class in intermediate python coding, and 
thought I was seeing a confiict between what i was being told, and what I was 
finding when running code.

so I will try not to come back here, unless I have some major problem, that 
seems more like a bug

thanks
bruce

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39641] concatenation of Tuples

2020-02-16 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

[Bruce]
> but try this, and it will NOT work:
> 
> FatThing= [(5, 4, "First Place"),
>(6, 6, "Fifer Place"),
>(2, 2, "Slowr Place")]
> print(FatThing)  #this works
> 
> FFThing = FatThing + ('22', '32', '55')  #this causes an error!

That is correct, it should cause an error because you are trying to 
concatenate a list and a tuple. This is an easier way to show the same 
behaviour:

[] + ()  # fails with TypeError

[Bruce]
> however if you change all the members to strings, it will work!!!

I'm afraid you are mistaken. It still fails, as it should.

py> FatThing = [("a", "b", "First Place"),
... ("c", "d", "Fifer Place"),
... ("e", "f", "Slowr Place")]
py> FFThing = FatThing + ('22', '32', '55')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can only concatenate list (not "tuple") to list

Please take more care when trying to report what you think is a bug. 
Remember that Python is about 30 years old and there are tens or 
hundreds of thousands of people using it every single day. 99% of the 
time, anything you, or I, find that looks like a bug, is a bug in *our* 
code, not Python. Especially when it is something as basic and 
fundamental as tuple concatenation.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39641] concatenation of Tuples

2020-02-16 Thread SilentGhost


SilentGhost  added the comment:

Bruce, error message says exactly why it doesn't work: you're trying to add a 
tuple to a list, and that doesn't work. There isn't a "third" string created 
anywhere, you're confused about the types of the objects. Also, please, do not 
re-open closed issues.

--
nosy: +SilentGhost
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39641] concatenation of Tuples

2020-02-16 Thread bruce blosser


bruce blosser  added the comment:

read the advice...
Yes this does work:

  ("Hello", 1, None) + (23, 19.5, "Goodbye")
('Hello', 1, None, 23, 19.5, 'Goodbye')
because you are not creating a 3rd string!

but try this, and it will NOT work:

FatThing= [(5, 4, "First Place"),
   (6, 6, "Fifer Place"),
   (2, 2, "Slowr Place")]
print(FatThing)  #this works

FFThing = FatThing + ('22', '32', '55')  #this causes an error!

however if you change all the members to strings, it will work!!!

--
status: closed -> open

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39641] concatenation of Tuples

2020-02-15 Thread Steven D'Aprano


Steven D'Aprano  added the comment:

> The concatenation of two tuples into a third tuple, using the + command, 
> causes an error if every member of each of the two tuples is NOT a string!

Works for me:

py> ("Hello", 1, None) + (23, 19.5, "Goodbye")
('Hello', 1, None, 23, 19.5, 'Goodbye')

If you still think there is a bug here, please follow the advice given here

http://www.sscce.org/

before re-opening this ticket.

--
nosy: +steven.daprano
resolution:  -> works for me
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39641] concatenation of Tuples

2020-02-15 Thread Ammar Askar


Ammar Askar  added the comment:

Are you trying to concatenate a single string? If so keep in mind you need a 
trailing comma:

>>> (1, 2) + (3, 4) + ('a',)
(1, 2, 3, 4, 'a')
>>> (1, 2) + (3, 4) + ('a')
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can only concatenate tuple (not "str") to tuple

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39641] concatenation of Tuples

2020-02-15 Thread Ammar Askar


Change by Ammar Askar :


--
Removed message: https://bugs.python.org/msg362037

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39641] concatenation of Tuples

2020-02-15 Thread Ammar Askar


Ammar Askar  added the comment:

tuple + tuple is NOT tuple concatenation. It adds each individual member of the 
tuple. So for example

(a, b) + (c, d)

results in

(a + c, b + d)

--
nosy: +ammar2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39641] concatenation of Tuples

2020-02-15 Thread bruce blosser


New submission from bruce blosser :

The concatenation of two tuples into a third tuple, using the + command, causes 
an error if every member of each of the two tuples is NOT a string!  This does 
not appear to be documented ANYWHERE, and really causes a whole lot of head 
scratching and more than enough foul language!  :)

So how does one "add" two tuples together, to create a third tuple, if the 
members are not all strings?

--
messages: 362036
nosy: bruceblosser
priority: normal
severity: normal
status: open
title: concatenation of Tuples
type: behavior
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com