Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Storing a big amount of path names Date: Fri, 12 Feb 2016 15:23:20 +1100 Lines: 39 Message-ID: References: <56BD4DCD.4080401@mrabarnett.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de VVZ6qjBVAZxgAmopTtjAcQAKGaKK1+pciyf4cvWGaxMA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; 'memory.': 0.05; 'mrab': 0.05; 'sys': 0.05; 'correct.': 0.07; 'cc:addr:python-list': 0.09; '__init__': 0.09; 'arg': 0.09; 'dirname': 0.09; ':-)': 0.12; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'paulo': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'string': 0.17; 'language': 0.19; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'fix': 0.21; 'simpler': 0.22; 'feb': 0.23; 'references': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'chris': 0.26; 'coding': 0.27; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'strings,': 0.29; 'character': 0.29; 'skip:s 30': 0.31; 'class': 0.33; 'equal': 0.34; 'running': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; '12,': 0.37; 'things': 0.38; 'received:209': 0.38; 'means': 0.39; "didn't": 0.39; 'takes': 0.39; 'your': 0.60; 'back': 0.62; '>>>>>': 0.66; 'apart': 0.70; 'million': 0.74; 'obvious': 0.76; 'you:': 0.79; 'chrisa': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=metySYucfdpKzi7DZ1HYFgYH+Qu6iHf9RoT0R6ltx+U=; b=d3S6Xw34Z+4pQuAmp06vvmWUMsBiB0+R2K97VO9hdy7znYOo9FK4jp28tj9LeDnXtX BLaev6L3Hb0Cci/lX1k7N6O2PLY13kXPW61Kp/bYB+IPDg0cH0vsaWKxk3gZWKZzVSpf kAUbZWswwvGylDDHMNZle640M6j5QC8lXD6Zym1cnJ0Ay4panWzsvBseh/qphlqOkKPe G9fTgA+hYNbPYhwVOiC20NGRisheyF0776/t2a+yTDr+X5KeKiHY7l00K6XL+xFVxFhl MXe2XvKZOayenPIgbW0bdhOT97Iih7dLUhcNJaYuUL5zytrdrAeN0qDzVLSWsloTtw+E xfIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc:content-type:content-transfer-encoding; bh=metySYucfdpKzi7DZ1HYFgYH+Qu6iHf9RoT0R6ltx+U=; b=V+ESieHNp/uSxIYH49+x6SevFLWdWrreQG5wWvJjks4x5PHsGEyUVqKkQIuyofLioY L4IS5R3PWOGrN8iUAJ2XSoYvLFF3StkSjVQ6gUEQVeetlrNRhhGchN+eTcSHFuqqpu6l lhQFRfuf4G9zbTlfdOYXOowc2a8cP4xOSmzy7CKYUNFEE6UBxvlwOvp0tYi5LVR4giNU wh1xHbPOHergC3po79C+TzjHvNKLQE1zhR5PG75lp+1fuQrgeycre+KDYi4vUC24Rs+2 D5D9YzW5+lrFExppQP1IEOoAI3K+FedUw7XqkyuDcipLa21XHGkWtWNYjuv2sg3I6tI8 Wk0A== X-Gm-Message-State: AG10YOQy5Fr0uTI+KWnY2uwub2LRMPTTjE3Hmkh1pjtvUIo+9fec/vgGVNJiXFNgdGAnvK+rwlxcNAQhAKPbwA== X-Received: by 10.107.132.90 with SMTP id g87mr579017iod.157.1455251000678; Thu, 11 Feb 2016 20:23:20 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 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:102843 On Fri, Feb 12, 2016 at 3:15 PM, Paulo da Silva wrote: > =C3=80s 03:49 de 12-02-2016, Chris Angelico escreveu: >> On Fri, Feb 12, 2016 at 2:13 PM, MRAB wrote= : >>> Apart from all of the other answers that have been given: >>> > ... >> >> Simpler to let the language do that for you: >> >>>>> import sys >>>>> p1 =3D sys.intern('foo/bar') >>>>> p2 =3D sys.intern('foo/bar') >>>>> id(p1), id(p2) >> (139621017266528, 139621017266528) >> > > I didn't know about id or sys.intern :-) > I need to look at them ... > > As I can understand I can do in MyFile class > > self.dirname=3Dsys.intern(dirname) # dirname passed as arg to the __init_= _ > > and the character string doesn't get repeated. > Is this correct? Correct. Two equal strings, passed to sys.intern(), will come back as identical strings, which means they use the same memory. You can have a million references to the same string and it takes up no additional memory. But I reiterate: Don't even bother with this unless you know your program is running short of memory. Start by coding things in the simple and obvious way, and then fix problems only when you see them. ChrisA