WordPress database error: [Table './ay6u3nor6dat6ba1/kn6_ayu1n9k4_5_actionscheduler_actions' is marked as crashed and last (automatic?) repair failed]
SELECT a.action_id FROM kn6_ayu1n9k4_5_actionscheduler_actions a WHERE 1=1 AND a.hook='aioseo_send_usage_data' AND a.status IN ('in-progress') ORDER BY a.scheduled_date_gmt ASC LIMIT 0, 1

WordPress database error: [Table './ay6u3nor6dat6ba1/kn6_ayu1n9k4_5_actionscheduler_actions' is marked as crashed and last (automatic?) repair failed]
SELECT a.action_id FROM kn6_ayu1n9k4_5_actionscheduler_actions a WHERE 1=1 AND a.hook='aioseo_send_usage_data' AND a.status IN ('pending') ORDER BY a.scheduled_date_gmt ASC LIMIT 0, 1

opening and reading a file | Loop and Break

opening and reading a file

Consider the following example to open and read file contents

Example

filename = raw_input('Enter file name: ')
file = open(filename, 'r')
allLines = file.readlines()
file.close()
for eachLine in allLines:
    print eachLine

We originally described how this program differs from most standard file access in that all the lines are read ahead of time before any display to the screen occurs. Obviously, this is not advantageous if the file is large. In those cases, it may be a good idea to go back to the tried-and-true way of reading and displaying one line at a time:

Example

filename = raw_input('Enter file name: ')
file = open(filename, 'r')
done = 0
while not done:
    aLine = file.readline()
    if aLine != " ":
        print aLine,
    else:
        done = 1
file.close()

In this example, we do not know when we will reach the end of the file, so we create a Boolean flag done, which is initially set for false. When we reach the end of the file, we will reset this value to true so that the while loop will exit. We change from using readlines()to read all lines to readline(), which reads only a single line. readline() will return a blank line if the end of the file has been reached. Otherwise, the line is displayed to the screen.

Share

You may also like...