Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63654 > unrolled thread

Input Error issues - Windows 7

Started bybryan.kardisco@gmail.com
First post2014-01-10 11:38 -0800
Last post2014-01-10 18:20 -0500
Articles 3 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Input Error issues - Windows 7 bryan.kardisco@gmail.com - 2014-01-10 11:38 -0800
    Re: Input Error issues - Windows 7 Ned Batchelder <ned@nedbatchelder.com> - 2014-01-10 14:48 -0500
    Re: Input Error issues - Windows 7 Dave Angel <davea@davea.name> - 2014-01-10 18:20 -0500

#63654 — Input Error issues - Windows 7

Frombryan.kardisco@gmail.com
Date2014-01-10 11:38 -0800
SubjectInput Error issues - Windows 7
Message-ID<e49eae5d-0ca8-44e6-a80a-7906b9dad8c0@googlegroups.com>
I'm new to python and am trying to just get some basic stuff up and going.

I have a very basic module called foo

It's in the following directory on my machine

C:\workspace\PyFoo\src\foo
In that folder is __init__.py (created automatically)  and foo.py

foo.py looks like this

class foo():
    def __init__(self, name, number):
        self.name = name
        self.number = number
    def getName(self):
        return self.name
    def getNumber(self):
        return self.number


If I open up command prompt and do following it works:

C:\workspace\PyFoo\src\foo>python
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from foo import foo
>>> f = foo(1,2)
>>> f.getName()
1
>>>


However, if I run this from C:\ I get the following

C:\>python
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from foo import foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'foo'
>>>


I thought, well maybe it's a system error

>>> import sys
>>> print(sys.path)
['', 'C:\\Python33', 'C:\\Python33\\Lib', 'C:\\Python33\\DLLs', 'C:\\workspace', 'C:\\Windows\\system32\\python33.zip',
 'C:\\Python33\\lib\\site-packages']
>>>

C:\>echo %PYTHONPATH%
C:\Python33;C:\Python33\Lib;C:\Python33\DLLs;C:\workspace

However, that seems OK.

Is there something I'm missing?

[toc] | [next] | [standalone]


#63656

FromNed Batchelder <ned@nedbatchelder.com>
Date2014-01-10 14:48 -0500
Message-ID<mailman.5298.1389383301.18130.python-list@python.org>
In reply to#63654
On 1/10/14 2:38 PM, bryan.kardisco@gmail.com wrote:
> I'm new to python and am trying to just get some basic stuff up and going.

Welcome!

>
> I have a very basic module called foo
>
> It's in the following directory on my machine
>
> C:\workspace\PyFoo\src\foo
> In that folder is __init__.py (created automatically)  and foo.py
>
> foo.py looks like this
>
> class foo():
>      def __init__(self, name, number):
>          self.name = name
>          self.number = number
>      def getName(self):
>          return self.name
>      def getNumber(self):
>          return self.number
>
>
> If I open up command prompt and do following it works:
>
> C:\workspace\PyFoo\src\foo>python
> Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from foo import foo
>>>> f = foo(1,2)
>>>> f.getName()
> 1
>>>>
>
>
> However, if I run this from C:\ I get the following
>
> C:\>python
> Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from foo import foo
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> ImportError: No module named 'foo'
>>>>
>
>
> I thought, well maybe it's a system error
>
>>>> import sys
>>>> print(sys.path)
> ['', 'C:\\Python33', 'C:\\Python33\\Lib', 'C:\\Python33\\DLLs', 'C:\\workspace', 'C:\\Windows\\system32\\python33.zip',
>   'C:\\Python33\\lib\\site-packages']
>>>>
>
> C:\>echo %PYTHONPATH%
> C:\Python33;C:\Python33\Lib;C:\Python33\DLLs;C:\workspace
>
> However, that seems OK.
>
> Is there something I'm missing?
>

The PYTHONPATH contains the directories that will be searched for 
modules and packages.  Your package is called foo, and is in 
c:\workspace\PyFoo\src.  That directory is not on the Python path, and 
it isn't the current directory.  Therefore, your package can't be found 
and imported.

BTW: writting getters like getName and getNumber is unusual in Python. 
The much more common technique is to simply use the attribute:  f.name

-- 
Ned Batchelder, http://nedbatchelder.com

[toc] | [prev] | [next] | [standalone]


#63673

FromDave Angel <davea@davea.name>
Date2014-01-10 18:20 -0500
Message-ID<mailman.5311.1389395925.18130.python-list@python.org>
In reply to#63654
On Fri, 10 Jan 2014 11:38:32 -0800 (PST), bryan.kardisco@gmail.com 
wrote:
> It's in the following directory on my machine


> C:\workspace\PyFoo\src\foo
> In that folder is __init__.py (created automatically)  and foo.py


> foo.py looks like this


> class foo():

Ned has pointed out your path problem.  But you have another,  
perhaps caused by overexposure to java. You have a package,  a module 
and a class, all with the same name. Convention says at least 
uppercase for the class. I say make every name unique till you learn 
how they work.

-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web