Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Problems with "re.fullmatch"
#1
Hi programmers! I am new in the forum and in Python.
I am programming a library whose function is to store books and comics and display data from them by screen.
Since I added some restrictions for some methods, the "Comic" class does not work for me, and the error it gives me I can not understand.
I'm programming with Atom and my terminal to run it.

The error in Terminal:

Error:
File "USO_BIBLIOTECA.py", line 4, in <module> from BIBLIOTECA import * File ... line 134, in <module> comic = Comic() File ... line 128, in __init__ libro.setAutor(self) File ... line 67, in setAutor if re.fullmatch(regex, new_autor): File ... line 168, in fullmatch return _compile(pattern, flags).fullmatch(string) TypeError: expected string or bytes-like object
The error in Atom:

Error:
File ... line 134, in <module> comic = Comic() File ... line 128, in __init__ libro.setAutor(self) File ... line 67, in setAutor if re.fullmatch(regex, new_autor): AttributeError: 'module' object has no attribute 'fullmatch'
The code of my program is:
import re
    class Biblioteca():  
        def __init__(self, tituloLibro, tituloComic):
            self.tituloLibro = tituloLibro
            self.tituloComic = tituloComic

        def setLibro(self, new_libro):
            self.tituloLibro = new_libro
        def setComic(self, new_comic):
            self.tituloComic = new_comic

        def getLibro(self):
            return self.tituloLibro
        def getComic(self):
            return self.tituloComic

    class Libro():
        def __init__(self):
            self.autor = ""
            self.editorial = ""
            self.idioma = ""
            self.paginasLeidas = 0
            self.paginasTotales = 0

        def setAutor(self, new_autor):
            regex = "[^\d\s]+( [^\d\s]+)*"
            if re.fullmatch(regex, new_autor):
               self.autor = new_autor
            else:
               print("\n\n ****** ERROR ******")
               self.autor = ""

        def setEditorial(self, new_editorial):
               regex = "[^\d\s]+( [^\d\s]+)*"
            if re.fullmatch(regex, new_editorial):
               self.editorial = new_editorial
            else:
               print("\n\n ****** ERROR ******")
               self.editorial = ""

        def setIdioma(self, new_idioma):
            regex = "[^\d\s]+( [^\d\s]+)*"
            if re.fullmatch(regex, new_idioma):
               self.idioma = new_idioma
            else:
               print("\n\n ****** ERROR ******")
               self.idioma = ""

        def setPaginasLeidas(self, new_paginasLeidas):
            try:
               self.paginasLeidas = int(new_paginasLeidas)
            except ValueError:
               print("\n\n ****** ERROR ******")
               self.paginasLeidas = 0
        def setPaginasTotales(self, new_paginasTotales):
            try:
               self.paginasTotales = int(new_paginasTotales)
            except ValueError:
               print("\n\n ****** ERROR ******")
               self.paginasLeidas = 0

        def getAutor(self):
            return self.autor

        def getEditorial(self):
            return self.editorial

        def getIdioma(self):
            return self.idioma

        def getPaginasLeidas(self):
            return self.paginasLeidas

        def getPaginasTotales(self):
            return self.paginasTotales

  libro  = Libro()

  class Comic(Libro):
       def __init__(self):
            Libro.__init__(self)
            libro.setAutor(self)
            libro.setEditorial(self)
            libro.setIdioma(self)
            libro.setPaginasLeidas(self)
            libro.setPaginasTotales(self)

  comic = Comic()
Thanks in advance.
Quote

Top Page

Messages In This Thread
Problems with "re.fullmatch" - by AlanT - May-16-2019, 07:18 PM
RE: Problems with "re.fullmatch" - by micseydel - May-16-2019, 07:30 PM
RE: Problems with "re.fullmatch" - by AlanT - May-16-2019, 08:49 PM
RE: Problems with "re.fullmatch" - by micseydel - May-16-2019, 10:34 PM
RE: Problems with "re.fullmatch" - by AlanT - May-17-2019, 12:42 PM
RE: Problems with "re.fullmatch" - by micseydel - May-17-2019, 09:11 PM
RE: Problems with "re.fullmatch" - by AlanT - May-17-2019, 10:59 PM
RE: Problems with "re.fullmatch" - by micseydel - May-17-2019, 11:02 PM
RE: Problems with "re.fullmatch" - by AlanT - May-18-2019, 04:45 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)