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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:42:26+00:00 2026-06-15T08:42:26+00:00

I just start learn python, and the code has some error, can’t run. so

  • 0

I just start learn python, and the code has some error, can’t run. so can you help me address it. it shows

File "ex2.py", line 21
if isRobotRecord(line)
                     ^
SyntaxError: invalid syntax

ex2.py

import time
robot_emails = ["googlebot@google.com"]
robot_emails.append("66.249.74.228")
robot_emails.append("61.147.110.22")
robot_emails.append("61.147.110.21")
robot_emails.append("61.147.112.231")
f = open("/opt/CLiMB/Storage1/log/vsftp.log")
def isRobotRecord(line):
    for email in robot_emails:
            if email in line.split("Client")[1]:
                    return False
    return True
def OnlyRecent(line):
    if  time.strptime(line.split("[")[0].strip(),"%a %b %d %H:%M:%S %Y")> time.gmtime(time.time()-(60*60*24*7)):
        return True
    return False
filename= time.strftime('%Y%m%d')+'.log'
f1= open(filename,'w')
for line in f:
    if OnlyRecent(line):
            if isRobotRecord(line)
                    print line
                    f1.write(line)
f.close()
f1.close()
  • 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-15T08:42:28+00:00Added an answer on June 15, 2026 at 8:42 am

    At a minimum, you need a : at the end of that if statement. That’s what’s causing your error, similar to the following transcript:

    pax> cat good.py 
    for plugh in (1,2,3):
        print plugh
    
    pax> python good.py 
    1
    2
    3
    
    pax> cat bad.py 
    for plugh in (1,2,3)
        print plugh
    
    pax> python bad.py 
      File "bad.py", line 1
        for plugh in (1,2,3)
                           ^
    SyntaxError: invalid syntax
    

    You may also want to look into your indentation – it looks like that if statement may be indented one too many times. There are eight spaces difference between it and the previous line despite the fact you appear to be using four most everywhere else.

    In a language where indentation is so important, you have to be particularly careful.

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

Sidebar

Related Questions

Just start to learn Java, and always see some tutorials mentioning, using the javaDoCs
I just start to learn python and web2py. Because of web2py's web interface development,
I just start learning WPF, is that possible I can create an IE toolbar
I just start learning Python + Tornado for my web servers. Every time I
Hi I've been coding a console version of Minesweeper just to learn some of
I'm trying to learn Python with the help of Learning Python the Hard Way.
I am on exercise 43 doing some self-directed work in Learn Python The Hard
The IM program was just an example, but where would I start to learn
I just start learn around Backbone js. In a few minutes I read pretty
I am a beginner to programming when I start to code I just start

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.