变量传递给外部程序 - 如何? [英] Variable passing to external program - How??
问题描述
好的,首先请耐心等待我,因为我是一个完整的Python n00b ..
任何人都可以解释为什么这样做不喜欢我在
os.system调用中使用%FileLoc ???
#!/ usr / bin / python
import sys
import os
#检查文件夹是否可访问和可写
FileLoc = os.path.exists(''/ home / rigga'')
if(FileLoc):
print"文件位置存在:"
AccFlag = os.access(' '%FileLoc'',os.R_OK | os.X_OK | os.W_OK)
if(AccFlag):
print"您可以完全访问该位置
else:
print" **错误 - 您无法访问该位置**"
else:
print"找不到文件退出...
sys.exit()
我有完全访问权限到我正在检查的文件夹但是它总是返回没有找到的
文件(FileLoc = 0)但是如果我指定的话我要测试的文件夹
os.system调用它工作正常...
任何帮助赞赏
Cheerz
Rigga
Rigga写道:
< blockquote class =post_quotes>
好的,首先请耐心等待,因为我是一个完整的Python n00b ..
好的,但是:帖子'的主题与你的代码无关;并且
你的文字也没有 - 你一直在谈论一个os.system
来电,那就是不存在。所以,noob或不,我不知所措。
有谁能解释为什么这不喜欢我在
os.system调用中使用%FileLoc ???
以下代码中没有os.system调用。
#!/ usr / bin / python
import sys
import os
#检查文件夹是否可访问和写入
FileLoc = os.path.exists(''/ home / rigga'')
if(FileLoc):
print 文件位置存在:
AccFlag = os.access(''%FileLoc'',os.R_OK | os.X_OK | os.W_OK)
你''重新检查一个名为''%FileLoc''的文件,该文件不存在。此时
变量FileLoc值得为True,所以你不可能想要
来将它传递给外部程序。根据主题,要么。
我可以完全访问我正在检查的文件夹但它总是返回
没有找到文件(FileLoc = 0)但是如果我指定了我想要的文件夹<在os.system调用中测试它工作正常...
上面的任何地方都没有os.system调用。
Alex
> FileLoc = os.path.exists(''/ home / rigga'')
这会产生真或假,具体取决于是否存在/ home / rigga>
我现在在猜,但你想要的是这个:
FileLoc =" / home / rigga"
if os .path.exists(FileLoc):
....
if(FileLoc):
print"文件位置存在:"
AccFlag = os.access(''%FileLoc'',os.R_OK | os.X_OK | os.W_OK)
再次猜测 - 你想检查你的烫发在你的FileLoc上 - 所以
为什么你不把它传递给函数?
AccFlag = os.access(FileLoc,os.R_OK | os。 X_OK | os.W_OK)
%运算符与C / PHP / Whatever中的printf类似。如果你绝对想要它,那么这将是有效的:
print"%s" %FileLoc
" / home / rigga"
-
Diez
> #!/ usr / bin / pythonimport sys
import os
#检查文件夹是否可访问和可写
FileLoc = os.path.exists(' '/ home / rigga'')
if(FileLoc):
print"文件位置存在:"
AccFlag = os.access(''%FileLoc'',os.R_OK | os.X_OK | os.W_OK)
if(AccFlag):
print"您可以完全访问该位置
否则:
print" **错误 - 您无权访问该位置**
else:
print未找到任何文件退出...
sys.exit()
导入os
FileLoc =''/ home / rigga''
如果是os.path。 exists(FileLoc):
print" File location exists"
AccFlag = os.access(FileLoc,os.R_OK | os.X_OK | os.W_OK)
if AccFlag:
print"您可以完全访问该位置"
else:
print" **错误 - 您无法访问该位置**"
else:
打印未找到任何文件退出...
Hi,
Ok first please bear with me as I am a total Python n00b..
Can anyone explain why this does not like me using % FileLoc in the
os.system call???
#!/usr/bin/python
import sys
import os
# Check that the folder is accessible and writeable
FileLoc = os.path.exists(''/home/rigga'')
if (FileLoc):
print "File location exists:"
AccFlag = os.access(''% FileLoc'',os.R_OK | os.X_OK | os.W_OK)
if (AccFlag):
print "You have FULL access to the location"
else:
print "**Error - You do not have access to the location**"
else:
print "No files found exiting..."
sys.exit()
I have full access to the folder I am checking however it always returns no
files found (FileLoc = 0) however if I specify the folder I want to test in
the os.system call it works fine...
Any help appreciated
Cheerz
Rigga
Rigga wrote:
Hi,
Ok first please bear with me as I am a total Python n00b..
OK, but: the post''s subject bears no relation to your code; and
neither does your text -- you keep talking about an os.system
call that just isn''t there. So, "noob" or not, I''m nonplussed.
Can anyone explain why this does not like me using % FileLoc in the
os.system call???
There is no os.system call in the following code.
#!/usr/bin/python
import sys
import os
# Check that the folder is accessible and writeable
FileLoc = os.path.exists(''/home/rigga'')
if (FileLoc):
print "File location exists:"
AccFlag = os.access(''% FileLoc'',os.R_OK | os.X_OK | os.W_OK)
You''re checking for a file called ''% FileLoc'', which does not exist. The
variable FileLoc at this point is worth True, so you can''t possibly want
to "pass it to an external program" as per subject, either.
I have full access to the folder I am checking however it always returns
no files found (FileLoc = 0) however if I specify the folder I want to
test in the os.system call it works fine...
There is no os.system call anywhere in the above.
Alex
> FileLoc = os.path.exists(''/home/rigga'')
This yields true or false, depending on the existence of "/home/rigga"
I''m guessing now, but what you want is this:
FileLoc = "/home/rigga"
if os.path.exists(FileLoc):
....
if (FileLoc):
print "File location exists:"
AccFlag = os.access(''% FileLoc'',os.R_OK | os.X_OK | os.W_OK)
Guessing again - you want to check your perms on that FileLoc of yours - so
why don''t you just pass it into the function?
AccFlag = os.access(FileLoc,os.R_OK | os.X_OK | os.W_OK)
The % operator works similar to printf in C/PHP/Whatever. If you absolutely
want it here, this would work:
print "%s" % FileLoc
"/home/rigga"
--
Diez
> #!/usr/bin/pythonimport sys
import os
# Check that the folder is accessible and writeable
FileLoc = os.path.exists(''/home/rigga'')
if (FileLoc):
print "File location exists:"
AccFlag = os.access(''% FileLoc'',os.R_OK | os.X_OK | os.W_OK)
if (AccFlag):
print "You have FULL access to the location"
else:
print "**Error - You do not have access to the location**"
else:
print "No files found exiting..."
sys.exit()
import os
FileLoc = ''/home/rigga''
if os.path.exists(FileLoc):
print "File location exists"
AccFlag = os.access(FileLoc, os.R_OK | os.X_OK | os.W_OK)
if AccFlag:
print "You have FULL access to the location"
else:
print "**Error - You do not have access to the location**"
else:
print "No files found exiting..."
这篇关于变量传递给外部程序 - 如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!