Error regarding guidance on building modules in the Head First Python book using Windows

Asked

Viewed 20 times

0

Hello! I’m reading the book Head First Python and a question arose regarding the creation of module and distribution of it using Windows. Following the author’s guidelines, I created a.py file with a specific def function and saved it to a Desktop folder named Module. Next, I created a setup.py file following the author’s guidelines and saved it in the same Module folder. Thus, there are 2 files inside the Module folder (.py file, with the def and setup.py function). Anyway, the author says that you need to build a distribution by following the steps: Open a terminal window 'inside' the Module folder (How so?? Open terminal inside the folder??), then type the command: python3 setup.py sdist, but I believe he used Linux and said that for Windows it would be "just" replace python3 by: c: Python3| python.exe, which DIDN’T WORK!! That is, there were two holes in this book: the first to say that I open the terminal inside the Module folder and the second with this crazy sequence of commands. Anyway, after I created a new program in IDLE using import Module, I saved in a folder ERROR in the execution saying I did not find the def function I had specified in the Module. I decided to create the.py module in the same folder as the program I had written to call the module with the def function, and IT DIDN’T WORK. Can anyone tell me what’s going on?. Thank you.

follow the codes, both are in the same folder:

py.list import Nester

CAST = ['joão','maria','Jose']

prints(CAST)

Nester.py

def prints(list):

for i in lista:
    if isinstance(i,list):
                    
        imprime(i)
    else:

        print(i)

1 answer

0

I believe that when it means to open the terminal inside the folder, it is to access folder through the windows CMD ( command prompt ), for this do the following:

  • Open Start menu > Type "cmd" without quotation marks > Open to command prompt ( a black screen );
  • Navigate to the folder you want ( according to you, this on the Desktop ) then type:

cd C:/Desktop/nome-da-pasta

Change the folder name to the folder name you created on your Desktop

Now your second question, for you to create a module and import it in another part of the code, just create a module, for example "list.py" and inside it has the function:

def imprimir(lista)
for i in lista:
    if isinstance(i,list):             
        imprime(i)
    else:
        print(i)

So in the other part of your code you will use this list, you need to import this part importing in the following way

from .lista import imprimir See which list refers to the file (list.py) and the print refers to the function you are calling within the file. list, to import another function, just add the comma and then call the next function.

And whenever you use it, type

imprimir(valores)

and thus for the other functions.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.