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 8322449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:23:31+00:00 2026-06-08T23:23:31+00:00

Here is my class Bar: class Bar: def __init__(self, start, end, open, volume, high=open,

  • 0

Here is my class Bar:

class Bar:
    def __init__(self, start, end, open, volume, high=open, low=open, last=open):
        self.start = start
        self.end = end
        self.open = open
        self.high = high
        self.low = low
        self.last = last
        self.volume = int(volume)

    def __str__(self):
        return self.start.strftime("%m/%d/%Y\t%H:%M:%S") + "\t" + self.end.strftime("%H:%M:%S") + "\t" +str(self.open) + "\t" + str(self.high) + "\t" + str(self.low) + "\t" + str(self.last) + "\t" + str(self.volume)

1) I am trying to initialize the high, low, and last for whatever open is. Is this the right way to do this?

2) When I do print(str(bar)) I get funny output such as…

03/13/2012 12:30:00 13:30:00 138.91 <built-in function open> 138.7 <built-in function open> 13177656

  • 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-08T23:23:32+00:00Added an answer on June 8, 2026 at 11:23 pm

    If you had written your function as

    def __init__(self, start, end, foo, volume, high=foo, low=foo, last=foo):
        self.start = start
        self.end = end
        self.open = foo
        self.high = high
        self.low = low
        self.last = last
        self.volume = int(volume)
    

    you would have gotten a NameError complaining that the name foo is not defined. This is because the default value for a parameter cannot refer to another parameter, which isn’t yet defined when you try to take its value. (Default values are set when the method is defined, not when it is called.)

    However, open is a built-in function in Python, so it was defined; it just wasn’t the open you meant it to be. The right way to do this is probably

    class Bar:
        def __init__(self, start, end, open, volume, high=None, low=None, last=None):
            self.start = start
            self.end = end
            self.open = open
            self.high = open if high is None else high
            self.low = open if low is None else low
            self.last = open if last is None else last
            self.volume = int(volume)
    

    In addition, you might want to use ‘open_’ instead of ‘open’ as the parameter name, just to avoid confusion (and temporarily shadowing) the built-in function.

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

Sidebar

Related Questions

Here's my situation: import foo, bar, etc frequency = [hours,days,weeks] class geoProcessClass(): def __init__(self,geoTaskHandler,startDate,frequency,frequencyMultiple=1,*args):
Suppose I have: class myclass: def __init__(self): self.foo = bar where the value of
My problem basically looks like this: module Foo class Bar def self.who self.class.to_s end
When inheriting from two objects like these class Foo(object): def __init__(self,a): self.a=a class Bar(object):
class Phone: def __init__(self): self.types = [Touch Screen,Flip, Slider, Bar, Bag] self.brand = No
Here's an example of my problem : class bar() : spam = foo() def
class GuiMaker(Frame): #more code def __init__(self, parent=None): Frame.__init__(self, parent) self.pack(expand=YES, fill=BOTH) # make frame
class Foo(object): def __init__(self,x): self.x = x self.is_bar = False def __repr__(self): return str(self.x)
I found this code here class Usable; class Usable_lock { friend class Usable; private:
Given the code from here : class lazy_init { mutable std::once_flag flag; mutable std::unique_ptr<expensive_data>

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.