Being a regular R user, I organize my script in a way that script will be run into a master script, say script.R
source("01_step_one.R")
source("02_step_two.R")
Learning python now, wonder if I can do similar in Python, I know the import command to import the function from one script to another, but how about source?
asked Jun 17, 2013 at 5:55
lokheart
24.9k40 gold badges108 silver badges175 bronze badges
1 Answer 1
Source call is good with simple intepreting languages, python has namespaces and imports, so why not use it. A good practice is to use such a scheme:
# example.py
def main():
main logic here...
if __name__ == "__main__":
main()
This allows you to run the script from a command line (the if name part), or just import the script in another script and run main(), i.e.
import example
example.main()
answered Jun 17, 2013 at 6:30
Darek
2,8964 gold badges30 silver badges52 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
tracebackto see which part of the script is having an issue. Of course I can skip the "spliting" and do my coding within one big py file, but it seems unorganized sometimes to me.