Search code examples
pythonpython-2.7setuptools

error while accessing method of class - python package


I have uploaded a simple package to https://testpypi.python.org/pypi . I have followed following steps,

python setup.py register -r https://testpypi.python.org/pypi

python setup.py sdist upload -r https://testpypi.python.org/pypi

Then downloaded this package to locally and executed setup.py with install command. ( package url https://testpypi.python.org/pypi/printlistonlynew/0.1 ) And then package was installed successfully.

Here is structure and code for package,

│   setup.py
│
└───listprint
        stack.py
        __init__.py

contents of stack.py are,

class Xyz:

    def __init__(self,):
        pass

    def printList(self):
        print [i for i in range(0,10)]

When I tried to import the method printList from the installed package it give me error ,

AttributeError: Xyz instance has no attribute 'printList'

Here is code I am trying to execute,

from listprint import stack
x=stack.Xyz()
print x
print x.printList()

What wrong I am doing here ? Any namespace problem ?


Solution

  • I've downloaded your file, and you have indentation issues. Because you're mixing tabs and spaces, Python is considering printList as nested inside __init__.

    Stick to spaces only.