The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Break class out from main file
Discuss Break class out from main file in the Python Programming forum on Dev Shed. Break class out from main file Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 21st, 2003, 06:12 PM
|
|
Junior Member
|
|
Join Date: Oct 2002
Posts: 17
Time spent in forums: < 1 sec
Reputation 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()
|

September 21st, 2003, 07:15 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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
|

September 21st, 2003, 07:34 PM
|
|
Junior Member
|
|
Join Date: Oct 2002
Posts: 17
Time spent in forums: < 1 sec
Reputation 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()
|

September 21st, 2003, 08:21 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
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.
|

September 22nd, 2003, 10:51 AM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
|
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.
|

September 22nd, 2003, 10:57 AM
|
|
Junior Member
|
|
Join Date: Oct 2002
Posts: 17
Time spent in forums: < 1 sec
Reputation 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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|