#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    17
    Rep Power
    0

    Break class out from main file


    Hi,

    I am tweaking Ensims skin file structure and I want to do two things:

    1. Remove the class from the main file and put it in it's own file and import it.

    2. All def's in the class in their own files also.

    So in the end there would be 3 files; main.py, class.py, and class_def.py. Below is the main file minus most of the main imports and class def's. I put one in there for example. Any help is appreciated.

    Code:
    #main.py
    import skin
    class Skin(skin.SkinBase):
        def appliance_navbar(self):
            filterobj = skin.UnhiddenServicesFilter(self.REQUEST)
            dict_to_menu()
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Hey kawika,

    Sorry maybe i missed this but what was the question? I gathered your making some changes to a program but other than that i'm lost.. you've seperated the classes and functions into files and you wanted somone to?

    Post the whole thing (zipped or something) i'd be happy to take a look just out of interest but i'm just not sure what you're looking for

    Have fun,
    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    17
    Rep Power
    0
    Hey Netytan, thanks for responding.

    There is currently one file, main.py which contains all the code above.

    What I want to do is remove the class definition and all the defs in the class from main.py and put them into seperate files.

    So there would be three files (attempted detail below), main.py which calls the class and the class file that calls a class def, and the finally the def file. Hope that makes sense.

    I successfully seperated the entire class from main.py but when I try to put one of the class defs into their own file it chokes.

    Thanks for your help.
    Kawika

    Code:
    #main.py
    import skin
    import Skin
    
    
    #Skin.py
    class Skin(skin.SkinBase):
    import def_appliance # this doesn't work.
    
    
    #def_appliance.py
    def appliance_navbar(self):
            filterobj = skin.UnhiddenServicesFilter(self.REQUEST)
            dict_to_menu()
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Ok i think i get you,

    just a few questions.. are the 3 comented code blocks below the 3 files? also, your saying it chokes, what error message are you getting here, it might help us figure out whats wrong. It might also help if you could attach the actual Python files as a zip so i can give it ago myself?

    then just one from me, why is it so impotant that they are in seperate files?

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    11
    It wouldn't make sense to remove a definition of a member method in a class and place it in another file. Well, you can do something similar, but I can't see the why of it.

    What you'd have to do to make it work similarly would be to import the method, then bind the method data object to a class variable name.

    This won't work well if you need to access class or instance attributes though, so it's mostly useless, since that's the only reason to have class/instance methods to begin with.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    17
    Rep Power
    0
    Hi, yeah I know it makes no sense but the file I'm working with contains lot's of funcations with html and I'm trying to write an editor for it. With all the code and html combined it would be easier if the files were seperated so my editor could easily know what it's dealing with and I could make incremental upgrades without replacing the entire file.

    Do you have an example of something like this or a link to an example?

    For now I'll just have to run a parsing routine on the 60K file everytime I want to edit some html in a class function. Very slow and ugly but if that's all I can do then oh well.

IMN logo majestic logo threadwatch logo seochat tools logo