python 3.x - Making and pre-shebanging scripts, running into unwanted effect -


i'm sure downvoted poor title, first question.

i'm writing program automate creation of python script, option create in own folder. pseudocode looks follows: -get file name use -get user's choice folder creation -make sure current working directory 1 script running in (for measure) -if user wants folder made, mkdir same name file made , cd it. -make file requested name, chmod +x it, , insert shebang line.

actual code looks this.

#!/usr/bin/python3 import os import stat import sys filename=sys.argv[1] makefolder=bool(sys.argv[2])   #this might error occurs? def makeexec(fname):     f=open(fname,'w+')     f.write("#!/usr/bin/python3")     f.close()     st=os.stat(fname)     os.chmod(fname,st.st_mode|stat.s_ixusr|stat.s_ixgrp|stat.s_ixoth) os.chdir('/home/pi/programs')                  #^^^ chmod +x if makefolder:     os.mkdir(filename)     os.chdir('./'+filename) makeexec(filename) 

the code called terminal follows:

./pymake examplescript 1 

1, 0, true, or false can inserted in second argument. true makes folder, false not. problem code make folder regardless of user's choice.

edit: solved. did not know how bool() works, , no meaningful input, bool assigned true.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -