Re: try except inside a with open

2018-07-21 Thread Cameron Simpson
Please try to preserve the attribution lines of previous authors. The inner quote below comes from Steven D'Aprano. On 21Jul2018 15:13, Ganesh Pal wrote: (1) Since this function always returns True (if it returns at all), what is the point? There's no point checking the return result, since it

Re: try except inside a with open

2018-07-21 Thread Ganesh Pal
> > > > (1) Since this function always returns True (if it returns at all), what > is the point? There's no point checking the return result, since it's > always true, so why bother returning anything? > > If I don't return anything from a function it returns None. But would it be better if for

Re: try except inside a with open

2018-07-20 Thread Steven D'Aprano
On Fri, 20 Jul 2018 23:29:21 +0530, Ganesh Pal wrote: > Dear python Friends, > > > I need a quick suggestion on the below code. > > def modify_various_line(f): > """ Try modifiying various line """ > try: > f.write('0123456789abcdef') > f.seek(5) # Go to the 6th byte

Re: try except inside a with open

2018-07-20 Thread MRAB
On 2018-07-20 18:59, Ganesh Pal wrote: Dear python Friends, I need a quick suggestion on the below code. def modify_various_line(f): """ Try modifiying various line """ try: f.write('0123456789abcdef') f.seek(5) # Go to the 6th byte in the file print f.

try except inside a with open

2018-07-20 Thread Ganesh Pal
Dear python Friends, I need a quick suggestion on the below code. def modify_various_line(f): """ Try modifiying various line """ try: f.write('0123456789abcdef') f.seek(5) # Go to the 6th byte in the file print f.read(1) f.seek(-3, 2) # Go to the 3rd