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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:19:31+00:00 2026-05-22T23:19:31+00:00

For the last half hour I’ve been trying to figure out what is wrong

  • 0

For the last half hour I’ve been trying to figure out what is wrong with this code. It should be very straight forward. I’ve practically copied it out of the documentation at this point. But no matter what I try I receive a syntax error.

Here’s the code:

def addfiles(folder):
    foldercont = [os.path.normcase(f) for f in os.listdir(folder)]
    for x in foldercont:
        if os.path.isfile(x) == True:
            files.append(os.path.realpath(x)
        if os.path.isdir(x) == True:
            addfiles(os.path.realpath(x))

Whenever I run this, i receive the error

 if os.path.isdir(x) == True:
                           ^
 SyntaxError: invalid syntax

However, if I write the equivlent code in the interactive interpreter it runs fine.

Can this method simply not be used in an if loop or something?

Thanks for the help. I’m getting really frustrated at this point… heh.

  • 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-22T23:19:31+00:00Added an answer on May 22, 2026 at 11:19 pm

    There’s a parenthesis missing at this line:

    files.append(os.path.realpath(x)
                                    ^
    

    Python complains about the True: bit because it’s expecting a statement like

    (x if condition else y)
    

    As jcomeau_ictx says, you should also leave out the == True when checking for booleans:

    if x:
        do_something
    if not y:
        do_something_else
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading about this for the last half hour, and here's what I
So this has been making me go bonkers for the last half hour. Is
For the last hour and a half I've trace Javascript calls in a Magento
Last time I asked about the reverse process , and got some very efficient
Last week we released Omniture's analytics code onto a large volume of web sites
I feel that it should be something very simple and obvious but just stuck
I'm looking at this code and thinking I can't see the error because there
I have an Android project developed on Eclipse (GNU/Linux) that I last touched half
I have been using zend studio 5.5.1 for the last year and and a
This question is not a homework, it is just out of personal interest and

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.