Re: I am out of trial and error again Lists

2014-10-23 Thread Larry Hudson

On 10/22/2014 03:30 PM, Seymore4Head wrote:

On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
 wrote:

One more question.
if y in str(range(10)
Why doesn't that work.
I commented it out and just did it "long hand"

def nametonumber(name):
 lst=[]
 nx=[]
 for x in (name):
 lst.append(x)
 for y in (lst):
 #if y in str(range(10)):
 if y in "1234567890":
 nx.append(y)
 if y in " -()":
 nx.append(y)
 if y in "abc":
 nx.append("2")
 if y in "def":
 nx.append("3")
 if y in "ghi":
 nx.append("4")
 if y in "jkl":
 nx.append("5")
 if y in "mno":
 nx.append("6")
 if y in "pqrs":
 nx.append("7")
 if y in "tuv":
 nx.append("8")
 if y in "wxyz":
 nx.append("9")
 number="".join(str(e) for e in nx)
 return (number)
a="1-800-getcharter"
print (nametonumber(a))#1800 438 2427 837
a="1-800-leo laporte"
print (nametonumber(a))
a="1 800 callaprogrammer"
print (nametonumber(a))

I know you are trying to explore lists here, but I found myself somewhat intrigued with the 
problem itself, so I wrote a different version.  This version does not use lists but only 
strings.  I'm just presenting it as-is to let you try to follow the logic, but if you ask, I'll 
explain it in detail.  It turns your long sequence of if's essentially into a single line -- 
unfortunately 's' and 'z' have to be handled as special-cases, which turns that single line into 
a six-line if/elif/else set.  You might consider this line 'tricky', but I'll just say it's just 
looking at the problem from a different viewpoint.  BTW, this version accepts upper-case as well 
as lower-case.  isdigit() and isalpha() are standard string methods.


#--  Code  --
def name2number(name):
nstr = ''#  Phone-number string to return
codes = 'abcdefghijklmnopqrtuvwxy'  #  Note missing s and z

for ch in name:
if ch in " -()":
nstr += ch
elif ch.isdigit():
nstr += ch
elif ch.isalpha():
ch = ch.lower()
#   S and Z are special cases
if ch == 's':
nstr += '7'
elif ch == 'z':
nstr += '9'
else:
nstr += str(codes.index(ch) // 3 + 2)
return nstr
#---  End of Code  -

A possible variation would be to make nstr a list instead of a string, and use .append() instead 
of the +=, and finally return the string by using join() on the list.  Also, the if and first 
elif in the for could be combined:  if ch in " -()" or ch.isdigit():


 -=- Larry -=-

--
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Mark Lawrence

On 23/10/2014 02:57, Seymore4Head wrote:

On Wed, 22 Oct 2014 21:35:19 -0400, Seymore4Head
 wrote:


On Thu, 23 Oct 2014 02:31:57 +0100, MRAB 
wrote:


On 2014-10-23 01:10, Seymore4Head wrote:

On Thu, 23 Oct 2014 11:05:08 +1100, Steven D'Aprano
 wrote:


Seymore4Head wrote:


Those string errors were desperate attempts to fix the "append" error
I didn't understand.


Ah, the good ol' "make random changes to the code until the error goes away"
technique. You know that it never works, right?

Start by *reading the error message*, assuming you're getting an error
message. I'm the first person to admit that Python's error messages are not
always as clear as they should be, especially syntax errors, but still
there is a lot of information that can be gleamed from most error messages.
Take this attempt to use append:

py> mylist.append(23)
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'mylist' is not defined

That tells me that I have forgotten to define a variable mylist. So I fix
that:

py> mylist = 23
py> mylist.append(23)
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'int' object has no attribute 'append'


That tells me that I can't append to a int. After googling for "Python
append" I learn that I can append to a list, so I try again:

py> mylist = []
py> mylist.append(23)
py> print(mylist)
[23]


Success!

If you are familiar with other programming languages, it might help to think
of append() as being like a procedure in Pascal, for example. You call
append() with an argument, but don't expect a return result.

Technically, *all* functions and methods in Python return something, even if
just the special value None, which can lead to "Gotchas!" like this one:

py> mylist = mylist.append(42)  # Don't do this!
py> print(mylist)  # I expect [23, 42] but get None instead.
None

Oops. One of the small annoyances of Python is that there is no way to tell
ahead of time, except by reading the documentation, whether something is a
proper function that returns a useful value, or a procedure-like function
that returns None. That's just something you have to learn.

The interactive interpreter is your friend. Learn to experiment at the
interactive interpreter -- you do know how to do that, don't you? If not,
ask. At the interactive interpreter, if a function or method returns a
value, it will be printed, *except for None*. So a function that doesn't
print anything might be procedure-like, and one which does print something
might not be:

py> mylist = [1, 5, 2, 6, 4, 3]
py> sorted(mylist)  # proper function returns a value
[1, 2, 3, 4, 5, 6]
py> mylist.sort()  # procedure-like function returns None
py> print(mylist)  # and modifies the list in place
[1, 2, 3, 4, 5, 6]


I am going to get around to learning the interpreter soon.


Why wait?

You're trying to learn the language _now_, and checking things
interactively will help you.


Because most of the practice I am getting is not using Python.  I use
Codeskulptor.

OK.Now is as good a time as ever.

Thanks


Now I remember why...nothing happens
http://i.imgur.com/MIRpqzY.jpg

If I click on the shell window, I can get the grayed options to show
up for one turn.
I hit step and everything goes gray again.

http://i.imgur.com/NtMdmU1.jpg

Not a very fruitful exercise.  :(



If you were to read and digest what is written it would help.  You're 
trying to run IDLE.  We're talking the interactive interpreter.  If (at 
least on Windows) you run a command prompt and then type python you 
should see something like this.


Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:16:31) [MSC v.1600 64 
bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Ian Kelly
On Thu, Oct 23, 2014 at 1:20 AM, Mark Lawrence  wrote:
> If you were to read and digest what is written it would help.  You're trying
> to run IDLE.  We're talking the interactive interpreter.

IDLE includes the interactive interpreter.

>  If (at least on
> Windows) you run a command prompt and then type python you should see
> something like this.
>
> Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:16:31) [MSC v.1600 64 bit
> (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.

Same thing comes up when I start IDLE, so what's your point?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Mark Lawrence

On 23/10/2014 08:56, Ian Kelly wrote:

On Thu, Oct 23, 2014 at 1:20 AM, Mark Lawrence  wrote:

If you were to read and digest what is written it would help.  You're trying
to run IDLE.  We're talking the interactive interpreter.


IDLE includes the interactive interpreter.


  If (at least on
Windows) you run a command prompt and then type python you should see
something like this.

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:16:31) [MSC v.1600 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.


Same thing comes up when I start IDLE, so what's your point?



When you run the interactive interpreter thats all you get.  The OP 
isn't the first person to try things with IDLE not realising you need to 
have a script loaded to do something.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Denis McMahon
On Wed, 22 Oct 2014 18:30:17 -0400, Seymore4Head wrote:

> One more question.
> if y in str(range(10)
> Why doesn't that work.
> I commented it out and just did it "long hand"

In the last post I made, I suggested to you the mechanisms of using the 
python console and using code which prints out variables after every line.

Try the following 3 commands at the console:

>>> 10
>>> range(10)
>>> str(range(10))

10 is just the number 10
range(10) is a list of 10 integers in the sequence 0 to 9
str(range(10)) is?

Please stop the stab in the dark trial and error coding followed by the 
plaintive "why doesn't it work" wailing, and put some effort into reading 
and understanding the manuals.

If a function doesn't do what you expect with the input you think you've 
given it, there is invariably one of three causes:

a) The input you actually gave it isn't the input you thought you gave it
b) You didn't read the description of the function, and it doesn't in 
fact do what you thought
c) Both a and b above

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Denis McMahon
On Wed, 22 Oct 2014 19:11:51 -0400, Seymore4Head wrote:

> On Wed, 22 Oct 2014 22:43:14 + (UTC), Denis McMahon
>  wrote:
> 
>>On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head wrote:
>>
>>> def nametonumber(name):
>>> lst=[""]
>>> for x,y in enumerate (name):
>>> lst=lst.append(y)
>>> print (lst)
>>> return (lst)
>>> a=["1-800-getcharter"]
>>> print (nametonumber(a))#18004382427837
>>> 
>>> 
>>> The syntax for when to use a () and when to use [] still throws me a
>>> curve.
>>> 
>>> For now, I am trying to end up with a list that has each character in
>>> "a" as a single item.
>>> 
>>> I get:
>>> None None
>>
>>First of all, an empty list is created with:
>>
>>emptylist = []
>>
>>whereas
>>
>>x = [""]
>>
>>creates a list containing one element, that element being an empty
>>string. Not the same thing!
>>
>>Did you try stepping through your code line by line in the interpreter
>>to see what happened at each step?
>>
>>note that append is a method of a list object, it has no return value,
>>the original list is modified in place.
>>
> l = ["a","b","c"]   # declare a list l.append( "d" ) # use the
> append method l   # show the list
>>['a', 'b', 'c', 'd']
>>
>>So your line:
>>
>>lst = lst.append(y)
>>
>>should be:
>>
>>lst.append(y)
>>
>>Finally, did you really intend to pass a single element list into the
>>function, or did you intend to pass a string into the function?
>>
> Those string errors were desperate attempts to fix the "append" error I
> didn't understand.

If you don't understand the error, that is the point that you should ask 
for help, rather than make stab in the dark attempts to fix it and then 
asking why the solutions don't work.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-23 Thread MRAB

On 2014-10-23 04:46, Gregory Ewing wrote:

Chris Angelico wrote:

I've seen much MUCH worse... where multiple conditional
expressions get combined arithmetically, and then the result used
somewhere...


In the days of old-school BASIC it was common to
exploit the fact that boolean expressions evaluated
to 0 or 1 (or -1, depending on your dialect :) to
achieve conditional expressions or other tricks.

Probably forgiveable, given that there were no real
conditional expressions, and every byte of your 48K
or less of RAM was precious...


48K? Luxury!
--
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-23 Thread BartC
"Dennis Lee Bieber"  wrote in message 
news:mailman.15097.1414022143.18130.python-l...@python.org...

On Wed, 22 Oct 2014 19:08:40 +0100, "BartC"  declaimed the
following:



Comparing:

x = cond ? f() : g();   # C version

with

x = [f(), g()] [cond]


(Should probably be x = [g(), f()] [cond])



the latter evaluates both f() and g() instead of just one. Apart from 
being

inefficient, it can have unintended side-effects.


Ah, but what would

x = [f, g][cond]()

produce?


It will select f or g (which should refer to functions), and call one of 
those depending on cond. That's not a problem.


The problem is it will still evaluate both f and g, even if they are simple 
in this case, and construct a list which is then indexed by cond. (Although 
in this case a bytecode compiler might be smart enough to avoid constructing 
the list, it can't do that with my example because the code might depend on 
both those options being evaluated.)


--
Bartc 


--
https://mail.python.org/mailman/listinfo/python-list


Re: OS X Menubar in Tkinter

2014-10-23 Thread Kevin Walzer

On 10/21/14, 1:58 AM, Mark Lawrence wrote:

I'm pleased to see that you have an answer.  In return would you please
access this list via
https://mail.python.org/mailman/listinfo/python-list or read and action
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us
seeing double line spacing and single line paragraphs, thanks.


And admonitions of this type should be taken to 
comp.misc.propernntpformatting or 
groups.google.com/propergroupsformatting. They are OT for a list devoted 
to the Python programming language. I'd rather see flame wars over 
indenting vs. curly braces than this kind of constant policing of folks 
who come to us via Google: they greatly increase the noise I have to 
filter out.


--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
https://mail.python.org/mailman/listinfo/python-list


Re: setuptools + data_files = 2

2014-10-23 Thread Simon Kennedy
On Wednesday, 22 October 2014 19:43:25 UTC+1, luc2  wrote:
> hello, would you know how to make data_files work in setuptools ?
> i can't figure out how to put datas in the generated .tar.gz

If you're creating an sdist then you'll need to create a MANIFEST.in file in 
the same folder as setup.py with the following contents

include share/test_file.txt

If you're creating a bdist (egg or wheel) the parameter name you need is

package_data={'share': [share/test_file.txt]},
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Rustom Mody
On Thursday, October 23, 2014 1:39:32 PM UTC+5:30, Mark Lawrence wrote:
> On 23/10/2014 08:56, Ian Kelly wrote:
> > On Thu, Oct 23, 2014 at 1:20 AM, Mark Lawrence  wrote:
> >> If you were to read and digest what is written it would help.  You're 
> >> trying
> >> to run IDLE.  We're talking the interactive interpreter.
> >
> > IDLE includes the interactive interpreter.
> >
> >>   If (at least on
> >> Windows) you run a command prompt and then type python you should see
> >> something like this.
> >>
> >> Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:16:31) [MSC v.1600 64 
> >> bit
> >> (AMD64)] on win32
> >> Type "help", "copyright", "credits" or "license" for more information.
> >
> > Same thing comes up when I start IDLE, so what's your point?
> >
> 
> When you run the interactive interpreter thats all you get.  The OP 
> isn't the first person to try things with IDLE not realising you need to 
> have a script loaded to do something.

If I do (at the shell prompt with an example)
$ python3
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 2+3
5

And if I do
$ idle3
I get a new window containing

Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
Type "copyright", "credits" or "license()" for more information.
>>> 2+3
5

so...
Still not clear whats your point.
idle and python interpreter seem to be mostly the same

[As best as I can make out the OP is not using the standalone
interpreter
nor idle
nor (the many options like) python-interpreter-inside-emacs
nor ipython
nor ...
]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-23 Thread Marko Rauhamaa
"BartC" :

>> Ah, but what would
>>
>> x = [f, g][cond]()
>>
>> produce?
>
> It will select f or g (which should refer to functions), and call one of
> those depending on cond. That's not a problem.
>
> The problem is it will still evaluate both f and g,

That's not really the problem. The problem is in readability.

However, the "[f, g][cond]()" technique is how pure lambda calculus
implements conditional branching so it is interesting in its own right.
IOW, you can do "short-circuiting" in purely functional programming:

j = j + 1 if j < 10 else 3

<=>

j = (lambda: 3, lambda: j + 1)[j < 10]()


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 00:10:28 -0700, Larry Hudson 
wrote:

>On 10/22/2014 03:30 PM, Seymore4Head wrote:
>> On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
>>  wrote:
>>
>> One more question.
>> if y in str(range(10)
>> Why doesn't that work.
>> I commented it out and just did it "long hand"
>>
>> def nametonumber(name):
>>  lst=[]
>>  nx=[]
>>  for x in (name):
>>  lst.append(x)
>>  for y in (lst):
>>  #if y in str(range(10)):
>>  if y in "1234567890":
>>  nx.append(y)
>>  if y in " -()":
>>  nx.append(y)
>>  if y in "abc":
>>  nx.append("2")
>>  if y in "def":
>>  nx.append("3")
>>  if y in "ghi":
>>  nx.append("4")
>>  if y in "jkl":
>>  nx.append("5")
>>  if y in "mno":
>>  nx.append("6")
>>  if y in "pqrs":
>>  nx.append("7")
>>  if y in "tuv":
>>  nx.append("8")
>>  if y in "wxyz":
>>  nx.append("9")
>>  number="".join(str(e) for e in nx)
>>  return (number)
>> a="1-800-getcharter"
>> print (nametonumber(a))#1800 438 2427 837
>> a="1-800-leo laporte"
>> print (nametonumber(a))
>> a="1 800 callaprogrammer"
>> print (nametonumber(a))
>>
>I know you are trying to explore lists here, but I found myself somewhat 
>intrigued with the 
>problem itself, so I wrote a different version.  This version does not use 
>lists but only 
>strings.  I'm just presenting it as-is to let you try to follow the logic, but 
>if you ask, I'll 
>explain it in detail.  It turns your long sequence of if's essentially into a 
>single line -- 
>unfortunately 's' and 'z' have to be handled as special-cases, which turns 
>that single line into 
>a six-line if/elif/else set.  You might consider this line 'tricky', but I'll 
>just say it's just 
>looking at the problem from a different viewpoint.  BTW, this version accepts 
>upper-case as well 
>as lower-case.  isdigit() and isalpha() are standard string methods.
>
>#--  Code  --
>def name2number(name):
> nstr = ''#  Phone-number string to return
> codes = 'abcdefghijklmnopqrtuvwxy'  #  Note missing s and z
>
> for ch in name:
> if ch in " -()":
> nstr += ch
> elif ch.isdigit():
> nstr += ch
> elif ch.isalpha():
> ch = ch.lower()
> #   S and Z are special cases
> if ch == 's':
> nstr += '7'
> elif ch == 'z':
> nstr += '9'
> else:
> nstr += str(codes.index(ch) // 3 + 2)
> return nstr
>#---  End of Code  -
>
>A possible variation would be to make nstr a list instead of a string, and use 
>.append() instead 
>of the +=, and finally return the string by using join() on the list.  Also, 
>the if and first 
>elif in the for could be combined:  if ch in " -()" or ch.isdigit():
>
>  -=- Larry -=-
Sure I will have a look at it.  I am always open on better ways to do
something.
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 09:23:29 -0400, Dennis Lee Bieber
 wrote:

>On Thu, 23 Oct 2014 00:10:28 -0700, Larry Hudson
> declaimed the following:
>
>
>>I know you are trying to explore lists here, but I found myself somewhat 
>>intrigued with the 
>>problem itself, so I wrote a different version.  This version does not use 
>>lists but only 
>>strings.  I'm just presenting it as-is to let you try to follow the logic, 
>>but if you ask, I'll 
>>explain it in detail.  It turns your long sequence of if's essentially into a 
>>single line -- 
>>unfortunately 's' and 'z' have to be handled as special-cases, which turns 
>>that single line into 
>>a six-line if/elif/else set.  You might consider this line 'tricky', but I'll 
>>just say it's just 
>>looking at the problem from a different viewpoint.  BTW, this version accepts 
>>upper-case as well 
>>as lower-case.  isdigit() and isalpha() are standard string methods.
>>
>
>
>
>   This is another example where changing data structures can simplify
>things a lot...
>
>-=-=-=-=-=-=-
>keys = {"a" : "2",  "b" : "2",  "c" : "2",  # 1 is not assigned
>"d" : "3",  "e" : "3",  "f" : "3",
>"g" : "4",  "h" : "4",  "i" : "4",
>"j" : "5",  "k" : "5",  "l" : "5",
>"m" : "6",  "n" : "6",  "o" : "6",
>"p" : "7",  "q" : "7",  "r" : "7",  "s" : "7",
>"t" : "8",  "u" : "8",  "v" : "8",
>"w" : "9",  "x" : "9",  "y" : "9",  "z" : "9"   }
>
>def textToNumber(inp):
>outp = []
>for c in inp.lower():
>outp.append(keys.get(c, c))
>return "".join(outp)
>
>if __name__ == "__main__":
>while True:
>#NOTE: Python 2.7!
>aNumStr = raw_input("\nEnter Phone Number String: ")
>if not aNumStr: break
>print "Converted to all numbers: %s" % textToNumber(aNumStr)
>
I'll have a look at this one too.  I haven't used a dictionary yet.
Thanks
>-=-=-=-=-=-=-
>Microsoft Windows [Version 6.1.7601]
>Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
>
>C:\Users\Wulfraed\Documents\Python Progs>Phone.py
>
>Enter Phone Number String: 1-800-getcharter
>Converted to all numbers: 1-800-4382427837
>
>Enter Phone Number String: 1-800-leo laporte
>Converted to all numbers: 1-800-536 5276783
>
>Enter Phone Number String: 1 800 callaprogrammer
>Converted to all numbers: 1 800 225527764726637
>
>Enter Phone Number String: +1(800)Leo-Laporte
>Converted to all numbers: +1(800)536-5276783
>
>Enter Phone Number String:
>
>C:\Users\Wulfraed\Documents\Python Progs>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 06:42:43 -0700 (PDT), Rustom Mody
 wrote:

>On Thursday, October 23, 2014 1:39:32 PM UTC+5:30, Mark Lawrence wrote:
>> On 23/10/2014 08:56, Ian Kelly wrote:
>> > On Thu, Oct 23, 2014 at 1:20 AM, Mark Lawrence  wrote:
>> >> If you were to read and digest what is written it would help.  You're 
>> >> trying
>> >> to run IDLE.  We're talking the interactive interpreter.
>> >
>> > IDLE includes the interactive interpreter.
>> >
>> >>   If (at least on
>> >> Windows) you run a command prompt and then type python you should see
>> >> something like this.
>> >>
>> >> Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:16:31) [MSC v.1600 64 
>> >> bit
>> >> (AMD64)] on win32
>> >> Type "help", "copyright", "credits" or "license" for more information.
>> >
>> > Same thing comes up when I start IDLE, so what's your point?
>> >
>> 
>> When you run the interactive interpreter thats all you get.  The OP 
>> isn't the first person to try things with IDLE not realising you need to 
>> have a script loaded to do something.
>
>If I do (at the shell prompt with an example)
>$ python3
>Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
>[GCC 4.9.1] on linux
>Type "help", "copyright", "credits" or "license" for more information.
 2+3
>5
>
>And if I do
>$ idle3
>I get a new window containing
>
>Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
>[GCC 4.9.1] on linux
>Type "copyright", "credits" or "license()" for more information.
 2+3
>5
>
>so...
>Still not clear whats your point.
>idle and python interpreter seem to be mostly the same
>
>[As best as I can make out the OP is not using the standalone
>interpreter
>nor idle
>nor (the many options like) python-interpreter-inside-emacs
>nor ipython
>nor ...
>]
I don't know the difference, yet.  I am gonna get around to reading
the Internet one of these days.
:)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 09:15:16 + (UTC), Denis McMahon
 wrote:

>On Wed, 22 Oct 2014 18:30:17 -0400, Seymore4Head wrote:
>
>> One more question.
>> if y in str(range(10)
>> Why doesn't that work.
>> I commented it out and just did it "long hand"
>
>In the last post I made, I suggested to you the mechanisms of using the 
>python console and using code which prints out variables after every line.
>
>Try the following 3 commands at the console:
>
 10
 range(10)
 str(range(10))
>
>10 is just the number 10
>range(10) is a list of 10 integers in the sequence 0 to 9
>str(range(10)) is?
>
>Please stop the stab in the dark trial and error coding followed by the 
>plaintive "why doesn't it work" wailing, and put some effort into reading 
>and understanding the manuals.
>
>If a function doesn't do what you expect with the input you think you've 
>given it, there is invariably one of three causes:
>
>a) The input you actually gave it isn't the input you thought you gave it
>b) You didn't read the description of the function, and it doesn't in 
>fact do what you thought
>c) Both a and b above
Ok
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 08:20:32 +0100, Mark Lawrence
 wrote:

>On 23/10/2014 02:57, Seymore4Head wrote:
>> On Wed, 22 Oct 2014 21:35:19 -0400, Seymore4Head
>>  wrote:
>>
>>> On Thu, 23 Oct 2014 02:31:57 +0100, MRAB 
>>> wrote:
>>>
 On 2014-10-23 01:10, Seymore4Head wrote:
> On Thu, 23 Oct 2014 11:05:08 +1100, Steven D'Aprano
>  wrote:
>
>> Seymore4Head wrote:
>>
>>> Those string errors were desperate attempts to fix the "append" error
>>> I didn't understand.
>>
>> Ah, the good ol' "make random changes to the code until the error goes 
>> away"
>> technique. You know that it never works, right?
>>
>> Start by *reading the error message*, assuming you're getting an error
>> message. I'm the first person to admit that Python's error messages are 
>> not
>> always as clear as they should be, especially syntax errors, but still
>> there is a lot of information that can be gleamed from most error 
>> messages.
>> Take this attempt to use append:
>>
>> py> mylist.append(23)
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> NameError: name 'mylist' is not defined
>>
>> That tells me that I have forgotten to define a variable mylist. So I fix
>> that:
>>
>> py> mylist = 23
>> py> mylist.append(23)
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> AttributeError: 'int' object has no attribute 'append'
>>
>>
>> That tells me that I can't append to a int. After googling for "Python
>> append" I learn that I can append to a list, so I try again:
>>
>> py> mylist = []
>> py> mylist.append(23)
>> py> print(mylist)
>> [23]
>>
>>
>> Success!
>>
>> If you are familiar with other programming languages, it might help to 
>> think
>> of append() as being like a procedure in Pascal, for example. You call
>> append() with an argument, but don't expect a return result.
>>
>> Technically, *all* functions and methods in Python return something, 
>> even if
>> just the special value None, which can lead to "Gotchas!" like this one:
>>
>> py> mylist = mylist.append(42)  # Don't do this!
>> py> print(mylist)  # I expect [23, 42] but get None instead.
>> None
>>
>> Oops. One of the small annoyances of Python is that there is no way to 
>> tell
>> ahead of time, except by reading the documentation, whether something is 
>> a
>> proper function that returns a useful value, or a procedure-like function
>> that returns None. That's just something you have to learn.
>>
>> The interactive interpreter is your friend. Learn to experiment at the
>> interactive interpreter -- you do know how to do that, don't you? If not,
>> ask. At the interactive interpreter, if a function or method returns a
>> value, it will be printed, *except for None*. So a function that doesn't
>> print anything might be procedure-like, and one which does print 
>> something
>> might not be:
>>
>> py> mylist = [1, 5, 2, 6, 4, 3]
>> py> sorted(mylist)  # proper function returns a value
>> [1, 2, 3, 4, 5, 6]
>> py> mylist.sort()  # procedure-like function returns None
>> py> print(mylist)  # and modifies the list in place
>> [1, 2, 3, 4, 5, 6]
>
> I am going to get around to learning the interpreter soon.
>
 Why wait?

 You're trying to learn the language _now_, and checking things
 interactively will help you.
>>>
>>> Because most of the practice I am getting is not using Python.  I use
>>> Codeskulptor.
>>>
>>> OK.Now is as good a time as ever.
>>>
>>> Thanks
>>
>> Now I remember why...nothing happens
>> http://i.imgur.com/MIRpqzY.jpg
>>
>> If I click on the shell window, I can get the grayed options to show
>> up for one turn.
>> I hit step and everything goes gray again.
>>
>> http://i.imgur.com/NtMdmU1.jpg
>>
>> Not a very fruitful exercise.  :(
>>
>
>If you were to read and digest what is written it would help.  You're 
>trying to run IDLE.  We're talking the interactive interpreter.  If (at 
>least on Windows) you run a command prompt and then type python you 
>should see something like this.
>
>Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:16:31) [MSC v.1600 64 
>bit (AMD64)] on win32
>Type "help", "copyright", "credits" or "license" for more information.

OK
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-23 Thread Ian Kelly
On Thu, Oct 23, 2014 at 7:44 AM, Marko Rauhamaa  wrote:
> However, the "[f, g][cond]()" technique is how pure lambda calculus
> implements conditional branching so it is interesting in its own right.

I wasn't aware that lambda calculus had lists and indexing built in.

> IOW, you can do "short-circuiting" in purely functional programming:
>
> j = j + 1 if j < 10 else 3
>
> <=>
>
> j = (lambda: 3, lambda: j + 1)[j < 10]()

The implementation given by Wikipedia (and translated into Python by me) is:

>>> true = lambda x: lambda y: x
>>> false = lambda x: lambda y: y
>>> ifthenelse = lambda p: lambda a: lambda b: p(a)(b)
>>> ifthenelse(true)(1)(2)
1
>>> ifthenelse(false)(1)(2)
2

For demonstration purposes I used Python ints as the branches rather
than actual lambda calculus constructs, but this shows how selection
can be done using only lambda abstractions and applications.

In any case I don't see how this relates to the "[f, g][cond]()"
technique of Python, unless you just meant the general approach of
first selecting a function and then applying it. In that sense though,
the ternary operator does the same thing; the application is just done
invisibly by the language in the form of evaluating an expression as
opposed to explicitly applying a function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread giacomo boffi
Rustom Mody  writes:

> [As best as I can make out the OP is not using the standalone
> interpreter
> nor idle
> nor (the many options like) python-interpreter-inside-emacs
> nor ipython
> nor ...

but CodeSkulptor ]

CodeSkulptor has been mentioned recently by S4H, and he had explained
why he uses CodeSkulptor, but I cannot remember anything of the explanation...

-- 
> Sarebbe ora gli scienziati italiani mostrassero un po' i coglioni
si`, vabbe`, ma a chi?   -- PLS, in IFQ
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 16:25:28 +0200, giacomo boffi 
wrote:

>Rustom Mody  writes:
>
>> [As best as I can make out the OP is not using the standalone
>> interpreter
>> nor idle
>> nor (the many options like) python-interpreter-inside-emacs
>> nor ipython
>> nor ...
>
>but CodeSkulptor ]
>
>CodeSkulptor has been mentioned recently by S4H, and he had explained
>why he uses CodeSkulptor, but I cannot remember anything of the explanation...

They are using it in the online course I am taking
An Introduction to Interactive Programming in Python
https://www.coursera.org/

It is clumsy and it is not compatible with Python3, but it is free.  3
more weeks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Truthiness

2014-10-23 Thread Simon Kennedy
Just out of academic interest, is there somewhere in the Python docs where the 
following is explained?

>>> 3 == True
False
>>> if 3:
print("It's Twue")

It's Twue

i.e. in the if statement 3 is True but not in the first
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-23 Thread Alain Ketterlin
Marko Rauhamaa  writes:

> "BartC" :

>>> x = [f, g][cond]()

>> It will select f or g (which should refer to functions), and call one of
>> those depending on cond. That's not a problem.
>>
>> The problem is it will still evaluate both f and g,
>
> That's not really the problem. The problem is in readability.

Readability is in the eye of the beholder. The evaluation is the central
concern here.

> However, the "[f, g][cond]()" technique is how pure lambda calculus
> implements conditional branching so it is interesting in its own
> right.

Yes, but lambda calculus constructs have no meaning without an
evaluation strategy ("reduction" strategy in lambda calculs parlance).

> IOW, you can do "short-circuiting" in purely functional programming:
>
> j = j + 1 if j < 10 else 3
> <=>
> j = (lambda: 3, lambda: j + 1)[j < 10]()

This is just a way to delay evaluation *of the potential results*, i.e.,
instill a bit of lazyness. One could object that, again, both
expressions in the tuple have been evaluated (building two lambdas),
only one of which is finally called. I guess that's what BartC meant.

-- Alain.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread giacomo boffi
Seymore4Head  writes:

> Because most of the practice I am getting is not using Python.  I
> use Codeskulptor.

Seymore,

it's been months that you're struggling with python, if you happen to
own a computer could you please take the time to install python on it
and familiarise with the interactive interpreter?  I'll see that as a
personal favor. If you have to hand in assignments using codeskulptor
or are in any other way bound by your institution to use that service
you could anyway use the interactive interpreter on your pc, applying
the debugging and self-learning techniques that were shown to you, in
many different circumstances, by the very, very helpful folks of clp.

thank you for your attention
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread Ian Kelly
On Thu, Oct 23, 2014 at 8:30 AM, Simon Kennedy  wrote:
> Just out of academic interest, is there somewhere in the Python docs where 
> the following is explained?

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

 3 == True
> False
 if 3:
> print("It's Twue")
>
> It's Twue
>
> i.e. in the if statement 3 is True but not in the first

No, 3 is merely true, not True.  True is just the name of a particular
singleton object that is also true.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread Wolfgang Maier

On 10/23/2014 04:30 PM, Simon Kennedy wrote:

Just out of academic interest, is there somewhere in the Python docs where the 
following is explained?



https://docs.python.org/3/library/stdtypes.html#truth-value-testing


3 == True

False


as opposed to:

https://docs.python.org/3/library/stdtypes.html#comparisons


if 3:

print("It's Twue")

It's Twue

i.e. in the if statement 3 is True but not in the first



Here is the misunderstanding: it is not true that 3 is True in the if 
example, but it's evaluated as True in a boolean context. Illustration:


>>> 3 == True
False

>>> bool(3) == True
True

>>> bool(3) is True
True

If you combine if and a comparison, it behaves like in your first example:

>>>
if 3 == True:
print('True')
else:
print('False')

False


--
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 16:40:22 +0200, giacomo boffi 
wrote:

>Seymore4Head  writes:
>
>> Because most of the practice I am getting is not using Python.  I
>> use Codeskulptor.
>
>Seymore,
>
>it's been months that you're struggling with python, if you happen to
>own a computer could you please take the time to install python on it
>and familiarise with the interactive interpreter?  I'll see that as a
>personal favor. If you have to hand in assignments using codeskulptor
>or are in any other way bound by your institution to use that service
>you could anyway use the interactive interpreter on your pc, applying
>the debugging and self-learning techniques that were shown to you, in
>many different circumstances, by the very, very helpful folks of clp.
>
>thank you for your attention

I have Python installed.  I will learn the interpreter.  I also
acknowledge there are very, very helpful folks here.

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread Alain Ketterlin
Simon Kennedy  writes:

> Just out of academic interest, is there somewhere in the Python docs where 
> the following is explained?
>
 3 == True
> False
 if 3:
>   print("It's Twue")
>   
> It's Twue
>
> i.e. in the if statement 3 is True but not in the first

https://docs.python.org/2/reference/compound_stmts.html#the-if-statement

says: "The if statement [...] selects exactly one of the suites by
evaluating the expressions one by one until one is found to be true (see
section Boolean operations for the definition of true and false)"

and then:

https://docs.python.org/2/reference/expressions.html#booleans

says: "In the context of Boolean operations, and also when expressions
are used by control flow statements, the following values are
interpreted as false: False, None, numeric zero of all types, and empty
strings and containers (including strings, tuples, lists, dictionaries,
sets and frozensets). All other values are interpreted as true."

(links are to the 2.7 version of the reference manual, I think not much
has changed in 3.* versions.)

-- Alain.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread Skip Montanaro
On Thu, Oct 23, 2014 at 9:30 AM, Simon Kennedy  wrote:

> Just out of academic interest, is there somewhere in the Python docs where
> the following is explained?


Yes:

https://docs.python.org/3/library/stdtypes.html#truth-value-testing
https://docs.python.org/2.7/library/stdtypes.html#truth-value-testing

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Tobiah

On 10/22/2014 01:30 PM, Seymore4Head wrote:

def nametonumber(name):
 lst=[""]
 for x,y in enumerate (name):
 lst=lst.append(y)
 print (lst)
 return (lst)
a=["1-800-getcharter"]
print (nametonumber(a))#18004382427837


The syntax for when to use a () and when to use [] still throws me a
curve.

For now, I am trying to end up with a list that has each character in
"a" as a single item.





a = "1-800-getcharter"
list(a)

['1', '-', '8', '0', '0', '-', 'g', 'e', 't', 'c', 'h', 'a', 'r', 't', 'e', 'r']




--
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread Simon Kennedy
Thanks everyone. That's a thorough enough explanation for me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread Wolfgang Maier

On 10/23/2014 04:47 PM, Alain Ketterlin wrote:

Simon Kennedy  writes:


Just out of academic interest, is there somewhere in the Python docs where the 
following is explained?


3 == True

False

if 3:

print("It's Twue")

It's Twue

i.e. in the if statement 3 is True but not in the first


https://docs.python.org/2/reference/compound_stmts.html#the-if-statement

says: "The if statement [...] selects exactly one of the suites by
evaluating the expressions one by one until one is found to be true (see
section Boolean operations for the definition of true and false)"



Exactly, but in

if 3 == True:

the expression is 3==True , in which 3 and True compare unequal, thus, 
the expression is false.

On the other hand, in

if 3:

the expression to evaluate is just the int object and the rules below apply.


and then:

https://docs.python.org/2/reference/expressions.html#booleans

says: "In the context of Boolean operations, and also when expressions
are used by control flow statements, the following values are
interpreted as false: False, None, numeric zero of all types, and empty
strings and containers (including strings, tuples, lists, dictionaries,
sets and frozensets). All other values are interpreted as true."

(links are to the 2.7 version of the reference manual, I think not much
has changed in 3.* versions.)

-- Alain.



--
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread random832
On Thu, Oct 23, 2014, at 10:56, Simon Kennedy wrote:
> Thanks everyone. That's a thorough enough explanation for me.

You should know, though, that numeric values equal to 1 (and 0 for
False) _are_ == True. This works for dictionary keys, array indexes,
etc. The bool type is actually a subclass of int. Mathematical
operations on it will simply return an int, or float for division -
logical operations and bitwise and/or/xor return bool (bitwise not
returns an int because it returns the values -1 and -2)

So checking if something is == True is the same as checking if it's ==
1, and checking if it's == False is the same as checking if it's == 0.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Rustom Mody
On Thursday, October 23, 2014 7:36:28 PM UTC+5:30, Seymore4Head wrote:
> On Thu, 23 Oct 2014 06:42:43 -0700 (PDT), Rustom Mody wrote:
> >[As best as I can make out the OP is not using the standalone
> >interpreter
> >nor idle
> >nor (the many options like) python-interpreter-inside-emacs
> >nor ipython
> >nor ...
> >]

> I don't know the difference, yet.  I am gonna get around to reading
> the Internet one of these days.
> :)

Hoo Boy!

You may like to start here
http://en.wikibooks.org/wiki/Python_Programming/Interactive_mode

Then stop and try what is suggested

Then come back here and ask what (if any) goes wrong
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Denis McMahon
On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote:

> On Thu, 23 Oct 2014 09:15:16 + (UTC), Denis McMahon
>  wrote:

>>Try the following 3 commands at the console:

You obviously didn't, so I'll try again. Try each of the following three 
commands in the python console at the ">>>" prompt.

1) 10
2) range(10)
3) str(range(10))

Show *and* describe the output in each case. Describing the output that 
you see is actually the key here, as it will allow us to assess whether 
you understand what you are actually seeing or not, and if you don't 
understand the output you see in the console, then we need to fix that 
very fundamental and basic issue before moving on to more complex stuff!

> Ok Thanks

You were expected to answer the question in the original. I have now set 
it as a clearer and more specific task.

If you're not going to do these things that are intended to help you 
learn some of the basic features of the language, then I and everyone 
else here that has so far been attempting to help you are wasting our 
time.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Denis McMahon
On Thu, 23 Oct 2014 16:25:28 +0200, giacomo boffi wrote:

> Rustom Mody  writes:
> 
>> [As best as I can make out the OP is not using the standalone
>> interpreter nor idle nor (the many options like)
>> python-interpreter-inside-emacs nor ipython nor ...
> 
> but CodeSkulptor ]
> 
> CodeSkulptor has been mentioned recently by S4H, and he had explained
> why he uses CodeSkulptor, but I cannot remember anything of the
> explanation...

CodeSkulptor is a tool used by a group of instructors at RICE to teach an 
on-line python programming course in a web browser environment. It may be 
a python IDE and interpreter implemented in HTML, CSS and javascript, I'm 
not sure.

IO is handled by a package called simplegui, and I believe there's a 
wrapper for tkinter that presents simplegui if you want to run code 
written for codeskulptor outside of the codeskulptor environment.

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread Denis McMahon
On Thu, 23 Oct 2014 16:47:27 +0200, Alain Ketterlin wrote:

> says: "In the context of Boolean operations, and also when expressions
> are used by control flow statements, the following values are
> interpreted as false: False, None, numeric zero of all types, and empty
> strings and containers (including strings, tuples, lists, dictionaries,
> sets and frozensets). All other values are interpreted as true."

Yep, and I expect this to bite S4H shortly, when he can't understand why 
the following are not all of the same truthiness:

0 (falsey - numeric 0)
[] (falsey - empty set)
"" (falsey - empty string)
[""] (truthy - non empty set)
[0] (truthy - non empty set)

-- 
Denis McMahon, denismfmcma...@gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-23 Thread Marko Rauhamaa
Alain Ketterlin :

>> j = (lambda: 3, lambda: j + 1)[j < 10]()
>
> This is just a way to delay evaluation *of the potential results*,
> i.e., instill a bit of lazyness.

That's one way to characterize a function, or code in general.

That point of view is apparent in PostScript, where control structures
are expressed "lazily" with lambdas:

5 eq {
gsave
0.85 1 0.85 setrgbcolor
fill
grestore
} if

The { ... } block is a piece of code pushed onto the stack.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 15:55:35 + (UTC), Denis McMahon
 wrote:

>On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote:
>
>> On Thu, 23 Oct 2014 09:15:16 + (UTC), Denis McMahon
>>  wrote:
>
>>>Try the following 3 commands at the console:
>
>You obviously didn't, so I'll try again. Try each of the following three 
>commands in the python console at the ">>>" prompt.
>
>1) 10
10

>2) range(10)
range(0, 10)

>3) str(range(10))
'range(0, 10)'
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>
>Show *and* describe the output in each case. Describing the output that 
>you see is actually the key here, as it will allow us to assess whether 
>you understand what you are actually seeing or not, and if you don't 
>understand the output you see in the console, then we need to fix that 
>very fundamental and basic issue before moving on to more complex stuff!
>
>> Ok Thanks
>
>You were expected to answer the question in the original. I have now set 
>it as a clearer and more specific task.
>
>If you're not going to do these things that are intended to help you 
>learn some of the basic features of the language, then I and everyone 
>else here that has so far been attempting to help you are wasting our 
>time.

I did try them.  I may have missed replying your to your specific
comment, but I tried them.

BTW str(range (10)) does work with Python 2 which is where I may have
got the idea.  I happened to be using Python 3 at the time I tried to
implement it.  It is a little confusing jumping back and forth, but
for the moment, I am going to tough it out.

I do appreciate all the help too.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 13:01:18 -0400, Seymore4Head
 wrote:

>On Thu, 23 Oct 2014 15:55:35 + (UTC), Denis McMahon
> wrote:
>
>>On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote:
>>
>>> On Thu, 23 Oct 2014 09:15:16 + (UTC), Denis McMahon
>>>  wrote:
>>
Try the following 3 commands at the console:
>>
>>You obviously didn't, so I'll try again. Try each of the following three 
>>commands in the python console at the ">>>" prompt.
>>
>>1) 10
>10
>
>>2) range(10)
>range(0, 10)
>
>>3) str(range(10))
>'range(0, 10)'
>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>
BTW I forgot to add that example 2 and 3 don't seem to be too useful
in Python 3, but they are in Python 2.  I don't understand how the
Python 3 is an improved version.

>>Show *and* describe the output in each case. Describing the output that 
>>you see is actually the key here, as it will allow us to assess whether 
>>you understand what you are actually seeing or not, and if you don't 
>>understand the output you see in the console, then we need to fix that 
>>very fundamental and basic issue before moving on to more complex stuff!
>>
>>> Ok Thanks
>>
>>You were expected to answer the question in the original. I have now set 
>>it as a clearer and more specific task.
>>
>>If you're not going to do these things that are intended to help you 
>>learn some of the basic features of the language, then I and everyone 
>>else here that has so far been attempting to help you are wasting our 
>>time.
>
>I did try them.  I may have missed replying your to your specific
>comment, but I tried them.
>
>BTW str(range (10)) does work with Python 2 which is where I may have
>got the idea.  I happened to be using Python 3 at the time I tried to
>implement it.  It is a little confusing jumping back and forth, but
>for the moment, I am going to tough it out.
>
>I do appreciate all the help too.
-- 
https://mail.python.org/mailman/listinfo/python-list


FYI: Micro Python running on kickstarter pyBoard project, now shipping

2014-10-23 Thread jkn
Hi all
I haven't heard in mentioned here, but since I saw one of the boards today 
thought I'd pass on the news:

The Kickstarter 'MicroPython' project, which has a tiny 'pyboard' (only a 
couple of sq.inches in size) with a processor running 'a complete re-write of 
the Python (version 3.4) programming language so that it fits and runs on a 
microcontroller' is now shipping.

https://micropython.org/

Looks nice; I have no connection but will be getting one myself to play with...

Cheers
J^n
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OS X Menubar in Tkinter

2014-10-23 Thread Terry Reedy

On 10/23/2014 9:25 AM, Kevin Walzer wrote:

On 10/21/14, 1:58 AM, Mark Lawrence wrote:

I'm pleased to see that you have an answer.  In return would you please
access this list via
https://mail.python.org/mailman/listinfo/python-list or read and action
this https://wiki.python.org/moin/GoogleGroupsPython to prevent us
seeing double line spacing and single line paragraphs, thanks.


And admonitions of this type should be taken to










comp.misc.propernntpformatting or










groups.google.com/propergroupsformatting. They are OT for a list devoted











to the Python programming language. I'd rather see flame wars over










indenting vs. curly braces than this kind of constant policing of folks











who come to us via Google: they greatly increase the noise I have to









filter out.


Kevin, feel free to filter out all of Mark's messages.  People posting 
from Google groups do not know that messages look like the above after a 
few rounds thru gg since gg apparently corrects its own misformatting in 
its displays.  Most people pay attention to Mark's information.  I 
ignore those who do not and send quad- or octo-spaced messages.


I have asked on python-list-admin that the same info be sent to new gg 
posters automatically and privately, or that the extra blanks be 
filtered out, but to no avail.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: OS X Menubar in Tkinter

2014-10-23 Thread Chris Angelico
On Fri, Oct 24, 2014 at 4:32 AM, Terry Reedy  wrote:
> I have asked on python-list-admin that the same info be sent to new gg
> posters automatically and privately, or that the extra blanks be filtered
> out, but to no avail.

I don't think it's possible to auto-solve the Google Groups formatting
issues at the mailing list level, as the fundamental problem is that
information isn't being transmitted. (Forcing everything to be wrapped
and forcing blank line removal risks breaking other formatting.) The
last time I had a job interview with Google, I said that I wanted to
spend my 20% time fixing Google Groups' paragraph handling... and then
they didn't hire me. Not sure if this is coincidental or not. :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Ian Kelly
On Thu, Oct 23, 2014 at 11:07 AM, Seymore4Head
 wrote:
> BTW I forgot to add that example 2 and 3 don't seem to be too useful
> in Python 3, but they are in Python 2.  I don't understand how the
> Python 3 is an improved version.

In Python 2, range returns a list containing all the requested
elements. This is simple to work with but often not desirable, because
it forces the entire sequence to be loaded into memory at once. Large
ranges may cause excessive memory use and related slowdowns, while
very large ranges may not even be usable.

In Python 3, range returns a compact object that knows what elements
it contains and can iterate over them (which is the most common use of
ranges by far), but without needing to load them all into memory at
once. While iterating, only the current element needs to exist in
memory. You can still get the range as a list if you want it, by
calling list(range(10)), but it doesn't force you to create a list,
which makes it more versatile than the Python 2 construct.

The more specialized data structure used in Python 3 also allows for
certain optimizations, for example membership testing. In Python 2, if
you do the test "97 in range(100)", it has to construct a 100-element
list and then iterate over 97 of the elements before discovering that
the list does in fact contain the number 97. The Python 3 range object
knows what the bounds of the range are, so all it has to do is check
that 0 <= 97 < 100 to know that the number 97 is included in the
range.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 13:39:06 -0600, Ian Kelly 
wrote:

>On Thu, Oct 23, 2014 at 11:07 AM, Seymore4Head
> wrote:
>> BTW I forgot to add that example 2 and 3 don't seem to be too useful
>> in Python 3, but they are in Python 2.  I don't understand how the
>> Python 3 is an improved version.
>
>In Python 2, range returns a list containing all the requested
>elements. This is simple to work with but often not desirable, because
>it forces the entire sequence to be loaded into memory at once. Large
>ranges may cause excessive memory use and related slowdowns, while
>very large ranges may not even be usable.
>
>In Python 3, range returns a compact object that knows what elements
>it contains and can iterate over them (which is the most common use of
>ranges by far), but without needing to load them all into memory at
>once. While iterating, only the current element needs to exist in
>memory. You can still get the range as a list if you want it, by
>calling list(range(10)), but it doesn't force you to create a list,
>which makes it more versatile than the Python 2 construct.
>
>The more specialized data structure used in Python 3 also allows for
>certain optimizations, for example membership testing. In Python 2, if
>you do the test "97 in range(100)", it has to construct a 100-element
>list and then iterate over 97 of the elements before discovering that
>the list does in fact contain the number 97. The Python 3 range object
>knows what the bounds of the range are, so all it has to do is check
>that 0 <= 97 < 100 to know that the number 97 is included in the
>range.

I agree that does seem improved.
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Seymore4Head
On Thu, 23 Oct 2014 13:39:06 -0600, Ian Kelly 
wrote:

>On Thu, Oct 23, 2014 at 11:07 AM, Seymore4Head
> wrote:
>> BTW I forgot to add that example 2 and 3 don't seem to be too useful
>> in Python 3, but they are in Python 2.  I don't understand how the
>> Python 3 is an improved version.
>
>In Python 2, range returns a list containing all the requested
>elements. This is simple to work with but often not desirable, because
>it forces the entire sequence to be loaded into memory at once. Large
>ranges may cause excessive memory use and related slowdowns, while
>very large ranges may not even be usable.
>
>In Python 3, range returns a compact object that knows what elements
>it contains and can iterate over them (which is the most common use of
>ranges by far), but without needing to load them all into memory at
>once. While iterating, only the current element needs to exist in
>memory. You can still get the range as a list if you want it, by
>calling list(range(10)), but it doesn't force you to create a list,
>which makes it more versatile than the Python 2 construct.
>
>The more specialized data structure used in Python 3 also allows for
>certain optimizations, for example membership testing. In Python 2, if
>you do the test "97 in range(100)", it has to construct a 100-element
>list and then iterate over 97 of the elements before discovering that
>the list does in fact contain the number 97. The Python 3 range object
>knows what the bounds of the range are, so all it has to do is check
>that 0 <= 97 < 100 to know that the number 97 is included in the
>range.

I tried to make range(10) work in Python 3 by:
if int(y) in range(10):
name.append(str(y))

It doesn't.

def nametonumber(name):
lst=[]
for y in (name):
y.lower()
if int(y) in range(10):
name.append(str(y))
if y in " -()":
name.append(y)
if y in "abc":
name.append("2")
if y in "def":
name.append("3")
if y in "ghi":
name.append("4")
if y in "jkl":
name.append("5")   
if y in "mno":
name.append("6")
if y in "pqrs":
name.append("7")
if y in "tuv":
name.append("8")
if y in "wxyz":
name.append("9")
number="".join(str(e) for e in name)
return (number)
a="1-800-getcharter"
print (nametonumber(a))#1800 438 2427 837
a="1-800-leo laporte"
print (nametonumber(a))
a="1 800 callaprogrammer"
print (nametonumber(a))





-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread MRAB

On 2014-10-23 21:44, Seymore4Head wrote:
[snip]


I tried to make range(10) work in Python 3 by:
 if int(y) in range(10):
 name.append(str(y))

It doesn't.


You didn't say what happened when you tried, but I can guess.

When given, say, "g", it complains that it's not valid. Well, "g" isn't
a valid digit, so no surprise there!


def nametonumber(name):
 lst=[]
 for y in (name):
 y.lower()


The .lower method _returns_ its result, which is just discarded.

What you need is:

y = y.lower()


 if int(y) in range(10):


Non-digits don't have a numeric value, so that can fail.


 name.append(str(y))


y is already a string, so str(y) is pointless.


 if y in " -()":
 name.append(y)
 if y in "abc":
 name.append("2")
 if y in "def":
 name.append("3")
 if y in "ghi":
 name.append("4")
 if y in "jkl":
 name.append("5")
 if y in "mno":
 name.append("6")
 if y in "pqrs":
 name.append("7")
 if y in "tuv":
 name.append("8")
 if y in "wxyz":
 name.append("9")
 number="".join(str(e) for e in name)


The elements of the list name are already strings.


 return (number)
a="1-800-getcharter"
print (nametonumber(a))#1800 438 2427 837
a="1-800-leo laporte"
print (nametonumber(a))
a="1 800 callaprogrammer"
print (nametonumber(a))



--
https://mail.python.org/mailman/listinfo/python-list


Re: FYI: Micro Python running on kickstarter pyBoard project, now shipping

2014-10-23 Thread sohcahtoa82
On Thursday, October 23, 2014 10:07:26 AM UTC-7, jkn wrote:
> Hi all
> I haven't heard in mentioned here, but since I saw one of the boards 
> today thought I'd pass on the news:
> 
> The Kickstarter 'MicroPython' project, which has a tiny 'pyboard' (only a 
> couple of sq.inches in size) with a processor running 'a complete re-write of 
> the Python (version 3.4) programming language so that it fits and runs on a 
> microcontroller' is now shipping.
> 
> https://micropython.org/
> 
> Looks nice; I have no connection but will be getting one myself to play 
> with...
> 
> Cheers
> J^n


Is there any particular reason to get one of these when I can get a Raspberry 
Pi which is faster, has more memory, and a bundle of other features?

I mean, the idea seems cool and all, but I'm trying to understand why I would 
want to spend the ~$45 on something like that when a ~$35 Raspberry Pi will do 
everything and more, and do it faster.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: FYI: Micro Python running on kickstarter pyBoard project, now shipping

2014-10-23 Thread Travis Griggs

> On Oct 23, 2014, at 2:11 PM, sohcahto...@gmail.com wrote:
> 
> On Thursday, October 23, 2014 10:07:26 AM UTC-7, jkn wrote:
>> Hi all
>>I haven't heard in mentioned here, but since I saw one of the boards 
>> today thought I'd pass on the news:
>> 
>> The Kickstarter 'MicroPython' project, which has a tiny 'pyboard' (only a 
>> couple of sq.inches in size) with a processor running 'a complete re-write 
>> of the Python (version 3.4) programming language so that it fits and runs on 
>> a microcontroller' is now shipping.
>> 
>>https://micropython.org/
>> 
>> Looks nice; I have no connection but will be getting one myself to play 
>> with...
>> 
>>Cheers
>>J^n
> 
> 
> Is there any particular reason to get one of these when I can get a Raspberry 
> Pi which is faster, has more memory, and a bundle of other features?
> 
> I mean, the idea seems cool and all, but I'm trying to understand why I would 
> want to spend the ~$45 on something like that when a ~$35 Raspberry Pi will 
> do everything and more, and do it faster.

Power Consumption.

I don’t know (looked quick, but didn’t find anything fast enough) the exact 
numbers, but the Pi is meant to be plugged in to something, or chew through 
batteries quickly. If your IoT device fits in that space and you need all that 
periphery, that’s great. The Pyboard is running a STM32F405RG (low power contex 
M4). So I’m betting various children of mine, that it can go a whole lot longer 
on the same bit of power. Coin cell operation for long periods is probable.

I think you look at the $45 as a development board. The site says you can get 
access to just about everything, so there’s nothing to keep you from 
prototyping your killer pythonic IoT gadget with these, then doing your own 
tiny board, populating them with the same chip that you can get from DigiKey 
for $7 a piece in quantity. Can’t really do that with the Pi.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Truthiness

2014-10-23 Thread Steven D'Aprano
Ian Kelly wrote:

> No, 3 is merely true, not True.  True is just the name of a particular
> singleton object that is also true.

Sometimes I distinguish between "true" and "True", where True is the
canonical boolean true object, but I prefer to refer
to "true-like", "true-ish", or "truthy" objects as a shorthand
for "evaluates the same as True in a boolean context"

Likewise for "false-like, false-ish, falsey" for objects which evaluate the
same as False in a boolean context.

It should also be pointed out that, for built-ins and the standard library
at least, a good distinction to make is that representations of Nothing
(e.g. None, empty string, empty list, zero, empty set, etc.) are falsey,
while representations of Something (e.g. non-empty strings, non-empty
lists, numbers other than zero, non-empty sets, etc.) are truthy.


-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Larry Hudson

On 10/23/2014 01:44 PM, Seymore4Head wrote:


I tried to make range(10) work in Python 3 by:
 if int(y) in range(10):
 name.append(str(y))

It doesn't.



That's true, it doesn't.  However, did you actually READ the error message it gives?  It has 
NOTHING to do with range().


BTW, did you notice that I cut out most of the quote of your post?  I do that because the parts 
I cut out are not relevant to what I'm referring to.  PLEASE, try that in your posts -- that 
will make them much less annoying to the other people here.  Quote enough to maintain context, 
but more is rarely necessary.


Also as others here have already pointed out, if you are replying to different parts of a post, 
use an interleaved style:



[Your reply]

[Another reply]
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Terry Reedy

On 10/23/2014 3:39 PM, Ian Kelly wrote:

On Thu, Oct 23, 2014 at 11:07 AM, Seymore4Head
 wrote:

BTW I forgot to add that example 2 and 3 don't seem to be too useful
in Python 3, but they are in Python 2.  I don't understand how the
Python 3 is an improved version.


In Python 2, range returns a list containing all the requested
elements. This is simple to work with but often not desirable, because
it forces the entire sequence to be loaded into memory at once. Large
ranges may cause excessive memory use and related slowdowns, while
very large ranges may not even be usable.

In Python 3, range returns a compact object that knows what elements
it contains and can iterate over them (which is the most common use of
ranges by far), but without needing to load them all into memory at
once. While iterating, only the current element needs to exist in
memory. You can still get the range as a list if you want it, by
calling list(range(10)), but it doesn't force you to create a list,
which makes it more versatile than the Python 2 construct.

The more specialized data structure used in Python 3 also allows for
certain optimizations, for example membership testing. In Python 2, if
you do the test "97 in range(100)", it has to construct a 100-element
list and then iterate over 97 of the elements before discovering that
the list does in fact contain the number 97. The Python 3 range object
knows what the bounds of the range are, so all it has to do is check
that 0 <= 97 < 100 to know that the number 97 is included in the
range.


Example that works 'instantly' in 3.x, but would be slightly insane in 
2.x, even if you have enough memory for it to work on a 64 bit build.


>>> r =range(0, 1000, 37)
>>> 3428761974385 in r
False
>>> 3428761974386 in r
True

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Chris Angelico
On Fri, Oct 24, 2014 at 2:14 PM, Terry Reedy  wrote:
> Example that works 'instantly' in 3.x, but would be slightly insane in 2.x,
> even if you have enough memory for it to work on a 64 bit build.
>
 r =range(0, 1000, 37)
 3428761974385 in r
> False
 3428761974386 in r
> True

That's over a billion entries. The array of pointers alone would be
roughly 4GB on a 32-bit build, so there's no way that'll ever fit...
on a 64-bit build, that'll take up 8GBish for the list, plus probably
24 bytes minimum per integer, so even if there's absolutely no heap
overhead, you're still looking at 32GB to store that list. Yeeeouch. I
think we can drop the "slightly" from your description! For
comparison, a 64-bit Python 3 says:

>>> sys.getsizeof(range(0, 1000, 37))
48

Thanks, much nicer.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: I am out of trial and error again Lists

2014-10-23 Thread Rustom Mody
On Thursday, October 23, 2014 10:33:57 PM UTC+5:30, Seymore4Head wrote:
> On Thu, 23 Oct 2014 15:55:35 + (UTC), Denis McMahon wrote:
> 
> >On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote:
> >
> >> On Thu, 23 Oct 2014 09:15:16 + (UTC), Denis McMahon wrote:
> >
> >>>Try the following 3 commands at the console:
> >
> >You obviously didn't, so I'll try again. Try each of the following three 
> >commands in the python console at the ">>>" prompt.
> >
> >1) 10
> 10
> 
> >2) range(10)
> range(0, 10)
> 
> >3) str(range(10))
> 'range(0, 10)'
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> >
> >Show *and* describe the output in each case. Describing the output that 
> >you see is actually the key here, as it will allow us to assess whether 
> >you understand what you are actually seeing or not, and if you don't 
> >understand the output you see in the console, then we need to fix that 
> >very fundamental and basic issue before moving on to more complex stuff!
> >
> >> Ok Thanks
> >
> >You were expected to answer the question in the original. I have now set 
> >it as a clearer and more specific task.
> >
> >If you're not going to do these things that are intended to help you 
> >learn some of the basic features of the language, then I and everyone 
> >else here that has so far been attempting to help you are wasting our 
> >time.
> 
> I did try them.  I may have missed replying your to your specific
> comment, but I tried them.
> 
> BTW str(range (10)) does work with Python 2 which is where I may have
> got the idea.  I happened to be using Python 3 at the time I tried to
> implement it.  It is a little confusing jumping back and forth, but
> for the moment, I am going to tough it out.
> 
> I do appreciate all the help too.

Hi Seymore!

Happy to see that you are moving on from
"reading much; understanding nothing; thrashing"

to

"reading a bit; understanding a bit"
[And thanks to Denis to getting you out of your confusion-hole]

So heres a small additional question set that I promise will more than repay
you your time.

Better done in python 2. But if you use python3, below replace
range(10)
with
list(range(10))

So now in the python console, please try

a.
>>> range(10)

and 

b.
>>> print (range(10))

And then post back (without consulting google!!)¹

1. Are they same or different?

2. If same, how come different expressions are same?

3. If different whats the difference?

4. [Most important]: When would you prefer which?

=
¹ Actually its ok to consult google AFTER you try

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: (test) ? a:b

2014-10-23 Thread ast



48K? Luxury!


ZX81 had an option for 64K
--
https://mail.python.org/mailman/listinfo/python-list