i beginner python , programming in general. learning python, tying develop habit or follow practice. let me first explain doing.
i use emacs (prelude) execute python scripts. keybinding c-c
c-c
evaluates buffer contains python script. new buffer python interpreter >>> prompt. in environment variables used in scripts accessible. example, if x
, y
defined in script, can >>> x + y
evaluate it.
i see many people (if not most) around me using command line execute python script (i.e., $ python scriptname.py
). if this, return shell prompt, , not able access variables x
, y
perform x + y
. wasn't sure advantage of running python scripts using command line.
should use emacs editor , use terminal (i using mac) execute script? better practice?
thank you!
people use different tools different purposes.
an important question interface program user? you, programmer, use interpreter test program , check errors. times, user doesn't need access variables inside because not interacting application/script interpreter. example, python web applications, there main.py script redirect client http requests appropriate handlers. these handlers execute python script automatically when client requests it. output displayed user. in python web applications, unless developer trying eliminate bug in program, don't care accessing variables within file main.py (in fact, giving client access variables pose security issue in cases). since need output of script, you'd execute script function in command line , display result client.
about best practices: again, depends on doing.
using python interpreter computation okay smaller testing of isolated functions doesn't work larger projects there more moving parts in python script. if have python script reaching few hundred lines, won't remember or need remember variable names. in case, it's better execute script in command-line, since don't need access internal components.
you want create new script file if fashioning script single set of tasks. example handlers example above, functions in main.py geared towards handling http requests. defining x, defining y, , adding it, don't need own file since aren't creating function might need in future , adding 2 numbers built-in method. however, have bunch of functions you've created aren't available in built-in method (complicated example: softmax function reduce k dimension vector k dimension vector every element value between 0 , 1 , elements sum 1), want capture in script file , cite script's procedure later. in case, you'd create own script file , cite in different python script execute.
Comments
Post a Comment