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

  • SEARCH
  • Home
  • 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 8794663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:16:56+00:00 2026-06-13T23:16:56+00:00

class makeCode: def __init__(self,code): self.codeSegment = code.upper() if checkSegment(self.codeSegment): quit() self.info=checkXNA(self.codeSegment) def echo(self,start=0,stop=len(self.codeSegment),search=None): #–>

  • 0
class makeCode:
    def __init__(self,code):
            self.codeSegment = code.upper()
            if checkSegment(self.codeSegment):
                    quit()
            self.info=checkXNA(self.codeSegment)
    def echo(self,start=0,stop=len(self.codeSegment),search=None): #--> self not defined
            pass

Not working…

  • it says that the variable self is not defined when it actually was;
  • the function checkSegment returns 1 if the input was not a string made of nucleotids letter, or if that contains nucleotids that can’t be together;
  • it quits if that happens, that’s ok it works perfectly;
  • then it assigns the information (if it’s RNA or DNA) checking with the function checkXNA that returns a string with the information “dnaSegment” or “rnaSegment”; works perfectly.

But then the function echo which will be designed for printing more specific information tells me that self is not defined, but why?

  • 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-13T23:16:57+00:00Added an answer on June 13, 2026 at 11:16 pm

    self is not defined at function definition time, you cannot use it to create a default argument.

    Expressions in a function definition are evaluated when the function is created, not when it is being called, see "Least Astonishment" and the Mutable Default Argument.

    Use the following technique instead:

    def echo(self, start=0, stop=None, search=None):
        if stop is None:
            stop = len(self.codeSegment)
    

    If you need to support None as a possible value for stop (e.g. None is a valid value for stop if specified explicitly), you’ll need to pick a different unique sentinel to use:

    _sentinel = object()
    
    class makeCode:
        def echo(self, start=0, stop=_sentinel, search=None):
            if stop is _sentinel:
                stop = len(self.codeSegment)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class ShortInputException(Exception): '''A user-defined exception class.''' def __init__(self, length, atleast): Exception.__init__(self) self.length = length
class StartAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): print "Hello" start.add_argument('-s', '--start', action=StartAction) I
class A: pass def b(self): print('b') A.b = b a = A() At this
Class Bar inherits from Foo: class Foo(object): def foo_meth_1(self): return 'foometh1' def foo_meth_2(self): return
How do I make code like this thread safe? public static class Converter {
class DefaultListMap[A, B <: List[B]] extends HashMap[A, B] { override def default(key: A) =
I have a domain class having an Integer variable 'code'. my requirement is to
class Widget; std::vector< std::shared_ptr<Widget> > container class Criterium { public: bool operator()(const Widget& left,
Class 1 private void checkDuplicateCustomer(BulkCustomerVO bulkCustomerVO) { PagedDuplicateCustomerVO duplicateCustomerVO = new PagedDuplicateCustomerVO(); duplicateCustomerVO.setCustomer(bulkCustomerVO.getCustomerVO()); duplicateCustomerVO
class X { int i; public: X() { i = 0; } void set(int

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.