简体   繁体   中英

Module and Parameter with the same name

I have seen a question on SO about having a Parameter and a Function with the same name, and how to deal with that, but I haven't found one that deals with having a parameter and a module with the same name.

I would prefer to avoid using the from x import * importing method in favor of import x . However, this leads me to the situation where I have a parameter to a function named x , which is the same as the module name x . What are the cleanest ways to get around this?

Rename the imported module to something else, so it lives in a different namespace:

import x as y

then you can use the imported object with a differently chosen name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM