[英]Python: is there a difference between using an object as an argument e.g. method(XXX) vs. this syntax: XXX.method()?
Sorry that I do not yet have the vocabulary to express this question properly.抱歉,我还没有正确表达这个问题的词汇。
For example:例如:
# Import sas7bdat package
from sas7bdat import SAS7BDAT
# Save file to a DataFrame: df_sas
with SAS7BDAT('sales.sas7bdat') as file:
df_sas = file.to_data_frame()
# Print head of DataFrame
print(df_sas.head())
and和
# Save file to a DataFrame: df_sas
with SAS7BDAT('sales.sas7bdat') as file:
df_sas = SAS7BDAT.to_data_frame(file)
# Print head of DataFrame
print(df_sas.head())
both produce the same result.两者都产生相同的结果。 Are they generally equivalent or is this a special circumstance?
它们通常是等效的还是特殊情况?
I wouldn't call it a special case but rather indirect.我不会称其为特殊情况,而是间接的。
You are creating an object file
that is an instance of that class SAS7BDAT with with SAS7BDAT('sales.sas7bdat') as file:
and then you are using the Class method to_data_frame
from the Class instead from the instance directly. You are creating an object
file
that is an instance of that class SAS7BDAT with with SAS7BDAT('sales.sas7bdat') as file:
and then you are using the Class method to_data_frame
from the Class instead from the instance directly.
It is really a special circumstance and maybe the second code has another side-effect you cant see yet.这确实是一种特殊情况,也许第二个代码还有另一个你看不到的副作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.