-2

I am newbie to python & want to run simple code to create & save HelloWorld.docx here is my code of default.py

asd = os.path.join(os.path.abspath("./"), "lib")
jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s" % asd)
hw = HelloWorld()
hw.main()

And here is my code of init.py()

class HelloWorld:
def __init__(self, dataDir):
    self.dataDir = dataDir

def main(self):
    """
        : The path to the documents directory. :
    """
    Document = jpype.JClass("com.aspose.words.Document")

    DocumentBuilder = jpype.JClass("com.aspose.words.DocumentBuilder")

    doc = Document()
    builder = DocumentBuilder(doc)

    builder.writeln('Hello World!')
    doc.save(self.dataDir +'HelloWorld.docx')

I am getting this error "TypeError: init() takes exactly 2 arguments (1 given)" I don't know how to fix it, I double check on everywhere but nothing prove helpful

3 Answers3

1

You missed the variable dataDir here:

hw = HelloWorld('path/to/your/dir')
Balas
  • 135
  • 8
0

By definition, init of your class Helloworld needs a value for dataDir.

But when instantiating you didn't supply any.

Building on the answers above, can you check if the error regarding missing class is the same in this link?

JPype class not found

Community
  • 1
  • 1
red ranger
  • 13
  • 6
0

When we create object of class, the __init__ function is called. the __init__ function accept two argument, one is class instance self and other is dataDir.

__init__ will initializes an instance of a class, or an object.

The __init__ function is called a constructor, or initialiser, and is automatically called when you create a new instance of a class.

Vivek Sable
  • 9,938
  • 3
  • 40
  • 56