473,385 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

os.access with wildcards

i'd like to use

os.access(path,mode)

where path may contain linux style wildcards.
i've failed so far.
my workaround is the bash command.

os.system('[ -e %s ]' % fn )

any suggestions?

Oct 7 '05 #1
17 2862
mike wrote:
i'd like to use

os.access(path,mode)

where path may contain linux style wildcards.


os.access(glob.glob(path), mode)
Oct 7 '05 #2
thanks Leif. poor question on my part.

I had been using

glob.glob(path)==[]

and was looking for something more readable, hence

os.system('[ -e %s ]' % path )

but that doesn't seem like a good idiom for crossplatform.

I thought there may either be a way to escape the wildcards, or an
alternative to os.access, or ....

any othr ideas?

Oct 7 '05 #3
thanks Leif. poor question on my part.

I had been using

glob.glob(path)==[]

and was looking for something more readable, hence

os.system('[ -e %s ]' % path )

but that doesn't seem like a good idiom for crossplatform.

I thought there may either be a way to escape the wildcards, or an
alternative to os.access, or ....

any other ideas?

Oct 7 '05 #4
Leif K-Brooks wrote:
os.access(path,mode)

where path may contain linux style wildcards.


os.access(glob.glob(path), mode)


Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: access() argument 1 must be string, not list

it's not clear from the OP if he wants

[os.access(file, mode) for file in glob.glob(path))]

os.access(glob.glob(path)[0], mode)

or, most likely, simply

if glob.glob(path):
... some matching file exists ...

</F>

Oct 7 '05 #5
Test for the existence of one or more matches of the wildcard
expression.

For example:

Are there any files that begin with 2005?

This doesn't work (wish it did):

os.access('2005*',os.F_OK)

However, these work arounds do the job:

glob.glob('2005*')==[]

as does this bash command:

os.system('[ -e %s ]' % path )

The 1st is not very readable and the 2nd has portability issues.

Oct 7 '05 #6
Test for the existence of one or more matches of the wildcard
expression.

For example:

Are there any files that begin with 2005?

This doesn't work (wish it did):

os.access('2005*',os.F_OK)

However, these work arounds do the job:

glob.glob('2005*')==[]

as does this bash command:

os.system('[ -e 2005* ]' )

The 1st is not very readable and the 2nd has portability issues.

Oct 7 '05 #7
"mike" wrote:
Test for the existence of one or more matches of the wildcard
expression.


why are you reposting variations of your question (in duplicates)
instead of reading the replies? that's not a good way to pass the
turing test.

</F>

Oct 7 '05 #8
dude, you are the sap that wrote "it's not clear". get a life.

Oct 7 '05 #9
"mike" wrote:
dude, you are the sap that wrote "it's not clear".
followed by three possible solutions to the stated problem, one
of which was marked as "most likely".
get a life.


oh, sorry for wasting my time. can I *plonk* you now?

</F>

Oct 7 '05 #10
No need to apologize for continuing to waste your
time, self.plonk. Get a life, though, and you'll be happier.

As to your question, well, not before you apologize for
thread crapping.

As for your possible solutions, if you consider any
of yours to be "readable", then i have no interest in
coding with you.

And for

if glob.glob(path):

I had already posted that work around.

Oct 7 '05 #11
"mike" <no******************@gmail.com> writes:
Test for the existence of one or more matches of the wildcard
expression.

For example:

Are there any files that begin with 2005?

This doesn't work (wish it did):
os.access('2005*',os.F_OK)
I would considering it suprising if it worked. os.access is for
testing access permissions of a single file. There's no reasonn for it
to do glob expansion on the name, as there can be only one such
name. Maybe if it took multiple names, but then you have to decide if
you're going to return the "or" or the "and" of the results of the
test. Or - more - likely - provide an optional argument to specify the
operation.

This is getting ugly. Best just leave it as it is.
However, these work arounds do the job:
glob.glob('2005*')==[] [Not very readable.]


Yup. A standard idiom in most languages for testing for a list to be
empty is to check the length of the list:

len(glob.glob('2005*')) == 0

Which I'd say is more readable. In Python, an empty list is false, so
you can skip the test completely, and just ask for the boolean
negation of the list:

not glob.glob('2005*')

I'd probably do it that way.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Oct 7 '05 #12
Thanks Mike. Would there be an idiom using "is"?
somethng like

glob.glob('2005*) is not Empty

I have not figured out what to put on the right hand
side of "is"

I guess, for readability, nothing has come up that
seems _great_. One last effort would be to hide
the code behind a method, and use something
readable to name the method.

Thanks also for the link to amaya. The compile is
running now :)

Oct 7 '05 #13
On 7 Oct 2005 16:17:22 -0700,
"mike" <no******************@gmail.com> wrote:
Thanks Mike. Would there be an idiom using "is"?
somethng like glob.glob('2005*) is not Empty I have not figured out what to put on the right hand
side of "is"


Don't put anything there:

if glob.glob('2005*'):
print 'there is at least one matching file'
else:
print 'there are no matching files'

Regards,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Oct 8 '05 #14
Hi Dan,

It works, it's elegant, and it uses python strengths.

I guess I have to settle the question of who my audience is. That is
who do I want to make it readable for.

All the solutions so far require some python specific knowledge, and
there are some which are horendous even at that. Perhaps less
dependency in this reagrd, the better. Perhaps not.

Oct 8 '05 #15
> > if glob.glob(...): ...

As for your possible solutions, if you consider any
of yours to be "readable", then i have no interest in
coding with you.

if glob.glob(...): ...


I guess, for readability, nothing has come up that
seems _great_.

if glob.glob(...): ...


It works, it's elegant, and it uses python strengths.


cute. I guess this thread shows that python can grow on you.

</F>

Oct 8 '05 #16
ugly. i guess this thread shows that you are clueless regarding your
thread crapping.

Oct 8 '05 #17
########################
########################
########################
########################
########################

os.path.exists()

########################
########################
########################
########################
########################

Oct 17 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mats | last post by:
It's good practice to validate input, not only where it should be coming from, but from anywhere it's possible to change or add input for a "client". If all user input is transfered using "post"...
3
by: soup_or_power | last post by:
The browser shows the alert but causes an error "access denied" and fails to set the upload.value to null. Please help! for(var i=0; i < fileName.length;i++) { if (fileName.charAt( i) ==' ' ||...
11
by: Randy Weber | last post by:
I am getting unexpected results with a Like Query using ASP and an Access database. This query - SELECT PN, Qty From Inventory Where PN Like 'SSW-10%'; returns what I expect: PN ...
2
by: Alex | last post by:
Hi all, I'm trying a very simple Like statement in MS Access XP, but it's acting strange. I've always used a percent (%) for wildcards in MS SQL, and I thought this was the same in MS Access......
10
by: Alvaro Puente | last post by:
Hi all! Do any of you know if wildcards are accepted when calling rename() function? Thanks/Alvaro
0
by: aviklund | last post by:
Hi, I made a simple data access page with a search button that does work properly, but now I would like to add a filtering to the command button also. Ideal solution would be like this: ...
2
by: Anthony Bollinger | last post by:
I don't know if this is the best group to ask this question, so redirect me if necessary. I have a valid query that uses the LIKE operator. I know it is valid because it works directly in Access....
1
by: jwebber | last post by:
I have a database in MS Access for a community calendar. It has a dropdown list from which to select a particular type of event, Art, Music, etc. The list works correctly for displaying the...
5
by: nidaar | last post by:
From a security point of view, is accepting wildcards like "%" in input parameters of stored procedures against any best practices? As an example, if a user defined function uses "Productname...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.