该程序应该采用两个名称,如果它们的长度相同,则应检查它们是否是同一个单词.如果它是相同的单词,它将打印"名称相同".如果它们长度相同但字母不同,则会打印"名称不同但长度相同".我遇到问题的部分是在底部4行.
#!/usr/bin/env python
# Enter your code for "What's In (The Length Of) A Name?" here.
name1 = input("Enter name 1: ")
name2 = input("Enter name 2: ")
len(name1)
len(name2)
if len(name1) == len(name2):
if name1 == name2:
print ("The names are the same")
else:
print ("The names are different, but are the same length")
if len(name1) > len(name2):
print ("'{0}' is longer than '{1}'"% name1, name2)
elif len(name1) < len(name2):
print ("'{0}'is longer than '{1}'"% …Run Code Online (Sandbox Code Playgroud) 我为我们的REST API定制了暴风代码,但是当我运行脚本时,在开头使用nosetests会产生一些奇怪的类型错误,如下所述,尽管脚本中的测试用例通过
Traceback (most recent call last):
File "/usr/lib64/python2.6/logging/__init__.py",line 776, in emit msg = self.format(record)
File "/usr/lib64/python2.6/logging/__init__.py", line 654, in format return fmt.format(record)
File "/home/rmcbuild/repository/rmc-test/tempest/openstack/common/log.py", line 516, in format return logging.Formatter.format(self, record)
File "/usr/lib64/python2.6/logging/__init__.py", line 436, in format record.message = record.getMessage()
File "/usr/lib64/python2.6/logging/__init__.py", line 306, in getMessage msg = msg % self.args
TypeError: not all arguments converted during string formatting
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过这种类型的错误,如果有人帮助我,我会很感激.
谢谢,
我正在尝试将变量“log_location”的内容添加到当前记录器。
log_location = log_folder_location + os.path.sep + log_file_name
logger.debug("log location", str(log_location))
print "log_location: ",log_location
Run Code Online (Sandbox Code Playgroud)
这会打印到控制台,但在日志记录中出错,
Traceback (most recent call last):
File "/usr/lib64/python2.6/logging/__init__.py", line 784, in emit
msg = self.format(record)
File "/usr/lib64/python2.6/logging/__init__.py", line 662, in format
return fmt.format(record)
File "/usr/lib64/python2.6/logging/__init__.py", line 444, in format
record.message = record.getMessage()
File "/usr/lib64/python2.6/logging/__init__.py", line 314, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
Run Code Online (Sandbox Code Playgroud)
它打印到,
log_location: /U01/Nova/Logs/DEV-INT/TEST/validation_20170203-164617-5.log
Run Code Online (Sandbox Code Playgroud)
当我尝试正常的 python 提示但在使用 Flask 时面临同样的问题时,不会发生此错误
我已经尝试将Python 标准输出记录到文件...使用活动标准输出(退格/更新) 和类型错误:并非所有参数都在字符串格式化 python 期间转换 …