Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Import" Help
#3
(Apr-28-2023, 02:10 AM)deanhystad Wrote: There is a problem with this:
from pyfiglet import Figlet
 
figlet = Figlet()
 
pyfiglet.getFonts()
figlet.setFont(font=f)
You did not import pyfiglet. You only imported Figlet. The "figlet = Figlet()" probably works. "pyfiglet.getFonts()" would fail and cause a crash with a NameError because you never assigned a value to a variable named "pyfiglet.

That is what import does, your know. Yes, it pulls in modules and compiles them to byte code, but it also creates objects and assigns them to variables. import inflext loads the inflect module, but it also creates a variable named "inflext" to which it assigns a module object. In your pyfiglet example you never did "import pyfiglet". There was no variable named "pyfiglet" created and no module object created. "from pyfiglet import Figlet" creates a variable named Figlet and assigns pyfiglet.Figlet (probably a class) to the variable.

This should work.
import pyfiglet
from pyfiglet import Figlet
 
figlet = Figlet()
 
pyfiglet.getFonts()
figlet.setFont(font=f)
I don't know why you would have a problem with inflect. Can you post a program that uses inflect and has an error. Also post the error message and error trace.

That worked perfectly, thank you for your help. As far as the inflect error, I have no idea what happened but it just started working and I was able to complete the assignment. Thank you again for the help!
Reply


Messages In This Thread
"Import" Help - by Chief816 - Apr-27-2023, 10:52 PM
RE: "Import" Help - by deanhystad - Apr-28-2023, 02:10 AM
RE: "Import" Help - by Chief816 - Apr-30-2023, 10:39 PM

Forum Jump:

User Panel Messages

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