2015-03-12 3 views
0

Я не мог найти вопрос, соответствующий этой конкретной проблеме; Я пишу автоматический мини-код в Python, но я не могу понять, как пропустить текущую итерацию цикла for.Python: Пропустить интервал между циклами

Вы можете помочь?

Вот сценарий:

import os 
import sys 
try: 
    file_path = sys.argv[1] 
except IndexError: 
    print("No file given") 
    sys.exit() 

minified_file = "" 
dbl_quotes = False 
sgl_quotes = False 
line_comment = False 
multi_line_comment = False 
current_index = 0 

if os.path.isfile(file_path): 
    print('Path: ' + file_path) 
    char_check = "" 
    file_handle = open(file_path) 
    file_content = file_handle.read() 
    for file_char in file_content: 
     if sgl_quotes or dbl_quotes: 
      if file_char == "'" and not dbl_quotes: 
       sgl_quotes = False 
      if file_char == '"' and not sgl_quotes: 
       dbl_quotes = False 
      minified_file += file_char 
      continue 
     else: 
      if file_char == "'": 
       sgl_quotes = True 
       minified_file += file_char 
       continue 
      elif file_char == '"': 
       dbl_quotes = True 
       minified_file += file_char 
       continue 

      if current_index+1 < len(file_content): 
       if file_char == '/' and file_content[current_index+1] == '*': 
        multi_line_comment = True 

    if current_index-1 >= 0: 
     if multi_line_comment == True and file_char == '/' and file_content[current_index-1] == '*': 
      multi_line_comment = False 
      continue 

    if current_index+1 < len(file_content): 
     if file_char == '/' and file_content[current_index+1] == '/' and not line_comment: 
      line_comment = True 
      continue 

    if line_comment: 
     if file_char == '\r' or file_char == '\n': 
      line_comment = False 
      continue 

    if line_comment or multi_line_comment: 
     continue 

    if file_char != '\r' and file_char != '\n' and file_char != '\t': 
     minified_file += file_char 

    current_index += 1 

print(minified_file) 
wait = input("PRESS ENTER TO CONTINUE.") 
+1

'continue' не делает то, что вы ожидали? – Alex

+0

Как вы можете видеть, я использовал 'continue', и он, похоже, не работает. – Stonestorm

+0

Извините, я не собираюсь прокручивать ваши 2 страницы раскованного кода, чтобы найти ошибку. Пожалуйста, уменьшите его до минимального примера, хотя бы потому, что таким образом вы, скорее всего, найдете ошибку самостоятельно. –

ответ

0

Я нашел этот вопрос:

Сниппет:

if current_index+1 < len(file_content): 
    if file_char == '/' and file_content[current_index+1] == '*': 
     multi_line_comment = True 

Была табличной одна вкладка слишком далеко вперед.

Я действительно не ожидаю изучения остальной части Python.

Смежные вопросы