Re: error in CSV resetting with seek(0)

2020-05-01 Thread Peter Otten
Rahul Gupta wrote: > consider the following code > import csv > import numpy as np > > with open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file1, > open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file2: > csv_reader1 = csv.DictReader(csv_file1) > csv_reader2 = csv.DictReader(csv_

error in CSV resetting with seek(0)

2020-05-01 Thread Rahul Gupta
consider the following code import csv import numpy as np with open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file1, open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file2: csv_reader1 = csv.DictReader(csv_file1) csv_reader2 = csv.DictReader(csv_file2) filename = "cell_split

Re: Function to avoid a global variable

2020-05-01 Thread DL Neil via Python-list
On 2/05/20 12:00 PM, Bob van der Poel wrote: I still think that the use of a keyword like "static" would be easiest. def foo(arg): static counter = 0 counter += 1 if counter ... And in this case static just means that it's a variable only readable inside foo() and it should maint

Re: Function to avoid a global variable

2020-05-01 Thread DL Neil via Python-list
On 2/05/20 11:30 AM, Chris Angelico wrote: On Sat, May 2, 2020 at 9:14 AM DL Neil via Python-list wrote: On 28/04/20 7:36 PM, Chris Angelico wrote: "Best"? Not sure about that. Functions are first-class objects in Python, so a function *is* a callable object. You don't have to create a custom

Re: Function to avoid a global variable

2020-05-01 Thread Bob van der Poel
I still think that the use of a keyword like "static" would be easiest. def foo(arg): static counter = 0 counter += 1 if counter ... And in this case static just means that it's a variable only readable inside foo() and it should maintain it's value between calls. A "global" without t

Re: Function to avoid a global variable

2020-05-01 Thread Chris Angelico
On Sat, May 2, 2020 at 9:14 AM DL Neil via Python-list wrote: > > On 28/04/20 7:36 PM, Chris Angelico wrote: > >>> "Best"? Not sure about that. Functions are first-class objects in > >>> Python, so a function *is* a callable object. You don't have to create > >>> a custom class with a call method

Re: Function to avoid a global variable

2020-05-01 Thread DL Neil via Python-list
On 28/04/20 7:36 PM, Chris Angelico wrote: "Best"? Not sure about that. Functions are first-class objects in Python, so a function *is* a callable object. You don't have to create a custom class with a call method just to be able to attach attributes to your function. ChrisA Using a mutable o

Re: How to test?

2020-05-01 Thread DL Neil via Python-list
Given your replies, 'now' might be a good time to take a look at Pytest, and see how you could use it to help build better code - by building tested units/functions which are assembled into ever-larger tested-units... (there is a range of choice/other testing aids if Pytest doesn't take your fancy

Re: Techniques to extend code without modifying it? (besides modules and decorators)

2020-05-01 Thread Christian Seberino
Paul Thanks! I'm glad there is theory about my concern. I knew I wasn't the only one with that question. cs > > https://en.wikipedia.org/wiki/Open%E2%80%93closed_principle > > Also: > > https://en.wikipedia.org/wiki/Expression_problem -- https://mail.python.org/mailman/listinfo/python-lis