how to properly pass literal strings python code to be excuted using python -c -


i need figuring out how execute python code python -c have trouble formatting python execute app in cmd understand there maybe other ways doing limited final execution using cmd python -c please keep in mind.

so have python code ie,

import os import shutil  mypath =r"c:\dingdongz" root, dirs, files in os.walk(mypath):     file in files:         os.remove(os.path(root, file))     dir in dirs:         shutil.rmtree(os.path.join(root,dir)) 

but trying excute using following method, python -c "print 'hotdogs'"

so have no worky

cmdline = "\" import os, shutil \n root, dirs, files in os.walk("+mypath+"):\n \t file in files: \n \t \t os.remove(os.path.join(root, file)) \n \t dir in dirs: \n \t\t shutil.rmtree(os.path.join(root, dir))"   windows cmd python -c "+ cmdline +'"' 

if really need 1 line hack (this totally not suggested or condoned) can this

python -c "import os; import shutil; root, dirs, files in os.walk('+mypath+'): file in files: os.remove(os.path.join(root, file)); dir in dirs: shutil.rmtree(os.path.join(root, dir))" 

but should make script inside windows path, can

python myfancyscript.py 

which seems lot nicer right?


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -