擅长:python、mysql、java
<p>在函数中导入包,而不是依赖全局范围</p>
<pre class="lang-py prettyprint-override"><code>def foo(obj):
import pandas as pd
import numpy as np
objdtypes = (list, tuple, np.ndarray, pd.core.series.Series)
if isinstance(obj, objdtypes):
print("It's there")
</code></pre>
<p>另外,不要使用<code>object</code>作为变量名,因为这将隐藏内置的<code>object</code></p>