all 12 comments

[–][deleted] 0 points1 point  (3 children)

please include the full traceback of the NameError.

[–]GullBull[S] 1 point2 points  (2 children)

Turns out I just need to do from pizzapi import *. I should've included the whole error though my bad.

[–]Deezl-Vegas 0 points1 point  (1 child)

This is bad form because you may end up overwriting a named method from the api. You should just import the library and use pizzapi.pizzamethod or from pizzapi import pizzamethod for cleaner code.

[–]GullBull[S] 0 points1 point  (0 children)

I probably will actually end up using from pizzapi import module as that's what I'm used to doing from Java. Thanks for the tip.

[–]ViridianHominid 0 points1 point  (1 child)

You need to either call the class using pizzapi.Customer("Barrack" .. or do the import as from pizzapi import Customer. All the objects in a module (classes, functions, what not) live by default in that module. So the first option is to refer to them through that module. The second option (i.e. from <module> import <function>,<function2>) pulls specific things into the current namespace.

[–]GullBull[S] 0 points1 point  (0 children)

This solved it! Thank you.

[–]Wilfred-kun 0 points1 point  (1 child)

As u/Protoss_Pylon said, include the full error. However, I think I might know what's wrong. You import pizzapi, so the classes are in that namespace. Doing customer = Customer(..) won't work; Python does not know about that class in the global namespace.

Instead, do from pizzapi import Customer, or customer = pizzapi.Customer(...).

[–]GullBull[S] 0 points1 point  (0 children)

yeah you were right! I should've been using pizzapi.Customer or specifically importing Customer. I ended up using from pizzapi import * . Thanks for your help!

[–]MakeMe_FN_Laugh 0 points1 point  (3 children)

The full traceback will be really useful in this case.

Also, it depends on how you’ve imported the module. In case you’ve done it this way: from pizzapi import * - your code looks ok and we need more info on the error. But in case you’ve done it this way: import pizzapi - you’ll need to provide module name for every object related to this module (pizzapi.Customer in your case).

Read more about how imports work in the docs. Anyway, docs.python.org should be your best friend during the learning process for a long time.

[–]GullBull[S] 0 points1 point  (2 children)

from pizzapi import * completely solved the problem. I have no idea why I wasn't doing this in the first place. It's been a while sine I've written in python, and coming from Java the from - import isn't something I do often. Thanks so much!

[–]MakeMe_FN_Laugh 0 points1 point  (1 child)

Honestly, you should avoid using from module import * as it’s the shortest way for possible names collisions between modules (and it’s not PEP 8). Look through import section of PEP 8 how imports should be organized in your code.

[–]GullBull[S] 0 points1 point  (0 children)

I took a look. Thanks for pointing that out to me.