Search code examples
pythonpython-webbrowser

can i integrate a Python module into my own python code?


I am in the process of writing a quiz using simple Python as part of a project- ultimately to create an executable file that runs the quiz when opened (so the user doesn't have to manually run the code and potentially see answers to some of the questions).

As part of my quiz, I use the webbrowser module to send the user to a Wikipedia page if their first answer submitted is incorrect so they can research the correct one. Is there any way to integrate this module into my code, so that it doesn't need to be imported (and therefore if it is used on another computer, the user doesn't have to download the module in order to take the quiz).


Solution

  • Seems like you are beginner to python . So let me tell you some basic , First of all whatever .py file you create is a module in itself , Lets say you have created a file with name Example.py , you can always call it as a module in another file by using:

    import Example   
    

    Note: .py is not required Once imported correctly,you can call the methods written in it Like:

    Example.Func()
    

    Now, if you have multiple modules, you can keep it inside a folder(lets say Package) ,So now you have:

    Package-
        A.py
        B.py 
        C.py
        __init__.py
    

    then you just have to have another file named init.py in the same folder containing :

    import A
    import B
    import C
    

    For more information read from

    For your problem When you compile the whole project , all modules will generate .pyc file so that is not in human readable form, so not at all a problem for your case what you mentioned user can read the answeres .