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 6179437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:39:46+00:00 2026-05-24T00:39:46+00:00

If I use filename = argv[n] from a windows command line, the extract() function

  • 0

If I use filename = argv[n] from a windows command line, the extract() function below seems to work okay. If I instead use the list of files names from the list(dir), which uses the os.listdir() built-in function to extract the filenames from the working directory, then the extract() function fails.

The input_file.read() recognises the filename as a valid value, but it seems to fail at date = list(date_match[0]) with ‘TypeError: coercing to Unicode: need string or buffer, tuple found’.

It seems that the os.listdir output list values are not normal strings, but something else instead. Any ideas?

import sys
import re
import os

def extract(filename):

    input_file = open(filename, 'r')
    data = input_file.read() #read file line by line

    #make list of time and date
    date_match = re.findall(r'(\d+:\d+)\t(\d+/\d+/\d+)', data) #find file date and time
    date = list(date_match[0])

    #extract date tuple from list above
    return date

def list(dir):
    directoryfiles = os.listdir(dir)
    diroutput = []
    for member in directoryfiles:
        if member != sys.argv[0]:
            diroutput.append(member)
    return diroutput

def main():

    inputfiles = list(sys.argv[1])

    for filename in inputfiles:
        date = extract(filename)

if __name__ == '__main__':
    main()
  • 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-24T00:39:48+00:00Added an answer on May 24, 2026 at 12:39 am

    You’ve redefined list! When you try to do date = list(date_match[0]), you’re calling your list function, not the builtin list function. Rename the list function and it should work fine.

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

Sidebar

Related Questions

I'm trying to use optparse to parse command line arguments. I would like my
I use the present command to submit MPI jobs: mpirun -np no.of processors filename
I use OpenFileDialog class, to open and display a filename chosen. List<string> paths; private
I want to escape a DOS filename so I can use it with sed.
Can I use a query in MSSQL to get the .mdf and .ldf filename/location
We use a data acquisition card to take readings from a device that increases
I use rsync to synchronize files to Windows clients in a server agnostic way.
I use the VS2008 command prompt for builds, TFS access etc. and the cygwin
// stream from file. ifstream file; int main (int argc, char * argv[]) {
I have experienced a strange problem in windows vista and above. When I use

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.