-1

Hey I am having some trouble figuring out what is being asked to import in this code

#!/opt/local/bin/python

import sys
from formatter import Formatter

def main():
#do stuff

in my class formatter.py, do I have had to define a function with a name Formatter. A little confused on this. I have been testing my code by putting

from formatter import *

Which takes all the definitions in my class(I believe).

2
  • formatter.py is a module, not a class, and by convention, Formatter would be a class, not a function. But yes, you’d create something with that name.
    – Ry-
    Jul 15, 2014 at 21:45
  • 2
    docs.python.org/3/reference/simple_stmts.html#import The docs are a great place to start. You should always Google before going to SO. Jul 15, 2014 at 21:48

1 Answer 1

0

your line from formatter import Formatter will search through the module formatter for anything with the name Formatter. so if you had a function called Formatter in that module, it would be imported, meaning you could use it in your main section (anywhere below the import line will work) It will import classes as well.

formatter.py is a module. a class might look something like:

class A:
    variable = 1
    def b():
        #do stuff

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.