Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9146571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:46:53+00:00 2026-06-17T10:46:53+00:00

def set_attribute(attributes, name, value): for i, attribute in enumerate(attributes): if name in attribute: quote_char

  • 0
def set_attribute(attributes, name, value):
    for i, attribute in enumerate(attributes):
        if name in attribute:
            quote_char = attribute.find('"')
            if quote_char == -1:
                raise ValueError
                return None
            attributes[i] = attribute[:quote_char+1] + str(value) + '"'
            return attributes

I’m a new programmer and I’m trying to properly understand exception handling.

In this example every name should also have a " character in it somewhere, so I want to raise an exception if this fails, but I was also trying to understand if the return None statement is necessary (or does anything).

My understanding was that I would escape from each level of scope until an exception handler was found. The Python tutorial says this:

  • First, the try clause (the statement(s) between the try and except keywords) is executed.
  • If no exception occurs, the except clause is skipped and execution of the try statement is finished.
  • If an exception occurs during execution of the try clause, the rest of the clause is skipped. Then if its type matches the exception named
    after the except keyword, the except clause is executed, and then
    execution continues after the try statement.
  • If an exception occurs during execution of the try clause, the rest of the clause is skipped. Then if its type matches the exception named
    after the except keyword, the except clause is executed, and then
    execution continues after the try statement.
  • If an exception occurs which does not match the exception named in the except clause, it is passed on to outer try statements; if no
    handler is found, it is an unhandled exception and execution stops
    with a message as shown above.

Yet, after reading this description, I’m realizing that I don’t understand exceptions, but I should.

So to state the question simply: is this return None statement necessary, and why? Also, where am I wrong about how exceptions work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:46:54+00:00Added an answer on June 17, 2026 at 10:46 am

    The return None is junk. Python will never get there.


    You could simplify the code and run a little experiment to see if the value FOO is ever returned:

    def foo():
        if True:
            raise ValueError('Bad value')
            return 'FOO'
        return 'BAR'
    
    try:
        print(foo())
    except ValueError as err:
        print(err)
        # Bad value
    

    If FOO were returned, you might see it in print(foo()), but indeed that line prints nothing. Instead you see Bad value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have: class C: aaa=2 class B: def __init__ (self,name): self.name self.value How can
class Warcraft def initialize &block instance_eval &block end def method_missing name, *args, &block instance_variable_set(@#{name}.to_sym,
def download_if_dne(href, filename): if os.path.isfile(filename): # print 'already downloaded:', href return False else: if
def self.jq_column_models COLUMN_NAME.collect {|x| {:name => x.to_s, :width => 80, :format => 'integer' if
class Foo(object): __slots__ = ('a',) class Bar(Foo): @property def a(self): return super(Bar, self).a super(Bar,
I have a Python dictionary that labels key name to attributes. The program that
I'm trying to use new-style properties declaration: class C(object): def __init__(self): self._x = 0
Is there a way of moving all attributes within a model with a value
Is there a way to display the name/content/functions of all attributes of a given
def findDistance(): first_coord = raw_input(Enter first coordinate set (format x, y): ).split(,) second_coord =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.