Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90751 > unrolled thread

Rule of order for dot operators?

Started by"C.D. Reimer" <chris@cdreimer.com>
First post2015-05-16 12:20 -0700
Last post2015-05-18 14:00 +0200
Articles 20 on this page of 21 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  Rule of order for dot operators? "C.D. Reimer" <chris@cdreimer.com> - 2015-05-16 12:20 -0700
    Re: Rule of order for dot operators? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-16 21:40 +0200
      Re: Rule of order for dot operators? "C.D. Reimer" <chris@cdreimer.com> - 2015-05-16 12:55 -0700
        Re: Rule of order for dot operators? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-17 19:17 +0200
          Re: Rule of order for dot operators? Ned Batchelder <ned@nedbatchelder.com> - 2015-05-17 10:30 -0700
            Re: Rule of order for dot operators? Rustom Mody <rustompmody@gmail.com> - 2015-05-17 12:13 -0700
          Re: Rule of order for dot operators? "C.D. Reimer" <chris@cdreimer.com> - 2015-05-17 11:35 -0700
      Re: Rule of order for dot operators? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-17 11:45 +1000
        Re: Rule of order for dot operators? Rustom Mody <rustompmody@gmail.com> - 2015-05-16 22:06 -0700
        Re: Rule of order for dot operators? Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-17 15:43 +0000
          Re: Rule of order for dot operators? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-20 00:30 +0200
            Re: Rule of order for dot operators? Ned Batchelder <ned@nedbatchelder.com> - 2015-05-19 18:36 -0700
              Re: Rule of order for dot operators? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-05-20 04:24 +0200
                Re: Rule of order for dot operators? Ned Batchelder <ned@nedbatchelder.com> - 2015-05-19 19:44 -0700
                Re: Rule of order for dot operators? Chris Angelico <rosuav@gmail.com> - 2015-05-20 13:11 +1000
                Re: Rule of order for dot operators? Ben Finney <ben+python@benfinney.id.au> - 2015-05-20 17:29 +1000
              Re: Rule of order for dot operators? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-20 12:31 +1000
        Re: Rule of order for dot operators? "C.D. Reimer" <chris@cdreimer.com> - 2015-05-17 10:50 -0700
        Re: Rule of order for dot operators? Chris Angelico <rosuav@gmail.com> - 2015-05-18 17:40 +1000
    Re: Rule of order for dot operators? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-05-17 11:31 +1000
    Re: Rule of order for dot operators? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2015-05-18 14:00 +0200

Page 1 of 2  [1] 2  Next page →


#90751 — Rule of order for dot operators?

From"C.D. Reimer" <chris@cdreimer.com>
Date2015-05-16 12:20 -0700
SubjectRule of order for dot operators?
Message-ID<mailman.80.1431804386.17265.python-list@python.org>
Greetings,

Noobie question regarding a single line of code that transforms a URL 
slug ("this-is-a-slug") into a title ("This Is A Slug").

title = slug.replace('-',' ').title()

This line also works if I switched the dot operators around.

title = slug.title().replace('-',' ')

I'm reading the first example as character replacement first and title 
capitalization second, and the second example as title capitalization 
first and character replacement second.

Does python perform the dot operators from left to right or according to 
a rule of order (i.e., multiplication/division before add/subtract)?

Thank you,

Chris Reimer

[toc] | [next] | [standalone]


#90755

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-05-16 21:40 +0200
Message-ID<3341326.d8VUBGAoep@PointedEars.de>
In reply to#90751
C.D. Reimer wrote:
^^^^
Who?

> Noobie

What?

> question regarding a single line of code that transforms a URL
> slug ("this-is-a-slug") into a title ("This Is A Slug").
> 
> title = slug.replace('-',' ').title()
> 
> This line also works if I switched the dot operators around.
> 
> title = slug.title().replace('-',' ')
> 
> I'm reading the first example as character replacement first and title
> capitalization second, and the second example as title capitalization
> first and character replacement second.

You are reading correctly.

> Does python perform the dot operators from left to right or according to
> a rule of order (i.e., multiplication/division before add/subtract)?

Yes.  If you debug the code, which you should have done before posting [1] , 
you will see that

  'this-is-a-slug'.title() == 'This-Is-A-Slug'

It follows that in this special case it does not matter if you call .title() 
before or after .replace().

However, for greater efficiency, in general you should call .replace() in 
such a way that the length of the string it operates on is minimized.  For 
example, if feasible, always slice *before* .replace().

[1] <http://www.catb.org/~esr/faqs/smart-questions.html>
 
-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#90756

From"C.D. Reimer" <chris@cdreimer.com>
Date2015-05-16 12:55 -0700
Message-ID<mailman.84.1431806129.17265.python-list@python.org>
In reply to#90755
On 5/16/2015 12:40 PM, Thomas 'PointedEars' Lahn wrote:
> However, for greater efficiency, in general you should call .replace() 
> in such a way that the length of the string it operates on is 
> minimized. For example, if feasible, always slice *before* .replace().

Slice was how I got the slug from the URL in the first place. :)

Thank you,

Chris Reimer

[toc] | [prev] | [next] | [standalone]


#90778

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-05-17 19:17 +0200
Message-ID<4369306.J7Y2hDxjVg@PointedEars.de>
In reply to#90756
C.D. Reimer wrote:

> On 5/16/2015 12:40 PM, Thomas 'PointedEars' Lahn wrote:
>> However, for greater efficiency, in general you should call .replace()
>> in such a way that the length of the string it operates on is
>> minimized. For example, if feasible, always slice *before* .replace().
> 
> Slice was how I got the slug from the URL in the first place. :)

Consider using a regular expression or the urllib object instead.  See 
RFC 3986, Appendix B, and <https://docs.python.org/3/library/urllib.html>, 
respectively.

> Thank you,

You are welcome.

> Chris Reimer

Please use this or something to that effect in your “From” header field 
value.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#90780

FromNed Batchelder <ned@nedbatchelder.com>
Date2015-05-17 10:30 -0700
Message-ID<d061de7f-a039-491a-964d-ec81b5ff8f5b@googlegroups.com>
In reply to#90778
On Sunday, May 17, 2015 at 1:19:59 PM UTC-4, Thomas 'PointedEars' Lahn wrote:
> C.D. Reimer wrote:
> > Chris Reimer
> 
> Please use this or something to that effect in your "From" header field 
> value.

Please stop making strange requests of others. "C.D. Reimer" is
a perfectly reasonable name to use.

--Ned.

> 
> -- 
> PointedEars

[toc] | [prev] | [next] | [standalone]


#90783

FromRustom Mody <rustompmody@gmail.com>
Date2015-05-17 12:13 -0700
Message-ID<9012c2cd-4a3e-4915-bfb8-79a13143e0e7@googlegroups.com>
In reply to#90780
On Sunday, May 17, 2015 at 11:01:01 PM UTC+5:30, Ned Batchelder wrote:
> On Sunday, May 17, 2015 at 1:19:59 PM UTC-4, Thomas 'PointedEars' Lahn wrote:
> > C.D. Reimer wrote:
> > > Chris Reimer
> > 
> > Please use this or something to that effect in your "From" header field 
> > value.
> 
> Please stop making strange requests of others. "C.D. Reimer" is
> a perfectly reasonable name to use.
> 
> --Ned.

And what about 'PointedEars'?
If that can be accepted so can 'C.D. Reimer'.


[toc] | [prev] | [next] | [standalone]


#90782

From"C.D. Reimer" <chris@cdreimer.com>
Date2015-05-17 11:35 -0700
Message-ID<mailman.97.1431887729.17265.python-list@python.org>
In reply to#90778
On 5/17/2015 10:17 AM, Thomas 'PointedEars' Lahn wrote:
> C.D. Reimer wrote:
>
> Consider using a regular expression or the urllib object instead. See 
> RFC 3986, Appendix B, and 
> <https://docs.python.org/3/library/urllib.html>, respectively.

That wouldn't work for me. I'm in the process of converting a WordPress 
website into a static website.

I wrote a script that pulled the HTML content from the SQL file to save 
each post in a text file with the URL as the file name (i.e., 
"2015-01-01-this-is-a-slug.html"). That created 275 files in the source 
folder.

Since I'm using Grav CMS (http://getgrav.org/) for my static website, I 
wrote a script to get the file names from the source folder, slice each 
file name into their respective component (i.e., year, month, day, slug, 
and title from the slug), convert the HTML into Markdown, and copy the 
content into a file called item.md inside a new folder (i.e., 
20150101.this-is-a-slug) in the destination folder.

After I get done cleaning up 275 item.md files in a Markdown editor, 
I'll write another script to create an .htaccess file to forward old url 
(i.e., /2015/01/01/this-is-a-slug) to the new URL (i.e., 
/blog/this-is-a-slug).

Gotta love string manipulations. ;)

Thank you,

Chris Reimer

[toc] | [prev] | [next] | [standalone]


#90763

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-05-17 11:45 +1000
Message-ID<5557f29f$0$12992$c3e8da3$5496439d@news.astraweb.com>
In reply to#90755
On Sun, 17 May 2015 05:40 am, Thomas 'PointedEars' Lahn wrote:

> C.D. Reimer wrote:
> ^^^^
> Who?

Don't be a dick, Thomas. Lots of people use their initials. You use your
nickname as part of your sender address, why are you questioning somebody
for using their initials?


>> Noobie
> 
> What?

Where? When? Why? How?

I'm pretty sure you've been on the Internet for long enough to know
what "noobie", "n00b", "newbie" etc mean.

But just in case you need help:

http://lmgtfy.com/?q=noobie



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#90766

FromRustom Mody <rustompmody@gmail.com>
Date2015-05-16 22:06 -0700
Message-ID<67e40749-f6a2-45e4-90ee-d189084fb2f7@googlegroups.com>
In reply to#90763
On Sunday, May 17, 2015 at 7:15:13 AM UTC+5:30, Steven D'Aprano wrote:
> On Sun, 17 May 2015 05:40 am, Thomas 'PointedEars' Lahn wrote:
> 
> > C.D. Reimer wrote:
> > ^^^^
> > Who?
> 
> Don't be a dick, Thomas. Lots of people use their initials. You use your
> nickname as part of your sender address, why are you questioning somebody
> for using their initials?

Not only is it a ridiculous objection, I dont even understand what the objection
is.

Among the eminent this is quite common
Dijkstra -- ewd
Stallman -- rms
Eric Raymond -- esr

And even for non-eminent like your truly, most of my working life most people
called me 'rpm' than Rusi/Mody or any such.

[toc] | [prev] | [next] | [standalone]


#90770

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2015-05-17 15:43 +0000
Message-ID<mjacv8$ods$6@dont-email.me>
In reply to#90763
On Sun, 17 May 2015 11:45:02 +1000, Steven D'Aprano wrote:

> On Sun, 17 May 2015 05:40 am, Thomas 'PointedEars' Lahn wrote:
> 
>> C.D. Reimer wrote:
>> ^^^^
>> Who?
> 
> Don't be a dick, Thomas.

Thomas is a professional dick, he can't help it, he's been a professional 
dick for years in php and javascript groups, and now he's obviously 
spreading himself further afield. He usually confines his wisdom to 
pointing out faults in other's posts, rather than offering any 
constructive input himself.

-- 
Denis McMahon, denismfmcmahon@gmail.com

[toc] | [prev] | [next] | [standalone]


#90900

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-05-20 00:30 +0200
Message-ID<2710946.pHPuBPdTgQ@PointedEars.de>
In reply to#90770
Denis McMahon wrote:

> On Sun, 17 May 2015 11:45:02 +1000, Steven D'Aprano wrote:
>> On Sun, 17 May 2015 05:40 am, Thomas 'PointedEars' Lahn wrote:
>>> C.D. Reimer wrote:
>>> ^^^^
>>> Who?
>> Don't be a dick, Thomas.
> 
> Thomas is a professional dick, he can't help it, he's been a professional
> dick for years in php and javascript groups, and now he's obviously
> spreading himself further afield. He usually confines his wisdom to
> pointing out faults in other's posts, rather than offering any
> constructive input himself.

Yes, I am a professional, while you are just a dick.  Every single time.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#90911

FromNed Batchelder <ned@nedbatchelder.com>
Date2015-05-19 18:36 -0700
Message-ID<f69e21a0-026a-4a9d-bac6-78ba891bfb13@googlegroups.com>
In reply to#90900
On Tuesday, May 19, 2015 at 6:33:46 PM UTC-4, Thomas 'PointedEars' Lahn wrote:
> Denis McMahon wrote:
> 
> > On Sun, 17 May 2015 11:45:02 +1000, Steven D'Aprano wrote:
> >> On Sun, 17 May 2015 05:40 am, Thomas 'PointedEars' Lahn wrote:
> >>> C.D. Reimer wrote:
> >>> ^^^^
> >>> Who?
> >> Don't be a dick, Thomas.
> > 
> > Thomas is a professional dick, he can't help it, he's been a professional
> > dick for years in php and javascript groups, and now he's obviously
> > spreading himself further afield. He usually confines his wisdom to
> > pointing out faults in other's posts, rather than offering any
> > constructive input himself.
> 
> Yes, I am a professional, while you are just a dick.  Every single time.

Everyone should stop calling people names.

Thomas, you were obnoxious to the OP, and now you are being obnoxious (and factually incorrect) to Denis.

Steven and Denis: you were too blunt in your objections.

Be considerate. Be respectful.

--Ned.

[toc] | [prev] | [next] | [standalone]


#90915

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-05-20 04:24 +0200
Message-ID<16277536.fgHiFt9JYW@PointedEars.de>
In reply to#90911
Ned Batchelder wrote:

> On Tuesday, May 19, 2015 at 6:33:46 PM UTC-4, Thomas 'PointedEars' Lahn
> wrote:
>> Denis McMahon wrote:
>> > On Sun, 17 May 2015 11:45:02 +1000, Steven D'Aprano wrote:
>> >> On Sun, 17 May 2015 05:40 am, Thomas 'PointedEars' Lahn wrote:
>> >>> C.D. Reimer wrote:
>> >>> ^^^^
>> >>> Who?
>> >> Don't be a dick, Thomas.
>> > 
>> > Thomas is a professional dick, he can't help it, he's been a
>> > professional dick for years in php and javascript groups, and now he's
>> > obviously spreading himself further afield. He usually confines his
>> > wisdom to pointing out faults in other's posts, rather than offering
>> > any constructive input himself.
>> 
>> Yes, I am a professional, while you are just a dick.  Every single time.
> 
> Everyone should stop calling people names.
> 
> Thomas, you were obnoxious to the OP, and now you are being obnoxious (and
> factually incorrect) to Denis.
> 
> Steven and Denis: you were too blunt in your objections.
> 
> Be considerate. Be respectful.

Yes, I could have skipped this comment, and I am not in the habit of calling 
names; but frankly, enough is enough.  Denis is posting libellous statements 
about me in every Big 8 newsgroup in which I participate because he often 
posts awfully wrong technically statements and just cannot stand being 
corrected by me.

And who appointed you moderator?  I would not mind if you *asked* people 
publicly for politeness as I do that myself sometimes, but I do mind the 
overall tone of your off-topic comments, your apparently trying to dictate 
what people are allowed to say here.  If that’s the way this newsgroup 
works, I am off here.  (But I seriously doubt it.)  Because that is _not_ 
how Usenet is supposed to work.

For now, just EOD for me, and F'up2 poster.

-- 
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#90918

FromNed Batchelder <ned@nedbatchelder.com>
Date2015-05-19 19:44 -0700
Message-ID<758d0ddf-cf4a-462c-9f75-a6265373cfad@googlegroups.com>
In reply to#90915
On Tuesday, May 19, 2015 at 10:26:56 PM UTC-4, Thomas 'PointedEars' Lahn wrote:
> 
> And who appointed you moderator?  I would not mind if you *asked* people 
> publicly for politeness as I do that myself sometimes, but I do mind the 
> overall tone of your off-topic comments, your apparently trying to dictate 
> what people are allowed to say here.  If that's the way this newsgroup 
> works, I am off here.  (But I seriously doubt it.)  Because that is _not_ 
> how Usenet is supposed to work.

I am not a moderator, just someone who cares about the tone
in the group.  

The Python community has a code of conduct
(https://www.python.org/psf/codeofconduct/), and people on this
mailing list are expected to adhere to it.  It is where I got
the words "respectful" and "considerate".  The code of conduct
is how the Python community is supposed to work.

I'm sorry my post seemed too pushy.  Consider it a request for
polite discourse.

--Ned.

[toc] | [prev] | [next] | [standalone]


#90920

FromChris Angelico <rosuav@gmail.com>
Date2015-05-20 13:11 +1000
Message-ID<mailman.158.1432091517.17265.python-list@python.org>
In reply to#90915
On Wed, May 20, 2015 at 12:24 PM, Thomas 'PointedEars' Lahn
<PointedEars@web.de> wrote:
> And who appointed you moderator?  I would not mind if you *asked* people
> publicly for politeness as I do that myself sometimes, but I do mind the
> overall tone of your off-topic comments, your apparently trying to dictate
> what people are allowed to say here.  If that’s the way this newsgroup
> works, I am off here.  (But I seriously doubt it.)  Because that is _not_
> how Usenet is supposed to work.

Usually, the people who threaten to leave are the ones we will least
miss. Go ahead, leave if you don't like Ned asking you to be more
polite.

ChrisA

[toc] | [prev] | [next] | [standalone]


#90941

FromBen Finney <ben+python@benfinney.id.au>
Date2015-05-20 17:29 +1000
Message-ID<mailman.163.1432106969.17265.python-list@python.org>
In reply to#90915
Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:

> Ned Batchelder wrote:
>
> > Be considerate. Be respectful.
>
> And who appointed you moderator?

Ned is telling you how we are all expected to behave here, and that you
have violated the norms of behaviour to other participants here.

He does so with authority as someone who understands the norms here.
Moderator privileges are not required for that.

> If that’s the way this newsgroup works, I am off here. (But I
> seriously doubt it.) Because that is _not_ how Usenet is supposed to
> work.

None the less, that is how this forum works. We are part of the Python
community here, and we expect all participants to treat each other with
respect and consideration.

-- 
 \     “It is not enough to have a good mind. The main thing is to use |
  `\                                         it well.” —Rene Descartes |
_o__)                                                                  |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#90916

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-05-20 12:31 +1000
Message-ID<555bf1f6$0$12980$c3e8da3$5496439d@news.astraweb.com>
In reply to#90911
On Wed, 20 May 2015 11:36 am, Ned Batchelder wrote:

> Steven and Denis: you were too blunt in your objections.

Fair enough.

In my defence, I'm from Australia, and we're notorious for calling a spade a
bloody shovel.

> Be considerate. Be respectful.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#90789

From"C.D. Reimer" <chris@cdreimer.com>
Date2015-05-17 10:50 -0700
Message-ID<mailman.99.1431934016.17265.python-list@python.org>
In reply to#90763
On 5/16/2015 6:45 PM, Steven D'Aprano wrote:
> On Sun, 17 May 2015 05:40 am, Thomas 'PointedEars' Lahn wrote:
>
>> C.D. Reimer wrote:
>> ^^^^
>> Who?
> Don't be a dick, Thomas. Lots of people use their initials. You use your
> nickname as part of your sender address, why are you questioning somebody
> for using their initials?

I used my initials to hide my online presence from the Real World(tm). If a hiring manager looks up my legal name on the Internet, he or she will find a bunch of Usenet postings when I was a SuSE Linux noob in the 1990's. The only online accounts I have under my legal name is a Yahoo email address and a LinkedIn profile. After working at one employer that allowed anything found on the Internet as ammo in the office politics, a blank online slate provides better protection from such nonsense.

Besides, I got called by my initials in school when the compact discs (CD) became popular. :)

As for my question, my 2007 Core Python Programming book (based on python 2.5) indexed the dot for search operations. Some code examples show a single call (i.e., object.method()) but not multiple calls (i.e., object.method().method()). Since I wasn't sure what I was looking for, an Internet search turned up nothing useful. Hence, IMHO, a noobie question.

Maybe I need a newer python book?

Thank you,

Chris Reimer

[toc] | [prev] | [next] | [standalone]


#90790

FromChris Angelico <rosuav@gmail.com>
Date2015-05-18 17:40 +1000
Message-ID<mailman.100.1431934852.17265.python-list@python.org>
In reply to#90763
On Mon, May 18, 2015 at 3:50 AM, C.D. Reimer <chris@cdreimer.com> wrote:
> On 5/16/2015 6:45 PM, Steven D'Aprano wrote:
>>
>> On Sun, 17 May 2015 05:40 am, Thomas 'PointedEars' Lahn wrote:
>>
>>> C.D. Reimer wrote:
>>> ^^^^
>>> Who?
>>
>> Don't be a dick, Thomas. Lots of people use their initials. You use your
>> nickname as part of your sender address, why are you questioning somebody
>> for using their initials?
>
>
> I used my initials to hide my online presence from the Real World(tm). If a
> hiring manager looks up my legal name on the Internet, he or she will find a
> bunch of Usenet postings when I was a SuSE Linux noob in the 1990's. The
> only online accounts I have under my legal name is a Yahoo email address and
> a LinkedIn profile. After working at one employer that allowed anything
> found on the Internet as ammo in the office politics, a blank online slate
> provides better protection from such nonsense.

Personally, I'd rather establish a strong presence under my actual
name than try to hide; otherwise, there'll still _be_ some sort of
presence, but it's less under your control. But that's a matter of
opinion.

> Besides, I got called by my initials in school when the compact discs (CD)
> became popular. :)

Could be worse. You could have been called Carrier Detect, Current
Directory (or Change Directory), candela (if written "cd"), Cadmium
(if written "Cd"), or any number of other things. I've heard tell you
can learn a lot about someone by what they first think of as an
expansion of "CD". :)

> As for my question, my 2007 Core Python Programming book (based on python
> 2.5) indexed the dot for search operations. Some code examples show a single
> call (i.e., object.method()) but not multiple calls (i.e.,
> object.method().method()). Since I wasn't sure what I was looking for, an
> Internet search turned up nothing useful. Hence, IMHO, a noobie question.
>
> Maybe I need a newer python book?

Based on 2.5? Probably; get yourself a book that focuses on 3.x,
ideally. But not because stuff is fundamentally different - more
because you'll be missing out on some improvements. From 2.5 to 2.7
there were a number of neat feature additions, many of them enabling
2.x/3.x compatibility, plus some tidyups and such; what you'd normally
expect of a couple of versions' worth of development. Most of what the
book says is probably still valid.

ChrisA

[toc] | [prev] | [next] | [standalone]


#90762

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2015-05-17 11:31 +1000
Message-ID<5557ef89$0$12982$c3e8da3$5496439d@news.astraweb.com>
In reply to#90751
On Sun, 17 May 2015 05:20 am, C.D. Reimer wrote:

> Greetings,
> 
> Noobie question regarding a single line of code that transforms a URL
> slug ("this-is-a-slug") into a title ("This Is A Slug").
> 
> title = slug.replace('-',' ').title()
> 
> This line also works if I switched the dot operators around.

Technically, dot is not an operator, but even if it was, swapping the *dots*
around makes no difference:

slug.replace('-',' ').title()  => slug.replace('-',' ').title()

Because a dot is a dot, right? What you mean is that you're swapping the
*methods* around, not just the dots:

slug.replace('-',' ').title()  => slug.title().replace('-',' ')


> title = slug.title().replace('-',' ')
> 
> I'm reading the first example as character replacement first and title
> capitalization second, and the second example as title capitalization
> first and character replacement second.
> 
> Does python perform the dot operators from left to right or according to
> a rule of order (i.e., multiplication/division before add/subtract)?

Left to right.




-- 
Steven

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web