Python Forum
TypeError: get_names() takes 0 positional arguments but 1 was given
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: get_names() takes 0 positional arguments but 1 was given
#3
[quote='snippsat' pid='55382' dateline='1534295409']
Sure can wonder if run again Confused
[/quote]

Just to mention that I still haven't finished the whole program. The main work is still to be done!

Will use your suggestions. Thank you!

[quote='snippsat' pid='55382' dateline='1534295409']
The parsing is already done so (html.select('li')): will not work.
[/output]

I don't understand this. I thought that parsing should make selectors available.

Also, I'm not quite satisfied with your solution ( sorry for that, not trying to be inpolite! Big Grin ). The goal of this exercise is to enlist all mathematicians, one in each row. Adding limitation to 5 is not what should be done here.

I made some modifications...
def get_names(url):
    """
    Downloads the page where the list of mathematicians is found
    and returns a list of strings, one per mathematician
    """
    
    response = simple_get(url)

    if response is not None:
        html = BeautifulSoup(response, 'html.parser')
        names = set()       # set ensures that you don’t end up with duplicate names.
        for li in html.select('li'):
            for name in li.text.split('\n'):
                if len(name) > 0:
                    names.add(name.strip())
        return str(names)

	# Raise an exception if we failed to get any data from the url
    raise Exception(f'Error retrieving contents at {format(url)}')
from bs4 import BeautifulSoup
from mathematicians import get_names
 
math_list = get_names('http://www.fabpedigree.com/james/mathmen.htm')
print((math_list.split('\n')))
Output:
['{\'Felix Christian Klein\', \'Felix Hausdorff\', \'Johannes Kepler\', \'Eudoxus of Cnidus\', \'Leonhard Euler\', \'James J. Sylvester\', \'Gaspard Monge\', \'Blaise Pascal\', \'Joseph Liouville\', \'Pythagoras of Samos\', "Jean le Rond d\'Alembert", \'Hipparchus of Nicaea\', \'Christiaan Huygens\', \'Omar al-Khayyám\', \'Georg Cantor\', \'Joseph-Louis Lagrange\', \'Pierre-Simon Laplace\', \'Isaac Newton\', \'William R. Hamilton\', \'Bernhard Riemann\', \'Élie Cartan\', \'Girolamo Cardano\', \'Stefan Banach\', \'M. E. Camille Jordan\', "Leonardo `Fibonacci\'", \'Siméon-Denis Poisson\', \'Bonaventura Cavalieri\', \'Archytas of Tarentum\', \'Gottfried W. Leibniz\', \'Johann Bernoulli\', \'Archimedes\', \'F. L. Gottlob Frege\', \'Giuseppe Peano\', \'Adrien M. Legendre\', \'Alfred Tarski\', \'Pappus of Alexandria\', \'George Pólya\', \'Pafnuti Chebyshev\', \'Karl W. T. Weierstrass\', \'Pierre de Fermat\', \'Emmy Noether\', \'Albert Einstein\', \'Michael F. Atiyah\', \'Srinivasa Ramanujan\', \'Charles Hermite\', \'Ernst E. Kummer\', \'Galileo Galilei\', \'Diophantus of Alexandria\', \'Arthur Cayley\', \'L.E.J. Brouwer\', \'Johann H. Lambert\', \'Richard Dedekind\', \'Carl F. Gauss\', \'Peter G. L. Dirichlet\', \'Alan M. Turing\', \'David Hilbert\', \'Aryabhata\', \'Carl G. J. Jacobi\', \'Panini of Shalatula\', \'Brahmagupta\', \'Atle Selberg\', \'Hermann K. H. Weyl\', \'Jean-Pierre Serre\', \'François Viète\', \'Godfrey H. Hardy\', \'Henri Poincaré\', \'Apollonius of Perga\', \'Hermann Minkowski\', \'Aristotle\', \'Carl Ludwig Siegel\', \'Évariste Galois\', \'George D. Birkhoff\', \'Jakob Steiner\', \'Marius Sophus Lie\', \'Bháscara (II) Áchárya\', \'Hermann G. Grassmann\', \'F. Gotthold Eisenstein\', \'Jacques Hadamard\', \'Euclid of Alexandria\', \'Joseph Fourier\', \'John E. Littlewood\', \'Shiing-Shen Chern\', \'Muhammed al-Khowârizmi\', \'Jean-Victor Poncelet\', \'Jacob Bernoulli\', \'Alhazen ibn al-Haytham\', \'Henri Léon Lebesgue\', \'F.E.J. Émile Borel\', \'Alexandre Grothendieck\', \'Julius Plücker\', \'André Weil\', \'John von Neumann\', \'Liu Hui\', \'Thales of Miletus\', \'Andrey N. Kolmogorov\', \'René Descartes\', \'Kurt Gödel\', \'Niels Abel\', \'Augustin Cauchy\', \'James C. Maxwell\'}']
why math_list.split('\n')) doesn't bring desired outcome ( one line for one name )?
Reply


Messages In This Thread
RE: TypeError: get_names() takes 0 positional arguments but 1 was given - by Truman - Aug-15-2018, 10:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  TypeError: to_capabilities() missing 1 required positional argument: 'self' OceansBlue 2 5,192 Dec-03-2020, 12:08 AM
Last Post: OceansBlue
  TypeError: missing 1 required positional argument (word counter Django app) Drone4four 2 14,538 Jul-11-2019, 09:34 PM
Last Post: Drone4four
  TypeError("index() missing 1 required positional argument: 'pymydb'" nikos 2 4,213 Mar-03-2019, 09:21 PM
Last Post: micseydel
  TypeError: Method takes takes exactly 1 argument but 2 given pras120687 1 9,085 Dec-15-2016, 07:10 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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