2

I am a super n00b beginner, I have been teaching myself python concepts for the last couple of months using juptyer notebook, and lessons in CFD & similar subjects that I am conceptually familiar with. My background is Mechanical Engineering.

In the lesson below I need to import functions from separate python files for brevity in implementing functions in later blocks of code. I understand this is like using modules? I'm just looking for a conceptual explanation here.

Basically my question is, how do I create my own modules and import them into Jupyter notebook? Do I use a script and save as a py file ? Where do I save it ? What is an interpreter? What is a decent text editor to use? Sorry I'm really beginner to CS concepts, any input would help.

image for block of code in question

jupyter notebook viewer lesson :

http://nbviewer.jupyter.org/github/numerical-mooc/numerical-mooc/blob/master/lessons/03_wave/03_04_MUSCL.ipynb

Code to save as py file and for import :

https://github.com/numerical-mooc/numerical-mooc/blob/master/lessons/03_wave/traffic.py

A thousand thanks & Cheers.

  • Possible duplicate of [Call a function from another file in Python](https://stackoverflow.com/questions/20309456/call-a-function-from-another-file-in-python) – HFBrowning Dec 13 '18 at 21:33
  • 2
    To answer your other questions (please only ask one question per SO question in the future): in Python the interpreter is the python.exe file. It's called an interpreter because it's the program that takes the source code you've written and "interprets" it for the computer. (Note this is an extremely not-technical answer). And questions about suggestions for programs/books/tutorials (like "what is a good text editor") are not considered on-topic on SO. – HFBrowning Dec 13 '18 at 21:36
  • 1
    Thank you much! I'll try to improve the quality of my questions in the very near future, I'm extremely new to this. – Leonardo Parra García Dec 18 '18 at 17:48

1 Answers1

3

I highly recommend Pycharm community edition as a text editor because it shows your file system and makes importing modules easy. For your question about importing functions from other projects if you have the .py file, you want to import the function from in the same directory as the one you want to import it to it should be ok (in pycharm at least) to just write the file name after import like this:

from filename import functionname

if you have any complications feel free to ask!

RedPython
  • 48
  • 5