Re: [Python-ideas] string.format() default variable assignment

Discussion in 'Python' started by Chris Angelico, Mar 1, 2013.

  1. On Sat, Mar 2, 2013 at 3:55 AM, 김용빈 <> wrote:
    > why we bother with '{variable}'.format(variable=variable) ?
    > can we just '{variable}.format()' ?
    >
    > if variable is exist, then assign it.
    > if variable is not exist, then raise error
    >
    > I am not language expert. so sorry if this is not a good idea, or already
    > discussed.


    You're asking for a facility whereby variables magically get pulled
    from the caller's scope. Let me put it to you another way:

    def func1():
    return foo + " world"

    def func2():
    foo = "Hello"
    print("func1 returns: "+func1())

    func2()

    Will this work? If not, why not?

    There are ways around this; you can, for instance, pass locals() to format():
    '{variable}'.format(**locals())

    But this is massive overkill and can unexpectedly expose a whole lot
    more than you wanted (an issue if you accept a format string from an
    untrusted source). Generally, it's best to be explicit. You can avoid
    repeating the name so much by using positional parameters instead:

    '{0}'.format(variable)

    Of course, this has its own considerations. But at least it isn't magical. :)

    ChrisA
    Chris Angelico, Mar 1, 2013
    #1
    1. Advertising

  2. On Sat, 02 Mar 2013 04:07:19 +1100, Chris Angelico replied to a thread of
    Python-ideas:

    > You're asking for a facility whereby variables magically get pulled from
    > the caller's scope.


    As interesting as that is, I think you sent it to the wrong list :)

    Again.

    o_O


    No offence Chris, but you're the only person I know who *regularly*
    replies to the wrong list. Does your mail client not have a "Reply to
    List" command, or "Reply All"? If so, then you should use it rather than
    manually typing the (wrong) list address in.



    --
    Steven
    Steven D'Aprano, Mar 2, 2013
    #2
    1. Advertising

  3. On Sat, Mar 2, 2013 at 12:43 PM, Steven D'Aprano
    <> wrote:
    > On Sat, 02 Mar 2013 04:07:19 +1100, Chris Angelico replied to a thread of
    > Python-ideas:
    >
    >> You're asking for a facility whereby variables magically get pulled from
    >> the caller's scope.

    >
    > As interesting as that is, I think you sent it to the wrong list :)


    Yes, as was pointed out to me privately.

    The message had the "feel" of something that belonged on python-list,
    and I never for a moment thought that it was an -ideas thread...

    > Again.
    >
    > o_O
    >
    >
    > No offence Chris, but you're the only person I know who *regularly*
    > replies to the wrong list. Does your mail client not have a "Reply to
    > List" command, or "Reply All"? If so, then you should use it rather than
    > manually typing the (wrong) list address in.


    Correct, Gmail doesn't. I should switch to Thunderbird (or something
    else, but I've heard a good many recommendations for Tbird) but have
    yet to get around to setting it up.

    ChrisA
    Chris Angelico, Mar 2, 2013
    #3
  4. On Fri, Mar 1, 2013 at 10:54 PM, Chris Angelico <> wrote:
    >> No offence Chris, but you're the only person I know who *regularly*
    >> replies to the wrong list. Does your mail client not have a "Reply to
    >> List" command, or "Reply All"? If so, then you should use it rather than
    >> manually typing the (wrong) list address in.

    >
    > Correct, Gmail doesn't. I should switch to Thunderbird (or something
    > else, but I've heard a good many recommendations for Tbird) but have
    > yet to get around to setting it up.


    Actually, it has a few ways to reply-to-all. In this screenshot, there
    are three things I could click to reply-to-all:
    http://imgur.com/914BNuY

    First, I could click the big reply button. I changed a setting so that
    reply-to-all is the default (Settings->General->Default reply
    behavior). Second, there is the reply-to-all menu item in the reply
    dropdown. Finally, in the textbox at the bottom, there's the
    reply-to-all hyperlink.

    It sounds like changing the default would do you the most good. It
    usually does what I want.

    -- Devin
    Devin Jeanpierre, Mar 2, 2013
    #4
  5. [--------- Sat 2.Mar'13 at 17:54:57 +1100 Chris Angelico :---------]

    > On Sat, Mar 2, 2013 at 5:09 PM, Devin Jeanpierre <> wrote:
    > > On Fri, Mar 1, 2013 at 10:54 PM, Chris Angelico <> wrote:
    > >>> No offence Chris, but you're the only person I know who *regularly*
    > >>> replies to the wrong list. Does your mail client not have a "Reply to
    > >>> List" command, or "Reply All"? If so, then you should use it rather than
    > >>> manually typing the (wrong) list address in.
    > >>
    > >> Correct, Gmail doesn't. I should switch to Thunderbird (or something
    > >> else, but I've heard a good many recommendations for Tbird) but have
    > >> yet to get around to setting it up.

    > >
    > > Actually, it has a few ways to reply-to-all. In this screenshot, there
    > > are three things I could click to reply-to-all:
    > > http://imgur.com/914BNuY

    >
    > Yes, but reply-all sends a copy to the poster as well as the list.
    > What I want is reply-list, acknowledging the list headers... and Gmail
    > simply doesn't have that.
    >
    > I also want to be able to change my mind as to whether it's
    > reply-all/reply-list/reply-sender after typing up a reply. Guess it's
    > time I grabbed Tbird to find out if it can do that...


    use mutt devel or [Al]pine. Text based MUA's and News readers are more efficient IMO.
    James Griffin, Mar 2, 2013
    #5
  6. On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico <> wrote:
    > Yes, but reply-all sends a copy to the poster as well as the list.
    > What I want is reply-list, acknowledging the list headers... and Gmail
    > simply doesn't have that.


    I've been replying to the poster and the list for ages. Is it bad netiquette?

    > I also want to be able to change my mind as to whether it's
    > reply-all/reply-list/reply-sender after typing up a reply. Guess it's
    > time I grabbed Tbird to find out if it can do that...


    You can change your mind for reply-all/reply/forward in gmail, but
    since there's no reply-list, can't do that one, of course.

    -- Devin
    Devin Jeanpierre, Mar 2, 2013
    #6
  7. Chris Angelico

    Tim Golden Guest

    On 02/03/2013 14:53, Devin Jeanpierre wrote:
    > On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico <> wrote:
    >> Yes, but reply-all sends a copy to the poster as well as the list.
    >> What I want is reply-list, acknowledging the list headers... and Gmail
    >> simply doesn't have that.

    >
    > I've been replying to the poster and the list for ages. Is it bad netiquette?


    Mixed, I'd say. Some do it, some even prefer it, some don't. I generally
    stick to the list only unless it's important that the OP sees the
    message sooner than later.

    TJG
    Tim Golden, Mar 2, 2013
    #7
  8. On Sat, 02 Mar 2013 15:01:47 +0000, Tim Golden <>
    declaimed the following in gmane.comp.python.general:

    >
    > Mixed, I'd say. Some do it, some even prefer it, some don't. I generally
    > stick to the list only unless it's important that the OP sees the
    > message sooner than later.
    >

    On the receiving side -- I tend to find email copies of replies an
    annoyance unless the sender has explained why they went to email. After
    all, I'm going to see the response in the list anyway, where it is in
    context (and I can see if anyone else has followed up to it).

    --
    Wulfraed Dennis Lee Bieber AF6VN
    HTTP://wlfraed.home.netcom.com/
    Dennis Lee Bieber, Mar 2, 2013
    #8
  9. Chris Angelico

    Ethan Furman Guest

    good mail readers [was Re: [Python-ideas] string.format() defaultvariable assignment]

    On 03/02/2013 12:06 AM, James Griffin wrote:
    > [--------- Sat 2.Mar'13 at 17:54:57 +1100 Chris Angelico :---------]
    >> I also want to be able to change my mind as to whether it's
    >> reply-all/reply-list/reply-sender after typing up a reply. Guess it's
    >> time I grabbed Tbird to find out if it can do that...

    >
    > use mutt devel or [Al]pine. Text based MUA's and News readers are more efficient IMO.


    I'll take a look at those three. While I certainly prefer Tbird over anything MS has to offer, it certainly has its own
    list of irritations.

    --
    ~Ethan~
    Ethan Furman, Mar 2, 2013
    #9
  10. On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote:

    > On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico <> wrote:
    >> Yes, but reply-all sends a copy to the poster as well as the list. What
    >> I want is reply-list, acknowledging the list headers... and Gmail
    >> simply doesn't have that.

    >
    > I've been replying to the poster and the list for ages. Is it bad
    > netiquette?


    I find it annoying, and yes I consider it rude. When we receive messages
    via a list, responses (unless personal and deliberately taken outside of
    the list) should remain on the list, rather than potentially bypassing
    any filters set up by the sender. E.g. the sender may have a filter that
    files mail to "Python-list" into a mail folder. If you send to the sender
    directly, you may break their filters.

    I read this list via Usenet, not email. So when somebody replies to me,
    and the list, I get a copy in my inbox and a copy in my news client.
    That's a de facto filter, which they have just broken.

    The mailman software used for the Python lists seem to be smart enough to
    only send the user one copy. But many mailing lists are not, and so when
    you reply to the author and CC the list, they may very well receive two
    copies.

    In effect, the person replying is saying "MY reply is so important that I
    don't care how you process mail, I'm going to try to force you to read it
    MY way instead of in your preferred way." So, yes, I do consider it rude.

    In the grand scheme of things though, it is a relatively minor rudeness.
    Pushing into line, or invading personal space, rather than breaking into
    my house and smearing excrement on the walls.


    --
    Steven
    Steven D'Aprano, Mar 3, 2013
    #10
  11. Chris Angelico

    Roy Smith Guest

    In article <513298fa$0$30001$c3e8da3$>,
    Steven D'Aprano <> wrote:

    > On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote:
    >
    > > On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico <> wrote:
    > >> Yes, but reply-all sends a copy to the poster as well as the list. What
    > >> I want is reply-list, acknowledging the list headers... and Gmail
    > >> simply doesn't have that.

    > >
    > > I've been replying to the poster and the list for ages. Is it bad
    > > netiquette?

    >
    > I find it annoying, and yes I consider it rude.


    I actually find it convenient and useful when people do that. If
    somebody's replying to a thread I'm active on, I consider the responses
    to that thread to be higher priority than the rest of the firehose, so
    it's good for me that they've copied me directly.

    I also read this list via usenet. During the workday, I don't have
    convenient access to a newsreader, but I do get mail. If I post a
    question to the group from home in the morning, when people cc me
    directly on replies, I get them quickly. If they only post to the
    group, I have to either wait until I get home to catch up on netnews, or
    use one of several less convenient means of accessing the group from
    work.
    Roy Smith, Mar 3, 2013
    #11
  12. On Sat, Mar 2, 2013 at 7:27 PM, Steven D'Aprano
    <> wrote:
    > On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote:
    >
    >> On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico <> wrote:
    >>> Yes, but reply-all sends a copy to the poster as well as the list. What
    >>> I want is reply-list, acknowledging the list headers... and Gmail
    >>> simply doesn't have that.

    >> I've been replying to the poster and the list for ages. Is it bad
    >> netiquette?

    >
    > I find it annoying, and yes I consider it rude. When we receive messages

    ...
    Do you consider it rude that you choose to use a newsreader, thus
    inconveniencing those of us who use the mailing list, as God intended.
    (I honestly can't remember if there's any advantage to News, not
    having used it this century)
    [Going out of my way to respond only to the list]
    David Robinow, Mar 3, 2013
    #12
  13. Chris Angelico

    Roy Smith Guest

    In article <>,
    David Robinow <> wrote:

    > On Sat, Mar 2, 2013 at 7:27 PM, Steven D'Aprano
    > <> wrote:
    > > On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote:
    > >
    > >> On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico <> wrote:
    > >>> Yes, but reply-all sends a copy to the poster as well as the list. What
    > >>> I want is reply-list, acknowledging the list headers... and Gmail
    > >>> simply doesn't have that.
    > >> I've been replying to the poster and the list for ages. Is it bad
    > >> netiquette?

    > >
    > > I find it annoying, and yes I consider it rude. When we receive messages

    > ...
    > Do you consider it rude that you choose to use a newsreader, thus
    > inconveniencing those of us who use the mailing list, as God intended.
    > (I honestly can't remember if there's any advantage to News, not
    > having used it this century)
    > [Going out of my way to respond only to the list]


    There's a number of advantages to news vs. mail. The biggest is that
    news spools generally keep a long history around, so it's easy to go
    back and review a long thread.
    Roy Smith, Mar 3, 2013
    #13
  14. On Sat, Mar 2, 2013 at 9:15 PM, Roy Smith <> wrote:
    > In article <>,
    > David Robinow <> wrote:
    >
    >> On Sat, Mar 2, 2013 at 7:27 PM, Steven D'Aprano
    >> <> wrote:
    >> > On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote:
    >> >
    >> >> On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico <> wrote:
    >> >>> Yes, but reply-all sends a copy to the poster as well as the list. What
    >> >>> I want is reply-list, acknowledging the list headers... and Gmail
    >> >>> simply doesn't have that.
    >> >> I've been replying to the poster and the list for ages. Is it bad
    >> >> netiquette?
    >> >
    >> > I find it annoying, and yes I consider it rude. When we receive messages

    >> ...
    >> Do you consider it rude that you choose to use a newsreader, thus
    >> inconveniencing those of us who use the mailing list, as God intended.
    >> (I honestly can't remember if there's any advantage to News, not
    >> having used it this century)
    >> [Going out of my way to respond only to the list]

    >
    > There's a number of advantages to news vs. mail. The biggest is that
    > news spools generally keep a long history around, so it's easy to go
    > back and review a long thread.

    That can't be the biggest since mail stays around forever unless
    deliberately deleted.
    David Robinow, Mar 3, 2013
    #14
  15. On Sun, Mar 3, 2013 at 2:01 PM, David Robinow <> wrote:
    > On Sat, Mar 2, 2013 at 9:15 PM, Roy Smith <> wrote:
    >> There's a number of advantages to news vs. mail. The biggest is that
    >> news spools generally keep a long history around, so it's easy to go
    >> back and review a long thread.

    > That can't be the biggest since mail stays around forever unless
    > deliberately deleted.


    But your mail has only what you receive. You have to hunt down a
    separate archive of what was posted before you joined the thread.
    Advantage goes to news, but a slight one, and if that's the biggest,
    it's not a great advertisement.

    ChrisA
    Chris Angelico, Mar 3, 2013
    #15
  16. On Sat, Mar 2, 2013 at 10:06 PM, Chris Angelico <> wrote:
    > On Sun, Mar 3, 2013 at 2:01 PM, David Robinow <> wrote:
    >> On Sat, Mar 2, 2013 at 9:15 PM, Roy Smith <> wrote:
    >>> There's a number of advantages to news vs. mail. The biggest is that
    >>> news spools generally keep a long history around, so it's easy to go
    >>> back and review a long thread.

    >> That can't be the biggest since mail stays around forever unless
    >> deliberately deleted.

    >
    > But your mail has only what you receive. You have to hunt down a
    > separate archive of what was posted before you joined the thread.
    > Advantage goes to news, but a slight one, and if that's the biggest,
    > it's not a great advertisement.

    I have no idea what you're trying to say here. As far as I know, when
    I subscribe to a list I get all the mail. I don't "join" threads. I
    don't even know what that means.
    [This has drifted way off topic so I won't be responding again, but
    I'll enjoy reading what anyone cares to write.]
    David Robinow, Mar 3, 2013
    #16
  17. On Sat, 02 Mar 2013 19:42:50 -0500, Roy Smith wrote:

    > In article <513298fa$0$30001$c3e8da3$>,
    > Steven D'Aprano <> wrote:
    >
    >> On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote:
    >>
    >> > On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico <>
    >> > wrote:
    >> >> Yes, but reply-all sends a copy to the poster as well as the list.
    >> >> What I want is reply-list, acknowledging the list headers... and
    >> >> Gmail simply doesn't have that.
    >> >
    >> > I've been replying to the poster and the list for ages. Is it bad
    >> > netiquette?

    >>
    >> I find it annoying, and yes I consider it rude.

    >
    > I actually find it convenient and useful when people do that. If
    > somebody's replying to a thread I'm active on, I consider the responses
    > to that thread to be higher priority than the rest of the firehose, so
    > it's good for me that they've copied me directly.


    Does your newsreader not have a "watch thread" command?


    > I also read this list via usenet. During the workday, I don't have
    > convenient access to a newsreader, but I do get mail. If I post a
    > question to the group from home in the morning, when people cc me
    > directly on replies, I get them quickly. If they only post to the
    > group, I have to either wait until I get home to catch up on netnews,
    > or use one of several less convenient means of accessing the group from
    > work.


    Or you could, I dunno, *work* while at work.

    <wink>



    --
    Steven
    Steven D'Aprano, Mar 3, 2013
    #17
  18. On Sat, 02 Mar 2013 21:11:04 -0500, David Robinow wrote:

    > On Sat, Mar 2, 2013 at 7:27 PM, Steven D'Aprano
    > <> wrote:
    >> On Sat, 02 Mar 2013 09:53:47 -0500, Devin Jeanpierre wrote:
    >>
    >>> On Sat, Mar 2, 2013 at 1:54 AM, Chris Angelico <>
    >>> wrote:
    >>>> Yes, but reply-all sends a copy to the poster as well as the list.
    >>>> What I want is reply-list, acknowledging the list headers... and
    >>>> Gmail simply doesn't have that.
    >>> I've been replying to the poster and the list for ages. Is it bad
    >>> netiquette?

    >>
    >> I find it annoying, and yes I consider it rude. When we receive
    >> messages

    > ...
    > Do you consider it rude that you choose to use a newsreader, thus
    > inconveniencing those of us who use the mailing list, as God intended.


    How the flying **** does my choice of where and how *I* read this forum
    inconvenience YOU?

    Talk about an overactive sense of entitlement. The world does not revolve
    around you and I do not arrange my day to suit your preferences.


    --
    Steven
    Steven D'Aprano, Mar 3, 2013
    #18
  19. On Sun, Mar 3, 2013 at 2:18 PM, David Robinow <> wrote:
    > On Sat, Mar 2, 2013 at 10:06 PM, Chris Angelico <> wrote:
    >> But your mail has only what you receive. You have to hunt down a
    >> separate archive of what was posted before you joined the thread.
    >> Advantage goes to news, but a slight one, and if that's the biggest,
    >> it's not a great advertisement.

    > I have no idea what you're trying to say here. As far as I know, when
    > I subscribe to a list I get all the mail. I don't "join" threads. I
    > don't even know what that means.
    > [This has drifted way off topic so I won't be responding again, but
    > I'll enjoy reading what anyone cares to write.]


    Err, joined the list is what I meant. At any given time, there are a
    certain number of active threads; anyone who joins the list will get
    the posts since joining but not the ones prior, for which they'll have
    to dig around elsewhere. Since netiquette recommends that posts quote
    enough of the prior posts to provide context, this shouldn't be a
    major problem, but there is a bit of advantage to news here.

    ChrisA
    Chris Angelico, Mar 3, 2013
    #19
  20. On Sun, 03 Mar 2013 03:21:37 +0000, Steven D'Aprano wrote:

    > On Sat, 02 Mar 2013 21:11:04 -0500, David Robinow wrote:


    >> Do you consider it rude that you choose to use a newsreader, thus
    >> inconveniencing those of us who use the mailing list, as God intended.

    >
    > How the flying **** does my choice of where and how *I* read this forum
    > inconvenience YOU?


    Hmmm. While I stand by the general sentiments, I think I flew off the
    handle there. In retrospect, I wish I had said that in a less aggressive
    manner.

    David, please consider this an apology for the bellicose response to your
    rhetorical question.


    --
    Steven
    Steven D'Aprano, Mar 3, 2013
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?YWRvbGYgZ2FybGlj?=

    US vs UK datetime/string format failing on certain machines. Ideas

    =?Utf-8?B?YWRvbGYgZ2FybGlj?=, Nov 18, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    5,365
    Daniel Fisher\(lennybacon\)
    Nov 18, 2004
  2. puzzlecracker
    Replies:
    8
    Views:
    416
    James Kanze
    Apr 15, 2008
  3. Chris Angelico
    Replies:
    3
    Views:
    141
    Mark Lawrence
    Mar 1, 2013
  4. Peter Otten
    Replies:
    0
    Views:
    121
    Peter Otten
    Feb 28, 2013
  5. Gene Heskett
    Replies:
    0
    Views:
    97
    Gene Heskett
    Mar 5, 2013
Loading...

Share This Page