3D surface plot
I should know this ...! Anyway, I have a list of 36 tuples, each with x, y, z values I want to create a surface plot ... Need help putting data into right format for matplot3D ... This is a gmail account used by Keith D. Anthony On Sat, Mar 16, 2019 at 12:03 PM wrote: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > python-list-requ...@python.org > > You can reach the person managing the list at > python-list-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > Today's Topics: > >1. Re: Question regarding the local function object (Terry Reedy) >2. subprocess svn checkout password issue (Martin De Kauwe) >3. RE: asyncio Question (Joseph L. Casale) >4. Re: Implement C's Switch in Python 3 (jf...@ms4.hinet.net) >5. Re: subprocess svn checkout password issue (dieter) >6. Re: subprocess svn checkout password issue (Martin De Kauwe) >7. Re: Question regarding the local function object (Gregory Ewing) >8. Re: how to embed non-tkinter VLC player into grid of tkinter > with python? (akashsahu...@gmail.com) >9. Re: subprocess svn checkout password issue (Dan Sommers) > > > > -- Forwarded message -- > From: Terry Reedy > To: python-list@python.org > Cc: > Bcc: > Date: Fri, 15 Mar 2019 13:00:50 -0400 > Subject: Re: Question regarding the local function object > On 3/15/2019 8:47 AM, Arup Rakshit wrote: > > Hi, > > > > I am reading a book where it says that: > > > > Just like module-level function definitions, the definition of a local > function happens at run time when the def keyword is executed. > Interestingly, this means that each call to sort_by_last_letter results in > a new definition of the function last_letter. That is, just like any other > name bound in a function body, last_letter is bound separately to a new > function each time sort_by_last_letter is called. > > > > If that above is true, why the below program shows the same object > reference for last_letter every time I call function sort_by_last_letter. > > > > # file name is sample.py > > > > def sort_by_last_letter(strings): > > def last_letter(s): > > return s[-1] > > print(last_letter) > > return sorted(strings, key=last_letter) > > > > python3 -i sample.py > sort_by_last_letter(['ghi', 'def', 'abc']) > > .last_letter at 0x1051e0730> > > ['abc', 'def', 'ghi'] > sort_by_last_letter(['ghi', 'def', 'abc']) > > .last_letter at 0x1051e0730> > > ['abc', 'def', 'ghi'] > sort_by_last_letter(['ghi', 'def', 'abckl']) > > .last_letter at 0x1051e0730> > > ['def', 'ghi', 'abckl'] > > To build on Calvin's explanation ... > intersperse other function definitions between the repeated calls > > sort_by_last_letter(['ghi', 'def', 'abc']) > def a(): return 'skjsjlskjlsjljs' > print(a) > sort_by_last_letter(['ghi', 'def', 'abc']) > def b(): return 546465465454 > print(b) > sort_by_last_letter(['ghi', 'def', 'abc']) > > and memory gets reused a different way. > > .last_letter at 0x03A51D40> > # <== is same memory as . > .last_letter at 0x043C2710> > # ditto > .last_letter at 0x043C2768> > > Creating a new list or string did not have the same effect. I believe > that CPython function objects must currently all have the same size or > at least the same max size and conclude that CPython currently allocates > them from a block of memory that is some multiple of that size. These > are, of course, current internal implementation details, subject to > change and even variation across hardware and OSes. > > -- > Terry Jan Reedy > > > > > > -- Forwarded message -- > From: Martin De Kauwe > To: python-list@python.org > Cc: > Bcc: > Date: Fri, 15 Mar 2019 15:17:22 -0700 (PDT) > Subject: subprocess svn checkout password issue > Hi, > > I'm trying to write a script that will make a checkout from a svn repo and > build the result for the user. However, when I attempt to interface with > the shell it asks the user for their filename and I don't know how to > capture this with my implementation. > > user = "XXX578" > root="https://trac.nci.org.au/svn/cable"; > repo_name = "CMIP6-MOSRS" > > cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name) > p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, > stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > error = subprocess.call(cmd, shell=True) > if error is 1: > raise("Error downloading repo" > > I tried adding .wait(timeout=60) to the subprocess.Popen command but that > didn't work. > > Any advice on whether there is an augmentation to the above, or a better > approach, would be much appreciated. I need to solve th
Question about the @staticmethod decorator
I am reading a book where the author says that: In principle, it would also be possible to implement any @staticmethod completely outside of the class at module scope without any loss of functionality — so you may want to consider carefully whether a particular function should be a module scope function or a static method. The @staticmethod decorator merely facilitates a particular organisation of the code allowing us to place what could otherwise be free functions within classes. I didn’t get quiet well this block of text. My first question is how would I make a module level function as static method of a class. Can anyone give me an example of this? What are the contexts that would let you to think if they are good fit inside the class or module level scope functions? Thanks, Arup Rakshit a...@zeit.io -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about the @staticmethod decorator
On Sun, 17 Mar 2019 at 18:18, Arup Rakshit wrote: > > I am reading a book where the author says that: > > In principle, it would also be possible to implement any @staticmethod > completely outside of the class at module scope without any loss of > functionality — so you may want to consider carefully whether a particular > function should be a module scope function or a static method. The > @staticmethod decorator merely facilitates a particular organisation of the > code allowing us to place what could otherwise be free functions within > classes. > > I didn’t get quiet well this block of text. My first question is how would I > make a module level function as static method of a class. Can anyone give me > an example of this? What are the contexts that would let you to think if they > are good fit inside the class or module level scope functions? The point the author is trying to make is that there's no practical difference between def say_hello(name): print("Hello,", name) and class Talker: @staticmethod def say_hello(name): print("Hello,", name) You refer to the first as "say_hello", and the second as "Talker.say_hello", but otherwise they are used identically. The static method has no access to the class or instance variables, so it has no special capabilities that the standalone "say_hello" function has. So, to rephrase the words you used, @staticmethod lets you organise your code in a certain way, but doesn't offer any extra capabilities over module-level functions. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about the @staticmethod decorator
On 17Mar2019 20:24, Paul Moore wrote: On Sun, 17 Mar 2019 at 18:18, Arup Rakshit wrote: I am reading a book where the author says that: In principle, it would also be possible to implement any @staticmethod completely outside of the class at module scope without any loss of functionality — so you may want to consider carefully whether a particular function should be a module scope function or a static method. The @staticmethod decorator merely facilitates a particular organisation of the code allowing us to place what could otherwise be free functions within classes. I didn’t get quiet well this block of text. My first question is how would I make a module level function as static method of a class. Can anyone give me an example of this? What are the contexts that would let you to think if they are good fit inside the class or module level scope functions? The point the author is trying to make is that there's no practical difference between def say_hello(name): print("Hello,", name) and class Talker: @staticmethod def say_hello(name): print("Hello,", name) You refer to the first as "say_hello", and the second as "Talker.say_hello", but otherwise they are used identically. The static method has no access to the class or instance variables, so it has no special capabilities that the standalone "say_hello" function has. So, to rephrase the words you used, @staticmethod lets you organise your code in a certain way, but doesn't offer any extra capabilities over module-level functions. This is true in the narrow sense that the function itself has no access to any class of instance implicit context. However, the method's _name_ is in the class namespace and findable from the class or any instance. This means that in your example above, if I have a Talker instance: talker = Talker() I can access the class _appropriate_ say_hello() function from the instance: talker.say_hello("Paul") Compare this with another class: class Writer: @staticmethod def say_hello(name): global_pen.transcribe_text("Hello " + name) If I've got a Writer instead of a talker, or better still a mix of them, I can call their .say_hello() methods without caring what their backend is: leader = "Arup" for member in social_group: member.say_hello(leader) So to Arup's question, a @staticmethod does not need any access to the instance or class context. However, there are still good reasons for putting it in the class definition: - code organisation: you find this function in the class definition with all the other methods - instance access to the _appropriate_ version of the method because the instance finds the method name in its own class. Now, to the converse question: if you've a potential @staticmethod, why would you bother? Aside from accessing it via an instance (or class), marking a method as a staticmethod has at least 2 other advantages: It means you can call it via an instance or a class: # use speech Talker.say_hello("Cameron") # use writing Writer.say_hello("Cameron") # use whatever "someone" prefers someone.say_hello("Cameron") Importantly, if it were an ordinary method: class Talker: def say_hello(self, name): print("Hello", name) then you _couldn't_ use the Talker.say_hello() or Writer.say_hello() forms because you've got nothing for the "self" parameter. It also makes linters happier. What's a linter? It is a tool to inspect code and complain about all sorts of dubious things. They're incredibly useful. Complaint vary from cosmetic, such as poor style (which tends to correlate with hard to ready and maintain code) to semntic, such as variables which are used before they are initialised (which usually indicates a bug in the code, often as simple as a misspelt variable name but also frequently geniuine logic bugs). In the case of a static method, if cosider these two: class Talker: def say_hello(self, name): print("Hello", name) @staticmethod def say_hello2(name): print("Hello", name) You can call either from an instance: someone.say_hello("Arup") and get the same result. However, a linter will complain about the former say_hello() method because the parameter "self" is unused. It won't complain about the latter because there isn't a "self" method. You might not care here, but if you use linters you will find complaints about unused parameters useful. They generally indicate things like: - you misspelt the parameter name inside the function (or conversely in the header) so that it isn't correct. This is a bug and the linter is helping you here. - your function genuinely isn't using the parameter. This often indicates that the function is not completely implemented, because changing the value of the parameters does not affect what the function does: that parameter is useless. So you can see that usually these lint complaints help you find bugs in your