-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable global functions for multiple questions #34
Comments
Allowing continuity between code blocks involves some complexity. I have an existing system that can manage this (https://github.com/gpoore/codebraid), but connecting that to text2qti will take some time. And I'm unfortunately short on time for the foreseeable future. For now, you might consider putting all your functions and variables in a module (could just be a .py file in the quiz directory), and then import that in each code block. |
@gpoore - I've taken a slightly different approach: I added the current working directory to PYTHONPATH. That seems to work in the sense you can do "from config import *" from a question code and it pulls everything in. You can find proposed modifications here. It has two problems I need to solve:
If you like this approach, I'm happy to fix the above issues and submit a PR so you can do a more careful review. |
@gordonwatts The current working directory for executed code should be the same as the directory of the quiz file. In |
No - that is perfect, I'd not realized there was a Let me know if you are interested in this modification and I'll submit a PR. |
@gordonwatts What differences are you seeing between operating systems? What isn't working that the modification to |
Hmmm... I'm using python environments under windows, and checked out the package and did The problem is the separator for PYTHONPATH. It is ":" on Linux/Mac, and ";" under Windows. I just need to fix that as the current code doesn't take care of that. For me it isn't currently mattering: PYTHONPATH isn't defined in my shell for this. The modification to PYTHONPATH means that you can now do 'import config' in your question text and it will find |
@gordonwatts I should have been more specific about environments. You can run text2qti in an environment, but when text2qti runs Python code from a quiz, under Windows it currently uses the default Python rather than the current environment. If you have been having import issues, this may be the cause. If that's the case, modifying I'll try to get this fix on GitHub in the dev version in the next day or two, and if it doesn't fix everything for you, then we can try to figure out what else |
Ah, I see. I wasn't trying to solve the problem of the environment. That is an interesting point. Instead, the only problem I'm trying to solve is the one in this bug report: I have a special file for this exam that has some common definitions in it. I want to do an "import config" at the top of my question to include it. I'll continue using this hacked version and try yours when you've updated it. If it doesn't solve what I'm trying to do then we can look to see if my changes make sense or another approach is appropriate. |
@gordonwatts The dev version on GitHub should now work with Python environments under Windows. If that doesn't fix the issues you were having, let me know what issues still remain. |
Thanks for the updates!! I'm not teaching the quarter, but I'll try to do the installs in the next few days. |
When I create questions in python, many times I must repeat functions or variables for every questions. Could you create global functions or variables to avoid repeating all the code?
The text was updated successfully, but these errors were encountered: