-
Notifications
You must be signed in to change notification settings - Fork 13
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
Keep/drop/update PYTHONPATH page? #4
Comments
+1 to drop it |
I seem to remember having the same reluctance when I wrote that section originally - but - have you got a better suggestion for an easy-to-explain way of putting some Python code on the Python path? I wonder whether we could start with PYTHONPATH, as here, because it is very easy to explain, then later move to say something like a tiny Python package with |
Yes, creating the files in the current working directory. I see |
Well - the problem there is that they always have to work in the same working directory to find their code. The problem gets obscured often if you use notebooks all the time, because you get used to not refactoring your code out into functions, but that's partly what I was trying to avoid here. I see PYTHONPATH as a primitive way of doing the job - but it's quite a good way of helping people to think about what's going on - that the package directories need to by on the Python Of PYTHONPATH, being primitive, is not the right way to do this when you've got started, but I think we can cover that. |
Honestly, IMHO it is a deviation from the course's focus that is definitely not worth the pain:
Talking about this without a single example where we have to run three mortal twists in the background to avoid having students playing with PYTHONPATH seems unnecessary to me. |
Absolutely - if they were always going to be working in the notebook, and we didn't worry to much about helping them not work in the notebook, then there would be little point in discussing stuff like packages and paths ... Of course - that is the stuff you see, mainly, in the current book, but even early on I focus on getting them to write tests and put functions into modules. Then their projects are to write code in modules and scripts to do outlier detection, and then, analyze an OpenFMRI study ... |
In that case, I'd give them some stub structure of Python files and tell them where to write their stuff. To me, it is more important to teach the logic of how you better structure code (in general). Then, making it digestible by the Python interpreter (in particular) comes naturally (and yes, then you may indicate someone at a given instance that modifying the PYTHONPATH is the fastest way - but I would avoid making it part of the general discourse of your teaching materials). |
Would the following do most of what people need to just get boostrapped? It would limit you to importing local (presumably related) code and not infect environments. import sys
import os
# Enable importing from the local directory until I turn this into a proper module
sys.path.insert(0, os.path.dirname(__file__)) The worry I have is that I write something like:
And then later I make a package |
Yes, that's not a bad idea (the |
In my experience, modifying the
PYTHONPATH
only leads to headaches, so I would be disinclined to encourage people to use it. On the other hand, it could be useful to know about for debugging messy environments.The text was updated successfully, but these errors were encountered: