Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Fri, 28 Feb 2014 09:43:58 +0200, Marko Rauhamaa wrote: Chris Angelico ros...@gmail.com: Simple rule of thumb: Never use 'is' with strings or ints. They're immutable, their identities should be their values. Playing with 'is' will only confuse you, unless you're specifically going for

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ben Finney
Steven D'Aprano st...@pearwood.info writes: On Fri, 28 Feb 2014 09:43:58 +0200, Marko Rauhamaa wrote: class Connection: IDLE = IDLE [...] CONNECTED = CONNECTED [...] def disconnect(self): ... if self.state is CONNECTED:

Re: extend methods of decimal module

2014-02-28 Thread Chris Angelico
On Fri, Feb 28, 2014 at 6:34 PM, Steven D'Aprano st...@pearwood.info wrote: On Fri, 28 Feb 2014 16:00:10 +1100, Chris Angelico wrote: If we had some other tag, like 'd', we could actually construct a Decimal straight from the source code. Since source code is a string, it'll be constructed

Re: extend methods of decimal module

2014-02-28 Thread Wolfgang Maier
Mark H. Harris harrismh777 at gmail.com writes: On Thursday, February 27, 2014 10:26:59 PM UTC-6, Chris Angelico wrote: Create Decimal values from strings, not from the str() of a float, which first rounds in binary and then rounds in decimal. Thanks Chris... another excellent

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Fri, Feb 28, 2014 at 6:43 PM, Marko Rauhamaa ma...@pacujo.net wrote: Here's a use case for is with strings (or ints): class Connection: IDLE = IDLE CONNECTING = CONNECTING CONNECTED = CONNECTED DISCONNECTING = DISCONNECTING DISCONNECTED =

Re: Output JSON-schema from bottle application?

2014-02-28 Thread Alister
On Fri, 28 Feb 2014 14:49:07 +1100, Alec Taylor wrote: Are there libraries for doing this? I would like to autogenerate JSON-schema for use inside an API explorer. However whenever there is a schema change; I would only like to change the schema in one place (where possible). E.g.: For

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Ben Finney ben+pyt...@benfinney.id.au: There are two reasons why I think this is *still* not a justification for using ‘is’ with string values: First reason: This is better done by making it clear the value is an arbitrary object that won't be compared for equality. Just use ‘object()’ to

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Fri, Feb 28, 2014 at 9:02 PM, Marko Rauhamaa ma...@pacujo.net wrote: Yes, enums are long overdue. However, since any distinct objects will do, there is nothing preventing you from using string objects. String literals will often be interned if they look like (especially, if they *are*)

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Fri, Feb 28, 2014 at 9:02 PM, Marko Rauhamaa ma...@pacujo.net wrote: PS On the topic of enums, when are we getting support for a switch statement? I don't see that they're particularly connected. In my C code, I've used enums frequently as quick constants, often never switching on them.

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: String literals will often be interned if they look like (especially, if they *are*) identifiers, so if you want to prevent other strings from happening to match, you can't trust 'is'. [...] If you're using strings as state values, you should be using == to

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: Python currently has dispatch tables and if/elif chains, and a strong cultural aversion to switch. You could change that by coming up with some *really* awesome proposal, but you'll be fighting against the tide a bit. It's easy have a cultural aversion when

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Fri, Feb 28, 2014 at 10:30 PM, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: String literals will often be interned if they look like (especially, if they *are*) identifiers, so if you want to prevent other strings from happening to match, you can't trust 'is'.

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Fri, Feb 28, 2014 at 10:38 PM, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: Python currently has dispatch tables and if/elif chains, and a strong cultural aversion to switch. You could change that by coming up with some *really* awesome proposal, but you'll be

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: On Fri, Feb 28, 2014 at 10:30 PM, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: a.state = a.INIT In theory, yes. If that's all people will ever do, then you can safely use == to check. Why are you using is? The main reason to

Re: Can global variable be passed into Python function?

2014-02-28 Thread Neil Cerutti
On 2014-02-28, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: Python currently has dispatch tables and if/elif chains, and a strong cultural aversion to switch. You could change that by coming up with some *really* awesome proposal, but you'll be fighting against the

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Neil Cerutti ne...@norwich.edu: Check out Go's switch statement for an example of what it might look like in Python. Except you'd get it without labeled break or the fallthrough statement. No need for the fallthrough (except that multiple cases should be supported). Labeled breaks wouldn't

Re: References, and avoiding use of ???variable??? (was: Can global variable be passed into Python function?)

2014-02-28 Thread Neil Cerutti
On 2014-02-28, Ben Finney ben+pyt...@benfinney.id.au wrote: Mark H. Harris harrismh...@gmail.com writes: So, yeah, thinking about variables is just not going away. Right. I would like, ideally, for the Python documentation to avoid mentioning that term entirely; and I would hope for that to

Re: extend methods of decimal module

2014-02-28 Thread casevh
On Thursday, February 27, 2014 2:33:35 AM UTC-8, Mark H. Harris wrote: No... was not aware of gmpy2... looks like a great project! I am wondering why it would be sooo much faster? For multiplication and division of ~1000 decimal digit numbers, gmpy2 is ~10x faster. The numbers I gave were

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 1:26 AM, Marko Rauhamaa ma...@pacujo.net wrote: Python isn't averse to the switch statement because it would be not that useful. Rather, the problem is that Python doesn't have nonliteral constants (scheme has builtin symbols). It is difficult to come up with truly

Re: Tuples and immutability

2014-02-28 Thread Joshua Landau
On 27 February 2014 16:14, Chris Angelico ros...@gmail.com wrote: On Fri, Feb 28, 2014 at 3:01 AM, Eric Jacoboni eric.jacob...@gmail.com wrote: a_tuple = (spam, [10, 30], eggs) a_tuple[1] += [20] Traceback (most recent call last): File stdin, line 1, in module TypeError: 'tuple' object

Re: extend methods of decimal module

2014-02-28 Thread Wolfgang Maier
Mark H. Harris harrismh777 at gmail.com writes: If you get a chance, take a look at the dmath.py code on: https://code.google.com/p/pythondecimallibrary/ Hi Mark, here is an enhancement for your epx function. Your current version comes with the disadvantage of potentially storing

Re: Tuples and immutability

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 1:41 AM, Joshua Landau jos...@landau.ws wrote: Would it be better to add a check here, such that if this gets raised to the top-level it includes a warning (Addition was inplace; variable probably mutated despite assignment failure)? That'd require figuring out whether

Re: extend methods of decimal module

2014-02-28 Thread Wolfgang
Uhh, the curse of not copy-pasting everything: exp(20) should, of course, read epx(19) Traceback (most recent call last): File pyshell#46, line 1, in module epx(19) File C:\Python34\dmath_rev.py, line 27, in epx n *= q decimal.Overflow: [class

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark Lawrence
On 28/02/2014 11:38, Marko Rauhamaa wrote: Switch statements provide for excellent readability in parsers and state machines, for example. They also allow the Python compiler to optimize the statement internally unlike long if-else chains. There are umpteen recipes for switch statements so

Re: extend methods of decimal module

2014-02-28 Thread Steven D'Aprano
On Fri, 28 Feb 2014 19:52:45 +1100, Chris Angelico wrote: On Fri, Feb 28, 2014 at 6:34 PM, Steven D'Aprano st...@pearwood.info wrote: On Fri, 28 Feb 2014 16:00:10 +1100, Chris Angelico wrote: If we had some other tag, like 'd', we could actually construct a Decimal straight from the source

Re: Can global variable be passed into Python function?

2014-02-28 Thread Michael Torrie
On 02/28/2014 01:46 AM, Ben Finney wrote: Steven D'Aprano st...@pearwood.info writes: On Fri, 28 Feb 2014 09:43:58 +0200, Marko Rauhamaa wrote: class Connection: IDLE = IDLE [...] CONNECTED = CONNECTED [...] def disconnect(self): ... if

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: Can you elaborate on this nonliteral constants point? How is it a problem if DISCONNECTING isn't technically a constant? It follows the Python convention of being in all upper-case, so the programmer understands not to rebind it. Is the problem that someone

Re: extend methods of decimal module

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 2:11 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: or there needs to be a system for constructing literals of non-built-in types. And if Decimal becomes built-in, then why that and not insert type name here? 'Cos we have ten fingers and in count in

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 2:29 AM, Marko Rauhamaa ma...@pacujo.net wrote: BTW, here's a syntax that doesn't introduce any new keywords: with self.state from Connection.State: if CONNECTING or CONNECTED: ... elif DISONNECTING: ... else:

Re: Output JSON-schema from bottle application?

2014-02-28 Thread donarb
On Thursday, February 27, 2014 7:49:07 PM UTC-8, Alec Taylor wrote: Are there libraries for doing this? I would like to autogenerate JSON-schema for use inside an API explorer. However whenever there is a schema change; I would only like to change the schema in one place (where possible).

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Fri, 28 Feb 2014 12:02:03 +0200, Marko Rauhamaa wrote: PS On the topic of enums, when are we getting support for a switch statement? http://legacy.python.org/dev/peps/pep-3103/ http://legacy.python.org/dev/peps/pep-0275/ -- Steven --

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 9:50:09 AM UTC-6, Steven D'Aprano wrote: PS On the topic of enums, when are we getting support for a switch statement? http://legacy.python.org/dev/peps/pep-3103/ http://legacy.python.org/dev/peps/pep-0275/ I have reviewed these peps, and I heard Guido's

Re: extend methods of decimal module

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 8:41:49 AM UTC-6, Wolfgang Maier wrote: Hi Mark, here is an enhancement for your epx function. Wolfgang hi Wolfgang, thanks much! As a matter of point in fact, I ran into this little snag and didn't understand it, because I was thinking that outside of

Re: extend methods of decimal module

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 2:54:12 AM UTC-6, Wolfgang Maier wrote: Since by now, I guess, we all agree that using the string representation is the wrong approach, you can simply use Decimal instead of D() throughout your code. Best, Wolfgang hi Wolfgang, ...right... I'm going to

Re: extend methods of decimal module

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 9:11:49 AM UTC-6, Steven D'Aprano wrote: Now that Python has a fast C implementation of Decimal, I would be happy for Python 4000 to default to decimal floats, and require special syntax for binary floats. Say, 0.1b if you want a binary float, and 0.1 for a

Re: extend methods of decimal module

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 5:34 AM, Mark H. Harris harrismh...@gmail.com wrote: Yes. ... and for clarification back to one of my previous comments, when I refer to 'float' I am speaking of the IEEE binary floating point representation built-in everywhere... including the processor!... not

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Mark H. Harris harrismh...@gmail.com: I think the real issue is about the syntax... because of python's unique indent strategy going back to ABC, a pythonized switch statement would play havoc with the many text parsers out there used for development (TestWrangler, and many others). I also

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 5:53 AM, Marko Rauhamaa ma...@pacujo.net wrote: A dict dispatch table is just awful. Really? How is that? I've used them, often. Yes, there are times when I could express something more cleanly with a C-style switch statement, but other times the dispatch table is

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: On Sat, Mar 1, 2014 at 5:53 AM, Marko Rauhamaa ma...@pacujo.net wrote: A dict dispatch table is just awful. Really? How is that? I've used them, often. Yes, there are times when I could express something more cleanly with a C-style switch statement, but

Re: extend methods of decimal module

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 12:37:37 PM UTC-6, Chris Angelico wrote: Are you aware that IEEE 754 includes specs for decimal floats? :) Yes. I am from back in the day... way back... so 754 1985 is what I have been referring to. IEEE 854 1987 and the generalized IEEE 754 2008 have

Re: extend methods of decimal module

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 1:34:27 AM UTC-6, Steven D'Aprano wrote: Now that Python has a fast C implementation of Decimal, I would be happy for Python 4000 to default to decimal floats, and require special syntax for binary floats. Say, 0.1b if you want a binary float, and 0.1 for a

Re: extend methods of decimal module

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 1:39:11 PM UTC-6, Mark H. Harris wrote: On Friday, February 28, 2014 1:34:27 AM UTC-6, Steven D'Aprano wrote: Now that Python has a fast C implementation of Decimal, I would be happy for Python 4000 to default to decimal floats, and require special syntax

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 1:20:52 PM UTC-6, Marko Rauhamaa wrote: Which do *you* find more readable? Yep, my point exactly. nice illustration. -- https://mail.python.org/mailman/listinfo/python-list

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Mark H. Harris harrismh...@gmail.com: Yep, my point exactly. nice illustration. So now, for you and me: let's compare. if key is ast.Assign: return ' '.join(dump(t) for t in node.targets) elif key is ast.AugAssign: # Same target and same operator. return

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark Lawrence
On 28/02/2014 21:03, Marko Rauhamaa wrote: Mark H. Harris harrismh...@gmail.com: Yep, my point exactly. nice illustration. So now, for you and me: let's compare. if key is ast.Assign: return ' '.join(dump(t) for t in node.targets) elif key is ast.AugAssign: #

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Fri, 28 Feb 2014 20:53:15 +0200, Marko Rauhamaa wrote: Mark H. Harris harrismh...@gmail.com: I think the real issue is about the syntax... because of python's unique indent strategy going back to ABC, a pythonized switch statement would play havoc with the many text parsers out there

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Mark Lawrence breamore...@yahoo.co.uk: http://c2.com/cgi/wiki?SwitchStatementsSmell Your brief summary, please, Mark? Anyway, the first 1000 lines or so that I managed to read from that page stated a valid principle, which however doesn't invalidate the existence of a switch statement. A

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ben Finney
Marko Rauhamaa ma...@pacujo.net writes: Ben Finney ben+pyt...@benfinney.id.au: First reason: This is better done by making it clear the value is an arbitrary object that won't be compared for equality. Just use ‘object()’ to creeate each value and be done with it. That's a hack, but

Re: References, and avoiding use of ???variable???

2014-02-28 Thread Ben Finney
Neil Cerutti ne...@norwich.edu writes: On 2014-02-28, Ben Finney ben+pyt...@benfinney.id.au wrote: Right. I would like, ideally, for the Python documentation to avoid mentioning that term entirely; and I would hope for that to promote a better understanding of Python's data model. I like

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Fri, 28 Feb 2014 21:20:52 +0200, Marko Rauhamaa wrote: Your example: [snip] I'm not going to show the example as quoted by you, because my news client is wrapping it in ugly ways and I don't want to spend the time fixing it. I'll just say that, as given, it's a great big wall of text, a

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote: Marko ... and between me and you, here is a snip from dmath.py from the atan(x) function: if (n**2 D(1)): a = __atan__(n) elif (n == D(1)): a = gpi/4 elif (n == D(-1)): a = -(gpi/4)

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ben Finney
Marko Rauhamaa ma...@pacujo.net writes: Mark Lawrence breamore...@yahoo.co.uk: http://c2.com/cgi/wiki?SwitchStatementsSmell Your brief summary, please, Mark? Anyway, the first 1000 lines or so that I managed to read from that page stated a valid principle, which however doesn't

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: You can't have it both ways: you cannot claim that switch or case is more readable than a chain of if...elif, and then propose a syntax which is effectively a chain of if...elif while still claiming it is an improvement. It's not. All

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Ben Finney ben+pyt...@benfinney.id.au: As has been pointed out to you, the whole point here is that string objects often *are not* distinct, despite conceptually having distinct cretion in the source. You know full well that this initialization creates references to distinct objects:

Re: Tuples and immutability

2014-02-28 Thread Mark H. Harris
On Thursday, February 27, 2014 10:01:39 AM UTC-6, Eric Jacoboni wrote: ('spam', [10, 30, 20], 'eggs') I get a TypeError for an illegal operation, but this operation is still completed? hi Eric, others have answered your question specifically, but the issue (which is recurring) begs a

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Fri, 28 Feb 2014 14:25:54 +0200, Marko Rauhamaa wrote: Chris Angelico ros...@gmail.com: On Fri, Feb 28, 2014 at 10:30 PM, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: a.state = a.INIT In theory, yes. If that's all people will ever do, then you can safely

Persist python objects without a relational DB

2014-02-28 Thread Ariel Argañaraz
Hi, I would like to know which is the best framework to persist my python objects in disk. I heard about ZODB (http://www.zodb.org/en/latest/index.html) is this the best or there is another ? -- Ariel Argañaraz -- https://mail.python.org/mailman/listinfo/python-list

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Mark H. Harris harrismh...@gmail.com: if (n**2 D(1)): a = __atan__(n) elif (n == D(1)): a = gpi/4 elif (n == D(-1)): a = -(gpi/4) elif (n D(-1)): a = __atan__Lt_neg1__(n) else: a = __atan__Gt_1__(n) Drop the outermost

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ned Batchelder
On 2/28/14 6:36 PM, Mark H. Harris wrote: On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote: Marko ... and between me and you, here is a snip from dmath.py from the atan(x) function: if (n**2 D(1)): a = __atan__(n) elif (n == D(1)): a =

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Sat, 01 Mar 2014 02:03:51 +0200, Marko Rauhamaa wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: You can't have it both ways: you cannot claim that switch or case is more readable than a chain of if...elif, and then propose a syntax which is effectively a chain of if...elif

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ben Finney
Marko Rauhamaa ma...@pacujo.net writes: Ben Finney ben+pyt...@benfinney.id.au: As has been pointed out to you, the whole point here is that string objects often *are not* distinct, despite conceptually having distinct cretion in the source. You know full well that this initialization

Re: Persist python objects without a relational DB

2014-02-28 Thread Ben Finney
Ariel Argañaraz arieli...@gmail.com writes: Hi, I would like to know which is the best framework to persist my python objects in disk. The Python Wiki has a directory of tools for object persistence in Python URL:https://wiki.python.org/moin/PersistenceTools. -- \ “Our task must be to

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Sat, 01 Mar 2014 02:11:53 +0200, Marko Rauhamaa wrote: Ben Finney ben+pyt...@benfinney.id.au: As has been pointed out to you, the whole point here is that string objects often *are not* distinct, despite conceptually having distinct cretion in the source. You know full well that this

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark Lawrence
On 01/03/2014 00:40, Ned Batchelder wrote: On 2/28/14 6:36 PM, Mark H. Harris wrote: On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote: Marko ... and between me and you, here is a snip from dmath.py from the atan(x) function: if (n**2 D(1)): a =

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: I can only imagine you mean something like this: class Outer: class InnerOne: ... class InnerTwo: ... class InnerThree: ... No, I mean this: class StateMachine: def __init__(self):

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 6:40:06 PM UTC-6, Ned Batchelder wrote: I don't understand: you show an if/elif chain that cannot be expressed as a switch statement (because it uses ), and then conclude that Python needs a switch statement? That doesn't make any sense. Forgive me. I

Re: Can global variable be passed into Python function?

2014-02-28 Thread Marko Rauhamaa
Ben Finney ben+pyt...@benfinney.id.au: From each other, of course they're distinct, because they are unequal. They are *not* necessarily distinct from other strings with equal value, defined elsewhere. That's what has been pointed out to you many times. That point is completely irrelevant.

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark Lawrence
On 01/03/2014 00:03, Marko Rauhamaa wrote: Dict dispatch tables are elegant, attractive and efficient if you are using pre-existing functions or functions you can create using lambda: I beg to differ. The dict dispatch tables are very hard to read. The fully blown-out if-else chain beats it

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark Lawrence
On 01/03/2014 01:10, Marko Rauhamaa wrote: Ben Finney ben+pyt...@benfinney.id.au: From each other, of course they're distinct, because they are unequal. They are *not* necessarily distinct from other strings with equal value, defined elsewhere. That's what has been pointed out to you many

Re: Tuples and immutability

2014-02-28 Thread Eric Jacoboni
Le 01/03/2014 01:22, Mark H. Harris a écrit : I'll address the second first by asking a question... should an immutable type (object) be able to hold (contain) mutable objects ... should tuples be allowed to hold lists? lists within a tuple should be converted to tuples.If you want

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 7:10:49 PM UTC-6, Mark Lawrence wrote: I think you're talking nonsense. I've been happily using dict dispatch tables for years and, like Steven and presumably many others, find them dead easy to read. Perhaps you should invest in a better optician and/or

Re: Tuples and immutability

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 11:22 AM, Mark H. Harris harrismh...@gmail.com wrote: lists within a tuple should be converted to tuples.If you want a tuple to hold a list, make it a list in the first place. Tuples should not be changed... and as you point out... half changing a tuple is not a

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ben Finney
Marko Rauhamaa ma...@pacujo.net writes: Ben Finney ben+pyt...@benfinney.id.au: They are *not* necessarily distinct from other strings with equal value, defined elsewhere. That's what has been pointed out to you many times. That point is completely irrelevant. The state objects only need

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 6:20 AM, Marko Rauhamaa ma...@pacujo.net wrote: Your example: compare_key = { # Same target(s). ast.Assign: lambda node: ' '.join(dump(t) for t in node.targets), # Same target and same operator. ast.AugAssign: lambda node:

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Sat, 01 Mar 2014 03:06:38 +0200, Marko Rauhamaa wrote: Steven D'Aprano steve+comp.lang.pyt...@pearwood.info: I can only imagine you mean something like this: class Outer: class InnerOne: ... class InnerTwo: ... class InnerThree: ... No, I

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 10:06 AM, Marko Rauhamaa ma...@pacujo.net wrote: A colleague of mine taught me decades back that the whole point of OO was the avoidance of if and switch statements. So if your code has an if or switch statement, chances are you are doing something wrong. I agree.

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 12:08 PM, Mark H. Harris harrismh...@gmail.com wrote: On Friday, February 28, 2014 6:40:06 PM UTC-6, Ned Batchelder wrote: I don't understand: you show an if/elif chain that cannot be expressed as a switch statement (because it uses ), and then conclude that Python

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 12:59 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: However, the example as given won't quite work. You never instantiate the Idle etc. classes, which means the methods won't work. You need to make them class methods or static methods, or perform some

Re: Can global variable be passed into Python function?

2014-02-28 Thread Ned Batchelder
On 2/28/14 8:08 PM, Mark H. Harris wrote: On Friday, February 28, 2014 6:40:06 PM UTC-6, Ned Batchelder wrote: I don't understand: you show an if/elif chain that cannot be expressed as a switch statement (because it uses ), and then conclude that Python needs a switch statement? That

Re: References, and avoiding use of ???variable???

2014-02-28 Thread Gregory Ewing
Ben Finney wrote: That whole chapter of the tutorial talks about “variable” and “variable assignment”, when IMO it should avoid those terms and use the clearer terminology of “reference”, “name”, and “binding a name to a value”. What about all the other things that can be assigned to but

Re: Can global variable be passed into Python function?

2014-02-28 Thread Gregory Ewing
Mark H. Harris wrote: if (n**2 D(1)): a = __atan__(n) elif (n == D(1)): a = gpi/4 elif (n == D(-1)): a = -(gpi/4) elif (n D(-1)): a = __atan__Lt_neg1__(n) else: a = __atan__Gt_1__(n) That's not a candidate for a switch statement,

Re: Can global variable be passed into Python function?

2014-02-28 Thread Steven D'Aprano
On Sat, 01 Mar 2014 13:03:53 +1100, Chris Angelico wrote: On Sat, Mar 1, 2014 at 12:59 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: However, the example as given won't quite work. You never instantiate the Idle etc. classes, which means the methods won't work. You need to

Re: References, and avoiding use of ???variable???

2014-02-28 Thread Ben Finney
Gregory Ewing greg.ew...@canterbury.ac.nz writes: Ben Finney wrote: That whole chapter of the tutorial talks about “variable” and “variable assignment”, when IMO it should avoid those terms and use the clearer terminology of “reference”, “name”, and “binding a name to a value”. What

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 8:15:38 PM UTC-6, Ned Batchelder wrote: Mark, if you are going to advocate for a feature, find a good use case, this one is absurd. Where did the constants GT_1 etc, come from? Not at all. Think of the C switch block... if you read about it in the K R you'll

Re: Tuples and immutability

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 7:27:17 PM UTC-6, Eric Jacoboni wrote: I agree with that too... My error was to first consider the list, then the tuple... I should have considered the tuple first... Anyway, the TypeError should rollback, not commit the mistake. I believe so too, but I'm not one

Re: Tuples and immutability

2014-02-28 Thread Ian Kelly
On Fri, Feb 28, 2014 at 5:22 PM, Mark H. Harris harrismh...@gmail.com wrote: I really think this is a bug; honestly. IMHO it should be an error to use += with an immutable type and that means not at all. In other words, the list should not even be considered, because we're talking about

Re: Tuples and immutability

2014-02-28 Thread Ian Kelly
On Fri, Feb 28, 2014 at 6:27 PM, Eric Jacoboni eric.jacob...@gmail.com wrote: Anyway, the TypeError should rollback, not commit the mistake. The Python interpreter isn't a database. It can't rollback the object because the operation that was performed may not be reversible. Consider for example

Re: Can global variable be passed into Python function?

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 8:01:45 PM UTC-6, Chris Angelico wrote: Does your switch construct have to handle the magic of GT_1 meaning 1, or do you first figure out where it falls with an if/elif tree? ChrisA hi Chris, yeah... well think again of the switch block in C... the switch

Re: Tuples and immutability

2014-02-28 Thread Ian Kelly
On Fri, Feb 28, 2014 at 9:45 PM, Mark H. Harris harrismh...@gmail.com wrote: I really believe IMHO that the error should have come when you made the list an item of a tuple. An immutable object should have NO REASON to contain a mutable object like list... I mean the whole point is to

Re: Tuples and immutability

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 11:34:56 PM UTC-6, Ian wrote: One very common example of tuples containing lists is when lists are passed to any function that accepts *args, because the extra arguments are passed in a tuple. A similarly common example is when returning multiple objects from a

Re: Tuples and immutability

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote: How would you propose doing that? Bear in mind that while Python knows that tuples specifically are immutable, it doesn't generally know whether a type is immutable. hi Ian, consider the problem... its a cake and eat it too

Re: Can global variable be passed into Python function?

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 4:30 PM, Mark H. Harris harrismh...@gmail.com wrote: hi Chris, yeah... well think again of the switch block in C... the switch block selects a branch based on an integral number (int character) that is generally a return code from a function. The function hides all

Re: Tuples and immutability

2014-02-28 Thread Chris Angelico
On Sat, Mar 1, 2014 at 5:16 PM, Mark H. Harris harrismh...@gmail.com wrote: This is what I mean... the error message is telling the user that it cannot do what he has requested, and yet IT DID. You have one of two scenarios: 1) the message is arbitrarily lying and it really can assign an

Re: Tuples and immutability

2014-02-28 Thread Mark H. Harris
On Friday, February 28, 2014 11:16:18 PM UTC-6, Ian wrote: How would you propose doing that? Bear in mind that while Python knows that tuples specifically are immutable, it doesn't generally know whether a type is immutable. I was going to bed, and then thought of the solution. Allow the

Re: how to install automatically missing modules on a debian-system

2014-02-28 Thread Anssi Saari
hugocoolens hugocool...@gmail.com writes: It often happens I start a python-script I wrote some time ago on another system and get messages like module_x is missing. I then perform an apt-cache search module_x, followed by an apt-get install name_of_missing_module.deb I was wondering

Re: extend methods of decimal module

2014-02-28 Thread Anssi Saari
Terry Reedy tjre...@udel.edu writes: On 2/27/2014 7:07 AM, Mark H. Harris wrote: Oh, and one more thing... whoever is doing the work on IDLE these days, nice job! It is stable, reliable, and just works/ appreciate it! As one of 'them', thank you for the feedback. There are still some

Help with Guess the number script

2014-02-28 Thread Scott W Dunning
Hello, i am working on a project for learning python and I’m stuck. The directions are confusing me. Please keep in mind I’m very ne to this. The directions are long so I’ll just add the paragraphs I’m confused about and my code if someone could help me out I’d greatly appreciate it! Also,

Re: Help with Guess the number script

2014-02-28 Thread Ben Finney
Scott W Dunning swdunn...@cox.net writes: Hello, i am working on a project for learning python and I’m stuck. The directions are confusing me. Please keep in mind I’m very ne to this. Scott, please default to asking these “covered in a beginner Python course” questions at the Python tutor

[issue20580] IDLE should support platform-specific default config defaults

2014-02-28 Thread Westley Martínez
Changes by Westley Martínez aniko...@gmail.com: -- nosy: +westley.martinez ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20580 ___ ___

[issue17128] OS X system openssl deprecated - installer should build local libssl

2014-02-28 Thread Christian Heimes
Christian Heimes added the comment: Thanks to Hynek we were able to dig deeper into Apple's modifications. OpenSSL on OSX uses TEA (TrustEvaluationAgent) to verify cert chains. TEA is pretty much undocumented on the internet but perhaps we can use it to verify certs with OpenSSL 1.x, too?

  1   2   >