python - Using a stat with a variable -


i writing script checks octal permissions of files , folders in linux. struggling line of code:

stat -c %a check 

check raw input user, example /home. when run script in terminal following error message when line above executed:

file "check.py", line 17 stat -c %a check                ^ syntaxerror: invalid syntax 

i tried putting check in brackets , got:

traceback (most recent call last):   file "check.py", line 34, in <module> main()   file "check.py", line 31, in main     folderexists(check)   file "check.py", line 17, in folderexists     stat -c %a (check) nameerror: global name 'c' not defined 

that line should executed in terminal, not in python script. contains invalid python syntax.

if want issue system command python, can use os.system:

import os os.system('stat -c %a check') 

if need add values command string, use str.format:

import os os.system('stat -c {} check'.format(value)) 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -