I Need A Placeholder

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

    I Need A Placeholder

    I'm trying to build a try/except case, and I want to have the except
    function like such:

    try:
    # Do some code here
    var = 1 # For example
    except:
    #Do nothing here

    The only problem is if I leave a comment only in the except block, I
    get an error back saying that the except block is not properly
    formatted, since it has no content other than a comment.

    So if anyone could suggest some code to put there as a placeholder
    that would be wonderful.
  • Daniel Mahoney

    #2
    Re: I Need A Placeholder

    On Thu, 26 Jun 2008 10:03:47 -0700, Ampedesign wrote:
    I'm trying to build a try/except case, and I want to have the except
    function like such:
    >
    try:
    # Do some code here
    var = 1 # For example
    except:
    #Do nothing here
    >
    The only problem is if I leave a comment only in the except block, I
    get an error back saying that the except block is not properly
    formatted, since it has no content other than a comment.
    >
    So if anyone could suggest some code to put there as a placeholder
    that would be wonderful.
    "pass" would work fine.

    try:
    # Do something that can throw an exception
    except:
    pass



    Comment

    • Ampedesign

      #3
      Re: I Need A Placeholder

      On Jun 26, 10:06 am, Daniel Mahoney <d...@catfolks. netwrote:
      On Thu, 26 Jun 2008 10:03:47 -0700, Ampedesign wrote:
      I'm trying to build a try/except case, and I want to have the except
      function like such:
      >
      try:
            # Do some code here
            var = 1         # For example
      except:
            #Do nothing here
      >
      The only problem is if I leave a comment only in the except block, I
      get an error back saying that the except block is not properly
      formatted, since it has no content other than a comment.
      >
      So if anyone could suggest some code to put there as a placeholder
      that would be wonderful.
      >
      "pass" would work fine.
      >
      try:
           # Do something that can throw an exception
      except:
           pass
      Thanks. That will work perfectly.

      Comment

      • Gary Herron

        #4
        Re: I Need A Placeholder

        Ampedesign wrote:
        I'm trying to build a try/except case, and I want to have the except
        function like such:
        >
        try:
        # Do some code here
        var = 1 # For example
        except:
        #Do nothing here
        >
        >
        try:
        # Do some code here
        var = 1 # For example
        except:
        pass



        Gary Herron



        The only problem is if I leave a comment only in the except block, I
        get an error back saying that the except block is not properly
        formatted, since it has no content other than a comment.
        >
        So if anyone could suggest some code to put there as a placeholder
        that would be wonderful.
        --

        >

        Comment

        • Duncan Booth

          #5
          Re: I Need A Placeholder

          Ampedesign <metalkeys404@g mail.comwrote:
          I'm trying to build a try/except case, and I want to have the except
          function like such:
          >
          try:
          # Do some code here
          var = 1 # For example
          except:
          #Do nothing here
          >
          The only problem is if I leave a comment only in the except block, I
          get an error back saying that the except block is not properly
          formatted, since it has no content other than a comment.
          >
          So if anyone could suggest some code to put there as a placeholder
          that would be wonderful.
          >
          Use the 'pass' statement.

          But really, you should not have a bare except: if you are going to ignore a
          specific exception that's fine, but don't ignore all exceptions. You'll
          regret it.

          Comment

          • Ampedesign

            #6
            Re: I Need A Placeholder

            On Jun 26, 10:08 am, Duncan Booth <duncan.bo...@i nvalid.invalid>
            wrote:
            Ampedesign <metalkeys...@g mail.comwrote:
            I'm trying to build a try/except case, and I want to have the except
            function like such:
            >
            try:
                  # Do some code here
                  var = 1         # For example
            except:
                  #Do nothing here
            >
            The only problem is if I leave a comment only in the except block, I
            get an error back saying that the except block is not properly
            formatted, since it has no content other than a comment.
            >
            So if anyone could suggest some code to put there as a placeholder
            that would be wonderful.
            >
            Use the 'pass' statement.
            >
            But really, you should not have a bare except: if you are going to ignorea
            specific exception that's fine, but don't ignore all exceptions. You'll
            regret it.
            This is true. Though I get a wide range of exceptions since I'm
            downloading and parsing a file. I will get everything from a socket
            error to an empty xml element.

            In the future however, I will make separate exceptions.

            Comment

            • Joshua Kugler

              #7
              Re: I Need A Placeholder

              Ampedesign wrote:
              I'm trying to build a try/except case, and I want to have the except
              function like such:
              >
              try:
              # Do some code here
              var = 1 # For example
              except:
              #Do nothing here
              >
              The only problem is if I leave a comment only in the except block, I
              get an error back saying that the except block is not properly
              formatted, since it has no content other than a comment.
              >
              So if anyone could suggest some code to put there as a placeholder
              that would be wonderful.
              except:
              pass

              is the usual technique there.

              j

              Comment

              • John Salerno

                #8
                Re: I Need A Placeholder

                "Joshua Kugler" <jkugler@bigfoo t.comwrote in message
                news:mailman.88 4.1214500462.10 44.python-list@python.org ...
                except:
                pass
                >
                is the usual technique there.
                Is there any other?


                Comment

                • Carsten Haese

                  #9
                  Re: I Need A Placeholder

                  John Salerno wrote:
                  "Joshua Kugler" <jkugler@bigfoo t.comwrote in message
                  news:mailman.88 4.1214500462.10 44.python-list@python.org ...
                  >except:
                  > pass
                  >>
                  >is the usual technique there.
                  >
                  Is there any other?
                  Sure. Evaluating any side-effect free expression and ignoring the result
                  will work:

                  try:
                  # do somthing
                  except:
                  None

                  try:
                  # do something
                  except:
                  "I don't care about the exception."

                  Of course, using pass *is* the preferred method.

                  --
                  Carsten Haese

                  Comment

                  • Peter Otten

                    #10
                    Re: I Need A Placeholder

                    John Salerno wrote:
                    "Joshua Kugler" <jkugler@bigfoo t.comwrote in message
                    news:mailman.88 4.1214500462.10 44.python-list@python.org ...
                    >except:
                    > pass
                    >>
                    >is the usual technique there.
                    >
                    Is there any other?
                    if 0: 42

                    Proof:
                    >>def cp(pass_):
                    .... return compile("try: 1/0\nexcept:\n %s" % pass_, "<nofile>", "exec")
                    ....
                    >>cp("pass") == cp("if 0: 42")
                    True

                    :-)

                    Peter

                    Comment

                    • John Salerno

                      #11
                      Re: I Need A Placeholder

                      "Peter Otten" <__peter__@web. dewrote in message
                      news:g40lar$45c $02$1@news.t-online.com...
                      if 0: 42
                      How Pythonic. ;-)


                      Comment

                      Working...