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_O K | 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 10 2532
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_O K | 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_O K | 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(FileL oc,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/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_O K | 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(FileL oc, 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..."
Alex Martelli wrote: 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_O K | 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
Alex, point taken I rushed when I was doing this and made many mistakes,
thatll learn me not to rush a post!.
To all the others that replied thanks for your input it has helped me a lot.
What I was going to add to the original post but forgot was how you pass
variables to external programs - hence the title. I have been reading
though the Python Bible however all this variable passing doesnt appear to
work as I would expect i.e.
FilePath = os.path('/home/rigga')
AccFlag = os.access('% FilePath',os.R_ OK)
I would expect % FilePath to contain /home/rigga and for os.access to parse
% FilePath in to that and return the results.... however it doesnt, it only
works if I specify the directory in os.access...
Or am I just being stupid?
Cheerz
Rigga
On Sat, 11 Oct 2003 15:50:29 +0000, Rigga <Ri***@noemail. com> wrote: FilePath = os.path('/home/rigga') AccFlag = os.access('% FilePath',os.R_ OK)
I would expect % FilePath to contain /home/rigga
Why would you expect that?
--
Christopher
Christopher Koppler wrote: On Sat, 11 Oct 2003 15:50:29 +0000, Rigga <Ri***@noemail. com> wrote:
FilePath = os.path('/home/rigga') AccFlag = os.access('% FilePath',os.R_ OK)
I would expect % FilePath to contain /home/rigga
Why would you expect that?
-- Christopher
because Ive assigned it using the FilePath = os.path('/home/rigga') -
surely therefore FilePath contains the value /home/rigga???????
On Sat, 11 Oct 2003 16:08:46 +0000, Rigga <Ri***@noemail. com> wrote: Christopher Koppler wrote:
On Sat, 11 Oct 2003 15:50:29 +0000, Rigga <Ri***@noemail. com> wrote:
FilePath = os.path('/home/rigga') AccFlag = os.access('% FilePath',os.R_ OK)
I would expect % FilePath to contain /home/rigga
Why would you expect that?
because Ive assigned it using the FilePath = os.path('/home/rigga') - surely therefore FilePath contains the value /home/rigga???????
Yes, but what do you think that '% FilePath' means? This is an
ordinary string, and does not magically expand to the variable's
contents, which I assume you wanted. You need to use just the variable
name for that:
AccFlag = os.access(FileP ath, os.R_OK)
If you wanted to use the % operator for strings, you could also write
that as
AccFlag = os.access('%s' % FilePath, os.R_OK)
which is completely unnecessary in this case, however.
--
Christopher
On Sat, 11 Oct 2003 15:22:36 GMT, Christopher Koppler
<kl******@chell o.at> wrote: On Sat, 11 Oct 2003 16:08:46 +0000, Rigga <Ri***@noemail. com> wrote:
Christopher Koppler wrote:
On Sat, 11 Oct 2003 15:50:29 +0000, Rigga <Ri***@noemail. com> wrote:
FilePath = os.path('/home/rigga') AccFlag = os.access('% FilePath',os.R_ OK)
I would expect % FilePath to contain /home/rigga
Why would you expect that?
because Ive assigned it using the FilePath = os.path('/home/rigga') - surely therefore FilePath contains the value /home/rigga???????
Yes, but what do you think that '% FilePath' means? This is an ordinary string, and does not magically expand to the variable's contents, which I assume you wanted. You need to use just the variable name for that:
AccFlag = os.access(FileP ath, os.R_OK)
If you wanted to use the % operator for strings, you could also write that as
AccFlag = os.access('%s' % FilePath, os.R_OK)
which is completely unnecessary in this case, however.
And also, I completely overlooked:
FilePath = os.path('/home/rigga') will not work either, because
os.path is a _module_ (which is not callable), not a function to
create paths. Pathnames are just strings, so
FilePath = '/home/rigga'
is what you want.
--
Christopher
Following is yet another version for checking file access
that takes the file_path as an argument to the module,
and differentiates R,E,W or NO access ....
'''
Module ....... os_file_access. py
NewsGroup .... comp.lang.pytho n
Date ......... 2003-10-10
Posted_By .... rigga
Edited_By .... Stanley C. Kitching
'''
import os
import sys
NL = '\n'
SP = ' '
SP3 = SP * 3
SP7 = SP * 7
module_this = sys.argv[ 0 ]
print '%s %s ' % ( NL , module_this ) , NL
if len( sys.argv ) < 2 :
print SP7 , 'Usage : python os_file_access. py file_path' , NL
sys.exit( -1 )
file_path = sys.argv[ 1 ] # Input File Path as 1st Argument
if os.path.exists( file_path ) :
print SP7 , "File Path Exists ...." , file_path , NL
read_flag = os.access( file_path , os.R_OK )
exec_flag = os.access( file_path , os.X_OK )
write_flag = os.access( file_path , os.W_OK )
else :
print SP7 , "*** File NOT Found ***" , NL
print SP7 , SP3 , file_path , NL
sys.exit( -2 )
list_access = []
if read_flag : list_access.app end( 'Read' )
if exec_flag : list_access.app end( 'Execute' )
if write_flag : list_access.app end( 'Write' )
if ( read_flag | exec_flag | write_flag ) :
str_access = ' , '.join( list_access )
else :
str_access = 'NO'
print SP7 , 'You have [ %s ] Access to the File' % ( str_access ) , NL
--
Cousin Stanley
Human Being
Phoenix, Arizona This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rigga |
last post by:
Hi
I would like to pass a variable to an external program i.e.
os.system('cd $variable')
However this doesnt work, I cant figure it out, any ideas?
Cheers
|
by: MC |
last post by:
Hi to all,
I would like to use in a XSL stylesheet an array variable which is
defined in a Java program.
For example, in my program, i defined a tab variable
String tab = {"first", "second", "third"};
which i pass to the XSLT processor like this :
transform.setParameter("tab", tab);
|
by: Cathie |
last post by:
Hi All,
I am trying to get my style sheet to work. It works fine in IE but I can't
get it to work in .net.
Below is the function I use for transforming, where advancedOptionsFile is
the path to the file containing an XML document required by the
transformation, and xmlSimplified is the XML document to trasform.
----------------------------------------------------------------------------
-------------------------------
|
by: Rich |
last post by:
I want to run an external program using os.system() but I want to
include a variable in the middle of the command line.
An example of the type of thing I want to be able to do:
pathname = os.path.dirname(sys.argv)
os.system('cscript /nologo ' + pathname + '\test.vbs')
When I run this, everything after pathname + seems to be ignored. Is
this just incorrect syntax or am I trying to do something fundamentally
wrong? Is there a better...
|
by: Roman Mashak |
last post by:
Hello,
I have a small piece of code, compiled by two 'gcc' and 'borland builder
compiler'. The latter one produces warnings:
Public symbol '_freq' defined in both module
C:\WRK\ISDB-T\XML\PROBE_XML.OBJ and C:\WRK\ISDB-T\XML\XML.OBJ
Public symbol '_power' defined in both module
C:\WRK\ISDB-T\XML\PROBE_XML.OBJ and C:\WRK\ISDB-T\XML\XML.OBJ
| |
by: istillshine |
last post by:
When I control if I print messages, I usually use a global variable
"int silent". When I set "-silent" flag in my command line
parameters, I set silent = 1 in my main.c.
I have many functions that may print some messages.
foo(...)
{
if (!silent)
|
by: whirlwindkevin |
last post by:
I saw a program source code in which a variable is defined in a header
file and that header file is included in 2 different C files.When i
compile and link the files no error is being thrown.How is this
possible.I thought it will throw "Variable redefinition Error". Giving
the source code for reference.Please help me out on this...
a.h
-----
int g;
void fun(void);
|
by: Jaco Naude |
last post by:
Hi,
I'm using a static library in my application which links fine except
for a few global variables. The static library only contains a bunch
of .cpp and .h files and the global variables are defined as follows:
extern unsigned mgl_numg, mgl_cur;
extern float mgl_fact;
extern long mgl_gen_fnt;
extern short mgl_buf_fnt;
|
by: Christian Meier |
last post by:
Hello NG
I have the following code:
file1.h:
static const int iValue = 5;
<EOF>
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |