-2

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).

Tim
  • 41,901
  • 18
  • 127
  • 145
Jeffster
  • 1
  • 2
  • you can package it with your program OR best practice would be installing from repo/pypi by mentioning it in setup.py as dependency. for more details please refer https://docs.python.org/2/distutils/setupscript.html – Pavan Gupta Sep 21 '15 at 11:36
  • Thanks Pavan, can I package it with my program by simply copy and pasting the module's code into my own? or is there another/ better way to do this? – Jeffster Sep 21 '15 at 11:44
  • Hey sorry for the confusion, I din't mean to copy paste, If webbrowser module is available for installing from [PIP]( https://en.wikipedia.org/wiki/Pip_(package_manager)) then go with PIP, if it is something privately available only to you then keep it in a separate file and package it using setup.py, import still be valid on other systems. in case you have 1+ module best practice is to create a setup file so that your quiz can be installed on any system(like exe file in windows.) – Pavan Gupta Sep 21 '15 at 11:56
  • I don't believe that was meant for me @PavanGupta – Tim Sep 21 '15 at 11:56

1 Answers1

1

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 .

coder3521
  • 2,608
  • 1
  • 28
  • 50
  • This doesn't really answer the question. – Peter Wood Sep 21 '15 at 12:34
  • but it seems , i understood the root cause of the problem and user has accepted it as an answer @peter Wood – coder3521 Sep 22 '15 at 04:42
  • It's not a good question, and it's not a good answer. The `webbrowser` module is part of python's builtin standard library, and you don't address how to package that with the interpreter so that it will make a portable application. – Peter Wood Sep 22 '15 at 06:27
  • I do understand that , but you didn't followed up the second part of question , he was trying to call his module from another module, and that's the reason for answer acceptance . – coder3521 Sep 22 '15 at 06:33
  • OP doesn't say he was trying to call his module from another module. Your answer is poor quality. The grammar, typing, explanation, tone, many aspects of the answer are inadequate. If someone else finds the question, the answer isn't useful. – Peter Wood Sep 22 '15 at 07:00
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/90292/discussion-between-csharpcoder-and-peter-wood). – coder3521 Sep 22 '15 at 07:13
  • Okay , tried to correct the grammatical error , If you want to something else to the answer , please go ahead , i will always appreciate that. Currently doesn't have access to chat, will do that , sometimes later . – coder3521 Sep 22 '15 at 07:17