Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
countryinfo package error
#1
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')
Reply
#2
Did you check the docs?
import countryinfo
country =  countryinfo.CountryInfo('Afghanistan')
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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.
Reply
#4
(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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  qpython package error Creepy 4 947 Jul-06-2023, 05:58 PM
Last Post: Creepy
  error with netcdf4 package damdam 0 1,793 Nov-18-2020, 06:44 PM
Last Post: damdam
  Importing module from a package results in import error goghvv 2 2,342 Mar-27-2020, 07:13 PM
Last Post: goghvv
  Beginner - simple package installation error mefeng2008 0 1,699 Mar-13-2020, 09:17 AM
Last Post: mefeng2008
  Error importing package julio2000 3 3,709 Jan-26-2020, 06:15 PM
Last Post: buran
  Error in importing package in pycharm fullstop 0 2,315 Dec-12-2019, 04:03 PM
Last Post: fullstop
  error using geoGen package from GITHUB hknarahari 4 3,227 Sep-17-2019, 06:59 AM
Last Post: buran
  package(s) error pykdtree zahid990170 0 2,185 Mar-21-2019, 06:18 PM
Last Post: zahid990170
  Error while importing my own package giu88 4 2,913 Sep-19-2018, 12:18 PM
Last Post: giu88
  Countryinfo package charmap error mkaru 6 7,193 Sep-16-2018, 02:58 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020