Why can't I import this?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Henry

    Why can't I import this?

    Hi list,

    I can't understand this. The following import statement works fine:

    from PythonCard.temp lates.dialogs import runOptionsDialo g

    but this one fails:

    from PythonCard.tool s.codeEditor.co deEditor import CodeEditor

    I've checked and rechecked to make sure that the spellings are proper
    and that the tools, the codeEditor directory, and codeEditor.py, and
    the class CodeEditor all exists and yet idle keep complaining that it
    can't import from PythonCard.tool s.

    What's going on? (Running Python2.5 under WinXP).

    Regards,
  • Diez B. Roggisch

    #2
    Re: Why can't I import this?

    John Henry schrieb:
    Hi list,
    >
    I can't understand this. The following import statement works fine:
    >
    from PythonCard.temp lates.dialogs import runOptionsDialo g
    >
    but this one fails:
    >
    from PythonCard.tool s.codeEditor.co deEditor import CodeEditor
    >
    I've checked and rechecked to make sure that the spellings are proper
    and that the tools, the codeEditor directory, and codeEditor.py, and
    the class CodeEditor all exists and yet idle keep complaining that it
    can't import from PythonCard.tool s.
    How do these complaints *look* - we can't read your mind nor your
    screen, as you might imagine....
    What's going on? (Running Python2.5 under WinXP).
    What do you think is more probable - pythons import-mechanism, the
    foundation of nearly all libraries, is broken - or you make a mistake?

    Diez

    Comment

    • John Henry

      #3
      Re: Why can't I import this?

      On May 13, 1:18 pm, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
      John Henry schrieb:
      >
      Hi list,
      >
      I can't understand this. The following import statement works fine:
      >
      from PythonCard.temp lates.dialogs import runOptionsDialo g
      >
      but this one fails:
      >
      from PythonCard.tool s.codeEditor.co deEditor import CodeEditor
      >
      I've checked and rechecked to make sure that the spellings are proper
      and that the tools, the codeEditor directory, and codeEditor.py, and
      the class CodeEditor all exists and yet idle keep complaining that it
      can't import from PythonCard.tool s.
      >
      How do these complaints *look* - we can't read your mind nor your
      screen, as you might imagine....
      >
      What's going on? (Running Python2.5 under WinXP).
      >
      What do you think is more probable - pythons import-mechanism, the
      foundation of nearly all libraries, is broken - or you make a mistake?
      >
      Diez
      Thumper's dad always told him: If you don't have anything nice/useful/
      garbage to say, then don't say noth'ng at all.

      Next.

      Comment

      • Gary Herron

        #4
        Re: Why can't I import this?

        John Henry wrote:
        Hi list,
        >
        I can't understand this. The following import statement works fine:
        >
        from PythonCard.temp lates.dialogs import runOptionsDialo g
        >
        but this one fails:
        >
        from PythonCard.tool s.codeEditor.co deEditor import CodeEditor
        >
        This kind of "dotted" name import only works for packages, and a
        directory is considered a package only if it contains a file name
        __init__.py. Looking around my installation of PythonCard (on Linux)
        I see that most of those directories *do NOT* have a __init__.py, so
        they are not packages and cannot be imported that way.


        Of course this leaves unanswered the question of *how* you are supposed
        to import that code. I've never used PythonCard so I can't help
        further, but I suggest looking at the documentation and examples
        supplied. And perhaps waiting for someone with experience with
        PythonCard to answer.


        Gary Herron

        P.S. It is usually a waste of time to tell us that something fails
        without telling us *how* it fails. (Cut and paste the error message
        always, and the traceback usually.) If you don't, you will usually get
        a request to supply that information, and then have wast3ed the time for
        one full round of message to the group. Even in this case, I'm only
        guessing how it failed for you.

        I've checked and rechecked to make sure that the spellings are proper
        and that the tools, the codeEditor directory, and codeEditor.py, and
        the class CodeEditor all exists and yet idle keep complaining that it
        can't import from PythonCard.tool s.
        >
        What's going on? (Running Python2.5 under WinXP).
        >
        Regards,
        --

        >

        Comment

        • Diez B. Roggisch

          #5
          Re: Why can't I import this?

          Thumper's dad always told him: If you don't have anything nice/useful/
          garbage to say, then don't say noth'ng at all.
          You mean it's not useful to tell you


          - to give more information on *what* acutally goes wrong?

          - in the meantime, to look harder for your mistake, because it's
          unlikely to be python's failure?


          Can't help you then. Won't happen again.

          Diez

          Comment

          • John Henry

            #6
            Re: Why can't I import this?

            On May 13, 1:49 pm, Gary Herron <gher...@island training.comwro te:
            John Henry wrote:
            Hi list,
            >
            I can't understand this. The following import statement works fine:
            >
            from PythonCard.temp lates.dialogs import runOptionsDialo g
            >
            but this one fails:
            >
            from PythonCard.tool s.codeEditor.co deEditor import CodeEditor
            >
            This kind of "dotted" name import only works for packages, and a
            directory is considered a package only if it contains a file name
            __init__.py. Looking around my installation of PythonCard (on Linux)
            I see that most of those directories *do NOT* have a __init__.py, so
            they are not packages and cannot be imported that way.
            >
            Of course this leaves unanswered the question of *how* you are supposed
            to import that code. I've never used PythonCard so I can't help
            further, but I suggest looking at the documentation and examples
            supplied. And perhaps waiting for someone with experience with
            PythonCard to answer.
            >
            Gary Herron
            >
            P.S. It is usually a waste of time to tell us that something fails
            without telling us *how* it fails. (Cut and paste the error message
            always, and the traceback usually.) If you don't, you will usually get
            a request to supply that information, and then have wast3ed the time for
            one full round of message to the group. Even in this case, I'm only
            guessing how it failed for you.
            >
            I've checked and rechecked to make sure that the spellings are proper
            and that the tools, the codeEditor directory, and codeEditor.py, and
            the class CodeEditor all exists and yet idle keep complaining that it
            can't import from PythonCard.tool s.
            >
            What's going on? (Running Python2.5 under WinXP).
            >
            Thank you very much. I didn't know about the __init__.py
            requirement. Appreciate it.

            Comment

            • Gary Herron

              #7
              Re: Why can't I import this?

              John Henry wrote:
              On May 13, 1:49 pm, Gary Herron <gher...@island training.comwro te:
              >
              >John Henry wrote:
              >>
              >>Hi list,
              >>>
              >>I can't understand this. The following import statement works fine:
              >>>
              >> from PythonCard.temp lates.dialogs import runOptionsDialo g
              >>>
              >>but this one fails:
              >>>
              >> from PythonCard.tool s.codeEditor.co deEditor import CodeEditor
              >>>
              >This kind of "dotted" name import only works for packages, and a
              >directory is considered a package only if it contains a file name
              >__init__.py. Looking around my installation of PythonCard (on Linux)
              >I see that most of those directories *do NOT* have a __init__.py, so
              >they are not packages and cannot be imported that way.
              >>
              >Of course this leaves unanswered the question of *how* you are supposed
              >to import that code. I've never used PythonCard so I can't help
              >further, but I suggest looking at the documentation and examples
              >supplied. And perhaps waiting for someone with experience with
              >PythonCard to answer.
              >>
              >Gary Herron
              >>
              >P.S. It is usually a waste of time to tell us that something fails
              >without telling us *how* it fails. (Cut and paste the error message
              >always, and the traceback usually.) If you don't, you will usually get
              >a request to supply that information, and then have wast3ed the time for
              >one full round of message to the group. Even in this case, I'm only
              >guessing how it failed for you.
              >>
              >>
              >>I've checked and rechecked to make sure that the spellings are proper
              >>and that the tools, the codeEditor directory, and codeEditor.py, and
              >>the class CodeEditor all exists and yet idle keep complaining that it
              >>can't import from PythonCard.tool s.
              >>>
              >>What's going on? (Running Python2.5 under WinXP).
              >>>
              >>Regards,
              >>--
              >>http://mail.python.org/mailman/listinfo/python-list
              >>>
              >
              Thank you very much. I didn't know about the __init__.py
              requirement. Appreciate it.
              Actually I should have added that there ways to import such things, and
              PythonCard must be using some such method itself. You can manipulate
              the sys.path variable, or directly call the import mechanism using the
              builtin __import__, or use a suppled "imp" module. However, you
              should not have to do any such thing to use PythonCard. It should do
              them in for you.

              Comment

              • Ben Finney

                #8
                Re: Why can't I import this?

                John Henry <john106henry@h otmail.comwrite s:
                On May 13, 1:18 pm, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
                John Henry schrieb:
                the class CodeEditor all exists and yet idle keep complaining
                that it can't import from PythonCard.tool s.
                How do these complaints *look* - we can't read your mind nor your
                screen, as you might imagine....
                >
                Thumper's dad always told him: If you don't have anything
                nice/useful/ garbage to say, then don't say noth'ng at all.
                Thanks for the aphorism. You're still no closer to actually getting a
                useful answer, until you can provide the information Diez explained
                that we need.

                --
                \ "I used to be a proofreader for a skywriting company." -- |
                `\ Steven Wright |
                _o__) |
                Ben Finney

                Comment

                • John Henry

                  #9
                  Re: Why can't I import this?

                  On May 13, 3:42 pm, Gary Herron <gher...@island training.comwro te:
                  John Henry wrote:
                  On May 13, 1:49 pm, Gary Herron <gher...@island training.comwro te:
                  >
                  John Henry wrote:
                  >
                  >Hi list,
                  >
                  >I can't understand this. The following import statement works fine:
                  >
                  > from PythonCard.temp lates.dialogs import runOptionsDialo g
                  >
                  >but this one fails:
                  >
                  > from PythonCard.tool s.codeEditor.co deEditor import CodeEditor
                  >
                  This kind of "dotted" name import only works for packages, and a
                  directory is considered a package only if it contains a file name
                  __init__.py. Looking around my installation of PythonCard (on Linux)
                  I see that most of those directories *do NOT* have a __init__.py, so
                  they are not packages and cannot be imported that way.
                  >
                  Of course this leaves unanswered the question of *how* you are supposed
                  to import that code. I've never used PythonCard so I can't help
                  further, but I suggest looking at the documentation and examples
                  supplied. And perhaps waiting for someone with experience with
                  PythonCard to answer.
                  >
                  Gary Herron
                  >
                  P.S. It is usually a waste of time to tell us that something fails
                  without telling us *how* it fails. (Cut and paste the error message
                  always, and the traceback usually.) If you don't, you will usually get
                  a request to supply that information, and then have wast3ed the time for
                  one full round of message to the group. Even in this case, I'm only
                  guessing how it failed for you.
                  >
                  >I've checked and rechecked to make sure that the spellings are proper
                  >and that the tools, the codeEditor directory, and codeEditor.py, and
                  >the class CodeEditor all exists and yet idle keep complaining that it
                  >can't import from PythonCard.tool s.
                  >
                  >What's going on? (Running Python2.5 under WinXP).
                  >>
                  Thank you very much. I didn't know about the __init__.py
                  requirement. Appreciate it.
                  >
                  Actually I should have added that there ways to import such things, and
                  PythonCard must be using some such method itself. You can manipulate
                  the sys.path variable, or directly call the import mechanism using the
                  builtin __import__, or use a suppled "imp" module. However, you
                  should not have to do any such thing to use PythonCard. It should do
                  them in for you.
                  I tried to call __import__ directly and didn't work neither.

                  What I was doing is to invoke their codeEditor directly into my
                  application. Their codeEditor was designed to be a stand alone
                  application and that's why it didn't include the file you cited.

                  I never quite understood what they were saying about __init__.py but
                  now I understand. Learn something new every day.

                  Thanks again.

                  Comment

                  Working...