[Tutor] How to use setUpmodule() variables in tests?

2016-05-07 Thread ramakrishna reddy
Dear All,

In unittesting in python, how can I use variables of setUpModule() in tests?

example:

import unittest

def setUpModule():
b = 20  #> how can I use this variable in testa print

class A(unittest.TestCase):
def testa(self):
a = 10
print(a + b)

if __name__ == '__main__':
unittest.main()

Thanks,
Ram
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Convert tuple within tuple into single tuple

2017-01-11 Thread ramakrishna reddy
Hi All,

Is there any way to convert x = (1, 2, 3, (4, 5)) to x = (1, 2, 3, 4, 5) in
python 2.7

Thanks  in advance
Ram.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] collections.Callable functionality

2017-03-05 Thread ramakrishna reddy
Hi,

Can you please explain the functionality of collections.Callable ? If
possible with a code snippet.

I could not find a good explanation on google.

Thanks,
Ram.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How sum() works in python

2017-08-01 Thread ramakrishna reddy
Hi All,

I know

> sum([1,2,3]) returns 6.

But sum with [] 'empty list' as second parameter returns as below.

> sum([[1,2,3], [3,4,5]], []) returns [1, 2, 3, 3, 4, 5]
Can any one please explain this logic ? I searched in google but could not
find the suitable answer.

Thanks in advance.


Thanks,
Ram.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How sum() works in python

2017-08-01 Thread ramakrishna reddy
nice explanation .. thanks

this cleared my doubt
>>> k = [20]
>>> for i in [[1,2,3],[3,4,5]]:
... k += i
...
>>> k
[20, 1, 2, 3, 3, 4, 5]

On Tue, Aug 1, 2017 at 1:35 AM, Alan Gauld via Tutor 
wrote:

> On 01/08/17 07:06, ramakrishna reddy wrote:
>
> >> sum([1,2,3]) returns 6.
> >
> > But sum with [] 'empty list' as second parameter returns as below.
> >
> >> sum([[1,2,3], [3,4,5]], []) returns [1, 2, 3, 3, 4, 5]
>
> An interesting question, I wasn't aware that you could
> add lists with sum.
>
> However, the results seem clear enough. Let's start with the help()
> description:
> #
> Help on built-in function sum in module builtins:
>
> sum(...)
> sum(iterable[, start]) -> value
>
> Return the sum of an iterable of numbers (NOT strings) plus
> the value of parameter 'start' (which defaults to 0).
> When the iterable is empty, return start.
> #
>
> And lets see how it behaves with integers first:
> >>> sum([1,2,3])   # use start default of 0
> 6
> >>> sum([1,2,3],0) # use explicit start=0
> 6
> >>> sum([1,2,3],1) # use start=1
> 7
> >>> sum([1,2,3],9) # start = 9
> 15
>
> So in each case we get the sum of the items in the iterable
> plus the value of start. sum() is effectively doing
>
> result = start
> for n in iterable: result += n
> return result
>
> Now lets try using a list of lists:
>
> >>> sum([ [1,2,3],[3,4,5] ])
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: unsupported operand type(s) for +: 'int' and 'list'
>
> We get a type error because the start uses 0 and we can't
> add an int and a list. So let's provide a list as the
> start value:
>
> >>> sum([ [1,2,3],[3,4,5] ], [])
> [1, 2, 3, 3, 4, 5]
> >>>
>
> We now get the behaviour you saw because it adds the
> three lists together using the same algorithm as above.
>
> And if we use a non-empty start it becomes even more clear:
>
> >>> sum([ [1,2,3],[3,4,5] ], [42])
> [42, 1, 2, 3, 3, 4, 5]
>
> We could use tuples instead of lists and get the same result.
>
> What is interesting is that if we try the same thing with
> other iterables, such as a string, it doesn't work, even
> though string addition is defined. There is obviously
> some type checking taking place in there.
>
> HTH
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Variable name containing '-'

2017-09-01 Thread ramakrishna reddy
Hi there,

I am implementing a soap webservice where a method which has keyword
parameter(named:abc-xyz) needs to be used to call third party app.

eg: obj.method(abc-xyz=10)

As python does not support '-' in variable names, I am a bit confused.
I know in case of methods we can use getattr(self.object, 'method-name')()
can be used. But in case of variable how we can use ?

Thanks,
Ram.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor