Re: [Tutor] pythonic

2018-04-01 Thread Steven D'Aprano
On Sun, Apr 01, 2018 at 10:58:51PM +0100, Alan Gauld via Tutor wrote: > On01/04/18 20:20, Albert-Jan Roskam wrote: > > fmt="%Y-%m-%d %H:%M\n" > > f.write(now.strftime(fmt)) > > Lately I've been using format(), which uses __format__, because I find it > > slightly more readable: > > format(datetime

Re: [Tutor] pythonic

2018-04-01 Thread Alan Gauld via Tutor
On01/04/18 20:20, Albert-Jan Roskam wrote: > fmt="%Y-%m-%d %H:%M\n" > f.write(now.strftime(fmt)) > Lately I've been using format(), which uses __format__, because I find it > slightly more readable: > format(datetime.now(), "%Y-%m-%d %H:%M") Interesting, I didn't know that format() recognised the

Re: [Tutor] pythonic

2018-04-01 Thread Albert-Jan Roskam
On Mar 30, 2018 10:39, Alan Gauld via Tutor wrote: > > On 30/03/18 03:48, Pat Martin wrote: > > > the "right" way to do it in python? > > More or less, a couple of comments below... > > > def Main(): > > Python function names begin with a lowercase letter by convention. > > > """Run if run as

Re: [Tutor] Proper way to unit test the raising of exceptions?

2018-04-01 Thread Simon Connah via Tutor
Awesome. Thank you all. Your solutions are great and should make the whole process a lot more simple. The only problem is that some_func() on my end is Django model with about 8 named arguments so it might be a bit of a pain passing all of those arguments. The context manager example seems like

Re: [Tutor] Proper way to unit test the raising of exceptions?

2018-04-01 Thread Mats Wichmann
On 04/01/2018 09:10 AM, Peter Otten wrote: > Simon Connah via Tutor wrote: > >> Hi, >> I'm just wondering what the accepted way to handle unit testing exceptions >> is? I know you are meant to use assertRaises, but my code seems a little >> off. > >> try: >> some_func() >> except SomeExcepti

Re: [Tutor] Proper way to unit test the raising of exceptions?

2018-04-01 Thread Peter Otten
Simon Connah via Tutor wrote: > Hi, > I'm just wondering what the accepted way to handle unit testing exceptions > is? I know you are meant to use assertRaises, but my code seems a little > off. > try: > some_func() > except SomeException: > self.assertRaises(SomeException) The logi

Re: [Tutor] Proper way to unit test the raising of exceptions?

2018-04-01 Thread Steven D'Aprano
On Sun, Apr 01, 2018 at 10:57:15AM +, Simon Connah via Tutor wrote: > I'm just wondering what the accepted way to handle unit testing > exceptions is? I know you are meant to use assertRaises, but my code > seems a little off. Here's a modified example from the statistics library in Python

[Tutor] Proper way to unit test the raising of exceptions?

2018-04-01 Thread Simon Connah via Tutor
Hi, I'm just wondering what the accepted way to handle unit testing exceptions is? I know you are meant to use assertRaises, but my code seems a little off. try:    some_func() except SomeException:    self.assertRaises(SomeException) Is there a better way to do this at all? The problem with the a