Python 3.7.3 while 循环条件中带数字的变量
Python 3.7.3 variables with numbers in while loop conditionals
所以我正在尝试使用下面所述的一些简单代码来学习一些 python3。代码的要点是有一个循环,该循环一直运行到其中一个文件存在并包含数据为止。出于某种原因,我得到一个错误 运行 这个,说变量有一个无效的语法,就好像变量中的数字是非法的 (which they arent?):
$ python3 test.py
File "test.py", line 14
While file1==False and file2==False and file3==False:
^
SyntaxError: invalid syntax
代码:
import os
filePath1 = '/some/path'
filePath2 = '/some/path'
filePath3 = '/some/path'
file1 = False
file2 = False
file3 = False
While file1==False and file2==False and file3==False:
if os.path.exists(filePath1):
with open(filePath1,'r') as f:
try:
file1 = f.read()
except:
print("No file data.")
if os.path.exists(filePath2):
with open(filePath2,'r') as f:
try:
file2 = f.read()
except:
print("No file data.")
if os.path.exists(filePath3):
with open(filePath3,'r') as f:
try:
file3 = f.read()
except:
print("No file data.")
我不明白,因为:
>>>file1=False
>>>file2=False
>>>file1==False and file2==False
True
如有任何帮助,我将不胜感激
invalid syntax
是由大写的 While
关键字引起的,python 无法识别。使用保留关键字 while
,仅限小写字母。
所以我正在尝试使用下面所述的一些简单代码来学习一些 python3。代码的要点是有一个循环,该循环一直运行到其中一个文件存在并包含数据为止。出于某种原因,我得到一个错误 运行 这个,说变量有一个无效的语法,就好像变量中的数字是非法的 (which they arent?):
$ python3 test.py
File "test.py", line 14
While file1==False and file2==False and file3==False:
^
SyntaxError: invalid syntax
代码:
import os
filePath1 = '/some/path'
filePath2 = '/some/path'
filePath3 = '/some/path'
file1 = False
file2 = False
file3 = False
While file1==False and file2==False and file3==False:
if os.path.exists(filePath1):
with open(filePath1,'r') as f:
try:
file1 = f.read()
except:
print("No file data.")
if os.path.exists(filePath2):
with open(filePath2,'r') as f:
try:
file2 = f.read()
except:
print("No file data.")
if os.path.exists(filePath3):
with open(filePath3,'r') as f:
try:
file3 = f.read()
except:
print("No file data.")
我不明白,因为:
>>>file1=False
>>>file2=False
>>>file1==False and file2==False
True
如有任何帮助,我将不胜感激
invalid syntax
是由大写的 While
关键字引起的,python 无法识别。使用保留关键字 while
,仅限小写字母。