Why no string return?

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

    Why no string return?

    Say i have the two methods:

    def ReturnMethod(re quest, x):
    if request is True:
    return x
    else: print "No String for you...False!"

    def SendMethod(requ est):
    xstring = "Some text"
    ReturnMethod(re quest, xstring)

    SendMethod(True )

    Why does ReturnMethod not return the string x? I do believe it is
    returning with a NoneType.
    Any help would be greatly obliged

    Thanks, Josh
  • Adonis Vargas

    #2
    Re: Why no string return?

    gargonx wrote:
    Say i have the two methods:
    >
    def ReturnMethod(re quest, x):
    if request is True:
    return x
    else: print "No String for you...False!"
    >
    def SendMethod(requ est):
    xstring = "Some text"
    ReturnMethod(re quest, xstring)
    >
    SendMethod(True )
    >
    Why does ReturnMethod not return the string x? I do believe it is
    returning with a NoneType.
    Any help would be greatly obliged
    >
    Thanks, Josh
    That is because request is bound a string (str) object. You are probably
    testing for null so it should look like:

    if request:
    return x
    else:
    print "No String for you...False!"

    Hope this helps.

    Adonis

    Comment

    • gargonx

      #3
      Re: Why no string return?

      On Mar 12, 4:45 am, Adonis Vargas <adonis_var.. .@-Remove-This-
      bellsouth.netwr ote:
      gargonx wrote:
      Say i have the two methods:
      >
      def ReturnMethod(re quest, x):
      if request is True:
      return x
      else: print "No String for you...False!"
      >
      def SendMethod(requ est):
      xstring = "Some text"
      ReturnMethod(re quest, xstring)
      >
      SendMethod(True )
      >
      Why does ReturnMethod not return the string x? I do believe it is
      returning with a NoneType.
      Any help would be greatly obliged
      >
      Thanks, Josh
      >
      That is because request is bound a string (str) object. You are probably
      testing for null so it should look like:
      >
      if request:
      return x
      else:
      print "No String for you...False!"
      >
      Hope this helps.
      >
      Adonis
      Still no return of string. The null testing is not really the deal.
      that could be replaced with anything EG:

      def ReturnMethod(re quest, x):
      if request is 'random':
      return x
      else: print "No String for you...False!"

      def SendMethod(requ est):
      xstring = "Some text"
      ReturnMethod(re quest, xstring)

      SendMethod('ran dom')

      Comment

      • Frank Millman

        #4
        Re: Why no string return?



        gargonx wrote:
        Say i have the two methods:
        >
        def ReturnMethod(re quest, x):
        if request is True:
        return x
        else: print "No String for you...False!"
        >
        def SendMethod(requ est):
        xstring = "Some text"
        ReturnMethod(re quest, xstring)
        >
        SendMethod(True )
        >
        Why does ReturnMethod not return the string x? I do believe it is
        returning with a NoneType.
        Any help would be greatly obliged
        >
        Thanks, Josh
        ReturnMethod() is executed, but you do nothing with the result.

        Try one of the following -

        def SendMethod(requ est):
        xstring = "Some text"
        print ReturnMethod(re quest, xstring)

        def SendMethod(requ est):
        xstring = "Some text"
        return ReturnMethod(re quest, xstring)

        HTH

        Frank Millman

        Comment

        • gargonx

          #5
          Re: Why no string return?

          On Mar 12, 5:10 am, Frank Millman <fr...@chagford .comwrote:
          gargonx wrote:
          Say i have the two methods:
          >
          def ReturnMethod(re quest, x):
          if request is True:
          return x
          else: print "No String for you...False!"
          >
          def SendMethod(requ est):
          xstring = "Some text"
          ReturnMethod(re quest, xstring)
          >
          SendMethod(True )
          >
          Why does ReturnMethod not return the string x? I do believe it is
          returning with a NoneType.
          Any help would be greatly obliged
          >
          Thanks, Josh
          >
          ReturnMethod() is executed, but you do nothing with the result.
          >
          Try one of the following -
          >
          def SendMethod(requ est):
          xstring = "Some text"
          print ReturnMethod(re quest, xstring)
          >
          def SendMethod(requ est):
          xstring = "Some text"
          return ReturnMethod(re quest, xstring)
          >
          HTH
          >
          Frank Millman
          Thanks Frank the latter worked for my purpose.

          Comment

          • Piet van Oostrum

            #6
            Re: Why no string return?

            >>>>gargonx <gargonx@gmail. com(g) wrote:
            >gStill no return of string. The null testing is not really the deal.
            >gthat could be replaced with anything EG:
            >gdef ReturnMethod(re quest, x):
            >g if request is 'random':
            You shouldn't test with `is' but with `=='.
            >g return x
            >g else: print "No String for you...False!"
            >gdef SendMethod(requ est):
            >g xstring = "Some text"
            >g ReturnMethod(re quest, xstring)
            >gSendMethod('r andom')
            --
            Piet van Oostrum <piet@cs.uu.n l>
            URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C 4]
            Private email: piet@vanoostrum .org

            Comment

            Working...