[英]What is the best code practice in this case?
I am browsing directory where i saved logs , i am using tmpdir pytest fixture : so which one of the two examples is better written : example 1 :我正在浏览我保存日志的目录,我正在使用 tmpdir pytest 夹具:所以这两个示例中的哪一个更好写:示例 1:
for root, dirname, files in os.walk(str(tmpdir + '/log/')):
....
example 2 :示例2:
directory = str(os.path.join(tmpdir, 'log'))
for root, dirname, files in os.walk(directory):
....
Which syntax i should use and why ?我应该使用哪种语法,为什么?
In short, if you will need to access that directory variable again then its best to have it as a variable.简而言之,如果您需要再次访问该目录变量,那么最好将其作为变量使用。
If not, having the variable it might be considered more "readable" but it is slightly redundant to have it without a second use.如果没有,拥有该变量可能会被认为更“可读”,但是如果没有第二次使用它就有点多余了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.