Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6949735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:59:43+00:00 2026-05-27T13:59:43+00:00

I am really stumped on this one. I have a simple python wrapper which

  • 0

I am really stumped on this one.

I have a simple python wrapper which looks something like this:

import glob

for found in glob.glob(filename):
  if not os.path.isdir(found):
    my_module.do_stuff(found)

where filename has been read in from sys.argv.

When I try glob in an interactive shell, or a hello world script, I get the full list of (in this case 5) files. However, when I use it in this context, I only get the first one (alphabetically).

I’ve checked by catching the result of glob.glob in an array and sure enough, it’s only got a len() of 1, even when the filename is just '*'.

What could I possibly be doing that breaks glob?!

Full code file, just in case you can spot my gotcha:

#! /usr/bin/python
import pynet.quadrons as q
import os, glob

def print_usage():
  print """
    (blah blah big long string.)

  """

if __name__ == "__main__":
  import sys
  if len(sys.argv) < 2:
    print_usage()
    exit()

  filename = ''

  try:
    filename = sys.argv[1]
  except:
    print "error parsing arguments."
    print_usage()
    exit()

  for found in glob.glob(filename):
    if not os.path.isdir(found):
      q.load_and_analyse_file(found)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:59:43+00:00Added an answer on May 27, 2026 at 1:59 pm

    The shell is expanding the glob before your Python script sees it. Therefore your Python script sees the first full filename that matches the glob in sys.argv[1], passes that to glob(), and of course it only matches one file.

    Either quote the argument in the shell with single quotes so that the shell does not expand it, or simply allow the shell to do the expanding and iterate over all items of sys.argv (except the first).

    It’s worthwhile to note that on Windows, the shell doesn’t do globbing, so if your script needs to work cross-platform, you should iterate over sys.argv[1:] and glob each item.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one really has me stumped. I have a documents table which hold info
Really stumped on this one. I have the following PHP file with a variable
This one has really got me stumped. I have certain forms that are being
This one really has me stumped. I have not ran across this problem on
I'm really stumped by this one! The StackFrame object ( MSDN Link ) has
This really has my stumped today. I'm sure its simple, but... Here is my
Really ripping my hair out on this one. I have a JAAS Authentication Provider
One of the things I really like with WPF is the extent to which
Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
So I am really stumped because I have basic ideas but I am looking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.