Re: Clarification on Immutability please

2020-01-28 Thread Chris Angelico
On Wed, Jan 29, 2020 at 1:50 AM Random832 wrote: > > On Wed, Jan 22, 2020, at 02:34, Stephen Tucker wrote: > > Oh dear, I am sorry. I have created quite a storm. > > > > Moreover, I am sorry because I misremembered what I had typed into Idle. My > > original tuple only had two elements, not three,

Re: Clarification on Immutability please

2020-01-28 Thread Random832
On Wed, Jan 22, 2020, at 02:34, Stephen Tucker wrote: > Oh dear, I am sorry. I have created quite a storm. > > Moreover, I am sorry because I misremembered what I had typed into Idle. My > original tuple only had two elements, not three, so the slicing [:2] didn't > affect the tuple at all - and s

Re: Clarification on Immutability please

2020-01-28 Thread Chris Angelico
On Tue, Jan 28, 2020 at 9:33 PM Daniel Haude wrote: > > Am 27.01.2020 15:23 schrieb Chris Angelico: > > > The way execution works in Python, you first evaluate the object, then > > assign it to the target. The new object HAS to exist before the old > > one is replaced. There's no such thing as "at

Re: Clarification on Immutability please

2020-01-28 Thread Daniel Haude
Am 27.01.2020 15:23 schrieb Chris Angelico: The way execution works in Python, you first evaluate the object, then assign it to the target. The new object HAS to exist before the old one is replaced. There's no such thing as "atomic reassignment" that simultaneously destroys the old object and a

Re: Clarification on Immutability please

2020-01-27 Thread Chris Angelico
On Tue, Jan 28, 2020 at 2:44 AM Souvik Dutta wrote: > > If the two objects have the same value that means that when called all of > them will point to the same object rather than creating the same value - > object pairs twice. Immutability is the characteristics that does not let you > change t

Re: Clarification on Immutability please

2020-01-27 Thread Chris Angelico
On Tue, Jan 28, 2020 at 1:13 AM Musbur wrote: > > Am 21.01.2020 19:38 schrieb Chris Angelico: > > Are you sure that it does? I can't reproduce this. When you slice the > > first two from a tuple, you create a new tuple, and until the > > assignment happens, both the new one and the original coexis

Re: Clarification on Immutability please

2020-01-27 Thread Musbur
Am 21.01.2020 19:38 schrieb Chris Angelico: On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker wrote: and even that the first id(mytup) returns the same address as the second one, I am left wondering exactly what immutability is. Let's look at id()'s documentation: id(object) Return the

Re: Clarification on Immutability please

2020-01-22 Thread Richard Damon
On 1/21/20 8:41 PM, Jon Ribbens via Python-list wrote: Whether we call the link between 'foo' and (1, 2) a pointer or a reference is almost entirely irrelevant, the difference is essentially meaningless. The issue is that in Python, objects and names are fairly distinct. Unlike a language like

Re: Clarification on Immutability please

2020-01-22 Thread Eryk Sun
On 1/21/20, Jon Ribbens via Python-list wrote: > > Whether we call the link between 'foo' and (1, 2) a pointer or a > reference is almost entirely irrelevant, the difference is essentially > meaningless. In programming terms, a "pointer" is always an address in memory, and, at least to me, the te

Re: Clarification on Immutability please

2020-01-21 Thread Stephen Tucker
Oh dear, I am sorry. I have created quite a storm. Moreover, I am sorry because I misremembered what I had typed into Idle. My original tuple only had two elements, not three, so the slicing [:2] didn't affect the tuple at all - and so the second id() gave the same address as the first one. So, y

Re: Clarification on Immutability please

2020-01-21 Thread Michael Torrie
On 1/21/20 6:52 PM, Ethan Furman wrote: > On 01/21/2020 10:55 AM, Michael Torrie wrote: > >> Slicing >> returns a new object whether one is slicing a tuple, list, or a string, >> the latter two are mutable objects. > > Strings are not mutable. Yup I got my items in the wrong order. I meant to sa

Re: Clarification on Immutability please

2020-01-21 Thread MRAB
On 2020-01-22 01:52, Ethan Furman wrote: On 01/21/2020 10:55 AM, Michael Torrie wrote: Slicing returns a new object whether one is slicing a tuple, list, or a string, the latter two are mutable objects. Strings are not mutable. In the case of tuples and strings, if the slicing encompasses th

Re: Clarification on Immutability please

2020-01-21 Thread Ethan Furman
On 01/21/2020 10:55 AM, Michael Torrie wrote: Slicing returns a new object whether one is slicing a tuple, list, or a string, the latter two are mutable objects. Strings are not mutable. -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list

Re: Clarification on Immutability please

2020-01-21 Thread Jon Ribbens via Python-list
On 2020-01-21, Chris Angelico wrote: > On Wed, Jan 22, 2020 at 8:01 AM Jon Ribbens via Python-list > wrote: >> On 2020-01-21, Chris Angelico wrote: >> > On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker >> > wrote: >> >> I am left concluding that mytup is not actually a tuple (even though type >>

Re: Clarification on Immutability please

2020-01-21 Thread Cameron Simpson
On 22Jan2020 09:15, Cameron Simpson wrote: It doesn't say anything about the contents of the internal objects: >>> mytup = (1, [2, 3], (4, 5)) [...] >>> mytupl[1] = [7, 8] Traceback (most recent call last): File "", line 1, in NameError: name 'mytupl' is not defined Please igno

Re: Clarification on Immutability please

2020-01-21 Thread Cameron Simpson
On 21Jan2020 17:40, Stephen Tucker wrote: I am sure this has been answered many times before, but I need to ask it again. Given that the following is valid Python 2.7.10 (when keyboarded into Idle): mytup = ("q", "w", "e") id(mytup) mytup = mytup [:2] id(mytup) and even that the first id(myt

Re: Clarification on Immutability please

2020-01-21 Thread Chris Angelico
On Wed, Jan 22, 2020 at 8:01 AM Jon Ribbens via Python-list wrote: > > On 2020-01-21, Chris Angelico wrote: > > On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker > > wrote: > >> I am left concluding that mytup is not actually a tuple (even though type > >> (mytup) tells me that it is). > > > > If

Re: Clarification on Immutability please

2020-01-21 Thread Jon Ribbens via Python-list
On 2020-01-21, Chris Angelico wrote: > On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker wrote: >> I am left concluding that mytup is not actually a tuple (even though type >> (mytup) tells me that it is). > > If type(mytup) is tuple, then mytup really truly is a tuple. There is > no other conclusio

Re: Clarification on Immutability please

2020-01-21 Thread Chris Angelico
On Wed, Jan 22, 2020 at 5:56 AM Michael Torrie wrote: > > On 1/21/20 11:38 AM, Chris Angelico wrote: > > Are you sure that it does? I can't reproduce this. When you slice the > > first two from a tuple, you create a new tuple, and until the > > assignment happens, both the new one and the original

Re: Clarification on Immutability please

2020-01-21 Thread Michael Torrie
On 1/21/20 11:38 AM, Chris Angelico wrote: > Are you sure that it does? I can't reproduce this. When you slice the > first two from a tuple, you create a new tuple, and until the > assignment happens, both the new one and the original coexist, which > means they MUST have unique IDs. And furthermo

Re: Clarification on Immutability please

2020-01-21 Thread Chris Angelico
On Wed, Jan 22, 2020 at 4:42 AM Stephen Tucker wrote: > > Hi Python-list folk, > > I am sure this has been answered many times before, but I need to ask it > again. > > Given that the following is valid Python 2.7.10 (when keyboarded into Idle): > > mytup = ("q", "w", "e") > id(mytup) > mytup = my

Re: Clarification of notation

2010-09-30 Thread Dave Angel
On 2:59 PM, Bruce W. wrote: So, this kind of notation would be different: args[0][2] verses args[[0][2]] the latter is multidimensional. Can you think of example of using this type of list? I don't know why this had me a bit confused. I've got to get into programming more... I had done mo

Re: Clarification of notation

2010-09-30 Thread Bruce W.
So, this kind of notation would be different: args[0][2] verses args[[0][2]] the latter is multidimensional. Can you think of example of using this type of list? I don't know why this had me a bit confused. I've got to get into programming more... I had done more in the past. Bruce Chriebe

Re: Clarification of notation

2010-09-29 Thread Terry Reedy
On 9/29/2010 10:32 PM, Bruce Whealton wrote: Would you, and could you combine a dictionary with a list in this fashion? A python list is a mutable sequence of Python objects. Extremely mixed example. >>> mixed = [1, 1.0, '1', [1], (1,), {1:1}, set((1,)), list, list.append] >>> mixed.append(m

Re: Clarification of notation

2010-09-29 Thread Chris Rebert
On Wed, Sep 29, 2010 at 7:32 PM, Bruce Whealton wrote: > Hello all, >         I recently started learning python.  I am a bit thrown by a certain > notation that I see.  I was watching a training course on lynda.com and this > notation was not presented.  For lists, when would you use what appears

Re: Clarification of notation

2010-09-29 Thread alex23
Bruce Whealton wrote: > For lists, when would > you use what appears to be nested lists, like: > [[], [], []] > a list of lists? Well, you'd use it when you'd want a list of lists ;) There's nothing magical about a list of lists, it's just a list with objects inside like any other, in this case

Re: Clarification of notation

2010-09-29 Thread Seebs
On 2010-09-30, Bruce Whealton wrote: > Next, from the documentation I see and this is just an example (this > kind of notation is seen elsewhere in the documentation: > str.count(sub[, start[, end]]) > This particular example is from the string methods. > Is this a nesting of two lists inside a

Re: clarification

2007-08-20 Thread Paul Rubin
[EMAIL PROTECTED] (Alex Martelli) writes: > > turn indicates that both implementations actually work about same and > > your "O(n squared)" argument is irrelevant. > > It's indeed irrelevant when the behavior _isn't_ quadratic (as in the > case of intersections) -- but unfortunately it _is_ needle

Re: clarification

2007-08-19 Thread Alex Martelli
samwyse <[EMAIL PROTECTED]> wrote: ... > > brain:~ alex$ python -mtimeit -s'sos=[set(range(x,x+4)) for x in > > range(0, 100, 3)]' 'r=set()' 'for x in sos: r.update(x)' > > 10 loops, best of 3: 18.8 usec per loop > > > > brain:~ alex$ python -mtimeit -s'sos=[set(range(x,x+4)) for x in > > r

Re: clarification

2007-08-19 Thread samwyse
Alex Martelli wrote: > Of course, hoisting the unbound method out of the loops can afford the > usual small optimization. But my point is that, in Python, these > operations (like, say, the concatenation of a sequence of lists, etc) > are best performed "in place" via loops calling mutator method

Re: clarification

2007-08-18 Thread Alex Martelli
samwyse <[EMAIL PROTECTED]> wrote: ... > Finally, does anyone familar with P3K know how best to do the reduction > without using 'reduce'? Right now, sets don't support the 'add' and > 'multiply' operators, so 'sum' and (the currently ficticious) 'product' > won't work at all; while 'any' and

Re: clarification

2007-08-18 Thread Tim Williams
On 17/08/07, Beema shafreen <[EMAIL PROTECTED]> wrote: > hi everybody, > i have a file with data separated by tab > mydata: > fhl1fkh2 > dfp1chk1 > mal3alp14 > mal3moe1 > mal3spi1 > mal3bub1 > mal3bub3 > mal3mph1 > mal3mad3 > hob1nak1 > hob1wsp1 > hob1

Re: clarification

2007-08-18 Thread samwyse
samwyse wrote: > Scott David Daniels wrote: > >> lefts = set() >> rights = set() >> with open('sheet1', 'r') as fh: >> for line in fh: >> trimmed = line.strip() >> if trimmed: # Skip blanks (file end often looks like that) >> left, right = line.strip()

Re: clarification

2007-08-17 Thread samwyse
Scott David Daniels wrote: > lefts = set() > rights = set() > with open('sheet1', 'r') as fh: > for line in fh: > trimmed = line.strip() > if trimmed: # Skip blanks (file end often looks like that) > left, right = line.strip().split('\t') >

Re: clarification

2007-08-17 Thread Scott David Daniels
Laurent Pointal wrote: > Thomas Jollans a écrit : >> On Friday 17 August 2007, Beema shafreen wrote: >>> hi everybody, >>> i have a file with data separated by tab >>> mydata: >>> fhl1fkh2 > >>> shows these two are separated by tab represented as columns >>> i have to check the common data bet

Re: clarification

2007-08-17 Thread Laurent Pointal
Laurent Pointal a écrit : [cleaning] fh = open('sheet1') for line in fh: -- http://mail.python.org/mailman/listinfo/python-list

Re: clarification

2007-08-17 Thread Laurent Pointal
Thomas Jollans a écrit : > On Friday 17 August 2007, Beema shafreen wrote: >> hi everybody, >> i have a file with data separated by tab >> mydata: >> fhl1fkh2 >> shows these two are separated by tab represented as columns >> i have to check the common data between these two coloumn1 an coloumn

Re: clarification

2007-08-17 Thread Thomas Jollans
On Friday 17 August 2007, Beema shafreen wrote: > hi everybody, > i have a file with data separated by tab > mydata: > fhl1fkh2 > dfp1chk1 > mal3alp14 > mal3moe1 > mal3spi1 > mal3bub1 > mal3bub3 > mal3mph1 > mal3mad3 > hob1nak1 > hob1wsp1 > hob1rad3 >

Re: clarification

2007-08-16 Thread Michael Bentley
On Aug 16, 2007, at 2:42 AM, Beema shafreen wrote: hi every body, i have compared two files: code: fh = open('HPRD_MAIN_20.txt','r') for line in fh.readlines(): data = line.strip().split('#') fh1 = open('NOMENCLATURE_MAIN_20.txt','r') for line1 in fh1.readlines():

Re: clarification on open file modes

2007-01-06 Thread Stefan Schwarzer
On 2007-01-05 03:46, tubby wrote: > Is this the safest, most portable way to open files on any platform: > > fp = open(file_name, 'rb') > fp.close() > > I understand that doing the following on Windows to a binary file (a > jpeg or exe files for example) can cause file corruption, is that correct?

Re: clarification on open file modes

2007-01-04 Thread Gabriel Genellina
At Thursday 4/1/2007 23:46, tubby wrote: I understand that doing the following on Windows to a binary file (a jpeg or exe files for example) can cause file corruption, is that correct? fp = open(file_name, 'r') fp.close() How can a simple open in read mode corrupt data??? You can't corrupt *

Re: Clarification on XML parsing & namespaces (xml.dom.minidom)

2005-01-27 Thread Uche Ogbuji
Greg Wogan-Browne wrote: > I am having some trouble figuring out what is going on here - is this a > bug, or correct behaviour? Basically, when I create an XML document with > a namespace using xml.dom.minidom.parse() or parseString(), the > namespace exists as an xmlns attribute in the DOM (fair e

Re: Clarification of two concepts (or maybe one?)

2004-12-11 Thread Larry Bates
What you are looking for are 2 apps: 1) Something to freeze your application into something that resembles an installation like what comes on commercial applications. On Windows a popular choice is py2exe. All dependent .py, .pyd, etc. files can be included in the distribution. It also includes

Re: Clarification of two concepts (or maybe one?)

2004-12-10 Thread Fredrik Lundh
Eddie Parker wrote: > What I’m looking for, is a way to turn a python ‘application’, into a > ‘stand-alone’ application. i.e., you don’t need the Python interpreter, > libraries, etc, installed on your hard drive. (I’m OK with .py files > existing – I just don’t want to have to bother the user to