Re: Intitalize values for a class

2018-11-23 Thread Ganesh Pal
On Fri, Nov 23, 2018, 19:30 Bob Gailer  What kind of feedback do you want?
>
Wanted to know if there is any problem in the code and if you can review it
:-)

>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Intitalize values for a class

2018-11-23 Thread Bob Gailer
On Nov 23, 2018 8:42 AM, "Ganesh Pal"  wrote:
>
> Hello team,
>
> I am a python 2.7 user on Linux. I will need feedback on the below program
> as I'm  new to oops .

My feedback is:

Firstly there's a blank line between every line of program text which makes
it hard to read.

Also some statements are spread out over more than one line which also
makes it hard to read.

Secondly this sounds like a homework assignment. Is that true? If so be
aware that we will be glad to help if you tell us where you are stuck but
we won't write the code for you.

Please learn how to write effective questions. You can Google that and find
several good resources.

Bob Gailer
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Intitalize values for a class

2018-11-23 Thread Bob Gailer
On Nov 23, 2018 8:42 AM, "Ganesh Pal"  wrote:
>
> Hello team,
>
> I am a python 2.7 user on Linux. I will need feedback on the below program
> as I'm  new to oops .

What kind of feedback do you want?
>
> #!/usr/bin/python
>
>
> class System(object):
>
>   '''Doc - Inside Class '''
>
>   def __init__(self, params=None):
>
>if params is None:
>
>   self.params = {'id': '1',
>
>   'name': 's-1'}
>
>   print self.params
>
>if type(params) is dict and params.get('id') == '0':
>
>  raise ValueError('ERROR: id 0 is reserved !! ')
>
>#print self.params
>
>else:
>
> self.params = params
>
> print self.params
>
> # Test all conditions
>
> #case 0 - Default should create {'id': '1','name': 's-1'}
> #s0 = System()
>
> #Case 1 (id has value '0')
> #test1_params = {'id': '0', 'name': 's-0'}
> #s1 = System(params=test1_params)
>
>
> #Case 2 (id has some other values)
> #test2_params = {'id': '10', 'name': 's-10'}
> #s2 = System(params=test2_params)
>
>
> Question:
>
> I have to initialize the values the below class such that
>
>  1.  Intitalize  default values if nothing is supplied by the username
i.e
> self.params = {'id': '1', 'name': 's-1'}
>
> 2. I need to raise an Exception if the value for the key params[id] is
'0'.
>
> 3. It should work if  params[I'd] has values other than (1) and (2)
>
> Regards,
> Ganesh
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list