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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:39:32+00:00 2026-05-28T03:39:32+00:00

I am a newbie in Python, and I only have been programming in the

  • 0

I am a newbie in Python, and I only have been programming in the language for the third day. I convert from Matlab because I am graduating from university and I just cannot afford the heavy cost of the software.

I am trying to add several filenames to a list, which fails. The following is my code:

    import os
    dirname = r"D:\MyFiles"
    temp = os.listdir(dirname)
    fl = []
    for fn in temp:
        if fn.startswith('L0116'):
            fl = fl.append(fn)

What I don’t understand is, the variable fl when initiated with [] returns as the list type, but then I fail to append the list with the above loop. I recheck my code using interactive prompt and I found out that the type changes to str and fails to append more.

I am stuck at this and I tried to google for about an hour without any clear clue to how I should do this.

Is there a better way? Or which part did I do it wrong?

Thank you so much for your help!

  • 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-28T03:39:33+00:00Added an answer on May 28, 2026 at 3:39 am

    The append() method mutates the list in place. You should just append fn like this:

    fl.append(fn)
    

    don’t try to assign the result of fl.append(fn) (which is None, by the way)

    Also, don’t use r"foo" strings for filenames. They are designed for use with regular expressions and using them for filenames or other kinds of strings will bite you. For example, you cannot end such a string with a backslash.

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

Sidebar

Related Questions

Newbie Python question. I have a class that inherits from several classes, and some
I'm a newbie to python and the app engine. I have this code that
I am a newbie to Python and have come across the following example in
I am learning Python and building my first web app. I have been going
I'm a python newbie so I apologize in advance if this question has been
i'm newbie for python programming, i'm having a .py file, now what shall i
I am a Python newbie coming from a C++ background. While I know it's
I'm not a newbie since I've been programming on and off since 1983, but
Newbie to Python, so this may seem silly. I have two dicts: default =
Newbie in Python need help! I have a file with a structure: [timestamp] [level]

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.