Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: 'string.join' is wrong in my Python console Date: Thu, 3 Dec 2015 12:23:20 -0500 Lines: 46 Message-ID: References: <88afafc5-699f-46ea-aaca-7e78b75a4552@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de RQ95uJI196+GVJs2FTvqUwobvavIuYab2npG2AuCBTpw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'string.': 0.04; 'subject:Python': 0.05; 'line:': 0.07; "subject:' ": 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tuple': 0.09; 'jan': 0.11; 'importing': 0.15; '*i*': 0.16; '*should*': 0.16; 'guess.': 0.16; 'iterable': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'stripped': 0.16; 'url:faq': 0.16; 'wrote:': 0.16; 'later': 0.16; 'string': 0.17; 'module,': 0.18; "shouldn't": 0.18; 'try:': 0.18; '>>>': 0.20; '2.x': 0.22; 'arguments': 0.22; 'trying': 0.22; 'am,': 0.23; 'import': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'function': 0.28; 'arguments,': 0.29; 'joining': 0.29; 'methods.': 0.29; 'tutorial': 0.29; 'allows': 0.30; "i'd": 0.31; 'error.': 0.31; 'entry': 0.31; 'problem': 0.33; 'url:python': 0.33; 'faq': 0.33; 'skip:- 10': 0.34; 'running': 0.34; 'list': 0.34; 'robert': 0.35; 'should': 0.36; 'instead': 0.36; 'url:org': 0.36; 'received:71': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'two': 0.37; 'method': 0.37; 'received:org': 0.37; 'late': 0.38; 'hi,': 0.38; 'skip:- 20': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'link:': 0.69; "'2',": 0.84; 'herron:': 0.84; 'upset': 0.84; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-71-185-227-36.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99976 On 12/3/2015 11:00 AM, Robin Koch wrote: > Am 03.12.2015 um 10:02 schrieb Gary Herron: >> On 12/02/2015 10:55 PM, Robert wrote: >>> Hi, >>> >>> I read the tutorial on "Why is join() a string method instead of a list >>> or tuple method?" >>> at link: >>> https://docs.python.org/2/faq/design.html#why-must-self-be-used-explicitly-in-method-definitions-and-calls >>> >>> >>> >>> I have a problem on running the last line: >>> --------------- >>> If none of these arguments persuade you, then for the moment you can >>> continue to use the join() function from the string module, which >>> allows >>> you to write >>> >>> string.join(['1', '2', '4', '8', '16'], ", ") >>> ----------------------- ... >> You are trying to use the *string* module without importing it, I'd >> guess. >> >> Try: >> import string >> first then you should be able to access string.join without error. > > Now *I* am confused. > > Shouldn't it be > > ", ".join(['1', '2', '4', '8', '16']) > > instead? Without any importing? Yes, that is what one *should* do in late 2.x and indeed must do in 3.x, where the string module has been stripped of the functions that later became string methods. The FAQ entry was written when the join method was new as a method and some people were upset by the reversal of the order of the two arguments, an iterable of strings and the joining string. -- Terry Jan Reedy