Re: generator to write N lines to file

2019-06-23 Thread Peter Otten
Sayth Renshaw wrote: > Afternoon > > Trying to create a generator to write the first N lines of text to a file. > However, I keep receiving the islice object not the text, why? > > from itertools import islice > > fileName = dir / "7oldsamr.txt" > dumpName = dir / "dump.txt" > > def getWord(in

generator to write N lines to file

2019-06-23 Thread Sayth Renshaw
Afternoon Trying to create a generator to write the first N lines of text to a file. However, I keep receiving the islice object not the text, why? from itertools import islice fileName = dir / "7oldsamr.txt" dumpName = dir / "dump.txt" def getWord(infile, lineNum): with open(infile, 'r+')

Re: Understand workflow about reading and writing files in Python

2019-06-23 Thread DL Neil
Yes, better to reply to list - others may 'jump in'... On 20/06/19 5:37 PM, Windson Yang wrote: Thank you so much for you review DL Neil, it really helps :D. However, there are some parts still confused me, I replyed as below. It's not a particularly easy topic... DL Neil

Fwd: Understand workflow about reading and writing files in Python

2019-06-23 Thread Windson Yang
Thank you so much for you review DL Neil, it really helps :D. However, there are some parts still confused me, I replyed as below. DL Neil 于2019年6月19日周三 下午2:03写道: > I've not gone 'back' to refer to any ComSc theory on buffer-management. > Perhaps you might benefit from such? > > I just take a cr

Re: Python refactoring question and create dynamic attributes

2019-06-23 Thread DL Neil
On 23/06/19 7:56 PM, Arup Rakshit wrote: In the below code: @classmethod def find(self, id): if isinstance(id, list): rows = self.__table__().get_all(*id).run(self.__db__().conn) result = [] for row in rows: acategory = C

Re: Python refactoring question and create dynamic attributes

2019-06-23 Thread MRAB
On 2019-06-23 10:44, Arup Rakshit wrote: On 23-Jun-2019, at 2:31 PM, Cameron Simpson wrote: On 23Jun2019 13:26, Arup Rakshit wrote: In the below code: @classmethod def find(self, id): if isinstance(id, list): rows = self.__table__().get_all(*id).run(self.__db__().conn)

Re: finding a component in a list of pairs

2019-06-23 Thread Peter Pearson
On 22 Jun 2019 13:24:38 GMT, Stefan Ram wrote: [snip] > > print( next( ( pair for pair in pairs if pair[ 0 ]== 'sun' ), > ( 0, '(unbekannt)' ))[ 1 ]) > print( next( itertools.dropwhile( lambda pair: pair[ 0 ]!= 'sun', pairs )) > [ 1 ]) [snip] > > The last two lines of

Re: Python refactoring question and create dynamic attributes

2019-06-23 Thread Arup Rakshit
> On 23-Jun-2019, at 2:31 PM, Cameron Simpson wrote: > > On 23Jun2019 13:26, Arup Rakshit wrote: >> In the below code: >> >> @classmethod >> def find(self, id): >> if isinstance(id, list): >> rows = self.__table__().get_all(*id).run(self.__db__().conn) >> result =

Re: Python refactoring question and create dynamic attributes

2019-06-23 Thread Cameron Simpson
On 23Jun2019 13:26, Arup Rakshit wrote: In the below code: @classmethod def find(self, id): if isinstance(id, list): rows = self.__table__().get_all(*id).run(self.__db__().conn) result = [] for row in rows: acategory = Category()

Python refactoring question and create dynamic attributes

2019-06-23 Thread Arup Rakshit
In the below code: @classmethod def find(self, id): if isinstance(id, list): rows = self.__table__().get_all(*id).run(self.__db__().conn) result = [] for row in rows: acategory = Category() acategory.__dict__.updat