Class problem

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

    Class problem

    Hello. I'm currently trying to create my first class in python, but I've
    ran into a bit of a problem which I fear may just be a simple error. I
    created a class called ImagePyramid.py which currently only contains an
    _init_ method which takes in 2 parameters and performs a bunch of things
    using these parameters. I believe I've followed the tutorial correctly,
    but when I import it and try to make an instance of it, it returns with
    the error that 'module' is not callable. I'm kind of new to this
    language so I believe that it's most likely a simple error on my behalf.
    Any advice on what I may be doing wrong would be greatly appreciated.

    Daniel

  • Rene Pijlman

    #2
    Re: Class problem

    Daniel Pryde:[color=blue]
    >when I import it and try to make an instance of it, it returns with
    >the error that 'module' is not callable.[/color]

    My guess is you should do:

    import spam
    eggs = spam.spam()

    instead of:

    import spam
    eggs = spam()

    If not, please post the source code and exact text of the error message.

    --
    René Pijlman

    Comment

    • Daniel Pryde

      #3
      Re: Class problem

      Rene Pijlman wrote:
      [color=blue]
      > Daniel Pryde:
      >[color=green]
      >>when I import it and try to make an instance of it, it returns with
      >>the error that 'module' is not callable.[/color]
      >
      >
      > My guess is you should do:
      >
      > import spam
      > eggs = spam.spam()
      >
      > instead of:
      >
      > import spam
      > eggs = spam()
      >
      > If not, please post the source code and exact text of the error message.
      >[/color]

      Thanks. Sorry everyone for not posting the problem code with it. I only
      have internet access at university and unfortunately the code's on my
      home hard drive, however it was something like:
      ===========
      import Image

      class ImagePyramid:
      def _init_(self, parameters):
      do stuff :-)
      ===========

      And I would use it as such:
      ===========
      import ImagePyramid
      pyramid = ImagePyramid(pa rameters)
      ===========

      I'l try out the above solution and hopefully that'll fix things. Thanks.:-)

      Daniel

      Comment

      • Rene Pijlman

        #4
        Re: Class problem

        Daniel Pryde:[color=blue]
        >the code's on my home hard drive[/color]

        Never leave home without it :-)
        [color=blue]
        >import ImagePyramid
        >pyramid = ImagePyramid(pa rameters)[/color]

        Yes, that should be:

        import ImagePyramid
        pyramid = ImagePyramid.Im agePyramid(para meters)

        This is explained in section 6 "Modules" of the tutorial on
        The official home of the Python Programming Language


        --
        René Pijlman

        Comment

        • Daniel Pryde

          #5
          Re: Class problem

          Rene Pijlman wrote:
          [color=blue]
          > Daniel Pryde:
          >[color=green]
          >>the code's on my home hard drive[/color]
          >
          >
          > Never leave home without it :-)
          >
          >[color=green]
          >>import ImagePyramid
          >>pyramid = ImagePyramid(pa rameters)[/color]
          >
          >
          > Yes, that should be:
          >
          > import ImagePyramid
          > pyramid = ImagePyramid.Im agePyramid(para meters)
          >
          > This is explained in section 6 "Modules" of the tutorial on
          > http://www.python.org/doc/current/tut/node8.html
          >[/color]
          Whoops! I got into trouble last time when I posted and found out that
          the answer was in the tutorial. I'll need to pay attention a bit more
          often. :-) Thanks for the help though.

          Daniel

          Comment

          Working...