[Tutor] how to instantiate a class

spir denis.spir at free.fr
Thu Feb 26 09:04:37 CET 2009


Le Thu, 26 Feb 2009 12:38:27 +0530,
Abhishek Kumar <abhishek.luck at gmail.com> s'exprima ainsi:

> hello list,
> 
> Below is the sample code of a class.
> 
> 
> import <someStandardModule>
> 
> Class ABC:
>              def __init__(self,a,b,c):
>                                 statement 1
>                                  statement 2
>              def func(x,y):
>                            statement 1
>                            statement 2
> 
> Here is the question:
> 
> how to make an object of this class
	abc = ABC(1,2,3)
>and how to use the methods listed
> in the class.
	abc.func(foo,bar)
> do i need to create the object in a separate file or in the same file
> it can be done ??
Both are possible.
If not in the same file, you must first import the file (module) where ABC is defined, then ABC will behave like an attribute of the module; or just the name ABC from this file, in which case ABC will be locally know:
	import ABCFile
	abc = ABCFile.ABC(1,2,3)
or
	from ABCFile import ABC
	abc = ABC(1,2,3)

denis
------
la vita e estrany


More information about the Tutor mailing list