i re-write it

Discussion in 'Python' started by codefly, Dec 16, 2009.

  1. codefly

    codefly Guest

    error message is here..
    when i type import code2

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "code2.py", line 11
    ~
    ^
    SyntaxError: invalid syntax


    and source code is here
    class codefly:
    def WaitFreecatz(self, hours):
    hours = self.hours
    i =1
    while i < hours:
    print ' i wait for %s hours' %(i)
    i = i+1
    if i ==hours:
    print 'he never comes'
    codefly, Dec 16, 2009
    #1
    1. Advertising

  2. codefly wrote:

    > error message is here..
    > when i type import code2
    >
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > File "code2.py", line 11
    > ~
    > ^
    > SyntaxError: invalid syntax
    >
    >
    > and source code is here


    No, it isn't. The above error says "line 11", but the code you show doesn't
    have 11 lines.

    From the above error, it looks as if you have a stray "tilde"-character on
    the last or so line in code.py. Remove it.

    Diez
    Diez B. Roggisch, Dec 16, 2009
    #2
    1. Advertising

  3. codefly

    codefly Guest

    On Dec 17, 12:43 am, "Diez B. Roggisch" <> wrote:
    > codefly wrote:
    > > error message is here..
    > > when i type import code2

    >
    > > Traceback (most recent call last):
    > >   File "<stdin>", line 1, in <module>
    > >   File "code2.py", line 11
    > >     ~
    > >                        ^
    > > SyntaxError: invalid syntax

    >
    > > and source code is here

    >
    > No, it isn't. The above error says "line 11", but the code you show doesn't
    > have 11 lines.
    >
    > From the above error, it looks as if you have a stray "tilde"-character on
    > the last or so line in code.py. Remove it.
    >
    > Diez


    Oh my Thanks..
    codefly, Dec 16, 2009
    #3
  4. codefly

    codefly Guest

    On Dec 17, 12:43 am, "Diez B. Roggisch" <> wrote:
    > codefly wrote:
    > > error message is here..
    > > when i type import code2

    >
    > > Traceback (most recent call last):
    > >   File "<stdin>", line 1, in <module>
    > >   File "code2.py", line 11
    > >     ~
    > >                        ^
    > > SyntaxError: invalid syntax

    >
    > > and source code is here

    >
    > No, it isn't. The above error says "line 11", but the code you show doesn't
    > have 11 lines.
    >
    > From the above error, it looks as if you have a stray "tilde"-character on
    > the last or so line in code.py. Remove it.
    >
    > Diez


    now.. another problem..

    when i type me = code2()

    the error is here..
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: 'module' object is not callable
    codefly, Dec 16, 2009
    #4
  5. codefly wrote:

    > On Dec 17, 12:43 am, "Diez B. Roggisch" <> wrote:
    >> codefly wrote:
    >> > error message is here..
    >> > when i type import code2

    >>
    >> > Traceback (most recent call last):
    >> > File "<stdin>", line 1, in <module>
    >> > File "code2.py", line 11
    >> > ~
    >> > ^
    >> > SyntaxError: invalid syntax

    >>
    >> > and source code is here

    >>
    >> No, it isn't. The above error says "line 11", but the code you show
    >> doesn't have 11 lines.
    >>
    >> From the above error, it looks as if you have a stray "tilde"-character
    >> on the last or so line in code.py. Remove it.
    >>
    >> Diez

    >
    > now.. another problem..
    >
    > when i type me = code2()
    >
    > the error is here..
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > TypeError: 'module' object is not callable


    Not surprisingly, because you try to instantiate a module. Which isn't
    possible.

    What you most probably want is

    me = code2.codefly()

    May I suggest you move your questions here:

    http://mail.python.org/mailman/listinfo/tutor

    It seems that you have some very basic misconceptions about python, so that
    might be a forum more geared towards your needs.

    Diez
    Diez B. Roggisch, Dec 16, 2009
    #5
  6. codefly a écrit :
    > now.. another problem..
    >
    > when i type me = code2()


    where ? and what is 'code2' in this context ? Sorry, my crystal ball is
    out for repair...

    > the error is here..
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > TypeError: 'module' object is not callable
    >


    Ok, so it's in the python shell, you imported your module named 'code2',
    and tried to call it.

    Well... the error message say it all: module objects are not callable
    (IOW : they are not functions). If I may ask : what's your background in
    programming ?
    Bruno Desthuilliers, Dec 16, 2009
    #6
  7. codefly

    Dave Angel Guest

    codefly wrote:
    > On Dec 17, 12:43 am, "Diez B. Roggisch" <> wrote:
    >
    >> codefly wrote:
    >>
    >>> error message is here..
    >>> when i type import code2
    >>>
    >>> Traceback (most recent call last):
    >>> File "<stdin>", line 1, in <module>
    >>> File "code2.py", line 11
    >>> ~
    >>> ^
    >>> SyntaxError: invalid syntax
    >>>
    >>> and source code is here
    >>>

    >> No, it isn't. The above error says "line 11", but the code you show doesn't
    >> have 11 lines.
    >>
    >> From the above error, it looks as if you have a stray "tilde"-character on
    >> the last or so line in code.py. Remove it.
    >>
    >> Diez
    >>

    >
    > now.. another problem..
    >
    > when i type me = code2()
    >
    > the error is here..
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > TypeError: 'module' object is not callable
    >
    >
    >


    Your code was/is in code2.py
    -----------------

    class codefly:
    def WaitFreecatz(self, hours):
    hours = self.hours
    i =1
    while i < hours:
    print ' i wait for %s hours' %(i)
    i = i+1
    if i ==hours:
    print 'he never comes'

    -----------------

    The message is pretty clear. Why are you trying to call the module you
    just imported? Perhaps you meant to instantiate the class that was
    defined there. In that case, the syntax would be:
    me = code2.codefly()

    To save you some trouble on your next bug, let me point out that your
    class does not initialize its instance variable self.hours That's
    normally done in the __init__() method. Also, you can interactively see
    the objects of an object with the dir() function. So try
    dir(code2) dir(code2.codefly) and dir(me)

    DaveA
    Dave Angel, Dec 16, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWJlbCBDaGFu?=
    Replies:
    6
    Views:
    9,328
    Rahul
    May 3, 2006
  2. Peter Hansen
    Replies:
    1
    Views:
    382
    Joona I Palaste
    Aug 24, 2003
  3. JasBascom
    Replies:
    1
    Views:
    367
    John Harrison
    Feb 24, 2004
  4. Peter Hansen
    Replies:
    1
    Views:
    417
    Joona I Palaste
    Aug 24, 2003
  5. Chuck Amadi
    Replies:
    0
    Views:
    516
    Chuck Amadi
    Jun 22, 2004
Loading...

Share This Page