Re: [Tutor] don't understand iteration

2014-11-11 Thread Alan Gauld

On 11/11/14 04:45, Clayton Kirkwood wrote:


*list(range(1,6))

   File "", line 1
SyntaxError: can use starred expression only as assignment target


list() is a function. You cannot unpack a function.

Also the * operator needs to be used inside a function parameter list.
(There may be some obscure case where you can use it outside of that but 
99% of the time that's the only place you'll see it used.)



a = list(*range(5))


And again range() is a function, you can only use * on a list/tuple.


a = list(range(*5))


And here 5 is an integer. It must be a sequence.


As far as I can tell, everything that has been suggested doesn't work:


What has been suggested is a collection inside a functions argument 
list. You haven't tried that in any of your examples.


Here are a couple of valid cases:

>>> def threeArgs(a,b,c):
...print(a,b,c)
...
>>> myList = [3,5,8]
>>>
>>> threeArgs(*myList)# unpack a variable
3 5 8
>>> threeArgs(*(9,3,1))   # unpack literal tuple
9 3 1


Has to be only in assignment target,


I agree the error message is not at all clear.
Its probably technically correct from the interpreters perspective
but its not that clear to the programmer.


Perhaps the vaunted try it in the console, doesn't work.


It does work as I showed above. But you still need to type in
the right syntax.


I am sure that I am missing something


The fact that it only works inside a function's argument list.


And the link to Calls:

https://docs.python.org/3/reference/expressions.html#calls

which says:
--
...
If the syntax *expression appears in the function call, expression must
evaluate to an iterable. Elements from this iterable are treated as if
they were additional positional arguments;


That's the explanation right there.
It says that if you call a function and use *name in the argument list 
Python will expect name to refer to an iterable and will unpack the 
iterables elements(values) and use them as positional arguments in

the function call. Like most of the Python docs its accurate but terse.


Yes, inside the call to a function call.

> My question is outside to a function call.

You cannot use the * operator outside a function call.
At least I can't think of a case where it works.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with Dice game

2014-11-11 Thread Dave Angel
 Wrote in message:
> 
> 
> 
> 
> 
> 
> Hello, I can not for the life of me figure out where I have gone wrong.  I 
> wrote the following code as a simulation for the table top game x-wing.  It 
> basically simulates dice rolls but the issue is the fact that every time I 
> choose a number of dice to roll, they all hit.  None of them ever miss.  
> Thank You.
> import random
> print("X-wing dice simulator")
> x = int(input("How many dice will the offensive player be rolling?\n"))
> y = int(input("How many dice will the defensive player be rolling?\n"))
> hits = 0
> crits = 0
> dodges = 0
> offense = 0
> defense = 0
> while offense < x:
> odie = random.randint(1,8)
> if odie <= 4:
> hits = hits + 1
> offense = offense + 1

> if odie == 4:

This should be indented, to line up with offens= line

> crits = crits + 1
> offense = offense + 1
> else:

Then this else will mean odie >4
But then instead of continue, you'll need to increment offense.
> continue


> while defense < y:
> ddie = random.randint(1,8)
> if ddie <= 3:
> dodges = dodges + 1
> defense = defense + 1
> else:
> continue

Continue doesn't help, you need to increment defense.

> print("The offensive player lands", hits,"hits and", crits,"crits\n")
> print("The defensive player dodges", dodges, "hits\n")
> print("The offensive player deals", int((hits + crits) - dodges), "to the 
> defensive player")
> 
> 

You'd have done yourself a favor to do loops with range (),
 instead of the while loops.

For example

for qq in range (x):

-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 129, Issue 22

2014-11-11 Thread Ben Smith
Hi - I'm a teacher & sometimes when we're holding a two minute silence for an 
important occasion an
email comes through & makes my computer ping loudly. Is there a python script 
to stop these kind of things happening?

;)

-Original Message-
From: Tutor [mailto:tutor-bounces+ben.smith=arnoldkeqms@python.org] On 
Behalf Of tutor-requ...@python.org
Sent: 11 November 2014 11:00
To: tutor@python.org
Subject: Tutor Digest, Vol 129, Issue 22

Send Tutor mailing list submissions to
tutor@python.org

To subscribe or unsubscribe via the World Wide Web, visit
https://mail.python.org/mailman/listinfo/tutor
or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

You can reach the person managing the list at
tutor-ow...@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: http  question (Clayton Kirkwood)
   2. Re: ?has a value of True? versus ?evaluates true? (was: don't
  understand iteration) (wesley chun)
   3. Re: don't understand iteration (Alan Gauld)


--

Message: 1
Date: Mon, 10 Nov 2014 20:52:23 -0800
From: "Clayton Kirkwood" 
To: 
Subject: Re: [Tutor] http  question
Message-ID: <01c801cffd6b$492408a0$db6c19e0$@us>
Content-Type: text/plain;   charset="us-ascii"



>-Original Message-
>From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On
>Behalf Of Steven D'Aprano
>Sent: Sunday, November 09, 2014 3:04 AM
>To: tutor@python.org
>Subject: Re: [Tutor] http question
>
>On Sat, Nov 08, 2014 at 09:53:33PM -0800, Clayton Kirkwood wrote:
>
>> >> but I also am aware of httplib2, but it still seems to be in
>> >> eternal alpha.
>> >
>> >What leads you to that conclusion? If you're talking about this:
>> >
>> >https://github.com/jcgregorio/httplib2
>> >
>> >I don't see any sign that it is alpha version software. According to
>> >the readme file, it is at version 0.8.
>> >
>> >I don't see any signs that the author publicly releases any alpha or
>> >beta versions, they all appear to be ready for production. But if
>> >you have seen something that suggests otherwise, please point it
>> >out, because I'm happy to be corrected.
>>
>> Well, I work from the premise that 0.anything is still a work in
>> progress
>
>All software is always a work in progress, until such time it is
>abandoned.

And how do you determine the abandoned timestamp? If I remember correctly, this 
hasn't been updated for several years, and a job for a customer shouldn't be 
based on 0.*, years old hypothetical's. It sounds like a very usable product.

>
>> and hasn't gotten to a point where the author is comfortable with
>> general use. I am sure that you disagree.
>
>In the FOSS (Free and Open Source Software) community, version 0.x does
>not always carry connotations of being unready for use. It may, or it
>may not. But normally "alpha" software will have an "a" in the version
>number, e.g. 0.7a, 0.7b for beta, 0.7rc1 (release candidate 1), 0.7 is
>ready for production.
>
>What matters is not my opinion, or yours, but that of the author of the
>software, and I don't know what that is.
>
>
>--
>Steve
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor





--

Message: 2
Date: Mon, 10 Nov 2014 23:35:07 -0800
From: wesley chun 
To: c...@godblessthe.us
Cc: tutor , Ben Finney 
Subject: Re: [Tutor] ?has a value of True? versus ?evaluates true?
(was: don't understand iteration)
Message-ID:

Content-Type: text/plain; charset="utf-8"

good catch, and definitely a distinction beginners should be more cognizant of.

it's also good to recognize that a call to "bool(match)" would render that 
statement correct, as the built-in/factory function will return what an object 
evaluates to (True [re.match object] or/vs.False [None]).

On Mon, Nov 10, 2014 at 5:31 PM, Clayton Kirkwood 
wrote:

> I reported it. I feel all grown up now. Kind of like one of the
> boys(girls...)
>
> Clayton:<)
>
>
> >-Original Message-
> >From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On
> >Behalf Of Ben Finney
> >Sent: Monday, November 10, 2014 3:24 PM
> >To: tutor@python.org
> >Subject: [Tutor] ?has a value of True? versus ?evaluates true? (was:
> >don't understand iteration)
> >
> >"Clayton Kirkwood"  writes:
> >
> >> Also of confusion, the library reference says:
> >>
> >> Match objects always have a boolean value of True. Since match()
> >> and
> >> search() return None when there is no match, you can test whether
> >> there was a match with a simple if statement:
> >>
> >> match = re.search(pattern, string)
> >> if match:
> >> process(match)
> >
> >The documentation is incorrect, as you point out: ?have a boolean
> >val

[Tutor] hexodecimal to decimal form

2014-11-11 Thread William Becerra
Hello, I'm new to programming using Python 2.7.8 and Windows 8 OS
I'm reading How to Think Like a Computer Scientist - learning with python
on chapter 12.2
theres the following code:
 class Point:
 pass
blank = point()
blank.x = 3.0
blank.y = 4.0

>>print blank.x
3.0
>>print blank.y
4.0

>>print blank
<__main__.point instance at 0x02B38E40>

the author says the the < 0x02B38E40> is in hexadecimal form

heres is my question:
How can i convert from hexodecimal form to decimal form?
is there any source i can read on it?
basically what i want is to use the attributes blank.x and blank.y as a
single point like in  the mathematics format (x, y) co-ordinates so that i
can workout distance

thank you
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] hexodecimal to decimal form

2014-11-11 Thread Dave Angel
William Becerra  Wrote in message:
> Hello, I'm new to programming using Python 2.7.8 and Windows 8 OSI'm reading 
> How to Think Like a Computer Scientist - learning with pythonon chapter 
> 12.2theres the following code: class Point: passblank = point()blank.x = 
> 3.0blank.y = 4.0
>>>print blank.x
> 3.0>>print blank.y4.0
>>>print blank<__main__.point instance at 0x02B38E40>
> 
> the author says the the < 0x02B38E40> is in hexadecimal form
> heres is my question:How can i convert from hexodecimal form to decimal form?

You don't care about that 0x02.. number, except to distinguish
 this object from another. And in code you'd do that with the 'is'
 operator.
That hex number happens to be an address in memory for one of the
 python implementations. 

> is there any source i can read on it?basically what i want is to use the 
> attributes blank.x and blank.y as a single point like in  the mathematics 
> format (x, y) co-ordinates so that i can workout distance
> thank you
> 
> 


If you want a tuple of the coordinates,  you could do (blank.x,
 blank.y)  And if you need to do arithmetic,  go right ahead.
 Like

x, y = blank.x, blank.y
dist_from_org = sqrt(x*x + y*y)



-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] don't understand iteration

2014-11-11 Thread eryksun
On Tue, Nov 11, 2014 at 4:52 AM, Alan Gauld  wrote:
> On 11/11/14 04:45, Clayton Kirkwood wrote:
>
 *list(range(1,6))
>>
>>File "", line 1
>> SyntaxError: can use starred expression only as assignment target
>
> list() is a function. You cannot unpack a function.
>
> Also the * operator needs to be used inside a function parameter list.
> (There may be some obscure case where you can use it outside of that but 99%
> of the time that's the only place you'll see it used.)

Python 3 extended unpacking:

>>> a, *bcd, e = 'abcde'
>>> a
'a'
>>> bcd
['b', 'c', 'd']
>>> e
'e'

>>> for x, *rest in ('abc', 'de'):
... print(x, rest)
...
a ['b', 'c']
d ['e']


> a = list(range(*5))
>
> And here 5 is an integer. It must be a sequence.

Any iterable suffices.

Refer to the table in section 8.4.1 for an overview of container interfaces:
http://docs.python.org/3/library/collections.abc

A common non-sequence example is unpacking a generator:

>>> gen = (c.upper() for c in 'abcde')
>>> print(*gen, sep='-')
A-B-C-D-E

A generator is an iterable:

>>> gen = (c.upper() for c in 'abcde')
>>> type(gen)


>>> hasattr(gen, '__iter__')
True
>>> isinstance(gen, collections.Iterable)
True

and also an iterator:

>>> hasattr(gen, '__next__')
True
>>> isinstance(gen, collections.Iterator)
True

>>> it = iter(gen)
>>> it is gen
True

>>> next(it), next(it), next(it), next(it), next(it)
('A', 'B', 'C', 'D', 'E')
>>> next(it)
Traceback (most recent call last):
  File "", line 1, in 
StopIteration
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 129, Issue 22

2014-11-11 Thread Alan Gauld

On 11/11/14 11:24, Ben Smith wrote:

Hi - I'm a teacher & sometimes when we're holding a two minute silence

> for an important occasion an email comes through & makes
> my computer ping loudly.
> Is there a python script to stop these kind of things happening?

I've no idea but why not just mute your speaker?
In (pre v8) windows thee was a widget in the task bar for controlling
the sound...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Silencing a speaker

2014-11-11 Thread Danny Yoo
On Nov 11, 2014 4:30 AM, "Ben Smith"  wrote:
>
> Hi - I'm a teacher & sometimes when we're holding a two minute silence
for an important occasion an
> email comes through & makes my computer ping loudly. Is there a python
script to stop these kind of things happening?

Lo tech solution: can you plug in a headphone during those periods?

What computer operating system?  I suspect this question is somewhat out of
scope for Python tutor; you might need to ask on a more general forum.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] hexodecimal to decimal form

2014-11-11 Thread Alan Gauld

On 11/11/14 09:00, William Becerra wrote:


 >>print blank
<__main__.point instance at 0x02B38E40>

the author says the the < 0x02B38E40> is in hexadecimal form


Correct that's what the 0x at the front signifies.


heres is my question:
How can i convert from hexodecimal form to decimal form?


You can use the int() type converter:

>>> int(0x16)
22
>>> int(0x02B38E40)
45321792


But there is little point since the hex number is a
memory address that means nothing to you as a programmer
since you can't change it, or do anything useful with it.


basically what i want is to use the attributes blank.x and blank.y as a
single point like in  the mathematics format (x, y) co-ordinates so that
i can workout distance


You can do that without any use of hex.
Just use blank.x and blank.y like any other variable.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] hexodecimal to decimal form

2014-11-11 Thread William Becerra
Thank you for your time
On 11 Nov 2014 15:02, "Dave Angel"  wrote:

> William Becerra  Wrote in message:
> > Hello, I'm new to programming using Python 2.7.8 and Windows 8 OSI'm
> reading How to Think Like a Computer Scientist - learning with pythonon
> chapter 12.2theres the following code: class Point: passblank =
> point()blank.x = 3.0blank.y = 4.0
> >>>print blank.x
> > 3.0>>print blank.y4.0
> >>>print blank<__main__.point instance at 0x02B38E40>
> >
> > the author says the the < 0x02B38E40> is in hexadecimal form
> > heres is my question:How can i convert from hexodecimal form to decimal
> form?
>
> You don't care about that 0x02.. number, except to distinguish
>  this object from another. And in code you'd do that with the 'is'
>  operator.
> That hex number happens to be an address in memory for one of the
>  python implementations.
>
> > is there any source i can read on it?basically what i want is to use the
> attributes blank.x and blank.y as a single point like in  the mathematics
> format (x, y) co-ordinates so that i can workout distance
> > thank you
> >
> >
>
>
> If you want a tuple of the coordinates,  you could do (blank.x,
>  blank.y)  And if you need to do arithmetic,  go right ahead.
>  Like
>
> x, y = blank.x, blank.y
> dist_from_org = sqrt(x*x + y*y)
>
>
>
> --
> DaveA
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] don't understand iteration

2014-11-11 Thread Alex Kleider

On 2014-11-11 06:19, eryksun wrote:
On Tue, Nov 11, 2014 at 4:52 AM, Alan Gauld  
wrote:




Python 3 extended unpacking:

>>> a, *bcd, e = 'abcde'
>>> a
'a'
>>> bcd
['b', 'c', 'd']
>>> e
'e'



Seeing the above in a recent post, it made me wonder what would happen 
if the string had only two characters.  All went well and I'm wondering 
if I've stumbled across a solution to a problem I don't yet know 
about:-)


b, *m, e = 'abcdefghi'  # Length can be even or odd.
while m:
print(b, m, e, sep='/')
b, *m, e = m


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Fwd: Project tree

2014-11-11 Thread Danny Yoo
-- Forwarded message -
From: Wiktor Matuszewski 
Date: Tue Nov 11 2014 at 4:47:10 AM
Subject: Re: [Tutor] Project tree
To: Danny Yoo 


W dniu 2014-11-11 o 03:02, Danny Yoo pisze:

> See: https://docs.python.org/3/tutorial/modules.html#intra-
package-references
> for more details.
>
> If you have more questions, please feel free to ask!

Hi Danny, thanks.
I've seen this part of tutorial earlier, but obviously I misunderstood
it. This part especially: "Note that relative imports are based on the
name of the current module".

When I execute moda.py separately - there's no problem with importing
modb relatively from it. And I thought, that during importing moda from
start.py, for short moment I'm "locally" in moda (that this is current
module) and every import statements in it works relatively to moda.py
not to start.py.

Can you please explain what is happening step by step when I'm executing
only moda.py, and what is happening when I'm executing start.py? And
what is different when it's executed in Py2?
Or even better, maybe you can write short snippet of code, which I could
paste to all three files, and it will print out all this differences
during execution (you know - so I could be able to track current_module,
path_where_i_am, and path_of_relative_import). I tried to put
"print(__name__)" and "print(os.getcwd())" in every file in this tree,
but it's not quite that. Output looks the same in Py2 and Py3, so it
gives me no explanation.


Is there a simple way of importing modb from moda (in Py3), that will
work when moda.py is executed directly (you know - for unit testing),
but also when start.py is executed (for testing whole "package"). For
now I use this try/except block:

try:
 import modb
except ImportError:
 from . import modb

But I'm not sure if it's Pythonic, and if there's no simpler solution.

--
Best regards,
Wiktor Matuszewski
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] “has a value of True” versus “evaluates true” (was: don't understand iteration)

2014-11-11 Thread Clayton Kirkwood
So, there is a difference between None and False, is that the issue? I don’t 
necessarily see the difference as stated in the subject line. 

A=True

If  A == True

If A

 

Is this the crux of the issue?

 

BTW, the feedback to my submittal suggests that this is a difference with no 
distinction.

 

Clayton

 

From: wesley chun [mailto:wes...@gmail.com] 
Sent: Monday, November 10, 2014 11:35 PM
To: c...@godblessthe.us
Cc: Ben Finney; tutor
Subject: Re: [Tutor] “has a value of True” versus “evaluates true” (was: don't 
understand iteration)

 

good catch, and definitely a distinction beginners should be more cognizant of.

it's also good to recognize that a call to "bool(match)" would render that 
statement correct, as the built-in/factory function will return what an object 
evaluates to (True [re.match object] or/vs.False [None]).

 

On Mon, Nov 10, 2014 at 5:31 PM, Clayton Kirkwood  wrote:

I reported it. I feel all grown up now. Kind of like one of the boys(girls...)

Clayton:<)



>-Original Message-
>From: Tutor [mailto:tutor-bounces+crk  
>=godblessthe...@python.org] On
>Behalf Of Ben Finney
>Sent: Monday, November 10, 2014 3:24 PM
>To: tutor@python.org
>Subject: [Tutor] “has a value of True” versus “evaluates true” (was:
>don't understand iteration)
>
>"Clayton Kirkwood"  writes:
>
>> Also of confusion, the library reference says:
>>
>> Match objects always have a boolean value of True. Since match() and
>> search() return None when there is no match, you can test whether
>> there was a match with a simple if statement:
>>
>> match = re.search(pattern, string)
>> if match:
>> process(match)
>
>The documentation is incorrect, as you point out: “have a boolean value
>of True” implies that the value is identical to the built-in ‘True’
>constant, which is never the case for these objects.
>
>Instead, the passage above should say “evaluates true in a boolean
>context”.
>
>Would you be so kind as to report a bug to that effect
>http://bugs.python.org/>?
>
>--
> \   “The Vatican is not a state.… a state must have people. There |
>  `\are no Vaticanians.… No-one gets born in the Vatican except by |
>_o__)an unfortunate accident.” —Geoffrey Robertson, 2010-09-18 |
>Ben Finney
>
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor




-- 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"A computer never does what you want... only what you tell it."
+wesley chun   : wescpy at gmail : @wescpy 
 
Python training & consulting : http://CyberwebConsulting.com
"Core Python" books : http://CorePython.com
Python blog: http://wescpy.blogspot.com

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] “has a value of True” versus “evaluates true”

2014-11-11 Thread Alan Gauld

On 11/11/14 20:04, Clayton Kirkwood wrote:

So, there is a difference between None and False, is that the issue?


Yes. True and False are the only literal boolean values.
Everything else is boolean-like. That is, they can be used
in a boolean context and Python will treat them as if
they were either True or False, but they are not identical
to the literal values True and False.

So if you use None as a boolean expression in an if test it will be 
treated like it was False. But if you compare it to literal False

using '==' or 'is' it will not be the same.

You can see that below:

>>> if not None: print('Its true')
...
Its true
>>> if not False: print('Its true')
...
Its true

So those two worked identically

>>> if None == False: print('Its not true')
...
>>> if None is False: print('Its not true')
...

But None is not the same as False since neither print() was called.

>>> if bool(None) == False: print('Its true this time')
...
Its true this time
>>>

But if we explicitly convert None to a boolean value it is False.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] “has a value of True” versus “evaluates true”

2014-11-11 Thread Ben Finney
"Clayton Kirkwood"  writes:

> So, there is a difference between None and False, is that the issue?

Yes. Those two values are different and not equal; but both evaluate
false in a boolean context.

> I don’t necessarily see the difference as stated in the subject line.

The difference is: there is exactly one ‘True’ value, but many values
which *evaluate* true in a boolean context.

That is, many values (any non-empty string, any non-zero number, any
non-empty collection, most values of most types) are not equal to
‘True’; but will evaluate true when used in an ‘if’ or ‘while’ or other
boolean context.

So, the documentation stating “X has a value of True” leads to the
incorrect inference you drew, of expecting it to *compare equal to* True
(and, indeed, to be *identical to* True).

Whereas what the documentation needs to say is that the objects it is
referring to have values which *evaluate true* in a boolean context such
as ‘if’ or ‘while’. No implications about values being equal to other
values.

-- 
 \ “I went to the cinema, it said ‘Adults: $5.00, Children $2.50’. |
  `\  So I said ‘Give me two boys and a girl.’” —Steven Wright |
_o__)  |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Error Cannot Import Name Core

2014-11-11 Thread Felisha Lawrence
Hello,
I am trying to install a version of pyart in OSX and I keep getting this
error

--ImportError
  Traceback (most recent call
last) in ()> 1 import pyart
/Users/felishalawrence/anaconda/lib/python2.7/site-packages/pyart/__init__.py
in ()  9 from .version import version as __version__
10 #import subpackages---> 11 from . import core 12 from . import
io 13 from . import correct
ImportError: cannot import name core


Any help as to what this means and how to fix it?

Thanks,
Felisha
-- 
Felisha Lawrence
Howard University Program for Atmospheric Sciences(HUPAS), Graduate Student

NASA URC/BCCSO Graduate Fellow
NOAA NCAS Graduate Fellow
Graduate Student Association for Atmospheric Sciences(GSAAS), Treasurer
(240)-535-6665 (cell)
felisha.lawre...@gmail.com (email)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Cannot Import Name Core

2014-11-11 Thread Danny Yoo
On Tue Nov 11 2014 at 5:17:53 PM Felisha Lawrence <
felisha.lawre...@gmail.com> wrote:

> Hello,
> I am trying to install a version of pyart in OSX and I keep getting this
> error
>
> --ImportError
>Traceback (most recent call 
> last) in ()> 1 import pyart
> /Users/felishalawrence/anaconda/lib/python2.7/site-packages/pyart/__init__.py 
> in ()  9 from .version import version as __version__ 10 
> #import subpackages---> 11 from . import core 12 from . import io 13 
> from . import correct
> ImportError: cannot import name core
>
>
> Any help as to what this means and how to fix it?
>
>
I don't know what pyart is, unfortunately.

Web searches are hitting several projects that have the name 'pyart', but
have different functionality.  I will guess from context that you're
talking about:

http://arm-doe.github.io/pyart/

but can not be absolutely certain.  Please be specific about what
third-party package you're trying to use, because unfortunately it's
ambiguous.

How did you install pyart?  I would expect the error you're seeing only if
the third party package were incorrectly installed.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] “has a value of True” versus “evaluates true”

2014-11-11 Thread Danny Yoo
On Tue Nov 11 2014 at 3:09:38 PM Ben Finney 
wrote:

> "Clayton Kirkwood"  writes:
>
> > So, there is a difference between None and False, is that the issue?
>
> Yes. Those two values are different and not equal; but both evaluate
> false in a boolean context.
>
>

Just to note; not all programming languages do it this way.  Python is
fairly permissive in what it allows to be "truthy".  See:
https://plus.google.com/+ShriramKrishnamurthi/posts/4qvvKYC1R8Y for a brief
survey of what many other programming languages do.

It can be confusing and bug-prone as heck.

For myself, I usually want as restrictive an approach as possible with
respect to what things are considered "truthy".  If I'm in a boolean
context, I will explicitly make the expression being tested be either True
or False, and that's it.  That way, I know I won't get into shaky waters.
I program in multiple languages: I don't want to spend brain power
remembering yet another a truth table about truth.

To quote: "Let your statement be: 'Yes, yes', or "no, no': anything beyond
these is of evil."

:P
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] “has a value of True” versus “evaluates true”

2014-11-11 Thread Clayton Kirkwood
 

 

From: Tutor [mailto:tutor-bounces+crk=godblessthe...@python.org] On Behalf Of 
Danny Yoo
Sent: Tuesday, November 11, 2014 5:25 PM
To: Ben Finney; tutor@python.org
Subject: Re: [Tutor] “has a value of True” versus “evaluates true”

 

 

On Tue Nov 11 2014 at 3:09:38 PM Ben Finney mailto:ben%2bpyt...@benfinney.id.au> > wrote:

"Clayton Kirkwood"  writes:

> So, there is a difference between None and False, is that the issue?

Yes. Those two values are different and not equal; but both evaluate
false in a boolean context.

 

 

Just to note; not all programming languages do it this way.  Python is fairly 
permissive in what it allows to be "truthy".  See: 
https://plus.google.com/+ShriramKrishnamurthi/posts/4qvvKYC1R8Y for a brief 
survey of what many other programming languages do.

 

It can be confusing and bug-prone as heck.

 

For myself, I usually want as restrictive an approach as possible with respect 
to what things are considered "truthy".  If I'm in a boolean context, I will 
explicitly make the expression being tested be either True or False, and that's 
it.  That way, I know I won't get into shaky waters.  I program in multiple 
languages: I don't want to spend brain power remembering yet another a truth 
table about truth.

 

Thanks, Danny, that’s kind of the thing I learned about this whole issue. Force 
the issue truth by casting. Don’t know if I’ll always keep it, but that seems 
prudent. What led to a portion of this whole issue was that I was assuming that 
equal sign assignment would produce a True/False certainty which could be 
tested. I vaguely recall this premise in another language, probably C or Perl.

 

Truthfully,

 

Clayton

 

To quote: "Let your statement be: 'Yes, yes', or "no, no': anything beyond 
these is of evil."

 

:P

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Error Cannot Import Name Core

2014-11-11 Thread Dave Angel
Felisha Lawrence  Wrote in message:
> Hello, 
> I am trying to install a version of pyart in OSX and I keep getting this 
> error 
> 
> --
> ImportError   Traceback (most recent call last)
>  in ()
> > 1 import pyart
> 
> /Users/felishalawrence/anaconda/lib/python2.7/site-packages/pyart/__init__.py 
> in ()
>   9 from .version import version as __version__
>  10 #import subpackages
> ---> 11 from . import core
>  12 from . import io
>  13 from . import correct
> 
> ImportError: cannot import name core
> 
> Any help as to what this means and how to fix it?

Usually questions involving uncommon 3rd party packages do better
 elsewhere, first choice being the package's support site, and
 second being comp.lang.python . The tutor list is really focused
 on the python language and standard library. Still you may get
 lucky.

You should also always specify Python version, and exact source
 and version of the 3rd party package. Do this with the first
 query on any new thread you create, regardless of where you're
 posting. 

Still, I'm going to mae a wild guess, that the library is intended
 for Python 3.x, and you're trying to use it in 2.7

If my guess is right,  you could probably confirm it by giving the
 location for core.*  Somebody else might then confirm it has
 something to do with relative imports.

Or you could go back to the pyart site and see if they offer
 alternative downloads. 




-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor