&gt;So why did you use two sets of parenthesis here?<br>&gt;Are you completely sure you understand everything that's happening here?<br><br>&nbsp;&nbsp;&nbsp; pyForge.promptForge.prompt()<br>TypeError: unbound method prompt() must be called with promptForge instance as first argument (got nothing instead)
<br><br>^ Thats why... I have to use :<br>import pyForge<br>pyForge.promptForge().prompt<br><br>&gt;Do you want just functions?<br>&gt;I haven't seen your pyForge class, but if you're not using any OO features,<br>&gt;like the magical 'self' or the different __repr__, __str__,
<br>&gt;__getitems__, etc. methods,<br>&gt;then why is it in a class in the first place, and not just functions?<br><br>Because I was trying to get a grip on classes and OOP... =P<br>pyForge for lack of a better description is kinda like my own mini-framework. It's basically all the methods(functions?) that I've basically rewritten in each of my python files that I grouped together into classes by functionality. For example, pyForge has class fileforge which has two methods, one for writing, and one for reading files. Each takes a few different parameters but it makes an entire block of code transparent so that when I'm trying to show someone my code at work its less to look at. There is a class for a &quot;console based splashscreen&quot; called promptForge which has a &quot;EULA&quot; mode enabled by bool and takes a few parameters. I've also got zipForge which is very similar to my fileForge, but zips/unzips. I might add a few more things that I've repeated... It was mainly an attempt at learning classes, and I wanted all my re-usable code to be centralized so I didn't keep opening scripts and cutting and pasting. 
<br><br><br><br><div><span class="gmail_quote">On 11/10/06, <b class="gmail_sendername">Luke Paireepinart</b> &lt;<a href="mailto:rabidpoobear@gmail.com">rabidpoobear@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Chris Hengge wrote:<br>&gt; As for saving memory.. I'm not particularily concerned since all my<br>&gt; systems have 2gb...<br>&gt; Also, before python I was writing C# database front ends (nothing<br>&gt; amazing) and I'm not even going to compare python's 10mb overhead to
<br>&gt; .net's 45mb+. I was mostly just curious if it would save the memory in<br>&gt; the same manner.<br>&gt;<br>&gt; As for using modules... I'm actually looking at my real code right<br>&gt; now.. (need to not reply to these emails while at work when I can't
<br>&gt; really see the code)<br>&gt; in my pyForge module (simple script to hold my common used objects<br>&gt; basically) there is a class promptForge, that contains a method prompt<br>&gt; &lt;-- I know this is a great name =P....
<br>&gt; To call it:<br>&gt; import pyForge # module name<br>&gt; promptForge.prompt() # Class.method<br>&gt; will tell me promptForge is undefined.<br>&gt; so I use:<br>&gt; promptForge().prompt()<br>&gt; will tell me promptForge is undefined
<br>Yeah, it's unidentified because it only exists in the imported module's<br>namespace.<br>&gt; so I use:<br>&gt; pyForge.promptForge().prompt() # module.class.method<br>So why did you use two sets of parenthesis here?<br>
Are you completely sure you understand everything that's happening here?<br><br>pyForge. -&gt; now we're working in the module's namespace.<br>promptForge -&gt; the class you're targeting in the pyForge namespace<br>() -&gt; create an instance of the class using the __init__ method.
<br>.prompt -&gt; get the method 'prompt' from the instance of the class you<br>just created.<br>() -&gt; execute this method.<br><br>So why are you creating an instance of promptForge here?<br>&gt; this works. (I just did all this while writing this email.)
<br>Yeah, it works, but is it necessary?<br>&gt; When I use:<br>&gt; import random<br>&gt; random.random () #This does its thing... most modules only have<br>&gt; module.whateverThisIs(params)<br>&gt; in my code I've got 
module.class().method(params)... Am I not<br>&gt; conforming to some sort of module standard?<br>You're just creating an instance when you probably don't mean to.<br>&gt; Are modules supposed to only be filled with methods,
<br>No.<br>Then they would be called functions :)<br>methods are functions inside classes that act upon the class' data<br>members (I.E. variables)<br>They're different terms so that people will know what you're talking about.
<br>&gt; using the module file itself as the seperation layer in place of using<br>&gt; a class?<br>Yeah, do that if you want just functions.<br>Do you want just functions?<br>I haven't seen your pyForge class, but if you're not using any OO features,
<br>like the magical 'self' or the different __repr__, __str__,<br>__getitems__, etc. methods,<br>then why is it in a class in the first place, and not just functions?<br>You can have a module of functions if you want.<br>
You can have a module of variables if you want.<br>a module is just the same as having all the stuff declared in your<br>program, except you refer to it all by module name.<br><br>#----- config.py<br>a = 1<br>#-----<br>#---- 
test.py<br>import config<br>print config.a<br>#------<br>etc.<br>&gt;<br>&gt; FYI... I dont know where it happened, but these last few e-mails are<br>&gt; off tutor.<br>Oops, yeah.&nbsp;&nbsp;This one is forwarded to tutor and if anyone wants to see
<br>the previous discussion you can check the reply-stuff below.<br><br>HTH,<br>-Luke<br>&gt;<br>&gt; On 11/10/06, *Luke Paireepinart* &lt;<a href="mailto:rabidpoobear@gmail.com">rabidpoobear@gmail.com</a><br>&gt; &lt;mailto:
<a href="mailto:rabidpoobear@gmail.com">rabidpoobear@gmail.com</a>&gt;&gt; wrote:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Chris Hengge wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Alright, that all makes sense other then one part...<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Okay! I'm shivering with anticipation :)
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; I'm all for you saying to just use:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; import module<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; module.class.method ()<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; I agree this code is easier on the eyes down the road...<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; but...( And this might be old world C++ coming in and shading my
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; view)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; In c++ you would be specific aka from module import class so<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; that you<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; could conserve memory by not importing the entire library. Is this<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; also true for python?
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Ah, well, now we step into sacred territory.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;_&gt;.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; The long and short of it is, yes, importing the whole module uses<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; more<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; memory.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; It shouldn't use significantly more memory.
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; If you're so constrained for memory that you're considering not using<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; 'import class' just for this reason,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; then you'll be fretting about the 10 mb of overhead (or whatever) the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Python interpreter takes up, I think :)
<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; In general, in Python, consider &quot;If it makes it easier on me and the<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; speed impact is not noticeable, why would I make it hard on myself?&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; premature optimization is the root of all evil.
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; In this case, I wouldn't even consider the memory usage in deciding<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; which syntax you like better.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Final question on the topic that hopefully has a clear answer =P
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Oh, let's hope. *crosses fingers*<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; When writing a module, is there some special way to do it? Like, do<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; they use only classes with no methods inside? Or do they only use<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; methods?
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; I ask because my pyForge is Class &gt; Methods and to use it I have<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; to say:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; import module<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; module().class().method(stuff)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Are you sure? :D<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; You should never have to do this.
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; if you import module,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; then everything inside of module is accessed the same way it would<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; be if<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; it were in your program,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; just with a 'module.' prepended to it.<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Imagine it like this.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #-----<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #test.py<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; def aFunction():<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;hello&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; aFunction()<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #-----<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; obviously outputs hello.
<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Now consider these two files.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #-----<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; # module.py<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; def aFunction():<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;hello&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; aVariable = &quot;hi&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #------
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; how would you use this in your test.py script?<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #-----<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #test-version2.py<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; import module<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; module.aFunction()<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; print module.aVariable<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; #-------
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; You'll see<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &quot;hello<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; hi&quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; as the output for this script.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; The 'import module' syntax&nbsp;&nbsp;you can imagine as it creating a new<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; variable<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; that points to the _entire_ script 'module.py' and everything<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; inside of it.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; So I don't think you'd ever have to do<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; 'module().class().function()'<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; in fact, I know you would never need to do that.
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; A simple test:<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; import random<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; random()<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; raises a TypeError: 'module' object is not callable.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Do not think of a module as a class, cause it's not.
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; it's just a separate namespace.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; So the 'from module import *' just says to get rid of that extra<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; level<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; of namespaces<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; that isolates those module functions from overwriting or interfering
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; with my own functions,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; and just put them all as global, and trust me not to accidentally<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; overwrite them later.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; but when I go to use most of the &quot;standard libraries&quot; I can just
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; write<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; something like<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; import module<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; module.method/class?(stuff)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Yeah.&nbsp;&nbsp;you should always have to have a module., never a<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; module()., as I
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; hope the above explanation clarifies.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Thanks again for your patience and clear answers Luke!<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Sure!&nbsp;&nbsp;It helps me to think about things like this too :)<br>&gt;<br>
&gt;&nbsp;&nbsp;&nbsp;&nbsp; Also, one final thing:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; You can have a class that you don't instantiate but still create<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; instances of inner classes.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; for example,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; class foo(object):
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class bar(object):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; def __init__(self):<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print &quot;Initializing bar!&quot;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; foo.bar ()<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Initializing bar!<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;__main__.bar object at 0x00B536D0&gt;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; foo<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;class '__main__.foo'&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; foo()<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;__main__.foo object at 0x00B53830&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&gt;&gt; foo().bar()<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Initializing bar!
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;__main__.bar object at 0x00B53890&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; You see, there's really no reason to initialize this class ('foo'),<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; because 'foo' is just holding the 'bar' class for us.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; yeah, you can initialize 'foo' if you want, but it does exactly
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; the same<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; thing uninitialized, because it has no instance methods or variables,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; or, in other words, nothing with 'self' in it.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; I just thought of this because of your<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &quot;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; I ask because my pyForge is Class &gt; Methods and to use it I have<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; to say:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; import module<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; module().class().method(stuff)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &quot;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; comment.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Let's assume you meant
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; module.class().method(stuff)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; since module() raises an exception :)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; so if you were doing this, it would mean on each call,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; you're creating an instance of the class called 'class' and calling a
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; method on that instance,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; but you're not storing the instance anywhere, so it's just<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; disappearing.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; remember when we were talking about that before?<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; It's possible that you need to instantiate it but not keep a copy
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; around, but it's probable that this isn't what you wanted to do,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; and you just put the () cause you thought they needed to go there.<br>&gt;<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; HTH,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; -Luke<br>&gt;<br>&gt;
<br><br></blockquote></div><br>