Depricated String Functions in Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Anoop

    Depricated String Functions in Python

    Hi All

    Can any one help me out with the various depricated string functions
    that is followed in Python.

    For example how will be string.lower depricated.

    As far as string.lower('P YTHON') is concerned it is depricated as
    'PYTHON'.lower( ). Both of them would return an output : >>python

    Thanks for your inputs

    Regards

    Anoop

  • Stefan Behnel

    #2
    Re: Depricated String Functions in Python

    Anoop wrote:
    Can any one help me out with the various depricated string functions
    that is followed in Python.
    >
    For example how will be string.lower depricated.
    >
    As far as string.lower('P YTHON') is concerned it is depricated as
    'PYTHON'.lower( ). Both of them would return an output : >>python
    I don't quite see the question in your post, but, yes, the module level
    functions of the "string" module are deprecated in favour of the methods of
    the str and unicode objects.

    Stefan

    Comment

    • Steve Holden

      #3
      Re: Depricated String Functions in Python

      Anoop wrote:
      Hi All
      >
      Can any one help me out with the various depricated string functions
      that is followed in Python.
      >
      For example how will be string.lower depricated.
      >
      As far as string.lower('P YTHON') is concerned it is depricated as
      'PYTHON'.lower( ). Both of them would return an output : >>python
      >
      Thanks for your inputs
      >
      I wonder if this isn't just an English problem: the fact that the
      functions of the string module is depracated just means that you are
      encouraged to use the string objects' methods instead, as the string
      module is likely to be removed at some time in the future.

      regards
      Steve
      --
      Steve Holden +44 150 684 7255 +1 800 494 3119
      Holden Web LLC/Ltd http://www.holdenweb.com
      Skype: holdenweb http://holdenweb.blogspot.com
      Recent Ramblings http://del.icio.us/steve.holden

      Comment

      • John Machin

        #4
        Re: Depricated String Functions in Python

        On 20/07/2006 5:18 PM, Steve Holden wrote:
        Anoop wrote:
        >Hi All
        >>
        >Can any one help me out with the various depricated string functions
        >that is followed in Python.
        >>
        >For example how will be string.lower depricated.
        >>
        >As far as string.lower('P YTHON') is concerned it is depricated as
        >'PYTHON'.lower (). Both of them would return an output : >>python
        >>
        >Thanks for your inputs
        >>
        I wonder if this isn't just an English problem: the fact that the
        functions of the string module is depracated
        "depracated "? "functions ... is"? Yup, sure looks like an English
        problem to me :-)

        Perhaps the docs should use simpler words like "outdated" or "not
        preferred" or such-like instead of "depr*e*cat ed".

        Cheers,
        John

        Comment

        • Steve Holden

          #5
          Re: Depricated String Functions in Python

          John Machin wrote:
          On 20/07/2006 5:18 PM, Steve Holden wrote:
          >
          >>Anoop wrote:
          >>
          >>>Hi All
          >>>
          >>>Can any one help me out with the various depricated string functions
          >>>that is followed in Python.
          >>>
          >>>For example how will be string.lower depricated.
          >>>
          >>>As far as string.lower('P YTHON') is concerned it is depricated as
          >>>'PYTHON'.low er(). Both of them would return an output : >>python
          >>>
          >>>Thanks for your inputs
          >>>
          >>
          >>I wonder if this isn't just an English problem: the fact that the
          >>functions of the string module is depracated
          >
          >
          "depracated "? "functions ... is"? Yup, sure looks like an English
          problem to me :-)
          >
          Nobody likes a smartarse :-)
          Perhaps the docs should use simpler words like "outdated" or "not
          preferred" or such-like instead of "depr*e*cat ed".
          >
          That probably wouldn't be a bad idea. Please note, however, that even if
          the documentation spelled everything correctly I would doubtless
          continue to mangle the spellings through typos.

          regards
          Steve
          --
          Steve Holden +44 150 684 7255 +1 800 494 3119
          Holden Web LLC/Ltd http://www.holdenweb.com
          Skype: holdenweb http://holdenweb.blogspot.com
          Recent Ramblings http://del.icio.us/steve.holden

          Comment

          • Anoop

            #6
            Re: Depricated String Functions in Python

            Thanks Stefen

            let me be more specific how would i have to write the following
            function in the deprecated format

            map(string.lowe r,list)

            Thanks Anoop


            Stefan Behnel wrote:
            Anoop wrote:
            Can any one help me out with the various depricated string functions
            that is followed in Python.

            For example how will be string.lower depricated.

            As far as string.lower('P YTHON') is concerned it is depricated as
            'PYTHON'.lower( ). Both of them would return an output : >>python
            >
            I don't quite see the question in your post, but, yes, the module level
            functions of the "string" module are deprecated in favour of the methods of
            the str and unicode objects.
            >
            Stefan

            Comment

            • Steve Holden

              #7
              Re: Depricated String Functions in Python

              Anoop wrote:
              Thanks Stefen
              >
              let me be more specific how would i have to write the following
              function in the deprecated format
              >
              map(string.lowe r,list)
              >
              To avoid the deprecated usage you would use the unbound method of the
              str type (that's the type of all strings):
              >>lst = ['Steve', 'Holden']
              >>map(str.lower , lst)
              ['steve', 'holden']
              >>>
              regards
              Steve
              --
              Steve Holden +44 150 684 7255 +1 800 494 3119
              Holden Web LLC/Ltd http://www.holdenweb.com
              Skype: holdenweb http://holdenweb.blogspot.com
              Recent Ramblings http://del.icio.us/steve.holden

              Comment

              • Simon Forman

                #8
                Re: Depricated String Functions in Python

                Anoop wrote:
                Thanks Stefen
                >
                let me be more specific how would i have to write the following
                function in the deprecated format
                >
                map(string.lowe r,list)
                >
                Thanks Anoop
                Ah. This is easy enough:

                lower_list = [s.lower() for s in str_list]

                Or, if you really like map() (or really don't like list comprehensions
                ;P ) you could use this:

                lower_list = map(lambda s : s.lower(), str_list)


                Hope this helps,
                ~Simon

                Comment

                • Duncan Booth

                  #9
                  Re: Depricated String Functions in Python

                  Anoop wrote:
                  let me be more specific how would i have to write the following
                  function in the deprecated format
                  >
                  map(string.lowe r,list)
                  What you just wrote is the deprecated format.

                  There are plenty of ways to write it in an undeprecated format. The
                  simplest is probably:

                  [ s.lower() for s in list ]

                  Comment

                  • riquito@gmail.com

                    #10
                    Re: Depricated String Functions in Python


                    Steve Holden ha scritto:
                    Anoop wrote:
                    Thanks Stefen

                    let me be more specific how would i have to write the following
                    function in the deprecated format

                    map(string.lowe r,list)
                    To avoid the deprecated usage you would use the unbound method of the
                    str type (that's the type of all strings):
                    >
                    >>lst = ['Steve', 'Holden']
                    >>map(str.lower , lst)
                    ['steve', 'holden']
                    >>>
                    This isn't exactly equal to use string.lower, because this work with
                    just encoded strings, when string.lower works with unicode too.
                    I'm used to have a "lower" func like this one
                    def lower(x): return x.lower()
                    to use in map. Of course it's a problem when you need many different
                    methods.

                    A solution could be something like this
                    >>def doit(what):
                    .... def func(x):
                    .... return getattr(x,what) ()
                    .... return func
                    ....
                    >>map(doit('low er'),['aBcD',u'\xc0'])
                    ['abcd', u'\xe0']
                    >>map(doit('upp er'),['aBcD',u'\xc0'])
                    ['ABCD', u'\xc0']

                    The best is to use in advance just unicode or encoded strings in your
                    program, but this is not always possible :-/

                    Riccardo Galli

                    Comment

                    • Donn Cave

                      #11
                      Re: Depricated String Functions in Python

                      In article <mailman.8368.1 153402047.27775 .python-list@python.org >,
                      Steve Holden <steve@holdenwe b.comwrote:
                      Anoop wrote:
                      Thanks Stefen

                      let me be more specific how would i have to write the following
                      function in the deprecated format

                      map(string.lowe r,list)
                      To avoid the deprecated usage you would use the unbound method of the
                      str type (that's the type of all strings):
                      >
                      >>lst = ['Steve', 'Holden']
                      >>map(str.lower , lst)
                      ['steve', 'holden']
                      Oh, excellent - the string module is dead, long live
                      the string module! I can replace string.join with
                      str.join, and never have to defile my code with that
                      ' '.join(x) abomination.


                      Donn Cave, donn@u.washingt on.edu

                      Comment

                      • Steve Holden

                        #12
                        Re: Depricated String Functions in Python

                        Donn Cave wrote:
                        [...]
                        >
                        Oh, excellent - the string module is dead, long live
                        the string module! I can replace string.join with
                        str.join, and never have to defile my code with that
                        ' '.join(x) abomination.
                        >
                        >>lst = ['Steve', 'Holden']
                        >>str.join(' ', lst)
                        'Steve Holden'
                        >>>
                        Just so long as you don't complain about the arguments being in the
                        wrong order ...

                        regards
                        Steve
                        --
                        Steve Holden +44 150 684 7255 +1 800 494 3119
                        Holden Web LLC/Ltd http://www.holdenweb.com
                        Skype: holdenweb http://holdenweb.blogspot.com
                        Recent Ramblings http://del.icio.us/steve.holden

                        Comment

                        • Duncan Booth

                          #13
                          Re: Depricated String Functions in Python

                          Sybren Stuvel wrote:
                          Donn Cave enlightened us with:
                          >Oh, excellent - the string module is dead, long live the string
                          >module! I can replace string.join with str.join, and never have to
                          >defile my code with that ' '.join(x) abomination.
                          >
                          It's not an abomination. It's a very clear way of telling those two
                          apart:
                          >
                          ' '.join(x)
                          u' '.join(x)
                          I don't understand that comment. Are you saying that str.join vs
                          unicode.join isn't a clear distinction?

                          I like using str.join/unicode.join myself, but one advantage of using
                          separator.join directly is that you can save the bound method:

                          joinlines = '\n'.join
                          joinwords = ' '.join

                          you can't do that by calling the method on the type.

                          Comment

                          Working...