Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Gary Herron Newsgroups: comp.lang.python Subject: Re: 'string.join' is wrong in my Python console Date: Thu, 3 Dec 2015 01:02:21 -0800 Lines: 57 Message-ID: References: <88afafc5-699f-46ea-aaca-7e78b75a4552@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de QFVSpzCy5vuN2b1e72T12Awd8AC/+wz+mC85TEPSyhqg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.05; 'line:': 0.07; "subject:' ": 0.07; 'nameerror:': 0.09; 'tuple': 0.09; 'python': 0.10; '2.7': 0.13; 'importing': 0.15; 'guess.': 0.16; 'last)': 0.16; 'nameerror': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'url:faq': 0.16; 'wrote:': 0.16; 'string': 0.17; 'module,': 0.18; 'try:': 0.18; 'arguments': 0.22; 'trying': 0.22; 'defined': 0.23; 'thanks,': 0.24; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'function': 0.28; 'context,': 0.29; 'tutorial': 0.29; 'allows': 0.30; 'too.': 0.30; 'skip:& 30': 0.30; "i'd": 0.31; 'error.': 0.31; 'problem': 0.33; 'url:python': 0.33; 'traceback': 0.33; 'skip:- 10': 0.34; 'running': 0.34; 'list': 0.34; 'could': 0.35; 'replaced': 0.35; 'robert': 0.35; 'something': 0.35; 'should': 0.36; 'instead': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'skip:& 10': 0.37; 'method': 0.37; 'hi,': 0.38; 'why': 0.39; 'skip:- 20': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'charset:windows-1252': 0.62; 'else.': 0.66; 'link:': 0.69; 'dr.': 0.69; 'received:204': 0.75; 'institute': 0.77; "'2',": 0.84; '(425)': 0.84; '2.7.': 0.84; '895-4418': 0.84; 'digipen': 0.84; 'herron': 0.84 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: <88afafc5-699f-46ea-aaca-7e78b75a4552@googlegroups.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ 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:99942 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'], ", ") > ----------------------- > > My Python console is 2.7. It should be no problem because I see the tutorial > is 2.7 too. > > The console has these display: > > string.join(['1', '2', '4', '8', '16'], ", ") > --------------------------------------------------------------------------- > NameError Traceback (most recent call last) > in () > ----> 1 string.join(['1', '2', '4', '8', '16'], ", ") > > NameError: name 'string' is not defined > > > From the context, I don't see string should be replaced by something else. > > Could you tell me why I have such an error? 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. Gary Herron > > > Thanks, -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418