I am a newbie for python and try to understand class Inheritance.

2011-10-14 Thread aaabbb16
Test.py
#!/usr/bin/python
from my_lib import my_function
class my_class(my_function.name):
def __initial__(self, name);
 pass
def test():
   print "this is a test"

If __name__ == '__maim__':
my_class.main()
---
my_lib.py
class my_function()
...


Can anyone finish above code and let me try to understand
Class inheritance?
TIA.
-david

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I am a newbie for python and try to understand class Inheritance.

2011-10-15 Thread aaabbb16
On 10月15日, 上午12时04分, Chris Rebert  wrote:
> On Fri, Oct 14, 2011 at 11:20 PM,   wrote:
> > Test.py
> > #!/usr/bin/python
> > from my_lib import test
> > class my_class(my_function.name):
>
> Why are you subclassing my_function.name and not just my_function?
try to inherit or change "name" attribute in "my_function".
>
> >    def __initial__(self, name);
> >         pass
>
> The initializer method should be named "__init__", not "__initial__".
ipad is so smart, it thinks I have spelling problem and
correct it. haha. sorry about it.
>
> >    def test():
>
> You forgot to include "self" as a parameter, like so:
>     def test(self):
right thanks!
>
> >       print "this is a test"
>
> > If __name__ == '__maim__':
>
> That should be "__main__" with an N, not "__maim__" with an M.
> And "if" must be in all-lowercase.
mistyping

> >    my_class.main()
>
> Your class doesn't define any method named "main" (you only defined
> test() and __initial__() ), so this call will fail.
how to do it?
> > ---
> > my_lib.py
> > class my_function()
>
> You're missing a colon after the parentheses. Also, you're writing a
> class, not a function, so please rename the class something less
> confusing.
sure. i like call it from my_lib
>
> > Can anyone finish above code and let me try to understand
> > Class inheritance?
> > TIA.
>
> Have you read any Python tutorial? There are several basic errors in
> your code which would suggest that you haven't. You really ought to;
> it's well worth it.
> The Beginner's Guide links to 2 lists of 
> tutorials:http://wiki.python.org/moin/BeginnersGuide
>
> There's also the python-tutor mailing list, which is specifically
> geared towards answering beginner 
> questions:http://mail.python.org/mailman/listinfo/tutor
>
> Cheers,
> Chris
> --http://rebertia.com

Thanks Chris! I'll check that link.

Test.py
#!/usr/bin/python
from my_lib import p_test
class my_class(p_test.name):
def __initial__(self, name):
 pass
def test(self):
   print "this is a test"

If __name__ == '__main__':
my_class.main()
---
my_lib.py
class p_test()
...


Can anyone finish it and give me a demo.
Class inheritance?
for this case, it inherit/change p_test "name" attribute.
I try to quick understand how to inherit parent attribute
TIA.
david
-- 
http://mail.python.org/mailman/listinfo/python-list


How to use shell return value like $? In python?

2011-10-23 Thread aaabbb16
exp:
os.system('ls -al')
#I like to catch return value after this command. 0 or 1,2,3
does python support to get "$?"?
then I can use something like:
 If $?==0:
 

TIA
david


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to use shell return value like $? In python?

2011-10-23 Thread aaabbb16
On Oct 23, 7:44 pm, aaabb...@hotmail.com wrote:
> exp:
> os.system('ls -al')
> #I like to catch return value after this command. 0 or 1,2,3
> does python support to get "$?"?
> then I can use something like:
>  If $?==0:
>      
> 
> TIA
> david

So for what I do is:
r_number =os.system('ls -al')
 if r_number == 0
  .
  .
any other way?
-- 
http://mail.python.org/mailman/listinfo/python-list