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

  • SEARCH
  • Home
  • 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 7773543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:09:22+00:00 2026-06-01T17:09:22+00:00

Basically I am running mapreduce so I’m going to pipe in to the reducer.

  • 0

Basically I am running mapreduce so I’m going to pipe in to the reducer. What I’m having trouble with is how to specify a directory path which I will use with os.listdir to essentially get to and then compute all the files in that directory alone. But I know I only want what is in the last directory and not the sub-directories on that same level. I may consider also using fileinput().

I think I may be using stdin wrong here, depends on if it has to be from the command line or if it can be indirectly from the command line.

This was my command-line input: “./path1/path2/path3” ./map.py | sort | ./red.py

What I got as an error from doing what I want to do is -bash, not a directory ./pythonfile.py

Using Python 2.7.2

This is what I’m doing:

def func():
    path = sys.argv[0]
    return [filenames for filenames in os.listdir(path)if os.path.isfile(os.path.join(path,filenames))]

if func() is not None: 
   for file in func():
       sys.stdin.read()
       ...etc..
  • 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-06-01T17:09:24+00:00Added an answer on June 1, 2026 at 5:09 pm
    "./path1/path2/path3" ./map.py | sort | ./red.py
    

    That tells bash to execute the program ./path1/path2/path3 with the argument ./map.py. This is almost certainly not what you want to do.

    path = sys.argv[0]
    

    This is the name of the script — the first element of argv[] is, by convention, the name of the program that is being executed. See this:

    $ cat echo.py 
    #!/usr/bin/python
    import sys
    print sys.argv[0]
    $ chmod 755 echo.py
    $ ./echo.py
    ./echo.py
    $ 
    

    Perhaps what you intended to do was echo the string to the script:

    echo path1/path2/path3 | ./map.py | sort | ./red.py
    

    But then you could not use the argv[] array to get at it easily. In fact, it is very difficult to properly parse multiple pathnames from a free-form input like this, so I’d avoid it entirely, and pass the names as arguments:

    ./map.py path1/path2/path3 /a/s/econd/pathname
    

    You could iterate over all paths passed as arguments using something like this:

    >>> a=["nothing", "passwd", "shadow"]
    >>> [f for f in a[1:]]
    ['passwd', 'shadow']
    >>> import os
    >>> [f for f in a[1:] if os.path.isfile(f)]
    ['passwd', 'shadow']
    >>> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm running a loop basically that will make an array that contains a million
I have a long running php script which is basically an infinite loop listening
Basically I am trying to put a button in my app which will warn
I've got a webapp (basically a CMS) running on Apache built with PHP5/MySQL. Which
Basically I have some sort of third party software running on Windows 7 which
I've got a simple tracking app running on Node.JS which basically parses the URL
EDIT: I am basically running into the following documented issue . I am using
I basically have a unix process running and it is doing some heavy processing
I've got a socket server running (it's something that's basically like a chat server).
I have code running in an iPhone application I am developing. Basically, the code

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.