Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

IndexError: list index out of range

using portable python 2.7 for windows7

Message      File Name      Line      Position      
Traceback                        
    <module>      C:\Users\Acer\Documents\portable-python\myfiles\homophone.py      65            
    read_dictionary      C:\Users\Acer\Documents\portable-python\myfiles\pronounce.py      29            
IndexError: list index out of range
Avatar of Patrick Bogers
Patrick Bogers
Flag of Netherlands image

Hi,

Try to install pylint, if not allready present and have it diagnose your code.
It will show you something like:

************* Module homophone
W: 19,8:make_word_dict: Redefining name 'word' from outer scope (line 68)
C: 16,4:make_word_dict: Invalid name "d" (should match [a-z_][a-z0-9_]{2,30}$)
W: 25,21:homophones: Redefining name 'phonetic' from outer scope (line 65)
C: 25,0:homophones: Invalid name "a" (should match [a-z_][a-z0-9_]{2,30}$)
C: 25,0:homophones: Invalid name "b" (should match [a-z_][a-z0-9_]{2,30}$)
C: 25,15:homophones: Invalid name "a" (should match [a-z_][a-z0-9_]{2,30}$)
C: 25,18:homophones: Invalid name "b" (should match [a-z_][a-z0-9_]{2,30}$)
W: 39,32:check_word: Redefining name 'phonetic' from outer scope (line 65)
W: 39,21:check_word: Redefining name 'word_dict' from outer scope (line 66)
W: 39,15:check_word: Redefining name 'word' from outer scope (line 68)
C: 65,4: Invalid name "phonetic" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 66,4: Invalid name "word_dict" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)



Look for invalids.... HTH
Avatar of rgb192

ASKER

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>cd ..

C:\Windows>cd ..

C:\>cd users

C:\Users>cd acer

C:\Users\Acer>cd documents

C:\Users\Acer\Documents>cd portable-python

C:\Users\Acer\Documents\portable-python>cd "portable python 2.7.2.1"

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1>cd app/scripts

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>easy
_install pylint
Searching for pylint
Reading http://pypi.python.org/simple/pylint/
Best match: pylint 1.2.1
Downloading https://pypi.python.org/packages/source/p/pylint/pylint-1.2.1.tar.gz
#md5=c49008134f2905cc88251f19d33e616c
Processing pylint-1.2.1.tar.gz
Running pylint-1.2.1\setup.py -q bdist_egg --dist-dir c:\users\acer\appdata\loca
l\temp\easy_install-ndd9mm\pylint-1.2.1\egg-dist-tmp-wdzdqc
warning: no files found matching 'Makefile' under directory 'doc'
zip_safe flag not set; analyzing archive contents...
pylint.epylint: module references __file__
pylint.checkers.__init__: module references __path__
pylint.reporters.__init__: module references __path__
SyntaxError: ('from __future__ imports must occur at the beginning of the file',
 ('c:\\users\\acer\\documents\\portable-python\\portable python 2.7.2.1\\app\\li
b\\site-packages\\pylint-1.2.1-py2.7.egg\\pylint\\test\\input\\func_3k_removed_s
tuff_py_30.py', 4, None, 'from __future__ import generators\n'))

SyntaxError: ('invalid syntax', ('c:\\users\\acer\\documents\\portable-python\\p
ortable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.egg\\pylint\
\test\\input\\func_abstract_class_instantiated_py30.py', 12, 34, 'class GoodClas
s(object, metaclass=abc.ABCMeta):\n'))

SyntaxError: ('invalid syntax', ('c:\\users\\acer\\documents\\portable-python\\p
ortable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.egg\\pylint\
\test\\input\\func_abstract_class_instantiated_py34.py', 12, 34, 'class GoodClas
s(object, metaclass=abc.ABCMeta):\n'))

c:\users\acer\documents\portable-python\portable python 2.7.2.1\app\lib\site-pac
kages\pylint-1.2.1-py2.7.egg\pylint\test\input\func_assert_2uple.py:4: SyntaxWar
ning: assertion is always true, perhaps remove parentheses?
  assert (1 == 1, 2 == 2), "no error"
c:\users\acer\documents\portable-python\portable python 2.7.2.1\app\lib\site-pac
kages\pylint-1.2.1-py2.7.egg\pylint\test\input\func_assert_2uple.py:5: SyntaxWar
ning: assertion is always true, perhaps remove parentheses?
  assert (1 == 1, 2 == 2) #this should generate a warning
c:\users\acer\documents\portable-python\portable python 2.7.2.1\app\lib\site-pac
kages\pylint-1.2.1-py2.7.egg\pylint\test\input\func_assert_2uple.py:7: SyntaxWar
ning: assertion is always true, perhaps remove parentheses?
  assert (1 == 1, ), "no error"
c:\users\acer\documents\portable-python\portable python 2.7.2.1\app\lib\site-pac
kages\pylint-1.2.1-py2.7.egg\pylint\test\input\func_assert_2uple.py:8: SyntaxWar
ning: assertion is always true, perhaps remove parentheses?
  assert (1 == 1, )
c:\users\acer\documents\portable-python\portable python 2.7.2.1\app\lib\site-pac
kages\pylint-1.2.1-py2.7.egg\pylint\test\input\func_assert_2uple.py:9: SyntaxWar
ning: assertion is always true, perhaps remove parentheses?
  assert (1 == 1, 2 == 2, 3 == 5), "no error"
c:\users\acer\documents\portable-python\portable python 2.7.2.1\app\lib\site-pac
kages\pylint-1.2.1-py2.7.egg\pylint\test\input\func_assert_2uple.py:11: SyntaxWa
rning: assertion is always true, perhaps remove parentheses?
  assert (True, 'error msg') #this should generate a warning
SyntaxError: ('invalid syntax', ('c:\\users\\acer\\documents\\portable-python\\p
ortable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.egg\\pylint\
\test\\input\\func_bad_exception_context_py30.py', 14, 25, '    raise IndexError
 from 1\n'))

SyntaxError: ("'continue' not properly in loop", ('c:\\users\\acer\\documents\\p
ortable-python\\portable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-p
y2.7.egg\\pylint\\test\\input\\func_continue_not_in_loop.py', 8, None, 'continue
\n'))

SyntaxError: ("duplicate argument '_' in function definition",)

SyntaxError: ('invalid syntax', ('c:\\users\\acer\\documents\\portable-python\\p
ortable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.egg\\pylint\
\test\\input\\func_exec_used_py30.py', 6, 22, "exec('a = 1', globals={})\n"))

SyntaxError: ('keyword argument repeated', ('c:\\users\\acer\\documents\\portabl
e-python\\portable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.e
gg\\pylint\\test\\input\\func_keyword_repeat.py', 8, None, 'function_default_arg
(two=5, two=7)\n'))

SyntaxError: ('invalid syntax', ('c:\\users\\acer\\documents\\portable-python\\p
ortable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.egg\\pylint\
\test\\input\\func_kwoa_py30.py', 3, 15, 'def function(*, foo):\n'))

SyntaxError: ('invalid syntax', ('c:\\users\\acer\\documents\\portable-python\\p
ortable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.egg\\pylint\
\test\\input\\func_noerror_abstract_method_py30.py', 9, 23, 'class Parent(metacl
ass=abc.ABCMeta):\n'))

SyntaxError: ("'return' outside function", ('c:\\users\\acer\\documents\\portabl
e-python\\portable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.e
gg\\pylint\\test\\input\\func_return_outside_func.py', 3, None, 'return\n'))

SyntaxError: ("'return' with argument inside generator",)

SyntaxError: ('invalid syntax', ('c:\\users\\acer\\documents\\portable-python\\p
ortable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.egg\\pylint\
\test\\input\\func_syntax_error.py', 1, 9, 'def toto\n'))

SyntaxError: ('unknown encoding: IBO-8859-1', ('c:\\users\\acer\\documents\\port
able-python\\portable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.
7.egg\\pylint\\test\\input\\func_unknown_encoding.py', 0, 0, None))

SyntaxError: ('invalid syntax', ('c:\\users\\acer\\documents\\portable-python\\p
ortable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.egg\\pylint\
\test\\input\\func_used_before_assignment_py30.py', 10, 20, '        nonlocal cn
t\n'))

SyntaxError: ("default 'except:' must be last", ('c:\\users\\acer\\documents\\po
rtable-python\\portable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py
2.7.egg\\pylint\\test\\input\\func_w0705.py', 28, None, '__revision__ += 1\n'))

SyntaxError: ("'yield' outside function", ('c:\\users\\acer\\documents\\portable
-python\\portable python 2.7.2.1\\app\\lib\\site-packages\\pylint-1.2.1-py2.7.eg
g\\pylint\\test\\input\\func_yield_outside_func.py', 3, None, 'yield 1\n'))

Sorry: IndentationError: ('expected an indented block', ('c:\\users\\acer\\docum
ents\\portable-python\\portable python 2.7.2.1\\app\\lib\\site-packages\\pylint-
1.2.1-py2.7.egg\\pylint\\test\\input\\syntax_error.py', 2, 5, "print('hop')\n"))

Adding pylint 1.2.1 to easy-install.pth file
Installing epylint script to C:\Users\Acer\Documents\portable-python\Portable Py
thon 2.7.2.1\App\Scripts
Installing epylint.bat script to C:\Users\Acer\Documents\portable-python\Portabl
e Python 2.7.2.1\App\Scripts
Installing pylint script to C:\Users\Acer\Documents\portable-python\Portable Pyt
hon 2.7.2.1\App\Scripts
Installing pylint-gui script to C:\Users\Acer\Documents\portable-python\Portable
 Python 2.7.2.1\App\Scripts
Installing pylint-gui.bat script to C:\Users\Acer\Documents\portable-python\Port
able Python 2.7.2.1\App\Scripts
Installing pylint.bat script to C:\Users\Acer\Documents\portable-python\Portable
 Python 2.7.2.1\App\Scripts
Installing pyreverse script to C:\Users\Acer\Documents\portable-python\Portable
Python 2.7.2.1\App\Scripts
Installing pyreverse.bat script to C:\Users\Acer\Documents\portable-python\Porta
ble Python 2.7.2.1\App\Scripts
Installing symilar script to C:\Users\Acer\Documents\portable-python\Portable Py
thon 2.7.2.1\App\Scripts
Installing symilar.bat script to C:\Users\Acer\Documents\portable-python\Portabl
e Python 2.7.2.1\App\Scripts
Installing pylint-script.py script to C:\Users\Acer\Documents\portable-python\Po
rtable Python 2.7.2.1\App\Scripts
Installing pylint.exe script to C:\Users\Acer\Documents\portable-python\Portable
 Python 2.7.2.1\App\Scripts
Installing pylint.exe.manifest script to C:\Users\Acer\Documents\portable-python
\Portable Python 2.7.2.1\App\Scripts
Installing epylint-script.py script to C:\Users\Acer\Documents\portable-python\P
ortable Python 2.7.2.1\App\Scripts
Installing epylint.exe script to C:\Users\Acer\Documents\portable-python\Portabl
e Python 2.7.2.1\App\Scripts
Installing epylint.exe.manifest script to C:\Users\Acer\Documents\portable-pytho
n\Portable Python 2.7.2.1\App\Scripts
Installing pyreverse-script.py script to C:\Users\Acer\Documents\portable-python
\Portable Python 2.7.2.1\App\Scripts
Installing pyreverse.exe script to C:\Users\Acer\Documents\portable-python\Porta
ble Python 2.7.2.1\App\Scripts
Installing pyreverse.exe.manifest script to C:\Users\Acer\Documents\portable-pyt
hon\Portable Python 2.7.2.1\App\Scripts
Installing pylint-gui-script.py script to C:\Users\Acer\Documents\portable-pytho
n\Portable Python 2.7.2.1\App\Scripts
Installing pylint-gui.exe script to C:\Users\Acer\Documents\portable-python\Port
able Python 2.7.2.1\App\Scripts
Installing pylint-gui.exe.manifest script to C:\Users\Acer\Documents\portable-py
thon\Portable Python 2.7.2.1\App\Scripts
Installing symilar-script.py script to C:\Users\Acer\Documents\portable-python\P
ortable Python 2.7.2.1\App\Scripts
Installing symilar.exe script to C:\Users\Acer\Documents\portable-python\Portabl
e Python 2.7.2.1\App\Scripts
Installing symilar.exe.manifest script to C:\Users\Acer\Documents\portable-pytho
n\Portable Python 2.7.2.1\App\Scripts

Installed c:\users\acer\documents\portable-python\portable python 2.7.2.1\app\li
b\site-packages\pylint-1.2.1-py2.7.egg
Processing dependencies for pylint
Searching for astroid>=1.1
Reading http://pypi.python.org/simple/astroid/
Best match: astroid 1.1.1
Downloading https://pypi.python.org/packages/source/a/astroid/astroid-1.1.1.tar.
gz#md5=b8153df72670f62bd8d6bc8be99cd184
Processing astroid-1.1.1.tar.gz
Running astroid-1.1.1\setup.py -q bdist_egg --dist-dir c:\users\acer\appdata\loc
al\temp\easy_install-egyexq\astroid-1.1.1\egg-dist-tmp-r_j6om
package init file '.\test\__init__.py' not found (or not a regular file)
package init file '.\test\__init__.py' not found (or not a regular file)
package init file '.\test\__init__.py' not found (or not a regular file)
Creating missing __init__.py for astroid.test
zip_safe flag not set; analyzing archive contents...
astroid.builder: module references __file__
astroid.manager: module references __file__
astroid.raw_building: module references __file__
astroid.raw_building: module references __path__
astroid.scoped_nodes: module references __file__
astroid.scoped_nodes: module references __path__
astroid.__init__: module references __file__
astroid.test.unittest_builder: module references __file__
astroid.test.unittest_builder: module references __path__
astroid.test.unittest_inference: module references __file__
astroid.test.unittest_inspector: module references __file__
astroid.test.unittest_lookup: module references __file__
astroid.test.unittest_lookup: module references __path__
astroid.test.unittest_manager: module references __file__
astroid.test.unittest_nodes: module references __file__
astroid.test.unittest_regrtest: module references __file__
astroid.test.unittest_scoped_nodes: module references __file__
astroid.test.unittest_scoped_nodes: module references __path__
astroid.test.unittest_utils: module references __file__
Adding astroid 1.1.1 to easy-install.pth file

Installed c:\users\acer\documents\portable-python\portable python 2.7.2.1\app\li
b\site-packages\astroid-1.1.1-py2.7.egg
Searching for logilab-common>=0.53.0
Reading http://pypi.python.org/simple/logilab-common/
Best match: logilab-common 0.62.0
Downloading https://pypi.python.org/packages/source/l/logilab-common/logilab-com
mon-0.62.0.tar.gz#md5=fb401ac8bd87eca6aa82b4640788d4ad
Processing logilab-common-0.62.0.tar.gz
Running logilab-common-0.62.0\setup.py -q bdist_egg --dist-dir c:\users\acer\app
data\local\temp\easy_install-79qofe\logilab-common-0.62.0\egg-dist-tmp-jn8lyo
package init file '.\test\__init__.py' not found (or not a regular file)
package init file '.\test\__init__.py' not found (or not a regular file)
package init file '.\test\__init__.py' not found (or not a regular file)
Creating missing __init__.py for logilab.common.test
zip_safe flag not set; analyzing archive contents...
logilab.common.debugger: module MAY be using inspect.getsource
logilab.common.modutils: module references __file__
logilab.common.modutils: module references __path__
logilab.common.pytest: module references __file__
logilab.common.registry: module references __file__
logilab.common.testlib: module references __file__
logilab.common.testlib: module MAY be using inspect.getinnerframes
logilab.common.test.unittest_changelog: module references __file__
logilab.common.test.unittest_configuration: module references __file__
logilab.common.test.unittest_fileutils: module references __file__
logilab.common.test.unittest_modutils: module references __file__
logilab.common.test.unittest_modutils: module references __path__
logilab.common.test.unittest_shellutils: module references __file__
logilab.common.test.unittest_testlib: module references __file__
logilab.common.test.unittest_umessage: module references __file__
Adding logilab-common 0.62.0 to easy-install.pth file
Installing pytest.bat script to C:\Users\Acer\Documents\portable-python\Portable
 Python 2.7.2.1\App\Scripts

Installed c:\users\acer\documents\portable-python\portable python 2.7.2.1\app\li
b\site-packages\logilab_common-0.62.0-py2.7.egg
Searching for colorama
Reading http://pypi.python.org/simple/colorama/
Best match: colorama 0.3.1
Downloading https://pypi.python.org/packages/source/c/colorama/colorama-0.3.1.zi
p#md5=54038459dba206a8af3db085be907d08
Processing colorama-0.3.1.zip
Running colorama-0.3.1\setup.py -q bdist_egg --dist-dir c:\users\acer\appdata\lo
cal\temp\easy_install-srqvg6\colorama-0.3.1\egg-dist-tmp-4mbm5l
zip_safe flag not set; analyzing archive contents...
Adding colorama 0.3.1 to easy-install.pth file

Installed c:\users\acer\documents\portable-python\portable python 2.7.2.1\app\li
b\site-packages\colorama-0.3.1-py2.7.egg
Finished processing dependencies for pylint

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>

Open in new window


using Portable Python 2.7.2.1 how do I run?
Not sure how to under windows, looks like you are trying the right way....

I just start an Ubuntu distro, VM or bootable media and did it from there.
If you need i can post the outcome from the other files here.

BTW: The appropriate rule would be something like: "should match [a-z_][a-z0-9_]{2,30}$". Notice the lowercase letters in the regular expression (a-z versus A-Z)
Avatar of rgb192

ASKER

Do I use ide to get the output you got

https://www.experts-exchange.com/questions/28479625/IndexError-list-index-out-of-range.html?anchorAnswerId=40207141#a40207141

Or is there a command to run the file in cmd.exe
Hi,

I simply ran the command in a Ubuntu VM calling:              pyling pronounce.py       and hit enter.
Avatar of rgb192

ASKER

python.exe
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> python ../myfiles/3.4.py
  File "<stdin>", line 1
    python ../myfiles/3.4.py
            ^
SyntaxError: invalid syntax
>>> python ..myfiles/3.4.py
  File "<stdin>", line 1
    python ..myfiles/3.4.py
            ^
SyntaxError: invalid syntax
>>> pyling
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'pyling' is not defined
>>>

Open in new window


cmd.exe
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>ipconfig

Windows IP Configuration


Wireless LAN adapter Wireless Network Connection 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Local Area Connection 4:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Local Area Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : nyc.rr.com

Wireless LAN adapter Wireless Network Connection:

   Connection-specific DNS Suffix  . :
   IPv6 Address. . . . . . . . . . . : 2604:2000:dee2:5a00:2461:10c0:386d:4c0d
   Temporary IPv6 Address. . . . . . : 2604:2000:dee2:5a00:20f4:b3fe:3c29:1c56
   Link-local IPv6 Address . . . . . : fe80::2461:10c0:386d:4c0d%10
   IPv4 Address. . . . . . . . . . . : 192.168.0.5
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : fe80::16cf:e2ff:fe8b:5457%10
                                       192.168.0.1

Ethernet adapter VMware Network Adapter VMnet1:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::1148:2387:c9d8:5b03%20
   IPv4 Address. . . . . . . . . . . : 192.168.113.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Ethernet adapter VMware Network Adapter VMnet8:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::64fa:c09e:3e53:737a%21
   IPv4 Address. . . . . . . . . . . : 192.168.116.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Tunnel adapter isatap.Belkin:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter isatap.nyc.rr.com:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter Teredo Tunneling Pseudo-Interface:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

C:\Windows\system32>cd ../users/acer/documents
The system cannot find the path specified.

C:\Windows\system32>cd users/acer/documents
The system cannot find the path specified.

C:\Windows\system32>cd users/acer/documents/
The system cannot find the path specified.

C:\Windows\system32>cd ../../users/acer/documents/

C:\Users\Acer\Documents>cd portable-python

C:\Users\Acer\Documents\portable-python>cd "portable python 2.7.2.1"

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1>cd app/scripts

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
ng prounce.py
'pyling' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
ng
'pyling' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>

Open in new window

Is pyling installed under C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts> ???

Wouldnt it be easier to run a Ubuntu image from VM or DVD or USB disk???
Avatar of rgb192

ASKER

is this correct?
cmd.exe
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>ipconfig

Windows IP Configuration


Wireless LAN adapter Wireless Network Connection 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Local Area Connection 4:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Local Area Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : nyc.rr.com

Wireless LAN adapter Wireless Network Connection:

   Connection-specific DNS Suffix  . :
   IPv6 Address. . . . . . . . . . . : 2604:2000:dee2:5a00:2461:10c0:386d:4c0d
   Temporary IPv6 Address. . . . . . : 2604:2000:dee2:5a00:20f4:b3fe:3c29:1c56
   Link-local IPv6 Address . . . . . : fe80::2461:10c0:386d:4c0d%10
   IPv4 Address. . . . . . . . . . . : 192.168.0.5
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : fe80::16cf:e2ff:fe8b:5457%10
                                       192.168.0.1

Ethernet adapter VMware Network Adapter VMnet1:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::1148:2387:c9d8:5b03%20
   IPv4 Address. . . . . . . . . . . : 192.168.113.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Ethernet adapter VMware Network Adapter VMnet8:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::64fa:c09e:3e53:737a%21
   IPv4 Address. . . . . . . . . . . : 192.168.116.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Tunnel adapter isatap.Belkin:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter isatap.nyc.rr.com:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter Teredo Tunneling Pseudo-Interface:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

C:\Windows\system32>cd ../users/acer/documents
The system cannot find the path specified.

C:\Windows\system32>cd users/acer/documents
The system cannot find the path specified.

C:\Windows\system32>cd users/acer/documents/
The system cannot find the path specified.

C:\Windows\system32>cd ../../users/acer/documents/

C:\Users\Acer\Documents>cd portable-python

C:\Users\Acer\Documents\portable-python>cd "portable python 2.7.2.1"

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1>cd app/scripts

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
ng prounce.py
'pyling' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
ng
'pyling' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
nt
No config file found, using default configuration
Usage:  pylint-script.py [options] module_or_package

  Check that a module satisfies a coding standard (and more !).

    pylint-script.py --help

  Display this help message and exit.

    pylint-script.py --help-msg <msg-id>[,<msg-id>]

  Display help messages about given message identifiers and exit.


Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  --long-help           more verbose help.

  Master:
    --rcfile=<file>     Specify a configuration file.
    -E, --errors-only   In error mode, checkers without error messages are
                        disabled and for others, only the ERROR messages are
                        displayed, and no reports are done by default
    --ignore=<file>[,<file>...]
                        Add files or directories to the blacklist. They should
                        be base names, not paths. [current: CVS]

  Commands:
    --help-msg=<msg-id>
                        Display a help message for the given message id and
                        exit. The value may be a comma separated list of
                        message ids.
    --generate-rcfile   Generate a sample configuration file according to the
                        current configuration. You can put other options
                        before this one to get them in the generated
                        configuration.

  Messages control:
    -e <msg ids>, --enable=<msg ids>
                        Enable the message, report, category or checker with
                        the given id(s). You can either give multiple
                        identifier separated by comma (,) or put this option
                        multiple time. See also the "--disable" option for
                        examples.
    -d <msg ids>, --disable=<msg ids>
                        Disable the message, report, category or checker with
                        the given id(s). You can either give multiple
                        identifiers separated by comma (,) or put this option
                        multiple times (only on the command line, not in the
                        configuration file where it should appear only
                        once).You can also use "--disable=all" to disable
                        everything first and then reenable specific checks.
                        For example, if you want to run only the similarities
                        checker, you can use "--disable=all
                        --enable=similarities". If you want to run only the
                        classes checker, but have no Warning level messages
                        displayed, use"--disable=all --enable=classes
                        --disable=W"

  Reports:
    -f <format>, --output-format=<format>
                        Set the output format. Available formats are text,
                        parseable, colorized, msvs (visual studio) and html.
                        You can also give a reporter class, eg
                        mypackage.mymodule.MyReporterClass. [current: text]
    -r <y_or_n>, --reports=<y_or_n>
                        Tells whether to display a full report or only the
                        messages [current: yes]
    --msg-template=<template>
                        Template used to display messages. This is a python
                        new-style format string used to format the message
                        information. See doc for all details


C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
nt prounce.py
No config file found, using default configuration
************* Module prounce.py
F:  1, 0: No module named prounce.py (fatal)

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
nt ../myfiles/prounce.py
No config file found, using default configuration
************* Module ../myfiles/prounce.py
F:  1, 0: No module named ../myfiles/prounce.py (fatal)

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
nt ../myfiles/pronounce.py
No config file found, using default configuration
************* Module ../myfiles/pronounce.py
F:  1, 0: No module named ../myfiles/pronounce.py (fatal)

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
nt ../myfiles/pronounce
No config file found, using default configuration
************* Module ../myfiles/pronounce
F:  1, 0: No module named ../myfiles/pronounce (fatal)

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
nt ../../../myfiles/pronounce
No config file found, using default configuration
************* Module ../../../myfiles/pronounce
F:  1, 0: No module named ../../../myfiles/pronounce (fatal)

C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>pyli
nt ../../../myfiles/pronounce.py
No config file found, using default configuration
************* Module pronounce
W: 21, 4: Redefining name 'd' from outer scope (line 37) (redefined-outer-name)
C: 21, 4: Invalid variable name "d" (invalid-name)
C: 26,27: More than one statement on a single line (multiple-statements)
C: 28, 8: Invalid variable name "t" (invalid-name)
C: 37, 4: Invalid constant name "d" (invalid-name)


Report
======
16 statements analysed.

Messages by category
--------------------

+-----------+-------+---------+-----------+
|type       |number |previous |difference |
+===========+=======+=========+===========+
|convention |4      |NC       |NC         |
+-----------+-------+---------+-----------+
|refactor   |0      |NC       |NC         |
+-----------+-------+---------+-----------+
|warning    |1      |NC       |NC         |
+-----------+-------+---------+-----------+
|error      |0      |NC       |NC         |
+-----------+-------+---------+-----------+



Messages
--------

+---------------------+------------+
|message id           |occurrences |
+=====================+============+
|invalid-name         |3           |
+---------------------+------------+
|redefined-outer-name |1           |
+---------------------+------------+
|multiple-statements  |1           |
+---------------------+------------+



Global evaluation
-----------------
Your code has been rated at 6.88/10

Duplication
-----------

+-------------------------+------+---------+-----------+
|                         |now   |previous |difference |
+=========================+======+=========+===========+
|nb duplicated lines      |0     |NC       |NC         |
+-------------------------+------+---------+-----------+
|percent duplicated lines |0.000 |NC       |NC         |
+-------------------------+------+---------+-----------+



Raw metrics
-----------

+----------+-------+------+---------+-----------+
|type      |number |%     |previous |difference |
+==========+=======+======+=========+===========+
|code      |15     |39.47 |NC       |NC         |
+----------+-------+------+---------+-----------+
|docstring |18     |47.37 |NC       |NC         |
+----------+-------+------+---------+-----------+
|comment   |1      |2.63  |NC       |NC         |
+----------+-------+------+---------+-----------+
|empty     |4      |10.53 |NC       |NC         |
+----------+-------+------+---------+-----------+



Statistics by type
------------------

+---------+-------+-----------+-----------+------------+---------+
|type     |number |old number |difference |%documented |%badname |
+=========+=======+===========+===========+============+=========+
|module   |1      |NC         |NC         |100.00      |0.00     |
+---------+-------+-----------+-----------+------------+---------+
|class    |0      |NC         |NC         |0           |0        |
+---------+-------+-----------+-----------+------------+---------+
|method   |0      |NC         |NC         |0           |0        |
+---------+-------+-----------+-----------+------------+---------+
|function |1      |NC         |NC         |100.00      |0.00     |
+---------+-------+-----------+-----------+------------+---------+




C:\Users\Acer\Documents\portable-python\Portable Python 2.7.2.1\App\Scripts>

Open in new window

It seems windows isnt reporting as complete as Linux does.
Below is the output for both python files reported by pylint in Ubuntu. HTH


@ubuntu$ pylint homophone.py
No config file found, using default configuration
************* Module homophone
W: 19,8:make_word_dict: Redefining name 'word' from outer scope (line 68)
C: 16,4:make_word_dict: Invalid name "d" (should match [a-z_][a-z0-9_]{2,30}$)
W: 25,21:homophones: Redefining name 'phonetic' from outer scope (line 65)
C: 25,0:homophones: Invalid name "a" (should match [a-z_][a-z0-9_]{2,30}$)
C: 25,0:homophones: Invalid name "b" (should match [a-z_][a-z0-9_]{2,30}$)
C: 25,15:homophones: Invalid name "a" (should match [a-z_][a-z0-9_]{2,30}$)
C: 25,18:homophones: Invalid name "b" (should match [a-z_][a-z0-9_]{2,30}$)
W: 39,32:check_word: Redefining name 'phonetic' from outer scope (line 65)
W: 39,21:check_word: Redefining name 'word_dict' from outer scope (line 66)
W: 39,15:check_word: Redefining name 'word' from outer scope (line 68)
C: 65,4: Invalid name "phonetic" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 66,4: Invalid name "word_dict" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)

@ubuntu$ pylint pronounce.py
No config file found, using default configuration
************* Module pronounce
W: 21,4:read_dictionary: Redefining name 'd' from outer scope (line 37)
C: 21,4:read_dictionary: Invalid name "d" (should match [a-z_][a-z0-9_]{2,30}$)
C: 26,27:read_dictionary: More than one statement on a single line
C: 28,8:read_dictionary: Invalid name "t" (should match [a-z_][a-z0-9_]{2,30}$)
C: 37,4: Invalid name "d" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
Avatar of rgb192

ASKER

can you explain to me what this means?

I am doing a tutorial and this is a code sample.
Ok

In my first reply i showed you this:
C: 65,4: Invalid name "phonetic" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 66,4: Invalid name "word_dict" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)

This is not compliant with the SEP8 rules.

Quote about SEP8:
The appropriate rule would be something like: "should match [a-z_][a-z0-9_]{2,30}$". Notice the lowercase letters in the regular expression (a-z versus A-Z)

Change this and we can look further.
Avatar of rgb192

ASKER

do I change
pronounce.py
or
homophone.py
Avatar of rgb192

ASKER

homophone.py
"""This module contains code from
Think Python by Allen B. Downey
http://thinkpython.com

Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html

"""

from pronounce import read_dictionary


def make_word_dict():
    """Read the words in words.txt and return a dictionary
    that contains the words as keys"""
    d = dict()
    fin = open('words.txt')
    for line in fin:
        word = line.strip().lower()
        d[word] = word

    return d


def homophones(a, b, phonetic):
    """Checks if words two can be pronounced the same way.

    If either word is not in the pronouncing dictionary, return False

    a, b: strings
    phonetic: map from words to pronunciation codes
    """
    if a not in phonetic or b not in phonetic:
        return False

    return phonetic[a] == phonetic[b]


def check_word(word, word_dict, phonetic):
    """Checks to see if the word has the following property:
    removing the first letter yields a word with the same
    pronunciation, and removing the second letter yields a word
    with the same pronunciation.

    word: string
    word_dict: dictionary with words as keys
    phonetic: map from words to pronunciation codes
    """
    word1 = word[1:]
    if word1 not in word_dict:
        return False
    if not homophones(word, word1, phonetic):
        return False

    word2 = word[0] + word[2:]
    if word2 not in word_dict:
        return False
    if not homophones(word, word2, phonetic):
        return False

    return True


if __name__ == '__main__':
    phonetic = read_dictionary()
    word_dict = make_word_dict()

    for word in word_dict:
        if check_word(word, word_dict, phonetic):
            print word, word[1:], word[0] + word[2:]

Open in new window


    phonetic = read_dictionary()
    word_dict = make_word_dict()


I do not see A_Z
Avatar of rgb192

ASKER

Should I provide additional information?
Avatar of rgb192

ASKER

Could you please tell me what should I do?
I've installed Portable-Python (2.7.6.1), and astroid (1.2.0), and pylint(1.2.0).
I don't see homophone.py or pronounce.py
From where did these files come?

I was able to successfully use the pylint-gui to select and process files.

Can you provide more information?  Thanks
Thanks for the pointers.

When I process homophone.py with pylint the output I see is:

************* Module homophone
C: 49, 0: Trailing whitespace (trailing-whitespace)
W: 19, 8: Redefining name 'word' from outer scope (line 68) (redefined-outer-name)
C: 16, 4: Invalid variable name "d" (invalid-name)
W: 25,21: Redefining name 'phonetic' from outer scope (line 65) (redefined-outer-name)
C: 25, 0: Invalid argument name "a" (invalid-name)
C: 25, 0: Invalid argument name "b" (invalid-name)
W: 39,32: Redefining name 'phonetic' from outer scope (line 65) (redefined-outer-name)
W: 39,21: Redefining name 'word_dict' from outer scope (line 66) (redefined-outer-name)
W: 39,15: Redefining name 'word' from outer scope (line 68) (redefined-outer-name)
C: 65, 4: Invalid constant name "phonetic" (invalid-name)
C: 66, 4: Invalid constant name "word_dict" (invalid-name)

Note the hilighted word that is missing from your output.  pylint is complaining that the constants should be all capitalized.
Avatar of rgb192

ASKER

homophone.py
I change line65,66 to capital letter
Phonetic
Word_dict
"""This module contains code from
Think Python by Allen B. Downey
http://thinkpython.com

Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html

"""

from pronounce import read_dictionary


def make_word_dict():
    """Read the words in words.txt and return a dictionary
    that contains the words as keys"""
    d = dict()
    fin = open('words.txt')
    for line in fin:
        word = line.strip().lower()
        d[word] = word

    return d


def homophones(a, b, phonetic):
    """Checks if words two can be pronounced the same way.

    If either word is not in the pronouncing dictionary, return False

    a, b: strings
    phonetic: map from words to pronunciation codes
    """
    if a not in phonetic or b not in phonetic:
        return False

    return phonetic[a] == phonetic[b]


def check_word(word, word_dict, phonetic):
    """Checks to see if the word has the following property:
    removing the first letter yields a word with the same
    pronunciation, and removing the second letter yields a word
    with the same pronunciation.

    word: string
    word_dict: dictionary with words as keys
    phonetic: map from words to pronunciation codes
    """
    word1 = word[1:]
    if word1 not in word_dict:
        return False
    if not homophones(word, word1, phonetic):
        return False

    word2 = word[0] + word[2:]
    if word2 not in word_dict:
        return False
    if not homophones(word, word2, phonetic):
        return False

    return True


if __name__ == '__main__':
    Phonetic = read_dictionary()
    Word_dict = make_word_dict()

    for word in word_dict:
        if check_word(word, word_dict, phonetic):
            print word, word[1:], word[0] + word[2:]

Open in new window


pronounce.py
"""This module contains code from
Think Python by Allen B. Downey
http://thinkpython.com

Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html

"""

def read_dictionary(filename='c06d'):
    """Reads from a file and builds a dictionary that maps from
    each word to a string that describes its primary pronunciation.

    Secondary pronunciations are added to the dictionary with
    a number, in parentheses, at the end of the key, so the
    key for the second pronunciation of "abdominal" is "abdominal(2)".

    filename: string
    returns: map from string to pronunciation
    """
    d = dict()
    fin = open(filename)
    for line in fin:

        # skip over the comments
        if line[0] == '#': continue

        t = line.split()
        word = t[0].lower()
        pron = ' '.join(t[1:])
        d[word] = pron

    return d


if __name__ == '__main__':
    d = read_dictionary()
    for k, v in d.items():
        print k, v

Open in new window


running homophone


Message      File Name      Line      Position      
Traceback                        
    <module>      C:\Users\Acer\Documents\portable-python\myfiles\homophone.py      65            
    read_dictionary      C:\Users\Acer\Documents\portable-python\myfiles\pronounce.py      29            
IndexError: list index out of range                        


I am still getting the same errors as the original question
How, exactly, are you "running homophone.py"?

When I start "Python-Portable", a new command prompt is opened, in which I see:

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Portable Python >>>

Open in new window


To execute "homophone.py" I enter:

execfile( 'homophone.py' )

Open in new window


Which results in the following output:

Portable Python >>> execfile( 'homophone.py' )
llama lama lama
llamas lamas lamas
scent cent sent
Portable Python >>>

Open in new window


Did you download the c06d file to the same directory?

What does it contain?

The file that I have contains 129531 lines, the last of which is empty, and the first few of which look like:

## Date:  August 8, 1998
##
## The Carnegie Mellon Pronouncing Dictionary [cmudict.0.6] is Copyright 1998
## by Carnegie Mellon University. Use of this dictionary, for any research or
## commercial purpose, is completely unrestricted.  If you make use of or
## redistribute this material, we would appreciate acknowlegement of its
## origin.

Open in new window

Avatar of rgb192

ASKER

How, exactly, are you "running homophone.py"?
windows portable python 2.7
debug run


User generated image
now that I have the correct c06d file

the new error is


Message	File Name	Line	Position	
Traceback				
    <module>	C:\Users\Acer\Documents\portable-python\myfiles\homophone.py	68		
NameError: name 'word_dict' is not defined				

Open in new window

Note that the named variable "word_dict" is different from the variable in the preceding assignment statement:

Word_dict = make_word_dict()

Python is case sensitive.  You have two options:

1. Change the assignment statement to be:
word_dict = make_word_dict()

  It doesn't appear that there are any other references to "Word_dict" in the code, at least no in that screen shot.  Search for that exact text and correct / changed them if appropriate.  When would it not be appropriate?  Well, depending upon the script, there may be some subtle, yet important, need for this variable to use this name, I don't think so, but it is best to be cautious.

2. Change the "for" statement to refer to the actual variable:
for word in Word_dict:

  However, you also need to look for any other references to the "word_dict" variable and change them as well (e.g., see the next "if" statement).

Good luck
Avatar of rgb192

ASKER

"""This module contains code from
Think Python by Allen B. Downey
http://thinkpython.com

Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html

"""

from pronounce import read_dictionary


def make_word_dict():
    """Read the words in words.txt and return a dictionary
    that contains the words as keys"""
    d = dict()
    fin = open('words.txt')
    for line in fin:
        word = line.strip().lower()
        d[word] = word

    return d


def homophones(a, b, phonetic):
    """Checks if words two can be pronounced the same way.

    If either word is not in the pronouncing dictionary, return False

    a, b: strings
    phonetic: map from words to pronunciation codes
    """
    if a not in phonetic or b not in phonetic:
        return False

    return phonetic[a] == phonetic[b]


def check_word(word, word_dict, phonetic):
    """Checks to see if the word has the following property:
    removing the first letter yields a word with the same
    pronunciation, and removing the second letter yields a word
    with the same pronunciation.

    word: string
    word_dict: dictionary with words as keys
    phonetic: map from words to pronunciation codes
    """
    word1 = word[1:]
    if word1 not in word_dict:
        return False
    if not homophones(word, word1, phonetic):
        return False

    word2 = word[0] + word[2:]
    if word2 not in word_dict:
        return False
    if not homophones(word, word2, phonetic):
        return False

    return True


if __name__ == '__main__':
    Phonetic = read_dictionary()
    word_dict = make_word_dict()

    for word in word_dict:
        if check_word(word, word_dict, phonetic):
            print word, word[1:], word[0] + word[2:]

Open in new window


word_dic is all lower case now



Message      File Name      Line      Position      
Traceback                        
    <module>      C:\Users\Acer\Documents\portable-python\myfiles\homophone.py      69            
NameError: name 'phonetic' is not defined
ASKER CERTIFIED SOLUTION
Avatar of HonorGod
HonorGod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

works.
Thanks.
You are very welcome.  Thanks for the grade & the points.  Good luck on your future endeavors.