close() the file when opening "with"?
So far I learnt "with" closes the file opened therefore "Generally" no need to close() file. I'm worry about this "Generally", then close() or not? -- https://mail.python.org/mailman/listinfo/python-list
Re: close() the file when opening "with"?
On Sun, Jun 14, 2020 at 8:16 PM Bischoop wrote: > > > So far I learnt "with" closes the file opened therefore "Generally" no > need to close() file. I'm worry about this "Generally", then close() or > not? Where did you learn that? Can you cite a reference? If you use a with block, the file is guaranteed to be closed as you exit that block. It's that simple. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: close() the file when opening "with"?
On 2020-06-14, Chris Angelico wrote: > On Sun, Jun 14, 2020 at 8:16 PM Bischoop wrote: >> >> >> So far I learnt "with" closes the file opened therefore "Generally" no >> need to close() file. I'm worry about this "Generally", then close() or >> not? > > Where did you learn that? Can you cite a reference? > > If you use a with block, the file is guaranteed to be closed as you > exit that block. It's that simple. > > ChrisA Where I learnt what that "with" closes the file or that "Generally" no need to close() file when using "with"? -- https://mail.python.org/mailman/listinfo/python-list
Re: Convert and analyze image data in a spreadsheet.
Dennis, Thanks for your ideas. The researcher I am working with just told me the data is wrong and needs to send me new data and there are other problems with exactly what their research questions is. So this goes nowhere for now. Thanks Vincent Davis 720-301-3003 *Want to get a hold of me?* *SMS: awesome.phone: ok...* *email: bad!* On Thu, Jun 11, 2020 at 1:17 PM Dennis Lee Bieber wrote: > > My previous response hasn't made it through the > gmane<>list<>usenet<>back cycle so I can't "talk to myself"... > > On Thu, 11 Jun 2020 07:44:25 -0600, Vincent Davis > declaimed the following: > > >Looking for a little advise. > >I have 6x6 color (CIELAB < > https://en.wikipedia.org/wiki/CIELAB_color_space>) > >data in a spreadsheet (color samples of clothing). I would like to > >visualize this as an image on a per channel (l,a,b) and as a color image. > I > >can read the data from the spreadsheet. I am not sure the path a should > >choose from there. I think the path is to read this data into a numpy > array > >and use scikit-image. > > > > I'm going to speak blasphemy and mention the R statistics package. > It > has > > https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/convertColor.html > which includes L*a*b* as a color space. Though it does not seem to have > Adobe RGB... > """ > "XYZ", "sRGB", "Apple RGB", "CIE RGB", "Lab", "Luv". > """ > > Also links to the main page of a source of the math used in > converting > > It also mentions something that wasn't obvious in other references: > """ > The Lab and Luv spaces describe colors of objects, and so require the > specification of a reference ‘white light’ color. Illuminant D65 is a > standard indirect daylight, Illuminant D50 is close to direct sunlight, and > Illuminant A is the light from a standard incandescent bulb. Other standard > CIE illuminants supported are B, C, E and D55. RGB colour spaces are > defined relative to a particular reference white, and can be only > approximately translated to other reference whites. > """ > > ... hence conversions from L*a*b* to, say, sRGB, will differ based upon > what illumination reference is used! > > > > -- > Wulfraed Dennis Lee Bieber AF6VN > [email protected] > http://wlfraed.microdiversity.freeddns.org/ > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Python database compatibility
Thanks Neil for your input . I am looking for opportunities to connect to the Tandem DB ( enscribe) via using Payton programs to analyse the data /patterns of the txns. I am very new in Python world so don,t know how these can be achieved ! In our setup , Tandem DB is not connected via any other 3rd party system therefore don’t know if JDBC/ODBC works here or not. But will go through the link you have given and see if there are any!! Thanks Sid On Sat, 13 Jun 2020 at 00:27, DL Neil via Python-list < [email protected]> wrote: > On 13/06/20 8:49 AM, Siddharth Joshi wrote: > > I am new in Python world and would like to use it for one of the our > > purpose . Before that, I would like to ask if Python has compatibility > with > > ENSCRIBE database . > > > > Enscribe database (file structured) is the native database of HP NonStop > > (Tandem) server, mainly used in applications running on nonStop Tandem . > > Almost all the applications which runs on Tandem using enscribe are Tier > 0 > > applications (often critical once). > > Wow, a 'blast from the past'! > > I worked on HP3000s (from which Tandem originally developed) forty years > ago. My first foray into 'non-stop' computing, supporting banking > systems and the like, involved jumping-ship to Stratus (or more > precisely, the re-badged IBM System/88). Others were also involved in > that project, so happily/sadly I ended-up consulting for a project that > no-one else wanted: figuring out how to network those new-fangled IBM > PC/XTs and integrate office systems with aforementioned DBs and similar. > After all that, please excuse me whilst I take a grandpa-snooze... > > > The question is broad. What do you want to do once an interface can be > found, eg do you merely want a one-off use to transcribe the old data to > a new system, do you want to build a front-end interface and > data-collection application, or is perhaps a back-end MIS analysis your > goal? The quality of the interface, its speed, its data-handling > capabilities, etc, etc, will all influence... > > > I haven't heard about Enscribe in recent years. My recollection is that > their direct interfaces were Java-based. Python offers a JDBC > "connector" which may be worth investigating. There are also other > new/improved/faster/super libraries, eg JayDeBeAPI - see PyPi. See also > Attunity (if still available, eg > http://whp-aus2.cold.extweb.hp.com/pub/nonstop/ccc/apr0110.pdf). > > HP pursued various 'modernisation' proposals, which may be worth review, > eg using SOAP/micro-services and XML/interchange. > > The comp.sys.tandem forum discussed ideas (five years ago): > https://groups.google.com/forum/#!topic/comp.sys.tandem/dG2t9faPzWg > > The lingua-franca of DB inter-connection is probably ODBC, and thus the > Python ODBC connector. > > > Trusting these give some food-for-thought... > -- > Regards =dn > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
How to keep Dict[str, List] default method parameter as local to the method?
Hi,
consider this example:
from typing import Dict, List
class chk_params:
def execute(self, params: Dict[str, List] = None):
if params is None:
params = {}
for k, v in params.items():
params[k] = [val + 10 for val in v]
return params.values()
params = {
'A' : [1],
'B': [2],
'C': [3],
'D': [4],
'E': [5]
}
print(params)
params_obj = chk_params()
print(params_obj.execute(params = params))
print(params)
Output is:
{'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]}
dict_values([[11], [12], [13], [14], [15]])
{'A': [11], 'B': [12], 'C': [13], 'D': [14], 'E': [15]}
I expected that last print statement will show original parameters A=1, B=2...
but this is not the case.
How to construct the method parameters, with params parameter as type of
Dict[str, List], but at the same time keep params as local dictionary to the
chk_params.execute() method?
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to keep Dict[str, List] default method parameter as local to the method?
[email protected] writes: > Hi, > > consider this example: > > from typing import Dict, List > > > class chk_params: > def execute(self, params: Dict[str, List] = None): > if params is None: > params = {} > > for k, v in params.items(): > params[k] = [val + 10 for val in v] > > return params.values() > > params = { > 'A' : [1], > 'B': [2], > 'C': [3], > 'D': [4], > 'E': [5] > } > print(params) > params_obj = chk_params() > > print(params_obj.execute(params = params)) > print(params) > > Output is: > {'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]} > dict_values([[11], [12], [13], [14], [15]]) > {'A': [11], 'B': [12], 'C': [13], 'D': [14], 'E': [15]} > > I expected that last print statement will show original parameters A=1, > B=2... but this is not the case. > > How to construct the method parameters, with params parameter as type of > Dict[str, List], but at the same time keep params as local dictionary to the > chk_params.execute() method? The execute method modifies the dict being passed into it. If you don't want that behaviour, you can pass in a copy of your params object. dict(params) will make a shallow copy, which will work in this particular case. If the execute method were to do in-place modification operation on the values (perhaps using v.append or v.extend in its loop), you'd need a deep copy provided by the standard library's copy.deepcopy function. -- regards, kushal -- https://mail.python.org/mailman/listinfo/python-list
Re: How to keep Dict[str, List] default method parameter as local to the method?
[email protected] wrote at 2020-6-14 08:20 -0700: >Hi, > >consider this example: > >from typing import Dict, List > > >class chk_params: >def execute(self, params: Dict[str, List] = None): >if params is None: >params = {} > >for k, v in params.items(): >params[k] = [val + 10 for val in v] > >return params.values() > >params = { >'A' : [1], >'B': [2], >'C': [3], >'D': [4], >'E': [5] >} >print(params) >params_obj = chk_params() > >print(params_obj.execute(params = params)) >print(params) > >Output is: >{'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]} >dict_values([[11], [12], [13], [14], [15]]) >{'A': [11], 'B': [12], 'C': [13], 'D': [14], 'E': [15]} > >I expected that last print statement will show original parameters A=1, B=2... >but this is not the case. You must distinquish between the "name -> object" binding of function arguments and modifications of the object. You change the binding via assignments to the name (in your case of the form "params = ..."). Those assignments affect only the local name (i.e. in the function), not bindings of the name name elsewhere. If you change the object itself ("params" is bound to) (in your case via "params[k] = ..."), then the object changes - and this change can be seen at other places where this object is accessible. If you want object modifications made in your function not be seen elsewhere, you must work on a local object (not accessible elsewhere: e.g. def execute(self, params: Dict[str, List] = None): params = {} if params is None else params.copy() # copies ... -- https://mail.python.org/mailman/listinfo/python-list
Re: close() the file when opening "with"?
On 2020-06-14 10:12:26 -, Bischoop wrote: > So far I learnt "with" closes the file opened therefore "Generally" no > need to close() file. I'm worry about this "Generally", then close() or > not? In some cases you don't want the file to be automatically closed when you leave the context where you opened it (for example, you might want to write a function which opens a file, does some checks on it and then returns the file handle to the caller so that it can read or write the file). In those cases you can't use "with open ..." and you will have to close the file in some other fashion (for example, the caller could be responsible for calling close, or you could write your function as a context manager and the caller could call it as "with my_open ...") So, "generally" you want to use open together with "with" (and then the file will be automatically closed), but sometimes you want to do soemthing else. hp -- _ | Peter J. Holzer| Story must make more sense than reality. |_|_) || | | | [email protected] |-- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" signature.asc Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Re: How to keep Dict[str, List] default method parameter as local to the method?
[email protected] wrote: > Hi, > > consider this example: > > from typing import Dict, List > > > class chk_params: > def execute(self, params: Dict[str, List] = None): > if params is None: > params = {} > > for k, v in params.items(): > params[k] = [val + 10 for val in v] > > return params.values() > > params = { > 'A' : [1], > 'B': [2], > 'C': [3], > 'D': [4], > 'E': [5] > } > print(params) > params_obj = chk_params() > > print(params_obj.execute(params = params)) > print(params) > > Output is: > {'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]} > dict_values([[11], [12], [13], [14], [15]]) > {'A': [11], 'B': [12], 'C': [13], 'D': [14], 'E': [15]} > > I expected that last print statement will show original parameters A=1, > B=2... but this is not the case. > > How to construct the method parameters, with params parameter as type of > Dict[str, List], but at the same time keep params as local dictionary to > the chk_params.execute() method? The type annotations are only a distraction here; let's give classical Python a chance with - no type annotations - no class - dangerous default, for the thrill of it;) def execute(params={}): return [[val + 10 for val in v] for v in params.values()] Clean and simple. If you insist on getting dict_values(): def execute(params={}): return {k: [val + 10 for val in v] for k, v in params.items()}.values() The relevant takeaway is: if you don't want to modify a value, don't modify it. Do not wait for a const modifier to save you. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to keep Dict[str, List] default method parameter as local to the method?
On 2020-06-14 08:20:46 -0700, [email protected] wrote: > consider this example: > > from typing import Dict, List > > > class chk_params: > def execute(self, params: Dict[str, List] = None): > if params is None: > params = {} > > for k, v in params.items(): > params[k] = [val + 10 for val in v] > > return params.values() > > params = { > 'A' : [1], > 'B': [2], > 'C': [3], > 'D': [4], > 'E': [5] > } > print(params) > params_obj = chk_params() > > print(params_obj.execute(params = params)) > print(params) > > Output is: > {'A': [1], 'B': [2], 'C': [3], 'D': [4], 'E': [5]} > dict_values([[11], [12], [13], [14], [15]]) > {'A': [11], 'B': [12], 'C': [13], 'D': [14], 'E': [15]} > > I expected that last print statement will show original parameters > A=1, B=2... but this is not the case. Others have already explained that. > How to construct the method parameters, with params parameter as type > of Dict[str, List], but at the same time keep params as local > dictionary to the chk_params.execute() method? Take one step back. What you really want is for chk_params.execute to return the new values and not to modify the old dict. Whether or not params is a "local dictionary" (that doesn't really make much sense in Python[1]) is an irrelevant implementation detail. So lets do that: class chk_params: def execute(self, params: Dict[str, List] = None): if params is None: params = {} result = {} for k, v in params.items(): result[k] = [val + 10 for val in v] return result.values() Of course at this point I notice that you are building a dict which you don't need, so I would simplify that further: class chk_params: def execute(self, params: Dict[str, List] = None): if params is None: params = {} result = [] for k, v in params.items(): result.append([val + 10 for val in v]) return result hp [1] There is a very good talk by Raymond Hettinger on how variables and objects in Python work. Unfortunately I can't find it at the moment. -- _ | Peter J. Holzer| Story must make more sense than reality. |_|_) || | | | [email protected] |-- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" signature.asc Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Re: How to keep Dict[str, List] default method parameter as local to the method?
On 2020-06-14 19:44:32 +0200, Peter J. Holzer wrote: > [1] There is a very good talk by Raymond Hettinger on how variables and > objects in Python work. Unfortunately I can't find it at the moment. Sorry, that talk was by Ned Batchelder (that's why I couldn't find it): https://www.youtube.com/watch?v=_AEJHKGk9ns hp -- _ | Peter J. Holzer| Story must make more sense than reality. |_|_) || | | | [email protected] |-- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" signature.asc Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Re: How to keep Dict[str, List] default method parameter as local to the method?
params = {} if params is None else params.copy()
has solved the problem.
I have provided just a toy example here. Execute method actually takes
dict[str, List]. List contains objects. Each object has two properties, so I
have a logic that analyzes these properties and returns None or List as a
dict[k] value.
Now when I have dict prepared with proper key/values pairs, I am proceeding to
execution of the jinjasql query.
What I have to ensure is that I will get dic[str, List] (I could go further and
ensure that list contains only object of certain class, by the way, how to do
that?).
Than I must ensure that I am working on local copy of parameters.
Anyway, copy that Dieter Maurer suggested works as it should.
Thanks.
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to keep Dict[str, List] default method parameter as local to the method?
Thanks for the video. Now it is clear to me what has happened and why copy solves the problem. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fwd: python 3.8.3 fails
On 6/13/2020 2:38 PM, Dennis Lee Bieber wrote:
On Sat, 13 Jun 2020 17:10:46 +0100, MRAB
declaimed the following:
I have Windows 10 Home and the stock Python from python.org. Typing just
"python" at the Powershell prompt starts Python without a problem.
99 44/100% sure what the OP called "PowerShell" is "PowerShell ISE",
not a PowerShell console. In my testing ISE intercepts STDIN and STDERR --
Interactive Python dumps its banner message on STDERR. ISE intercepts that
banner and tries to interpret it as a PowerShell error object, which fails,
causing a PowerShell error dump to be shown. The interception of STDIN
prevents the Python >>> prompt from receiving any input. Buffering of
STDOUT is also in play...
-=-=-=- ISE (using to abort hanging commands)
PS C:\Users\Wulfraed> python -c "print(input('type something'))"
PS C:\Users\Wulfraed> python -c "x = input('Enter something '); print(x)"
PS C:\Users\Wulfraed> python -c "x = input('Enter something\n '); print(x)"
Enter something
PS C:\Users\Wulfraed>
-=-=-=- PS console window
PS C:\Users\Wulfraed> python -c "print(input('type something'))"
type somethingabc
abc
PS C:\Users\Wulfraed> python -c "x = input('Enter something '); print(x)"
Enter something abcd
abcd
PS C:\Users\Wulfraed> python -c "x = input('Enter something\n '); print(x)"
Enter something
something
something
PS C:\Users\Wulfraed>
Could you open a tracker issue to put 'Do not use PowerShell IDE' is the
Windows chapter of 'Using Python'? This is obviously not common
knowledge? Or open as a possible bug issue. Maybe the install can be
done a big differently.
--
Terry Jan Reedy
--
https://mail.python.org/mailman/listinfo/python-list
Multiple event loops within the same thread ?
Hi all, It's possible to create several event loops in the same thread by calling asyncio.new_event_loop() Question: is there any use case where that could be useful ? Thank you in advance -- ∞ -- https://mail.python.org/mailman/listinfo/python-list
Re: close() the file when opening "with"?
On 6/14/2020 6:36 AM, Bischoop wrote: On 2020-06-14, Chris Angelico wrote: On Sun, Jun 14, 2020 at 8:16 PM Bischoop wrote: So far I learnt "with" closes the file opened therefore "Generally" no need to close() file. I'm worry about this "Generally", then close() or not? Where did you learn that? Can you cite a reference? If you use a with block, the file is guaranteed to be closed as you exit that block. It's that simple. ChrisA Where I learnt what that "with" closes the file or that "Generally" no need to close() file when using "with"? The latter. Chris said that the former is true. The qualification in the latter should not be. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
In this episode we write a full-text search engine using bloom filters! What other packages are you aware of that can act as search engines?
https://youtu.be/MHatF6Hpm1U -- https://mail.python.org/mailman/listinfo/python-list
