This is a summary of my code:
# import whatever def createFolder(): #someCode var1=Gdrive.createFolder(name) return var1 def main(): #someCode var2=createFolder() return var2 if __name__ == "__main__": print main()
One of the ways I managed to return the value to the bash variable was to print what was returned from main (). Another way is to simply print the variable anywhere in the script.
Is there a way to get it back in a more pythonic way?
The script is called like this:
folder=$(python create_folder.py "string_as_arg")
If you are working in bash, you can simply do:
export var="value"
Python . os.environ, . , .
os.environ
pythonic , bash python.
, bash - bash.
bash
bash python , (IPC) . IPC, bash (, ). bash, bash, , python ( python ).
- . , .
, bash, - stdout , python print. . ( fifo), python write. .
print
write
python bash script. , " " . , : Python
, , . : Python script bash script
sys.exit(), ..:
sys.exit()
import sys [...] if __name__ == "__main__": sys.exit(main())