Re: Most probably a stupid question, but I still want to ask

2016-04-11 Thread Steven D'Aprano
On Monday 11 April 2016 14:03, Fillmore wrote: > I'll make sure I approach the temple of pythonistas bare-footed and with > greater humility next time Don't forget to rip your clothes into rags and heap ashes on your head too. -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-11 Thread Tim Chase
On 2016-04-11 01:33, MRAB wrote: > A one-element tuple can be written as: > > >>> ('hello',) > ('hello',) > > As has been said already, it's the comma that makes the tuple. The > parentheses are often needed to avoid ambiguity. Except when the comma *doesn't* make the tuple: >>> t = ()

Re: Most probably a stupid question, but I still want to ask

2016-04-11 Thread Rustom Mody
On Monday, April 11, 2016 at 11:12:39 AM UTC+5:30, Stephen Hansen wrote: > On Sun, Apr 10, 2016, at 10:18 PM, Rustom Mody wrote: > > On Monday, April 11, 2016 at 10:17:13 AM UTC+5:30, Stephen Hansen wrote: > > > On Sun, Apr 10, 2016, at 09:03 PM, Fillmore wrote: > > > > and the (almost always to

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Marko Rauhamaa
Terry Reedy : > On 4/10/2016 8:17 PM, Fillmore wrote: > >> apparently my 'discontinuity' is mappable to the fact that there's no >> such thing as one-element tuples in Python, and attempts to create >> one will result in a string (i.e. an object of a different kind!)... > >

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Stephen Hansen
On Sun, Apr 10, 2016, at 10:18 PM, Rustom Mody wrote: > On Monday, April 11, 2016 at 10:17:13 AM UTC+5:30, Stephen Hansen wrote: > > On Sun, Apr 10, 2016, at 09:03 PM, Fillmore wrote: > > > and the (almost always to be avoided) use of eval() > > > > FWIW, there's ast.literal_eval which is safe

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Rustom Mody
On Monday, April 11, 2016 at 10:17:13 AM UTC+5:30, Stephen Hansen wrote: > On Sun, Apr 10, 2016, at 09:03 PM, Fillmore wrote: > > and the (almost always to be avoided) use of eval() > > FWIW, there's ast.literal_eval which is safe and there's no reason to > avoid it. Its error reporting is

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Stephen Hansen
On Sun, Apr 10, 2016, at 09:03 PM, Fillmore wrote: > and the (almost always to be avoided) use of eval() FWIW, there's ast.literal_eval which is safe and there's no reason to avoid it. You'll still have to deal with the fact that a single string on a line will return a string while multiples will

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Fillmore
On 04/10/2016 11:54 PM, Steven D'Aprano wrote: On Mon, 11 Apr 2016 12:48 pm, Fillmore wrote: funny, but it seems to me that you are taking it personally... thank god i even apologized in advance for what was most probably a stupid question.. I hope you did get a laugh out of it, because it

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Steven D'Aprano
On Mon, 11 Apr 2016 12:48 pm, Fillmore wrote: > > funny, but it seems to me that you are taking it personally... thank god i > even apologized in advance for what was most probably a stupid question.. I hope you did get a laugh out of it, because it wasn't meant to be nasty. But it was meant to

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Fillmore
funny, but it seems to me that you are taking it personally... thank god i even apologized in advance for what was most probably a stupid question.. On 04/10/2016 09:50 PM, Steven D'Aprano wrote: Fillmore, you should feel very pleased with yourself. All the tens of thousands of Python

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Chris Angelico
On Mon, Apr 11, 2016 at 12:22 PM, Dan Sommers wrote: > On Mon, 11 Apr 2016 01:33:10 +0100, MRAB wrote: > >> There _is_ one exception though: (). It's the empty tuple (a 0-element >> tuple). It doesn't have a comma and the parentheses are mandatory. >> There's no other way

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Dan Sommers
On Mon, 11 Apr 2016 01:33:10 +0100, MRAB wrote: > There _is_ one exception though: (). It's the empty tuple (a 0-element > tuple). It doesn't have a comma and the parentheses are mandatory. > There's no other way to write it. The other way to write it is: tuple() --

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Steven D'Aprano
On Mon, 11 Apr 2016 08:51 am, Fillmore wrote: > at which point did the language designers decide to betray the > "path of least surprise" principle and create a 'discontinuity' in the > language? It was March 1996, and I was there. I don't remember the date, I'm afraid. Some of the core Python

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Terry Reedy
On 4/10/2016 8:17 PM, Fillmore wrote: apparently my 'discontinuity' is mappable to the fact that there's no such thing as one-element tuples in Python, and attempts to create one will result in a string (i.e. an object of a different kind!)... Please work through the tutorial before posting

Re: Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask])

2016-04-10 Thread Tim Chase
On 2016-04-11 10:45, Ben Finney wrote: > Also, there is another obvious way to create an empty tuple: call > the ‘tuple’ type directly: > > >>> foo = tuple() > >>> print(type(foo), len(foo)) > 0 But here the parens make the tuple too: >>> foo = tuple >>> print(type(foo))

Re: Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask])

2016-04-10 Thread Stephen Hansen
On Sun, Apr 10, 2016, at 05:45 PM, Ben Finney wrote: > So, let's please stop saying “parens don't create a tuple”. They do, and > because of that I've stopped saying that false over-simplification. I stand by "parens don't make a tuple", with the caveat that I should have mentioned the empty

Re: Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask])

2016-04-10 Thread Chris Angelico
On Mon, Apr 11, 2016 at 10:45 AM, Ben Finney wrote: > So the expanation that remains true when you examine it is: People > wanted a literal syntax to create a zero-length tuple. A pair of parens > is that literal syntax, and it's the parens that create the (empty) >

Parens do create a tuple (was: one-element tuples [Was: Most probably a stupid question, but I still want to ask])

2016-04-10 Thread Ben Finney
Stephen Hansen writes: > […] parens don't make tuples, commas do. Chris Angelico writes: > The thing you're confused at is that it's not the parentheses that > create a tuple. Parentheses merely group. MRAB writes: > As

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Chris Angelico
On Mon, Apr 11, 2016 at 10:33 AM, MRAB wrote: > For example, object are passed into a function thus: > > f(x, y) > > (In reality, it's making a tuple and then passing that in.) Actually that's not the case; certain syntactic constructs allow you to specify

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Stephen Hansen
On Sun, Apr 10, 2016, at 05:17 PM, Fillmore wrote: > On 04/10/2016 07:30 PM, Stephen Hansen wrote: > > > There's nothing inconsistent or surprising going on besides you doing > > something vaguely weird and not really expressing what you find > > surprising. > > well, I was getting some

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Ben Finney
Fillmore writes: > Sorry guys. It was not my intention to piss off anyone...just trying > to understand how the languare works Frustration is understandable when learning something new :-) Hopefully that can be a signal to take a breath, and compose messages to

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread MRAB
On 2016-04-11 01:13, Fillmore wrote: Sorry guys. It was not my intention to piss off anyone...just trying to understand how the languare works I guess that the answer to my question is: there is no such thing as a one-element tuple, and Python will automatically convert a one-element tuple

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Stephen Hansen
On Sun, Apr 10, 2016, at 05:22 PM, Fillmore wrote: > Hold on a sec! it turns up that there is such thing as single-element > tuples in python: > > >>> c = ('hello',) > >>> c > ('hello',) > >>> c[0] > 'hello' > >>> c[1] > Traceback (most recent call last): >File "", line 1, in >

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Chris Angelico
On Mon, Apr 11, 2016 at 10:13 AM, Fillmore wrote: > Sorry guys. It was not my intention to piss off anyone...just trying to > understand how the languare works > > I guess that the answer to my question is: there is no such thing as a > one-element tuple, > and Python

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Fillmore
On 04/10/2016 08:13 PM, Fillmore wrote: Sorry guys. It was not my intention to piss off anyone...just trying to understand how the languare works I guess that the answer to my question is: there is no such thing as a one-element tuple, and Python will automatically convert a one-element

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Fillmore
On 04/10/2016 07:30 PM, Stephen Hansen wrote: There's nothing inconsistent or surprising going on besides you doing something vaguely weird and not really expressing what you find surprising. well, I was getting some surprising results for some of my data, so I can guarantee that I was

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Stephen Hansen
On Sun, Apr 10, 2016, at 05:18 PM, Stephen Hansen wrote: > The parens are optional, I always put them in because: > >>> b = "hello", Ahem, "because its easy to miss the trailing comma" is what I meant to say here. -- https://mail.python.org/mailman/listinfo/python-list

Re: one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Stephen Hansen
On Sun, Apr 10, 2016, at 05:13 PM, Fillmore wrote: > I guess that the answer to my question is: there is no such thing as a > one-element tuple, > and Python will automatically convert a one-element tuple to a string... > hence the > behavior I observed is explained... > > >>> a =

one-element tuples [Was: Most probably a stupid question, but I still want to ask]

2016-04-10 Thread Fillmore
Sorry guys. It was not my intention to piss off anyone...just trying to understand how the languare works I guess that the answer to my question is: there is no such thing as a one-element tuple, and Python will automatically convert a one-element tuple to a string... hence the behavior I

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Stephen Hansen
On Sun, Apr 10, 2016, at 03:51 PM, Fillmore wrote: > > let's look at this: > > $ python3.4 > Python 3.4.0 (default, Apr 11 2014, 13:05:11) > [GCC 4.8.2] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> line1 = '"String1" | bla' > >>> parts1 =

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Ben Finney
Fillmore writes: > let's look at this: Can you set a “Subject” field that pertains to the actual question? As is, it doesn't help know what you want to discuss. > the question is: at which point did the language designers decide to > betray the "path of least

Re: Most probably a stupid question, but I still want to ask

2016-04-10 Thread Chris Angelico
On Mon, Apr 11, 2016 at 8:51 AM, Fillmore wrote: > the question is: at which point did the language designers decide to betray > the > "path of least surprise" principle and create a 'discontinuity' in the > language? > Open to the idea that I am getting something

Most probably a stupid question, but I still want to ask

2016-04-10 Thread Fillmore
let's look at this: $ python3.4 Python 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> line1 = '"String1" | bla' >>> parts1 = line1.split(" | ") >>> parts1 ['"String1"', 'bla'] >>> tokens1 = eval(parts1[0])