Python Forum
countryinfo package error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: countryinfo package error (/thread-32965.html)



countryinfo package error - MarcusAurelius - Mar-20-2021

Hi, I get the following error while I'm using python 3.9
Package countryinfo succesfully installed with pip.
Why the module object isn't callable ? What do I wrong ?

country = countryinfo('Afghanistan')
TypeError: 'module' object is not callable


import countryinfo
country =  countryinfo('Afghanistan')



RE: countryinfo package error - buran - Mar-20-2021

Did you check the docs?
import countryinfo
country =  countryinfo.CountryInfo('Afghanistan')



RE: countryinfo package error - MarcusAurelius - Mar-20-2021

(Mar-20-2021, 12:34 PM)buran Wrote: Did you check the docs?
import countryinfo
country =  countryinfo.CountryInfo('Afghanistan')

Thanks Anyway.
Yes it is very logical, that your must use two times the same names separated by a point.
It isn't for sure not Einstein who invent this naming convention.


RE: countryinfo package error - buran - Mar-20-2021

(Mar-20-2021, 04:27 PM)MarcusAurelius Wrote: Yes it is very logical, that your must use two times the same names separated by a point.
No, it's not the same name.
countrname is the package. CountryName is a class inside that package. These are different names. In python letter case matters.

import countryinfo
country =  countryinfo.CountryInfo('Afghanistan')
or

from countryinfo import CountryInfo
country =  CountryInfo('Afghanistan')
in both cases country is instance of class CountryInfo.


RE: countryinfo package error - deanhystad - Mar-20-2021

The idea behind the module.attribute naming convention is two-fold. Primarily it is a way to allow massive parallel development without having to worry about name clashes. Imagine what a pain it would be to write software if you had to verify that every function name and variable name you use in your program is never been used in any other Python module. With module.attribute I can write a function that has the same name as an attribute in numpy or matplotlib or sqlite3 or tkinter and still use those packages.

The second, and less important reason for module.attribute is consistent with the way attributes are specified for other Python container types who's attributes are specified by name: classes and named tuples for example. If you think of the module as a container and the function or class as an attribute, container.attribute is a very pleasing and logical way to specify an attribute outside the local namespace. I wish they had done the same thing with "global" so I could do global.x = 5 instead of:
global x
x = 5
The module.attribute naming convention is more natural when modules contain more than one attribute. For example, the random module has random.choice, random.sample, random.uniform as well as random.random. The time module has time.asctime, time.strftime and time.sleep as well as time.time.