How do I use 'ex25 import *'?

I tried entering ex 25 import * in the python interpreter in every way that I could but it dosen’t do anything good(Either idk how to enter it, or is meant to be like that.)

Can I get the syntax or a picture of the console so that it helps?

Hello @Dynamo_Nishant

You need to start the import with ”from”.

Then it looks like two different files you want to import (”ex” and ”25”).
You can only do one import at the time.
But I guess your are the same file (ex_25.py?)

It should something like this:

from ex_25 import *

Hi, everyone! I did two variants of import and from ex25 import * does not works at all. I have Windows 10. I do not know where the problem is. So, it is weird. I just use import ex25.

>>> from ex25 import *
>>> help(ex25)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'ex25' is not defined
>>> import ex25
>>> help(ex25)
Help on module ex25:

NAME
    ex25

FUNCTIONS
    break_words(stuff)
        This function will break up words for us.

    print_first_and_last(sentence)
        Prints the first and last words of the sentence.

    print_first_and_last_sorted(sentence)
        Sorts the words then prints the first and last one.

    print_first_word(words)
        Prints the first word after popping it off.

    print_last_word(words)
        Prints the last word after popping it off.

    sort_sentence(sentence)
        Takes in a full sentence and returns the sorted words.

    sort_words(words)
        Sorts the words.

FILE
    c:\users\user\lpthw\ex25.py


>>>

Hello

Try if it helps to create in the same folder as ex_25.py, an empty file called:

__init__.py

This help Python to find files.

Otherwise you have to set the PYTHONPATH.
But I dont know how to do this on Windows.
Perhaps someone else can help with that part.

:triangular_flag_on_post:
I found this tonight in exercise 52 in the book (LPTHW):

On Windows PowerShell do:
$env : PYTHONPATH = ”$env : PYTHONPATH ; . ”

I hope that is useful.

Actually @JohnP, it did work, just maybe not as you expected. You see the help(ex25) printed out help the 2nd time? Notice how it listed all the functions in your ex25.py file?

The first time it imported you did this:

from ex25 import *

That’s telling python “Load the ex25.py code, and then pull out all the functions and put them right here.” That means you can just type break_words instead of ex25.break_words.

Try both of those to see what I mean.

1 Like

Thank you. Now I see.

1 Like