[Tutor] Tutor Digest, Vol 114, Issue 73

I. Alejandro Fleischer iafleischer at gmail.com
Thu Sep 5 21:13:16 CEST 2013


Dear Friends,

I have a set of data to fit to a custom equation, y=a+b*exp(k*x), would you
advice me on the how to, or tutorial?

Thank you


On Thu, Aug 22, 2013 at 10:11 AM, <tutor-request at python.org> wrote:

> Send Tutor mailing list submissions to
>         tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>         tutor-request at python.org
>
> You can reach the person managing the list at
>         tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>    1. Re: hi (Oscar Benjamin)
>    2. global variables (Matthew Ngaha)
>    3. Re: global variables (Chris Down)
>    4. Re: global variables (Matthew Ngaha)
>    5. Re: global variables (Chris Down)
>    6. Re: global variables (Alan Gauld)
>    7. Re: global variables (Alan Gauld)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 22 Aug 2013 13:03:10 +0100
> From: Oscar Benjamin <oscar.j.benjamin at gmail.com>
> To: Vick <vick1975 at orange.mu>
> Cc: "Tutor at python.org" <tutor at python.org>
> Subject: Re: [Tutor] hi
> Message-ID:
>         <CAHVvXxS-ebGx20GhGsMwtdgVAFz3geKKbA-UHDmAw=
> On53Hr1g at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On 20 August 2013 13:49, Vick <vick1975 at orange.mu> wrote:
> >
> > From: Oscar Benjamin [mailto:oscar.j.benjamin at gmail.com]
> >
> >> Well just send me some tutorial on how to build and obtain the
> >> coefficients for the butcher tableau for the RK4 as an example, and
> >> after I've mastered it, I'd give the dopri8 a shot.
> >
> > I am up for it so I'll see if I can find time to write a script that
> shows
> > how to do it.
> >
> > [Vick] Hope you've had the time to code it. I'm waiting for it.
>
> Sorry, I haven't found the time yet. It is still on my todo list though!
>
> > By the way your code for the Adams-Moulton coefficients are actually the
> > Adams-Bashforth ones and so I copied it and modified the copy to have the
> > Adams-Moulton coefficients as well. This means that I have now an
> nth-order
> > predictor-corrector method to solve for ODEs.
>
> Oh sorry. That'll be a cut and paste error. My code lives in a private
> software library that I keep meaning to release on PyPI but it's not
> ready for public consumption in quite a number of ways.
>
> I'm glad that you worked it out though. You''ll probably understand
> what I mean now when I say that the AM or AB integrators need a
> secondary algorithm to bootstrap. The accuracy of the subsequent AM/AB
> method depends on the accuracy of that step. In the worst case you can
> just use rk4 with a very small time-step for this bit though.
>
>
> Oscar
>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 22 Aug 2013 13:36:24 +0100
> From: Matthew Ngaha <chigga101 at gmail.com>
> To: "tutor at python.org" <tutor at python.org>
> Subject: [Tutor] global variables
> Message-ID:
>         <CACzNyA1WPMsoWDF9cLSvhDsd+g20=
> zO+y3BY20vkAumhaPTQ0w at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> I'm always told to avoid using them. I read discussions on the python
> irc channel about them but honestly i feel there are some times where
> i can't avoid using them. Like where i want to keep track of a state
> variable in many different functions that may or may not alter its
> value and also not wanting any of the functions to return it to the
> caller.
>
> My question is how many global variables did your last decent sized
> program have? Also please share any insight you have about them. I do
> try to avoid them, but is this always possible?
>
>
> ------------------------------
>
> Message: 3
> Date: Thu, 22 Aug 2013 14:40:34 +0200
> From: Chris Down <chris at chrisdown.name>
> To: Matthew Ngaha <chigga101 at gmail.com>
> Cc: "tutor at python.org" <tutor at python.org>
> Subject: Re: [Tutor] global variables
> Message-ID: <20130822124033.GC4577 at chrisdown.name>
> Content-Type: text/plain; charset="us-ascii"
>
> On 2013-08-22 13:36, Matthew Ngaha wrote:
> > I'm always told to avoid using them. I read discussions on the python
> > irc channel about them but honestly i feel there are some times where
> > i can't avoid using them. Like where i want to keep track of a state
> > variable in many different functions that may or may not alter its
> > value and also not wanting any of the functions to return it to the
> > caller.
>
> It sounds like you want to use a class.
>
> > My question is how many global variables did your last decent sized
> > program have? Also please share any insight you have about them. I do
> > try to avoid them, but is this always possible?
>
> I don't have any global variables in any of my projects, and I've been
> programming Python in some capacity for almost 8 years now. Why would you
> not
> just use a class if you want to store state?
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: not available
> Type: application/pgp-signature
> Size: 490 bytes
> Desc: not available
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20130822/02883212/attachment-0001.sig
> >
>
> ------------------------------
>
> Message: 4
> Date: Thu, 22 Aug 2013 14:43:03 +0100
> From: Matthew Ngaha <chigga101 at gmail.com>
> To: Chris Down <chris at chrisdown.name>
> Cc: "tutor at python.org" <tutor at python.org>
> Subject: Re: [Tutor] global variables
> Message-ID:
>         <
> CACzNyA3K-hj8PTRTa9W2NaShUtqbPFgYAU0_a7Sa_jTRoXY8NA at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Thu, Aug 22, 2013 at 1:40 PM, Chris Down <chris at chrisdown.name> wrote:
>
> > It sounds like you want to use a class.
> > Why would you not just use a class if you want to store state?
>
> I don't feel my program needs a class. Also i have been told to stop
> using classes by some very experienced Python programmers on irc even
> though i don't see why. It's confusing being told different things.
>
>
> ------------------------------
>
> Message: 5
> Date: Thu, 22 Aug 2013 15:52:13 +0200
> From: Chris Down <chris at chrisdown.name>
> To: Matthew Ngaha <chigga101 at gmail.com>
> Cc: "tutor at python.org" <tutor at python.org>
> Subject: Re: [Tutor] global variables
> Message-ID: <20130822135212.GA6965 at chrisdown.name>
> Content-Type: text/plain; charset="us-ascii"
>
> On 2013-08-22 14:43, Matthew Ngaha wrote:
> > I don't feel my program needs a class. Also i have been told to stop
> > using classes by some very experienced Python programmers on irc even
> > though i don't see why. It's confusing being told different things.
>
> Well, if you want to store state, you should really be using a class. What
> has
> made you think that your program doesn't "need a class"? There's no "need",
> there's just what's best suited to your problem case (which you have not
> made
> clear, so nobody can comment on it).
>
> No experienced Python programmers are going to universally tell you not to
> use
> classes, likewise, no experienced Python programmers are going to
> universally
> tell you to use them all the time. It's a matter of context and
> suitability,
> which is entirely dependent on what it is that you are coding in the first
> place. I would doubt that anyone has told you "don't ever use classes",
> because
> that's nonsense; you've probably misread a dissuasion from that path in a
> single instance as applying more broadly than was intended.
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: not available
> Type: application/pgp-signature
> Size: 490 bytes
> Desc: not available
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20130822/8b858999/attachment-0001.sig
> >
>
> ------------------------------
>
> Message: 6
> Date: Thu, 22 Aug 2013 15:04:42 +0100
> From: Alan Gauld <alan.gauld at btinternet.com>
> To: tutor at python.org
> Subject: Re: [Tutor] global variables
> Message-ID: <kv55pi$691$1 at ger.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 22/08/13 13:36, Matthew Ngaha wrote:
> > I'm always told to avoid using them.
>
> Global variables  in themselves are not the problem.
> It's how they tend to get used that causes problems.
> Read-only global values - aka constants (so not
> really variables!) - are not an issue.
>
> Globals that are only changed via a set of
> dedicated functions are not topo much of a
> problem - although they should probably be
> bundled as a class (or module) if you have
> such features available.
>
> > i can't avoid using them. Like where i want to
>  > keep track of a state variable in many
> > different functions
>
> Usually that should be in a class. A class represents
> a set of operations using common data. Therefore shared
> state would naturally fit in a class along with the
> operations which depend on/modify that state.
>
> You may then have a single global variable which
> is the instance of that class.
>
> > also not wanting any of the functions to return it to the
> > caller.
>
> Thats more problematic and usually a sign of a bad design.
> Even if using global variables you should modify them
> explicitly via return values of functions rather than
> as hidden side-effects inside other functions.
>
> mystate = changestate(mystate, some, other, args)
>
> > My question is how many global variables did your last decent sized
> > program have?
>
> I usually have not more than a half dozen plus one per
> thousand lines of code. So in a 10,000 line program I'd
> expect to have less than 16 in total (actually I'd hope
> less than 10!). And many of those would be instances
> of classes. I would not expect to have more than one
> or two fundamental typed globals (ints, strings, bools etc),
> if any.
>
> > Also please share any insight you have about them. I do
> > try to avoid them, but is this always possible?
>
> It is possible but only by playing silly games with
> semantics such as:
>
> class MyProgram
>     global1 = 0
>     global2 = True
>
>     def __init__(self, lots, of, args,
>        self.inst1 = .... # initialise program runtime vars
>     def run(self)
>        # my program code all goes here
>        # and accesses the class level globals and instance
>        # level runtime and state values
>
> if __name__  = __main__":
>      MyProgram(args....).run()
>
> [Or alternatively you can hide them inside a database.]
>
> Now technically there are no globals but in fact we are
> just moving them inside the meaningless class and have
> all the same potential issues with global side effects
> etc.
>
> In my experience there are usually a few globals required
> for any meaningful program. It's not avoiding globals
> completely that's important, it's being careful to use
> them sensibly and with good adherence to the principles
> of coupling and cohesion in the design.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
> ------------------------------
>
> Message: 7
> Date: Thu, 22 Aug 2013 15:10:55 +0100
> From: Alan Gauld <alan.gauld at btinternet.com>
> To: tutor at python.org
> Subject: Re: [Tutor] global variables
> Message-ID: <kv5658$an8$1 at ger.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 22/08/13 14:43, Matthew Ngaha wrote:
> > On Thu, Aug 22, 2013 at 1:40 PM, Chris Down <chris at chrisdown.name>
> wrote:
> >> It sounds like you want to use a class.
> >> Why would you not just use a class if you want to store state?
>
> Local coding conventions or programmer skill levels may preclude it.
>
> > I don't feel my program needs a class.
>
> But in this case it sounds like a class is the best solution.
> Why would you "feel" that you don't need a class when you have a
> situation  where several functions share common state? That's
> almost the definition of a class.
>
> > Also i have been told to stop using classes by some very
>  > experienced Python programmers on irc
>
> Really? What reasons did they give.
> Unless they are talking about very specific circumstances
> that doesn't sound like good advice!
>
> > It's confusing being told different things.
>
> Software engineering, like any branch of engineering, is about learning
> to use many different tools and selecting the best set for a problem.
> There are cases where classes are not in the best set, there are cases
> where many global variables are a good fit. But both of these are the
> exceptions to the rule and the engineer's job is to identify when a
> genuine exception exists and make the right choice. There is never a
> single right answer. Sorry, but that's life.
>
> HTH
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> ------------------------------
>
> End of Tutor Digest, Vol 114, Issue 73
> **************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130905/20768a9c/attachment-0001.html>


More information about the Tutor mailing list