Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Steven D'Aprano

On 16/06/13 11:53, Dave Angel wrote:

On 06/15/2013 08:36 PM, Steven D'Aprano wrote:



for key in sorted(mydict.keys()):
 ...

works fine.

[...]

The sort() method doesn't work, but sorted does.

[...]

for key in sorted(mydict.keys()):


Not only that, but sorted works too:

for key in sorted(mydict.keys())


*wink*


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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Dave Angel

On 06/16/2013 01:58 AM, Steven D'Aprano wrote:

On 16/06/13 11:53, Dave Angel wrote:

On 06/15/2013 08:36 PM, Steven D'Aprano wrote:



for key in sorted(mydict.keys()):
 ...

works fine.

[...]

The sort() method doesn't work, but sorted does.

[...]

for key in sorted(mydict.keys()):


Not only that, but sorted works too:

for key in sorted(mydict.keys())


*wink*




Whoops, I guess I didn't read the whole thing.

Not only that, I didn't read all of it.

Sorry, some of it was inadequately read.

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


Re: [Tutor] What are these two string-formatting styles called?

2013-06-16 Thread Dave Angel

On 06/16/2013 01:40 AM, Dotan Cohen wrote:

On Sat, Jun 15, 2013 at 2:32 PM, Dave Angel da...@davea.name wrote:

Thank you. So would it be clear if I were to say I prefer
printf-style formatting over the format method.?



I'd be careful there, since method is an English word as well as a Python
one.  So I'd make it clear i was referrring to a method of a class, by
naming the class.

Something like:

the format() method of the str class.



Actually, I specifically said 'method' in the OOP-sense of the word. I
don't see any ambiguity, as there is no other relevant class that I
know of which has a format() method. But I'm here to learn, and I
would love nothing more than for you to tell me where the sentence is
ambiguous.



You were thinking of the OOP-sense of the word, but you didn't say it. 
So the listener might choose to figure you meant method as in 
technique.  After all the word style is used in its English meaning, 
even though Word documents can have styles.


You're quite right that once we're thinking in the OOPS-sense, there's 
no ambiguity.  But I figure a few words more were needed to make sure 
the listener is in sync.  And the easiest way to make sure it's clear we 
mean a class-method is to name the class.  If it were being written, the 
parentheses might be enough.  But parentheses are usually silent when 
speaking.





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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Roel Schroeven

Jim Mooney schreef:

On 15 June 2013 14:55, Alan Gauld alan.ga...@btinternet.com wrote:


I think your making it harder than it is.
Just use the result as you would expect and it will work.


I just meant that since I'm learning I'll create a dictionary on the
fly to try something out. All goes well except my IDE will type two
quotes if I type one, then center the cursor in between. the same for
braces, brackets, etc. It's a great convenience. But in a dictionary
I'll get to here:

{'alpha':'beta'

Only my cursor is to the Left of the final quote. Then I have to go
hunt the Right Arrow or End key, which is a big pain since I'm far
from a perfect touch typist and they're both far from the home keys.


Can't you disable that behavior somewhere in the settings of your IDE? I 
know IDEs do that to be helpful, but I don't like it and so far I've 
been able to disable it in all IDEs I've used.


--
People almost invariably arrive at their beliefs not on the basis of
proof but on the basis of what they find attractive.
-- Pascal Blaise

r...@roelschroeven.net

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


Re: [Tutor] What is the difference between checking false?

2013-06-16 Thread eryksun
On Sat, Jun 15, 2013 at 11:53 PM, Jim Mooney cybervigila...@gmail.com wrote:

 class NobodyHome: pass
 x = NobodyHome()
 print(not x) # Result is False when I thought this would be True.

Quote:

 If neither __bool__ nor __len__ is defined, the object defaults to being 
 truthy:

  not not object()
 True
  not object()
 False
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is the difference between checking false?

2013-06-16 Thread eryksun
On Sat, Jun 15, 2013 at 11:15 PM, Jim Mooney cybervigila...@gmail.com wrote:

 ## Comparing different types for equality always fails:

 if '5' != 5:
 print('oops')

It depends on the __eq__ and __ne__ methods defined by the types. int
and str have their own implementations of rich comparisons. But
that's a subject for another thread and another time, when you've
gotten deeper into implementing your own classes.

 Finally, 1 and 0 are oh-so-special standins for True and False,
 that should have been strangled in the cradle.

As I already said, you can't return an int from __bool__ in 3.x. In
2.x, __nonzero__ can return 0 for False and a non-zero int for True
-- but only an int (not long, float, etc).
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What are these two string-formatting styles called?

2013-06-16 Thread Dotan Cohen
On Sun, Jun 16, 2013 at 9:27 AM, Dave Angel da...@davea.name wrote:
 You were thinking of the OOP-sense of the word, but you didn't say it. So
 the listener might choose to figure you meant method as in technique.
 After all the word style is used in its English meaning, even though Word
 documents can have styles.

 You're quite right that once we're thinking in the OOPS-sense, there's no
 ambiguity.  But I figure a few words more were needed to make sure the
 listener is in sync.  And the easiest way to make sure it's clear we mean a
 class-method is to name the class.  If it were being written, the
 parentheses might be enough.  But parentheses are usually silent when
 speaking.


I see, thanks.

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What is the difference between checking false?

2013-06-16 Thread Chris “Kwpolska” Warrick
On Sun, Jun 16, 2013 at 7:52 AM, Jim Mooney cybervigila...@gmail.com wrote:
 On 15 June 2013 22:32, Steven D'Aprano st...@pearwood.info wrote:
 http://mail.python.org/pipermail/python-list/2013-June/649710.html

 A succinct list - worth putting in my Keep file ;')

 -
 Jim
 After indictment the bacon smuggler was put on the no-fry list
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

Another thing worthy putting there may be may be the three ways to do
`if` statements to compare stuff:

1. `if x` — runs bool(x), see list above, can be negated by `if not x`
2. `if x == y` — tests if they have the same value, negated by `if x
!= y` or `if not x == y` (not used).
3. `if x is y` — tests if they are the same object, used for `is
None`/`is not None` comparisons and not much else.
-- 
Kwpolska http://kwpolska.tk | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issue w/ program: Flip a coin and count heads and tails

2013-06-16 Thread Bhanu Pratap Singh
Hi Rafeal,

You have called random function two times. It must be called single time and 
check if it produced 1 or 2. See my code.
/* code
---*/
import random
print(
This program flips a coin 10 times.
It then counts the number of heads and tails.
)
flips = 0
heads = 0
tails = 0
while flips  10:
rand = random.randint(1, 2)
if rand == 1:
heads += 1
print(We've got  + str(heads) +  heads here.)
elif rand == 2:
tails += 1
print(We've got  + str(tails) +  tails here.)
flips = flips + 1
/*--- */

-Original Message-
From: Tutor [mailto:tutor-bounces+bhanubais=gmail@python.org] On Behalf Of 
Bod Soutar
Sent: Friday, May 24, 2013 4:37 PM
To: Rafael Knuth
Cc: Tutor@python.org
Subject: Re: [Tutor] Issue w/ program: Flip a coin and count heads and tails

On 24 May 2013 12:01, Rafael Knuth rafael.kn...@gmail.com wrote:
 Hello,

 I am writing a program in Python 3.3.0 which flips a coin 10 x times 
 and then counts the number of heads and tails. It obviously does 
 something else than I intended, and I am wondering what I did wrong:

 import random

 print (

 This program flips a coin 10 times.

 It then counts the number of heads and tails.

 )

 flips = 0

 heads = 0

 tails = 0

 while flips  10:

 flips = flips + 1

 if random.randint(1,2) == 1:

 heads = heads + 1

 print(We've got  + str(heads) +  heads here.

 if random.randint(1,2) == 2:

 tails = tails + 1

 print(We've got  + str(tails) +  tails here.)

 This is what I get as output:

 This program flips a coin 10 times.

 It then counts the number of heads and tails.

 We've got 1 tails here.

 We've got 1 heads here.

 We've got 2 tails here.

 We've got 2 heads here.

 We've got 3 tails here.

 We've got 3 heads here.

 We've got 4 tails here.

 We've got 5 tails here.

 We've got 4 heads here.

 We've got 6 tails here.

 We've got 7 tails here.

 We've got 5 heads here.

 Can anyone help?

 Thank you so much!

 All the best,



 Rafael

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


Hint: Look at your second if statement

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

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


Re: [Tutor] producing PDF files

2013-06-16 Thread Chris Fuller
On Tuesday, June 11, 2013, Khalid Al-Ghamdi wrote:
 Hi,
 
 Do you know of a python module for converting text files to PDF format?
 
 thanks

Another one, that I've used extensively, is ReportLab.
http://www.reportlab.com/software/opensource/

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


[Tutor] a bug which I can't fix

2013-06-16 Thread Gal Hyams
I'm using win 7 64 bit, and Python 3.3. I've ask the flowing question on  a
form, and friends of mine, and I've brought here the answers. I've made
after the instactions, and yet, the problem isn't fixed.. can someone help
me on this, please?

When I open Python's IDLE, sometimes and error name 'port binding error' is
accrues, and IDLE is filed to run on the computer. one this error accrues,
it will repeat every time I'll open IDLE, till the computer will be
restarted. the error box saies: ' ILDE can't bind to a TCP/IP port, which
is necessary to communicate with its Python execution server. This might be
because no networking is installed on this computer. Run IDLE with the -n
command line switch to start without a subprocess and refer to help/IDLE
Help 'Running without a subprocess' for further details.'

WFT?

Every command you type into the idle after  will usually be sent to
another subprocess that executes it = the UI can do what it wants, the
user can do as he/she likes. If you use Tkinter to create your own GUI,
this can prevent you from crashing the IDLE windows.

IDLE uses port 3000 I think. It could be that there is something listening
there for connections other than the subprocess.

in the folder of idlelib:

import idlelibprint idlelib.__file__

there is the idle.py, idle.pyw and idle.bat that can be started with -n to
not make a new subproces.

I hope your WTF is answered.
As they said, it looks like a networking problem.
When IDLE starts, it needs to bind a TCP/IP port 8833 (I don't think it's
3000, but it might depend on the version)
In case you have another application that is running and is using the same
port, or you have another instance of IDLE, the new process will fail when
it tries to bind the new port.
Another possible scenario is port lock due to incomplete shutdown of a
previous IDLE instance.

To verify that go to:
Start  run  cmd.exe
Type the following command:
netstat -no | findstr Proto 8833

This command will show you which process is locking the 8833 port.
You can locate the PID of that process, and kill it with:
taskkill /PID pid_number_here


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


[Tutor] 2 basic problems

2013-06-16 Thread charles benoit
1:Python 2.7.4 (default, Apr 19 2013, 18:32:33)
[GCC 4.7.3] on linux2
Type copyright, credits or license() for more information.
 4+4
8
 3+3=4
SyntaxError: can't assign to operator
 3=1
SyntaxError: can't assign to literal

I thought the last 2 lines should return False


2:
lot=('1'+'6'+'8')
print(lot)
a=open(acc,w)
a.write(lot)
a.close
b=open(acc,r)
b.read()
print (b)
b.close


returns

168
open file 'acc', mode 'r' at 0xb6f9a650


I thought I was saving a string to a file and reading and printing the
string. The output looks like a description of the IO textwrapper at some
location. I'm sure this is a syntax/format problem.but this like the other
examples I saw. I ran this using python 2.6.7 on ubuntu 13.0  Thank you for
any help
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python web related scripts needed

2013-06-16 Thread Manigopal Vepati
Hi,

I need scripts for the following .

1) check whether username and password fields are present in Gmail
2) Code to access the system which doesn’t have ip address


i am using python 3.3


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


[Tutor] just cleared the moderation queue., sorry for the backlog.

2013-06-16 Thread Alan Gauld

FWIW about 6 or7 genuine messages and about a dozen spam...
The usual ratio... :-(

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

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


[Tutor] Hi, First question

2013-06-16 Thread Patrick Williams
Hi so I am making a bit of code to extract a bit of numbers data from a
file and then find the average of that data, however while I can get the
code to extract each specific piece of data I need, I can't seem to get the
numbers to add separately  so I can get a proper average. My sum1 variable
seems to only take the last bit of data entered. I was just wondering if
anyone knows what I'm doing wrong, the course I'm following hadn't started
using regex (or even proper lists) at this point, so there must be a way to
do it without. here's the code. the average of the data should be 0.6789 or
something, but I get 0.0334343 or something.

count=0
lst=list()
fname='mbox-short.txt'
fhand=open(fname)
for line in fhand:
if line.startswith('X-DSPAM-Confidence:'):
count=count+1
colpos=line.find(':')
zpos=line.find('0',colpos)
num=float(line[zpos:50])
sum1=0+num
avg=float(sum1)/int(count)
print 'Count-', count,'--', 'Average-', avg

Any help at all is appreciated, and thanks in advance.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] 2 basic problems

2013-06-16 Thread Ricardo Aráoz

El 29/05/13 18:23, charles benoit escribió:

1:Python 2.7.4 (default, Apr 19 2013, 18:32:33)
[GCC 4.7.3] on linux2
Type copyright, credits or license() for more information.
 4+4
8
 3+3=4
SyntaxError: can't assign to operator
 3=1
SyntaxError: can't assign to literal

I thought the last 2 lines should return False


2:
lot=('1'+'6'+'8')
print(lot)
a=open(acc,w)
a.write(lot)
a.close
b=open(acc,r)
b.read()
print (b)
b.close


returns

168
open file 'acc', mode 'r' at 0xb6f9a650


I thought I was saving a string to a file and reading and printing the 
string. The output looks like a description of the IO textwrapper at 
some location. I'm sure this is a syntax/format problem.but this like 
the other examples I saw. I ran this using python 2.6.7 on ubuntu 
13.0  Thank you for any help





Python 2.7.3 (default, Aug  1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type copyright, credits or license() for more information.
 No Subprocess 
 2+2
4
 4+4
8
 4+4=6
SyntaxError: can't assign to operator
 4+4 == 6
False



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


Re: [Tutor] On a looping input, subsequent inputs are hidden

2013-06-16 Thread eryksun
On Tue, Jun 11, 2013 at 2:00 PM, Jim Mooney cybervigila...@gmail.com wrote:
 On 11 June 2013 05:59, Steven D'Aprano st...@pearwood.info wrote:

 I'm afraid I don't understand what you mean. Second and subsequent inputs? I
 only see one. Hide the input with dots?

 Can you copy and paste an example?

 That would be a graphic of the input popup and this is a text-only
 list. Or would an attachment work?

 Well, the best way to find out is to try. Graphic attached of the
 second call to input since a non-integer was entered. If it appears,
 the second input window, when I enter integers, shows little black
 security-dots, as in web entries of your password, instead of the
 integers. On the first input, I can see the numbers.

In your original description, you said

But the Second and subsequent inputs, in Windows, hide the input
with dots, while the first shows the input, and I can't figure
out why But it's just python input, not tkinter. Unless it's
a Windows peculiarity. The input Always shows in DOS.

I see now. When you said in Windows, you meant you ran the script in
PyScripter. Unlike IDLE, PyScripter chooses to pop up a dialog box for
input. No wonder I couldn't reproduce the problem.

Also, there is no DOS. If you're running 64-bit Windows you don't even
have the NT Virtual DOS Machine (NTVDM) and can't run 16-bit DOS and
Win16 apps without installing an emulator. What you keep calling 'DOS'
is a console window, running text-mode *Windows* programs such as
python.exe and cmd.exe.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hi, First question

2013-06-16 Thread Alexander
On Sat, Jun 15, 2013 at 1:22 AM, Patrick Williams pdw0...@gmail.com wrote:

 Hi so I am making a bit of code to extract a bit of numbers data from a
 file and then find the average of that data, however while I can get the
 code to extract each specific piece of data I need, I can't seem to get the
 numbers to add separately  so I can get a proper average. My sum1 variable
 seems to only take the last bit of data entered. I was just wondering if
 anyone knows what I'm doing wrong, the course I'm following hadn't started
 using regex (or even proper lists) at this point, so there must be a way to
 do it without. here's the code. the average of the data should be 0.6789 or
 something, but I get 0.0334343 or something.

 count=0
 lst=list()
 fname='mbox-short.txt'
 fhand=open(fname)
 for line in fhand:
 if line.startswith('X-DSPAM-Confidence:'):
 count=count+1
 colpos=line.find(':')
 zpos=line.find('0',colpos)
 num=float(line[zpos:50])
 sum1=0+num
 avg=float(sum1)/int(count)
 print 'Count-', count,'--', 'Average-', avg

 Any help at all is appreciated, and thanks in advance.

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


Please include the mbox-short.txt file. Also you should include the
output of your code (copy and paste it).


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


Re: [Tutor] 2 basic problems

2013-06-16 Thread Chris “Kwpolska” Warrick
On Wed, May 29, 2013 at 11:23 PM, charles benoit
feather.duster.kung...@gmail.com wrote:
 1:Python 2.7.4 (default, Apr 19 2013, 18:32:33)
 [GCC 4.7.3] on linux2
 Type copyright, credits or license() for more information.
 4+4
 8
 3+3=4
 SyntaxError: can't assign to operator
 3=1
 SyntaxError: can't assign to literal

 I thought the last 2 lines should return False

`=` is the assignment operator (`a = 2` sets the variable `a` to the
value of `2`), whereas `==` is the comparison operator.

 2:
 lot=('1'+'6'+'8')
 print(lot)
 a=open(acc,w)
 a.write(lot)
 a.close

missing `()` here

 b=open(acc,r)
 b.read()
 print (b)

1. There should be no parenthesis here in Python 2.
2. The proper syntax is `print b.read()`.  You are reading the text
and discarding the return value (you aren’t setting a variable to it
or passing it to something else, like print), then printing the
information of what the `b` object is.

 b.close
missing `()` here, too


 returns

prints*, there is no return value


 168
 open file 'acc', mode 'r' at 0xb6f9a650


 I thought I was saving a string to a file and reading and printing the
 string. The output looks like a description of the IO textwrapper at some
 location. I'm sure this is a syntax/format problem.but this like the other
 examples I saw. I ran this using python 2.6.7 on ubuntu 13.0  Thank you for
 any help

Please use the 2.7.4 interpreter (the same one you used for the first
example) instead.

Moreover, you could do it all in one step ('w+' stands for “clear file
and allow read/write output”, while f.seek(0) is used to return the
pointer back to the beginning of the file):

f = open('acc', 'w+')
f.write(lot)
f.seek(0)
print f.read()
f.close()

Or using the `with` syntax (a.k.a. the context manager syntax):

with open('acc', 'w+') as f:
f.write(lot)
f.seek(0)
print f.read()

--
Kwpolska http://kwpolska.tk | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hi, First question

2013-06-16 Thread Chris “Kwpolska” Warrick
On Sat, Jun 15, 2013 at 7:22 AM, Patrick Williams pdw0...@gmail.com wrote:
 Hi so I am making a bit of code to extract a bit of numbers data from a file
 and then find the average of that data, however while I can get the code to
 extract each specific piece of data I need, I can't seem to get the numbers
 to add separately  so I can get a proper average. My sum1 variable seems to
 only take the last bit of data entered. I was just wondering if anyone knows
 what I'm doing wrong, the course I'm following hadn't started using regex
 (or even proper lists) at this point, so there must be a way to do it
 without. here's the code. the average of the data should be 0.6789 or
 something, but I get 0.0334343 or something.

 count=0
 lst=list()

`lst = []` is the preferred syntax.

 fname='mbox-short.txt'
 fhand=open(fname)
 for line in fhand:
 if line.startswith('X-DSPAM-Confidence:'):
 count=count+1
 colpos=line.find(':')
 zpos=line.find('0',colpos)
 num=float(line[zpos:50])
 sum1=0+num
 avg=float(sum1)/int(count)
 print 'Count-', count,'--', 'Average-', avg

 Any help at all is appreciated, and thanks in advance.

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


I don’t know what file you used, but the message you sent got this
header from Gmail, and the format doesn’t seem to be much different:

 X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; 'separately': 0.09;
'wrong,': 0.09; 'subject:question': 0.10; 'code.': 0.18;
'variable': 0.18; 'bit': 0.19; 'advance.': 0.19; 'seems': 0.21;
'8bit%:5': 0.22; 'print': 0.22; 'skip:l 30': 0.24; '\xa0so': 0.24;
 [snip 11 more lines]
(replaced tabstops with spaces)

Can you guess what’s wrong in your code?

You are reading only the first line.  There are more.  How do you
handle that?  You need to make your algorithm read all the further
lines that begin with the indentation your thing uses (it might be the
tab character '\t' or some spaces), and stop when it encounters
another header.  This can be done either by checking if the line
begins with the indentation OR by checking match with regexp
'[A-Za-z]+: .+'

--
Kwpolska http://kwpolska.tk | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
   
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python web related scripts needed

2013-06-16 Thread Steve Willoughby

On 12-Jun-2013, at 05:48, Manigopal Vepati manigopa...@gmail.com wrote:

 Hi,
 
 I need scripts for the following .
 
 1) check whether username and password fields are present in Gmail
 2) Code to access the system which doesn’t have ip address
 

And what have you found as you've started writing those scripts? Anything in 
particular you've run into that you're puzzled by?

This list can be a wonderful resource to assist you as you learn to write your 
first scripts, but please remember that it is staffed by volunteers who take 
their valuable personal time to help others learn. We're not here to perform 
contract programming for you, or to do homework for you, just to help you along 
the way as you learn to program in Python.

When you do get to a point where you need help, you need to be sure to ask 
meaningful questions and provide as much background information as would be 
needed for someone to truly understand what you're doing.  For example, in the 
message you sent, it's impossible to know what you're even trying to accomplish 
because you don't say what you mean by fields present in Gmail (I can think 
of a dozen completely different things that could mean, and you don't give 
enough information to actually be able to move forward with any of them even 
were I to guess which of them you intended.  I can't even make sense of the 
second one at all. You don't say what kind of access you're referring to, or 
what IP address has to do with anything (e.g., are you asking how to look up an 
IP address in DNS, or that the system isn't on a standard network which uses IP 
protocols, or what).

Assuming that you have your programming goals better developed than is apparent 
in your email, make a good start at your implementation and then tell us in 
detail what  you get stuck with. 

And just because we tend to get asked this from time to time, in case what you 
mean here is to somehow hack or illegally access a system you aren't 
otherwise allowed to access, we won't help you at all with anything like that. 
Don't bother even asking.

 
 i am using python 3.3

Ok, that's a very valuable piece of information. Since you're also accessing 
resources outside your scripts (other machines and mail services), it would 
also be useful to know the operating system and version of the systems involved.

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

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


Re: [Tutor] python web related scripts needed

2013-06-16 Thread Mark Lawrence

On 12/06/2013 13:48, Manigopal Vepati wrote:

Hi,

I need scripts for the following .

1) check whether username and password fields are present in Gmail
2)Code to access the system which doesn’t have ip address


i am using python 3.3


thanks
manigopal



Sorry but we don't work in this manner.  You show that you've made an 
attempt to implement something and have run into problems, and we'll help.


--
Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green. Snooker 
commentator 'Whispering' Ted Lowe.


Mark Lawrence

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


Re: [Tutor] Hi, First question

2013-06-16 Thread Mark Lawrence

On 16/06/2013 16:55, Chris “Kwpolska” Warrick wrote:

On Sat, Jun 15, 2013 at 7:22 AM, Patrick Williams pdw0...@gmail.com wrote:

Hi so I am making a bit of code to extract a bit of numbers data from a file
and then find the average of that data, however while I can get the code to
extract each specific piece of data I need, I can't seem to get the numbers
to add separately  so I can get a proper average. My sum1 variable seems to
only take the last bit of data entered. I was just wondering if anyone knows
what I'm doing wrong, the course I'm following hadn't started using regex
(or even proper lists) at this point, so there must be a way to do it
without. here's the code. the average of the data should be 0.6789 or
something, but I get 0.0334343 or something.

count=0
lst=list()


`lst = []` is the preferred syntax.


fname='mbox-short.txt'
fhand=open(fname)
for line in fhand:
 if line.startswith('X-DSPAM-Confidence:'):
 count=count+1
 colpos=line.find(':')
 zpos=line.find('0',colpos)
 num=float(line[zpos:50])
 sum1=0+num
 avg=float(sum1)/int(count)


I'll assume unless someone tells me differently that sum1 does not need 
reinitialising every time, and that avg needs to be calculated when the 
loop has finished.



print 'Count-', count,'--', 'Average-', avg

Any help at all is appreciated, and thanks in advance.



I don’t know what file you used, but the message you sent got this
header from Gmail, and the format doesn’t seem to be much different:


X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; 'separately': 0.09;
'wrong,': 0.09; 'subject:question': 0.10; 'code.': 0.18;
'variable': 0.18; 'bit': 0.19; 'advance.': 0.19; 'seems': 0.21;
'8bit%:5': 0.22; 'print': 0.22; 'skip:l 30': 0.24; '\xa0so': 0.24;
[snip 11 more lines]

(replaced tabstops with spaces)

Can you guess what’s wrong in your code?

You are reading only the first line. 


What does for line in fhand: do then?

--
Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green. Snooker 
commentator 'Whispering' Ted Lowe.


Mark Lawrence

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


Re: [Tutor] Hi, First question

2013-06-16 Thread Steve Willoughby

On 16-Jun-2013, at 09:21, Mark Lawrence breamore...@yahoo.co.uk wrote:

 On 16/06/2013 16:55, Chris “Kwpolska” Warrick wrote:
 On Sat, Jun 15, 2013 at 7:22 AM, Patrick Williams pdw0...@gmail.com wrote:
 Hi so I am making a bit of code to extract a bit of numbers data from a file
 and then find the average of that data, however while I can get the code to
 extract each specific piece of data I need, I can't seem to get the numbers
 to add separately  so I can get a proper average. My sum1 variable seems to
 only take the last bit of data entered. I was just wondering if anyone knows
 what I'm doing wrong, the course I'm following hadn't started using regex
 (or even proper lists) at this point, so there must be a way to do it
 without. here's the code. the average of the data should be 0.6789 or
 something, but I get 0.0334343 or something.
 
 count=0
 lst=list()
 
 `lst = []` is the preferred syntax.
 
 fname='mbox-short.txt'
 fhand=open(fname)
 for line in fhand:
 if line.startswith('X-DSPAM-Confidence:'):
 count=count+1
 colpos=line.find(':')
 zpos=line.find('0',colpos)
 num=float(line[zpos:50])
 sum1=0+num
 avg=float(sum1)/int(count)
 
 I'll assume unless someone tells me differently that sum1 does not need 
 reinitialising every time, and that avg needs to be calculated when the loop 
 has finished.
 
 print 'Count-', count,'--', 'Average-', avg
 
 Any help at all is appreciated, and thanks in advance.
 
 
 I don’t know what file you used, but the message you sent got this
 header from Gmail, and the format doesn’t seem to be much different:
 
 X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; 'separately': 0.09;
'wrong,': 0.09; 'subject:question': 0.10; 'code.': 0.18;
'variable': 0.18; 'bit': 0.19; 'advance.': 0.19; 'seems': 0.21;
'8bit%:5': 0.22; 'print': 0.22; 'skip:l 30': 0.24; '\xa0so': 0.24;
 [snip 11 more lines]
 (replaced tabstops with spaces)
 
 Can you guess what’s wrong in your code?
 
 You are reading only the first line. 
 
 What does for line in fhand: do then?

I think what that was referring to was the assumption that you're reading mail 
header lines from that file, and they can be split out over multiple lines (see 
the example cited above).  If that's the case, then for line in fhand will 
iterate over each line in the file, but you're only looking for lines which 
start with X-Spam-.. which would only be the FIRST part of the header if it's 
split out like that.

If your file is NOT organized like that, then your situation is different.  
However, if your files are like that, you're going to randomly miss data if the 
fields you're looking for don't happen to be on the first line of the 
multi-line header.

Now if you are reading RFC-822 (et al) standard mail messages in those files, 
there are bits of the Python standard library which will be immensely useful to 
you in parsing out those headers rather than trying to do it yourself.  That's 
something you're going to find to be the case frequently with Python.
 
 
 -- 
 Steve is going for the pink ball - and for those of you who are watching in 
 black and white, the pink is next to the green. Snooker commentator 
 'Whispering' Ted Lowe.
 
 Mark Lawrence
 
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] 2 basic problems

2013-06-16 Thread Alan Gauld

On 16/06/13 16:45, Chris “Kwpolska” Warrick wrote:


Moreover, you could do it all in one step ('w+' stands for “clear file
and allow read/write output”, while f.seek(0) is used to return the
pointer back to the beginning of the file):


I'm always very wary of recommending mixed read/write mode to beginners.
Its simple in this case but in other scenarios its very easy to lose 
track of where the cursor is and start overwriting your previously 
written data!


I usually recommend writing the data, closing the file, and then opening 
for reading.


Powerful tools have the capacity to be powerfully bad as well
as good...

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

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


Re: [Tutor] Hi, First question

2013-06-16 Thread Alan Gauld

On 15/06/13 06:22, Patrick Williams wrote:

Hi so I am making a bit of code to extract a bit of numbers data from a
file and then find the average of that data, however while I can get the
code to extract each specific piece of data I need, I can't seem to get
the numbers to add separately  so I can get a proper average. My sum1
variable seems to only take the last bit of data entered.




for line in fhand:
 if line.startswith('X-DSPAM-Confidence:'):
 count=count+1
 colpos=line.find(':')
 zpos=line.find('0',colpos)
 num=float(line[zpos:50])
 sum1=0+num


Are you sure that last line is right?

Its effectively just doing

sum1 = num

adding zero does nothing interesting.

So sum1 ends up at whatever num was at the end of the loop.

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

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


[Tutor] How to redirect console output to a TextEdit box on a QT Python Gui ?

2013-06-16 Thread SM
Hi
I have implemented a GUI using PyQt4/python3, which allows the user to
select a few files as command-line arguments. When I hit OK button, my
application runs and the output text is displayed on the terminal where I
run the python script. I would like to redirect this text to a TextEdit
window I have created on the GUI:

self.textEdit = QtGui.QTextEdit(Form)
self.textEdit.setGeometry(QtCore.QRect(10, 300, 421, 141))
self.textEdit.setObjectName(_fromUtf8(textEdit))

Do you have any suggestions/tips as to how I can accomplish this task?
Using some suggestions online,  I tried creating a QProcess object and
connect the signal to a function which  reads the std output. But I don't
know how to set the arguments to the call process.start.

self.process = QtCore.QProcess()
QtCore.QObject.connect(self.process, QtCore.SIGNAL(readyReadStdout()),
self.readOutput)
I know I have to call self.process.start here but am not able to find
examples of how to do it. One example online uses
self.process.setArguments, but python3/pyQt4 doesn't seem to know about
it. Using the argument directly with process.start is not helping either.

Appreciate any pointers. If there are better ways than what I am trying to
use, appreciate that as well.

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


[Tutor] How to find descendants recursively?

2013-06-16 Thread Timo
I have a datafile which is parsed by an external library, I'm having
trouble creating a hierarchical structure of the data.

This is what I got so far:

items = get_items() # returns a generator
for item in items:
print(item)
children = get_children(item) # also returns a generator
for child in children:
print(--, child)

This is fine as it will get the children for each parent item. I can't seem
to figure out how to go further and get the chidren of the children and so
on.

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


[Tutor] The Whole Tree

2013-06-16 Thread Jim Mooney
My first impression of Python was that it had dynamic types but didn't
mix them. so if I was wrong on equality, is there a general rule of
what different types can still be equal? Is it an inheritance thing?

Speaking of which, I put Python class hierarchy in Google but just
got a bunch of specific wheeze. What I want is a
list of the whole tree. Is there such, or a way I can generate it?

-- 
Jim
Everyone has made bad decisions; it's just that some pretend they haven't.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Jim Mooney
On 15 June 2013 23:30, Dave Angel da...@davea.name wrote:

 The sort() method doesn't work, but sorted does.

How many times have I read you can't sort a dictionary in Python. Was
I just misreading or was that true of older Pythons?

-- 
Jim
After indictment the bacon smuggler was put on the no-fry list
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Jim Mooney
On 16 June 2013 01:43, Roel Schroeven r...@roelschroeven.net wrote:

 Can't you disable that behavior somewhere in the settings of your IDE? I
 know IDEs do that to be helpful, but I don't like it and so far I've been
 able to disable it in all IDEs I've used.

PyScripter does in Tools  Options  IDE Options  Editor 
Auto-complete brackets (which also kills quotes but doesn't tell you.)
It looks like a non-fine-grained choice, though. You can't just kill
quotes - you have to kill all bracket auto-completion. Which was
overkill in my case, so I'll keep my keyboard remapping. The best tool
I've seen for that, and for all sorts of automation (including
programmatic) is a free windows program called autohotkey. I've only
scratched the surface, but it looks like it can do everything but cook
eggs.

VIM sounds good but I don't think there's a version for Windows.
Keeping different programs open is great if you have dual monitors,
which I did when I was webmastering. Alas, some $#@ fooled with my
computer and wiped out the dual monitor card. But when I fixed his
front end I left a bolt off and his wheel went rolling down the
highway, so I guess we're even ;')

As for the one-week learning curve on VIM, reminds me of that claim
for Joomla. Yes, you can set up a site in a few hours after your first
install of Joomla, but learning to fix the blowups and problems while
people are screaming at you, since it's all public, takes considerably
longer. Although an editor that's been around since the stone age
probably doesn't blow up. I doubt VIM has a constant stream of
upgrades (not always compatible), bug fixes, and security fixes ;')

-- 
Jim
After indictment the bacon smuggler was put on the no-fry list
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The Whole Tree

2013-06-16 Thread Alan Gauld

On 16/06/13 18:21, Jim Mooney wrote:

My first impression of Python was that it had dynamic types but didn't
mix them.


Umm yes, sort of. It depends on how you define some of those terms 
though. mix them???




so if I was wrong on equality, is there a general rule of
what different types can still be equal?


I'm not sure what was wrong with equality?
Whether two types can be compared depends on whether the
comparison operators for those types work.
Its hard to tell in advance, that's why you should use
try/except to catch the errors (better to ask forgiveness
principle...)


Is it an inheritance thing?


That can play a part. But its not the only factor.


Speaking of which, I put Python class hierarchy in Google but just
got a bunch of specific wheeze. What I want is a
list of the whole tree. Is there such,


Not that I'm aware. Not even for the standard library.

As far as I can recall Pythonwin IDE under Windows has
a class browser that will show the heirarchy for any
given object. But I haven't used it in a long time,
I may be mistaken. Your IDE (Wing?) may have a similar
feature...

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

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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Chris “Kwpolska” Warrick
On Sun, Jun 16, 2013 at 7:25 PM, Jim Mooney cybervigila...@gmail.com wrote:
 On 15 June 2013 23:30, Dave Angel da...@davea.name wrote:

 The sort() method doesn't work, but sorted does.

 How many times have I read you can't sort a dictionary in Python. Was
 I just misreading or was that true of older Pythons?

Dicts have no order:

 {'b': 'c', 'a': 'z'}
{'a': 'z', 'b': 'c'}

Moreover, the sorted() function sorts the keys only (something that
list() does anyway).  If you are looking for a way to have dicts with
an order of keys (and you don’t need that most of the time), look at
collection.OrderedDict.

--
Kwpolska http://kwpolska.tk | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Steve Willoughby

On 16-Jun-2013, at 10:49, Jim Mooney cybervigila...@gmail.com wrote:

 On 16 June 2013 01:43, Roel Schroeven r...@roelschroeven.net wrote:
 
 Can't you disable that behavior somewhere in the settings of your IDE? I
 know IDEs do that to be helpful, but I don't like it and so far I've been
 able to disable it in all IDEs I've used.
 
 
 VIM sounds good but I don't think there's a version for Windows.

There's a version of VIM for about everything, including Windows and OS X.

 As for the one-week learning curve on VIM, reminds me of that claim
 for Joomla. Yes, you can set up a site in a few hours after your first
 install of Joomla, but learning to fix the blowups and problems while
 people are screaming at you, since it's all public, takes considerably
 longer. Although an editor that's been around since the stone age
 probably doesn't blow up. I doubt VIM has a constant stream of
 upgrades (not always compatible), bug fixes, and security fixes ;')

Yeah, at this point it's pretty stable.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to find descendants recursively?

2013-06-16 Thread Alan Gauld

On 16/06/13 18:20, Timo wrote:


items = get_items() # returns a generator
for item in items:
 print(item)
 children = get_children(item) # also returns a generator
 for child in children:
 print(--, child)

This is fine as it will get the children for each parent item. I can't
seem to figure out how to go further and get the chidren of the children
and so on.


Presumably you can call get_children on each child?

  children = get_children(item) # also returns a generator
  for child in children:
  grandchildren = get_children(child)

If you don't know how many levels it goes down the normal approach is to 
use recursion to define a function that get called until the result is 
empty. If there are too many layers for recursion then you will need to 
keep a flag to count the layers and create/manage the heirarchy pointer 
for you.


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

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


Re: [Tutor] How to redirect console output to a TextEdit box on a QT Python Gui ?

2013-06-16 Thread Chris “Kwpolska” Warrick
On Sun, Jun 16, 2013 at 7:15 PM, SM sunith...@gmail.com wrote:
 Hi
 I have implemented a GUI using PyQt4/python3, which allows the user to
 select a few files as command-line arguments. When I hit OK button, my
 application runs and the output text is displayed on the terminal where I
 run the python script. I would like to redirect this text to a TextEdit
 window I have created on the GUI:

 self.textEdit = QtGui.QTextEdit(Form)
 self.textEdit.setGeometry(QtCore.QRect(10, 300, 421, 141))
 self.textEdit.setObjectName(_fromUtf8(textEdit))

 Do you have any suggestions/tips as to how I can accomplish this task? Using
 some suggestions online,  I tried creating a QProcess object and connect the
 signal to a function which  reads the std output. But I don't know how to
 set the arguments to the call process.start.

 self.process = QtCore.QProcess()
 QtCore.QObject.connect(self.process, QtCore.SIGNAL(readyReadStdout()),
 self.readOutput)
 I know I have to call self.process.start here but am not able to find
 examples of how to do it. One example online uses
 self.process.setArguments, but python3/pyQt4 doesn't seem to know about
 it. Using the argument directly with process.start is not helping either.

 Appreciate any pointers. If there are better ways than what I am trying to
 use, appreciate that as well.

If the application you run is a Python script, import it, execute the
functions and have the data returned (as opposed to printing it), and
then you can do self.textEdit.setText(output_goes_here)

If the application isn’t Python, use the (stock aka vanilla)
subprocess module.  The easiest solution is:

import subprocess
self.textEdit.setText(subprocess.check_output(('command',
'argument1', 'argument2')))

And you do that in the function that is called when you press OK.

Bonus suggestion: do nice layouts instead of setting the coordinates
manually.  The options you want are in the Form menu of Qt Designer.
If you don’t do this, resizing windows is nonsense.

--
Kwpolska http://kwpolska.tk | GPG KEY: 5EAAEA16
stop html mail| always bottom-post
http://asciiribbon.org| http://caliburn.nl/topposting.html
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] just cleared the moderation queue., sorry for the backlog.

2013-06-16 Thread Jim Mooney
On 16 June 2013 08:15, Alan Gauld alan.ga...@btinternet.com wrote:
 FWIW about 6 or7 genuine messages and about a dozen spam...
 The usual ratio... :-(


I was wondering why my message showed up late. I Already had the
answer and it was only moderated because I tried a picture attachment
to reply to a query.

Only a dozen? You're lucky this is not a Really high volume and more
general list. I spend a half hour every week just deleting junk email,
unsubscribing from things, blocking or reporting spam, etc. I've
subscribed to things I've never heard of. But I keep my old
webmaster email, which got a lot of traffic.

One trick you have to watch out for is a blanket email with a phony
unsub link. That's to find out if there's a live person on the other
end, rather than a dead box chosen at random from a huge spam-list.
When you unsub, they can then try to really get you with a phony
letter from your bank or You won a Prize or something more devious.
Although the appeals from Nigerian princes have dropped way off ;')

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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Steven D'Aprano

On 17/06/13 03:25, Jim Mooney wrote:

On 15 June 2013 23:30, Dave Angel da...@davea.name wrote:


The sort() method doesn't work, but sorted does.


How many times have I read you can't sort a dictionary in Python. Was
I just misreading or was that true of older Pythons?


You can't sort a dictionary, because dicts don't have any inherent order. 
(Unlike paper dictionaries.) That's done for performance reasons.

However, if you extract the keys from a dict, you can sort the keys separately.

So mydict.sort() fails, since dicts can't be sorted. But:

keys = list(mydict.keys())
keys.sort()

works fine. And here's something which, at first glance, *appears* to be 
sorting a dict, but actually isn't:

sorted(mydict)
= returns a list of mydict's keys, sorted.



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


Re: [Tutor] The Whole Tree

2013-06-16 Thread Andreas Perstinger

On 16.06.2013 19:21, Jim Mooney wrote:

Speaking of which, I put Python class hierarchy in Google but just
got a bunch of specific wheeze. What I want is a
list of the whole tree. Is there such, or a way I can generate it?


I'm not sure if that's what you are looking for but the language 
reference describes the standard type hierarchy:

http://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy

Bye, Andreas

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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Steven D'Aprano

On 17/06/13 03:59, Steve Willoughby wrote:


On 16-Jun-2013, at 10:49, Jim Mooney cybervigila...@gmail.com wrote:


On 16 June 2013 01:43, Roel Schroeven r...@roelschroeven.net wrote:


Can't you disable that behavior somewhere in the settings of your IDE? I
know IDEs do that to be helpful, but I don't like it and so far I've been
able to disable it in all IDEs I've used.



VIM sounds good but I don't think there's a version for Windows.


There's a version of VIM for about everything, including Windows and OS X.


Pfft! VIM. VIM is not the standard editor. There is only one standard editor, 
ed. That's why it's called an EDitor, not a VIMitor.

http://www.gnu.org/fun/jokes/ed-msg.html


As for stability, ed hasn't been updated since 1929. There's no need -- how can 
you improve perfection?



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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Steve Willoughby

On 16-Jun-2013, at 11:35, Steven D'Aprano st...@pearwood.info wrote:

 On 17/06/13 03:59, Steve Willoughby wrote:
 
 On 16-Jun-2013, at 10:49, Jim Mooney cybervigila...@gmail.com wrote:
 
 On 16 June 2013 01:43, Roel Schroeven r...@roelschroeven.net wrote:
 
 Can't you disable that behavior somewhere in the settings of your IDE? I
 know IDEs do that to be helpful, but I don't like it and so far I've been
 able to disable it in all IDEs I've used.
 
 
 VIM sounds good but I don't think there's a version for Windows.
 
 There's a version of VIM for about everything, including Windows and OS X.
 
 Pfft! VIM. VIM is not the standard editor. There is only one standard editor, 
 ed. That's why it's called an EDitor, not a VIMitor.


Pfft. Only for people who can't handle using the Real One True Editor: TECO.

http://en.wikipedia.org/wiki/TECO_(text_editor)

steve


Although I admit back in my MSDOS days I found a copy of ED which was ported 
there since it was at least infinitely better than EDLIN.
And to be fair, VIM grew out of the classic vi which itself grew directly out 
of ed, so there's a little ed hiding in VIM trying to escape.

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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Joel Goldstick
On Sun, Jun 16, 2013 at 2:48 PM, Steve Willoughby st...@alchemy.com wrote:


 On 16-Jun-2013, at 11:35, Steven D'Aprano st...@pearwood.info wrote:

  On 17/06/13 03:59, Steve Willoughby wrote:
 
  On 16-Jun-2013, at 10:49, Jim Mooney cybervigila...@gmail.com wrote:
 
  On 16 June 2013 01:43, Roel Schroeven r...@roelschroeven.net wrote:
 
  Can't you disable that behavior somewhere in the settings of your
 IDE? I
  know IDEs do that to be helpful, but I don't like it and so far I've
 been
  able to disable it in all IDEs I've used.
 
 
  VIM sounds good but I don't think there's a version for Windows.
 
  There's a version of VIM for about everything, including Windows and OS
 X.
 
  Pfft! VIM. VIM is not the standard editor. There is only one standard
 editor, ed. That's why it's called an EDitor, not a VIMitor.


 Pfft. Only for people who can't handle using the Real One True Editor:
 TECO.

 http://en.wikipedia.org/wiki/TECO_(text_editor)


I remember teco.  It could do anything  -- a line editor and text processor
all in one.  Then I worked on a Data General project and had to use SPEED.

I think VIM is somehow a descendent of  TECO


 steve


 Although I admit back in my MSDOS days I found a copy of ED which was
 ported there since it was at least infinitely better than EDLIN.
 And to be fair, VIM grew out of the classic vi which itself grew directly
 out of ed, so there's a little ed hiding in VIM trying to escape.

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




-- 
Joel Goldstick
http://joelgoldstick.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The Whole Tree

2013-06-16 Thread Steven D'Aprano

On 17/06/13 03:21, Jim Mooney wrote:

My first impression of Python was that it had dynamic types but didn't
mix them. so if I was wrong on equality, is there a general rule of
what different types can still be equal? Is it an inheritance thing?


The general rule is, types can define equality whatever way makes sense for 
themselves. That usually means:

* All numeric types are normally considered compatible; that is,
  if two numbers have the same numeric value, they should compare
  equal even if they have different types.

* Instances of a class and any of its subclasses are expected to
  compare equal if they have the same value.

* Unrelated classes are expected to compare unequal.

* By default, objects compare equal only to themselves.

* But equality is under the programmer's control with the __eq__
  and __ne__ (equal and not-equal) methods.



Speaking of which, I put Python class hierarchy in Google but just
got a bunch of specific wheeze. What I want is a
list of the whole tree. Is there such, or a way I can generate it?


It's a pretty shallow tree. Off the top of my head, the built-ins look 
something like this in Python 3:


object
+-- BaseException
+-- a bunch of exception subclasses
+-- BuiltinFunctionType (*)
+-- bytearray
+-- bytes
+-- CodeType (*)
+-- complex
+-- dict
+-- float
+-- frozenset
+-- FunctionType (*)
+-- int
+-- bool
+-- list
+-- NoneType (*)
+-- range
+-- set
+-- str
+-- tuple
+-- type


plus some more exotic built-ins, which I haven't shown. Items marked (*) are 
built-in types, but you need to import them from the types module to get access 
to them by name.

Nearly all other classes and types inherit directly from object, Python doesn't 
usually go in for the sort of deeply nested hierarchies that Java loves.

However, there is a complication: ABCs (Abstract Base Classes). ABCs introduce 
something of a hierarchy to Python objects, one which is not reflected by the 
(shallow) inheritance hierarchy shown above. ABCs can be considered relatively 
advanced, so don't worry about them if you don't wish to.

As far as I know, there is no documented tree of *all* Python types in the 
standard library. It would be big, boring, shallow, and contain an awful lot 
types which are for internal use only and not useable by the programmer.


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


Re: [Tutor] The Whole Tree

2013-06-16 Thread Jim Mooney
On 16 June 2013 11:32, Andreas Perstinger andiper...@gmail.com wrote:

 I'm not sure if that's what you are looking for but the language reference
 describes the standard type hierarchy:
 http://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy

Yes, that's what I meant. I was thinking of an actual visible tree,
but it doesn't go that deep, so that wouldn't be of use.

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


[Tutor] Getting the real exception clause

2013-06-16 Thread Jim Mooney
'''I'm using general Exception to print out what the exception is
until I learn them, but
it will print out [Errno 2] No such file or directory in this case,
when the real
exception I'd need to use in an except clause is FileNotFoundError.
How do I get the
exception I need to use in the except clause from the more English-like message?
'''

#Using C:\Python33\python.exe on Win 7 in c:\python33\jimprogs
try:
fh = open('nosuchdirectory/text/truthyfalsey.txt')
for line in fh:
print(line,end='')
fh.close()
except Exception as err:
print(err)

Jim
After indictment the bacon smuggler was put on the no-fry list
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting the real exception clause

2013-06-16 Thread Mark Lawrence

On 16/06/2013 21:26, Jim Mooney wrote:

'''I'm using general Exception to print out what the exception is
until I learn them, but
it will print out [Errno 2] No such file or directory in this case,
when the real
exception I'd need to use in an except clause is FileNotFoundError.
How do I get the
exception I need to use in the except clause from the more English-like message?
'''

#Using C:\Python33\python.exe on Win 7 in c:\python33\jimprogs
try:
 fh = open('nosuchdirectory/text/truthyfalsey.txt')
 for line in fh:
 print(line,end='')
 fh.close()
except Exception as err:
 print(err)

Jim
After indictment the bacon smuggler was put on the no-fry list


Easy, strip out the exception handling you have above.

c:\Users\Mark\MyPythontype a.py
with open('nosuchdirectory/text/truthyfalsey.txt') as fh:
for line in fh:
print(line,end='')

c:\Users\Mark\MyPythona
Traceback (most recent call last):
  File C:\Users\Mark\MyPython\a.py, line 1, in module
with open('nosuchdirectory/text/truthyfalsey.txt') as fh:
FileNotFoundError: [Errno 2] No such file or directory: 
'nosuchdirectory/text/truthyfalsey.txt'


A slight aside, note I've used the 'with' clause so there's no need to 
explicity close the file, good ole Python does it for you.


--
Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green. Snooker 
commentator 'Whispering' Ted Lowe.


Mark Lawrence

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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread pyt...@outofoptions.net

On 06/16/2013 01:49 PM, Jim Mooney wrote:
VIM sounds good but I don't think there's a version for Windows. 
Keeping different programs open is great if you have dual monitors, 
which I did when I was webmastering. Alas, some $#@ fooled with my 
computer and wiped out the dual monitor card. But when I fixed his 
front end I left a bolt off and his wheel went rolling down the 
highway, so I guess we're even ;') As for the one-week learning curve 
on VIM, reminds me of that claim for Joomla. Yes, you can set up a 
site in a few hours after your first install of Joomla, but learning 
to fix the blowups and problems while people are screaming at you, 
since it's all public, takes considerably longer. Although an editor 
that's been around since the stone age probably doesn't blow up. I 
doubt VIM has a constant stream of upgrades (not always compatible), 
bug fixes, and security fixes ;') 


vimtutor gets you a good start rather quickly.

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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Joel Goldstick
On Sun, Jun 16, 2013 at 5:01 PM, pyt...@outofoptions.net 
pyt...@outofoptions.net wrote:

 On 06/16/2013 01:49 PM, Jim Mooney wrote:

 VIM sounds good but I don't think there's a version for Windows.


There definitely is a windows version

Keeping different programs open is great if you have dual monitors, which I
 did when I was webmastering. Alas, some $#@ fooled with my computer and
 wiped out the dual monitor card. But when I fixed his front end I left a
 bolt off and his wheel went rolling down the highway, so I guess we're even
 ;') As for the one-week learning curve on VIM, reminds me of that claim for
 Joomla. Yes, you can set up a site in a few hours after your first install
 of Joomla, but learning to fix the blowups and problems while people are
 screaming at you, since it's all public, takes considerably longer.
 Although an editor that's been around since the stone age probably doesn't
 blow up. I doubt VIM has a constant stream of upgrades (not always
 compatible), bug fixes, and security fixes ;')


 Vim is active.  Lots of people really like it so lots of add ons.  But you
are right about not being able to master it in a week.   You can use it on
day one, but keep learning more about what it can do for you for -- well
maybe forever.

The good thing about Vim  (well its not installed on Windows) is that it is
usually just there on any *nix system and I think Mac too.  So even if you
don't like it for your primary editor its good to know a little VIM if you
have need to log onto various machines


 vimtutor gets you a good start rather quickly.


 __**_
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/**mailman/listinfo/tutorhttp://mail.python.org/mailman/listinfo/tutor




-- 
Joel Goldstick
http://joelgoldstick.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Oscar Benjamin
On 16 June 2013 18:49, Jim Mooney cybervigila...@gmail.com wrote:
 Although an editor that's been around since the stone age
 probably doesn't blow up. I doubt VIM has a constant stream of
 upgrades (not always compatible), bug fixes, and security fixes ;')

I use Vim pretty much exclusively and work on Linux and Windows. It
does have a constant stream of upgrades and fixes but the core
functionality hasn't changed in any noticeable way in years. However
Vim already has much more functionality than I will ever use; since I
only know a small subset of what it can already do I don't really
notice new features as they are added.

The only time I can remember discovering a new feature in Vim and then
actually using it is with undo branches and apparently (I just
checked) this feature was released in 2006. Typically if I think that
I want Vim to have some or other feature I find after a quick search
that Vim already has several ways of doing what I want.

There is also an active community writing third-party plugins for Vim
and this is probably where the bulk of significant new features are
developed.


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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Jim Mooney
 There is also an active community writing third-party plugins for Vim
 and this is probably where the bulk of significant new features are
 developed.

So as Dr. Frankenstein exclaimed: It's Alive! ;')

-- 
Jim
After indictment the bacon smuggler was put on the no-fry list
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to find descendants recursively?

2013-06-16 Thread Dave Angel

On 06/16/2013 01:20 PM, Timo wrote:

I have a datafile which is parsed by an external library, I'm having
trouble creating a hierarchical structure of the data.

This is what I got so far:

items = get_items() # returns a generator
for item in items:
 print(item)
 children = get_children(item) # also returns a generator
 for child in children:
 print(--, child)

This is fine as it will get the children for each parent item. I can't seem
to figure out how to go further and get the chidren of the children and so
on.

I can't see any way of doing recursion without writing a function.  You 
can always fake it, but if you want the language's help, do it in a 
function.


We don't know your external library.  But if the effect is to produce a 
tree, where any node may have items as children, then recursion is the 
easiest way to process the whole tree.  Some assumptions are important:


The tree has reasonable max-depth, like less than 1000.  If it's 
somewhat larger, but has a known limit, you can probably just get away 
with telling Python to use a larger stacksize.  But if the depth could 
be arbitrarily large, say a million levels, then you need another 
approach than the language's recursion.


Second assumption is that no node appears more than once in the tree. 
For example, in a Unix directory tree, if a symlink points back up the 
tree, it can cause troubles.  Avoiding these troubles is not hard if you 
plan ahead, but it's easier if you know it cannot happen.


Assuming the tree is well-enough behaved then, we want to define a 
function, with a name, that will call itself.  Each time you descend 
into a  child node, you call the function recursively to process that 
childlist.


Now, eventually you'll probably want to make this recursive function a 
generator, so you can reuse it for other tree processing of the same 
kind of tree.  But that can wait.


First you have to decide how you can test the limit-condition.  For 
example, perhaps your unknown library returns Null from  the 
get_children() call if there are no children.  Or perhaps there's 
another call, like has_children() which returns a bool.  Without knowing 
that, it's hard to structure the rest of the function.  But roughly it 
looks like:


after the children= line, simply test your condition and call yourself 
with children as the argument.


children = get_children(item)
if children not is None:
my_recursive_function(children)

You don't need or want to write a loop for child in children, since that 
same loop is already written (if item in items).




You pick your own better name for the function, based on what it does.

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


Re: [Tutor] The Whole Tree

2013-06-16 Thread Oscar Benjamin
On 16 June 2013 20:49, Jim Mooney cybervigila...@gmail.com wrote:
 On 16 June 2013 11:32, Andreas Perstinger andiper...@gmail.com wrote:

 I'm not sure if that's what you are looking for but the language reference
 describes the standard type hierarchy:
 http://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy

 Yes, that's what I meant. I was thinking of an actual visible tree,
 but it doesn't go that deep, so that wouldn't be of use.

As Steven mentioned Java has a complex inheritance tree for its
objects. However the reason for that is that Java is statically typed
and the compiler makes guarantees about the compiled code based on the
type hierarchy. Having a complex hierarchy gives programmers the
flexibility to specify broad sets of types that are acceptable in a
particular context.

For the most part in Python exactly where the type of an object
appears in some class hierarchy doesn't really matter. Consequently
there's often not really any point in putting objects into a hierarchy
unless they actually share a significant amount of code. Unless
someone goes out of their way to actually test the type of an object
with isinstance() the class hierarchy can often be considered
irrelevant.

The exception to this is exception classes. When an exception is
caught with try/except the isinstance() function is used for matching.
The exception class hierarchy is precisely what determines whether or
not an exception is caught. As a result there is something of a tree
that you can see here:
http://docs.python.org/3.3/library/exceptions.html#exception-hierarchy

Otherwise in Python what matters is in many cases is that an object
has the right methods or properties. It is common to specify (in
documentation) that the input to a function should be e.g. an
iterable, a sequence or a number rather than explicitly require
a set of types or a subtree of a class hierarchy. This specification
implicitly designates that the object shall have certain properties
but in Python this not enforced (until you attempt to use a missing
property). This approach is similar to interfaces in Java or to the
type system of Haskell but is fuzzier than both. You can see a
representation of the core Haskell type system here:
http://www.haskell.org/onlinereport/basic.html#standard-classes

As Steven mentioned Python also has an abstract base class hierarchy.
This is unrelated to the actual class inheritance hierarchy and is
based on objects having the appropriate properties to be an iterator
etc. The table here describes the hierarchy and associated methods:
http://docs.python.org/dev/library/collections.abc.html

I was interested to see how that would look as a tree so I constructed
a dot file for the graph:

$ cat collections.dot
digraph G{
Container
Hashable
Iterable
Iterable - Iterator
Callable
{Sized Iterable Container} - Sequence
Sequence - MutableSequence
{Sized Iterable Container} - Set
Set - MutableSet
{Sized Iterable Container} - Mapping
Mapping - MutableMapping
Sized - MappingView
{MappingView Set} - ItemsView
{MappingView Set} - KeysView
MappingView - ValuesView
}

If you have graphviz installed you can turn this into a png image with:

$ dot -Tpng -o collections.png  collections.dot


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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Alan Gauld

On 16/06/13 19:55, Joel Goldstick wrote:


I think VIM is somehow a descendent of  TECO


I think your confusing it with emacs which originally stood
for EditingMACroS and was just a set of Teco macros which
made it easier to use. Then James Gosling and Richard Stallman
got their respective hands on it... :-)

Vim is a descendant of vi (by Bill Joy of Sun fame) which is a 
descendant of ex which is an enhanced (eXtended) version of ed.

My first unix box didn't have a vi, it only had ex... And in Uni
I did my final year project using SCRED which was the OS/9
clone of vi...

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

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


Re: [Tutor] The Whole Tree

2013-06-16 Thread Dave Angel

On 06/16/2013 01:21 PM, Jim Mooney wrote:

My first impression of Python was that it had dynamic types but didn't
mix them. so if I was wrong on equality, is there a general rule of
what different types can still be equal? Is it an inheritance thing?


Several other good replies, but I'll give my two cents as well.

Python types are either really dynamic, or non-existent, depending on 
how you define them.  In particular names have no types at all, unless 
you want to count the type of the object the name is currently connected 
to.  And if that's what you mean, then names are extremely dynamic, 
because a name which was bound to a str a minute ago may be currently 
bound to a file, and may be soon bound to an iterator.


As for whether objects of different types can be equal.  The answer is 
yes, if one or both of them define the special methods __eq__() and 
__ne__().  If neither of those exist, the objects are unequal.


But you may be asking instead which standard library types have those 
special methods, and how do they behave.  In that case, I defer to 
Steven's answer.




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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread Alan Gauld

On 17/06/13 00:12, Jim Mooney wrote:

There is also an active community writing third-party plugins for Vim
and this is probably where the bulk of significant new features are
developed.


So as Dr. Frankenstein exclaimed: It's Alive! ;')

Vim as a project is very much alive but to be honest I usually advise 
not using too many of the add-ons because you then get further away from 
the original vi which is still the standard editor on any modern Unix 
box. So if you ever  have to login to some non vimified box knowing the 
original commands is very useful.


And once you get your head around them they are incredibly efficient
and consistent in how they work. I often guess at how things might work 
in vim and it just works.


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

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


Re: [Tutor] Getting the real exception clause

2013-06-16 Thread Dave Angel

On 06/16/2013 04:26 PM, Jim Mooney wrote:

'''I'm using general Exception to print out what the exception is
until I learn them, but
it will print out [Errno 2] No such file or directory in this case,
when the real
exception I'd need to use in an except clause is FileNotFoundError.
How do I get the
exception I need to use in the except clause from the more English-like message?
'''

#Using C:\Python33\python.exe on Win 7 in c:\python33\jimprogs
try:
 fh = open('nosuchdirectory/text/truthyfalsey.txt')
 for line in fh:
 print(line,end='')
 fh.close()
except Exception as err:
 print(err)



Mark is correct.  The best way to print out the exception type and 
description is to not use try/except, or at least such a base class as 
Exception.


But if you have some other reason to do it your way, then just look at 
the type of err.


print( type(err), err)


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


Re: [Tutor] Getting the real exception clause

2013-06-16 Thread Jim Mooney
On 16 June 2013 16:41, Dave Angel da...@davea.name wrote:

 But if you have some other reason to do it your way, then just look at the
 type of err.

 print( type(err), err)

Yes, that's what I was looking for. It's just a learning tool to see
the exceptions without the ugly BUNG! and red traceback screen I get
from my IDE, then having to close the message-box so I can see the
interpreter again ;')

Jim
After indictment the bacon smuggler was put on the no-fry list
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Getting the real exception clause

2013-06-16 Thread Dave Angel

On 06/16/2013 08:04 PM, Jim Mooney wrote:

On 16 June 2013 16:41, Dave Angel da...@davea.name wrote:


But if you have some other reason to do it your way, then just look at the
type of err.

print( type(err), err)


Yes, that's what I was looking for. It's just a learning tool to see
the exceptions without the ugly BUNG! and red traceback screen I get
from my IDE, then having to close the message-box so I can see the
interpreter again ;')


So let me get this straight. Your IDE is busted and ruins the standard 
error traceback message.  So you catch exception and try to recreate 
the feature as it was intended to work.


I'd look closer at the IDE and see if it's configurable to remove ugly 
features.





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


Re: [Tutor] Getting the real exception clause

2013-06-16 Thread Jim Mooney
 I'd look closer at the IDE and see if it's configurable to remove ugly
 features.

Well, at least the BUNG! which sounds like a spring flew out of my
front end. It's a jarring feature ;')

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


Re: [Tutor] Getting the real exception clause

2013-06-16 Thread Mark Lawrence

On 17/06/2013 01:12, Dave Angel wrote:

On 06/16/2013 08:04 PM, Jim Mooney wrote:

On 16 June 2013 16:41, Dave Angel da...@davea.name wrote:


But if you have some other reason to do it your way, then just look
at the
type of err.

print( type(err), err)


Yes, that's what I was looking for. It's just a learning tool to see
the exceptions without the ugly BUNG! and red traceback screen I get
from my IDE, then having to close the message-box so I can see the
interpreter again ;')


So let me get this straight. Your IDE is busted and ruins the standard
error traceback message.  So you catch exception and try to recreate
the feature as it was intended to work.

I'd look closer at the IDE and see if it's configurable to remove ugly
features.



Since when is code meant to be run from an IDE?  For the simple stuff 
that the OP is doing, why not use any semi-decent text editor and run 
the code from the command line?


Thinking about it, for years I happily used Mark Hammond's excellent 
pywin32 stuff to do just this.  I only moved to Eclipse and Pydev when I 
had some heayweight porting of Java code to Python, but that would be a 
massive overkill for the OP.


Just my £0.02p worth.

--
Steve is going for the pink ball - and for those of you who are 
watching in black and white, the pink is next to the green. Snooker 
commentator 'Whispering' Ted Lowe.


Mark Lawrence

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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread Amit Saha
On Mon, Jun 17, 2013 at 11:25 AM, bob gailer bgai...@gmail.com wrote:
 On 6/15/2013 5:53 AM, Amit Saha wrote:

   Symbolic math?

 What is that?

Eg: https://gist.github.com/amitsaha/5787802

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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread bob gailer

On 6/15/2013 5:53 AM, Amit Saha wrote:

  Symbolic math?

What is that?

--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread Steven D'Aprano

On 17/06/13 11:25, bob gailer wrote:

On 6/15/2013 5:53 AM, Amit Saha wrote:

  Symbolic math?

What is that?


Algebra, calculus and similar.


py import sympy
py x = sympy.Symbol('x')
py ((x + 2)**3).expand()
x**3 + 6*x**2 + 12*x + 8


Where possible, it calculates exact mathematical results:

py sympy.sin(3*sympy.pi/4)
2**(1/2)/2


compared to floating point approximations:

py import math
py math.sin(3*math.pi/4)
0.7071067811865476



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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread epi
i guess you'll find this pretty interesting :

http://nbviewer.ipython.org/url/edu.scios.ch/sympy/nb_sample_sympy.ipynb

sympy latex rendering using the ipython notebook …

Have fun ;)

Il giorno 15/giu/2013, alle ore 05:53, Amit Saha amitsaha...@gmail.com ha 
scritto:

 Hello Tutors,
 
 Would any of you have any teaching (or substantial self learning)
 experience with a library for Symbolic math?
 
 I am currently exploring sympy (http://sympy.org) as part of writing a
 book chapter and would like to know if there any better/easier option
 out there which can successfully introduce symbolic math to young
 programmers.
 
 Thank you for any suggestions in advance.
 
 Best,
 Amit.
 
 
 --
 http://echorand.me
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread pyt...@outofoptions.net

On 06/16/2013 10:14 PM, epi wrote:

i guess you'll find this pretty interesting :

http://nbviewer.ipython.org/url/edu.scios.ch/sympy/nb_sample_sympy.ipynb

sympy latex rendering using the ipython notebook ...

Have fun ;)


Is this intertwined with Sage?  I know Sage is mostly python.
http://www.sagemath.org/




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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread Amit Saha
On Mon, Jun 17, 2013 at 12:14 PM, epi massimodisa...@gmail.com wrote:
 i guess you'll find this pretty interesting :

 http://nbviewer.ipython.org/url/edu.scios.ch/sympy/nb_sample_sympy.ipynb

 sympy latex rendering using the ipython notebook …

 Have fun ;)

Thanks, I am aware of that. I was asking for any other beginner
friendly alternative to SymPy that folks may be aware of.

Best,
Amit.


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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread Amit Saha
On Mon, Jun 17, 2013 at 12:47 PM, Jim Mooney cybervigila...@gmail.com wrote:
 On 16 June 2013 18:28, Amit Saha amitsaha...@gmail.com wrote:
 On Mon, Jun 17, 2013 at 11:25 AM, bob gailer bgai...@gmail.com wrote:
 On 6/15/2013 5:53 AM, Amit Saha wrote:

   Symbolic math?

 What is that?

 Eg: https://gist.github.com/amitsaha/5787802

 x wasn't defined, and it didn't look like you needed  solve(expr,x,
 dict=True)  the first time
 since it's repeated in pprint, so I ditched it. Then it worked nicely.

'x' was defined earlier, I didn't paste it there :-), and Yes I didn't need
the first solve.


 That's a nice little package. Just about self-explanatory, and you
 don't need a big, honking GUI or TeX. I think I'll keep it. And works
 in 3.3. I think I'll keep it ;')

yeah, I am playing with the Python 3 version. Works great so far.


 --
 Jim
 After indictment the bacon smuggler was put on the no-fry list



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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread Jim Mooney
On 16 June 2013 18:28, Amit Saha amitsaha...@gmail.com wrote:
 On Mon, Jun 17, 2013 at 11:25 AM, bob gailer bgai...@gmail.com wrote:
 On 6/15/2013 5:53 AM, Amit Saha wrote:

   Symbolic math?

 What is that?

 Eg: https://gist.github.com/amitsaha/5787802

x wasn't defined, and it didn't look like you needed  solve(expr,x,
dict=True)  the first time
since it's repeated in pprint, so I ditched it. Then it worked nicely.

That's a nice little package. Just about self-explanatory, and you
don't need a big, honking GUI or TeX. I think I'll keep it. And works
in 3.3. I think I'll keep it ;')

-- 
Jim
After indictment the bacon smuggler was put on the no-fry list
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread Jim Mooney
 yeah, I am playing with the Python 3 version. Works great so far.

I didn't even look at the docs, but I think I got the solve part
working. I cut down on typing a bit, though. Typing Symbol all day
long could get tedious:

from sympy import Symbol as S, solve, pprint
a,b,c,x = S('a'),S('b'),S('c'),S('x')
pprint(solve(a*x*x + b*x + c, x, dict=True))

## pretty picture here

a,b,c = 3,5,6 ## seeing if it solves stuff the way I think

y = solve(a*x*x + b*x + c, x, dict=True)

print(y)

## result: [{x: -5/6 - sqrt(47)*I/6}, {x: -5/6 + sqrt(47)*I/6}]
## Oops, looks like I accidentally went complex ;')

I certainly like a module where you don't have to search and ponder,
and it works about like you expect. It seems very straightforward.

-- 
Jim
After indictment the bacon smuggler was put on the no-fry list
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread Amit Saha
On Mon, Jun 17, 2013 at 1:16 PM, Jim Mooney cybervigila...@gmail.com wrote:
 yeah, I am playing with the Python 3 version. Works great so far.

 I didn't even look at the docs, but I think I got the solve part
 working. I cut down on typing a bit, though. Typing Symbol all day
 long could get tedious:

 from sympy import Symbol as S, solve, pprint
 a,b,c,x = S('a'),S('b'),S('c'),S('x')
 pprint(solve(a*x*x + b*x + c, x, dict=True))

 ## pretty picture here

 a,b,c = 3,5,6 ## seeing if it solves stuff the way I think

 y = solve(a*x*x + b*x + c, x, dict=True)

 print(y)

 ## result: [{x: -5/6 - sqrt(47)*I/6}, {x: -5/6 + sqrt(47)*I/6}]
 ## Oops, looks like I accidentally went complex ;')

 I certainly like a module where you don't have to search and ponder,
 and it works about like you expect. It seems very straightforward.

This is a new tutorial the SymPy guys are working on:
http://docs.sympy.org/tutorial/tutorial/index.html

I certainly found it much more coherent and it clarified a few doubts
I was having.



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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread Jim Mooney
On 16 June 2013 20:18, Amit Saha amitsaha...@gmail.com wrote:

 This is a new tutorial the SymPy guys are working on:
 http://docs.sympy.org/tutorial/tutorial/index.html

Thanks. A lot of math bored me but I see it has matrices, and I really
liked linear algebra for some odd reason. I might fool with it again
since this package is just basics and not some Huge graphical
overkill.

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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread Amit Saha
On Mon, Jun 17, 2013 at 1:25 PM, Jim Mooney cybervigila...@gmail.com wrote:
 On 16 June 2013 20:18, Amit Saha amitsaha...@gmail.com wrote:

 This is a new tutorial the SymPy guys are working on:
 http://docs.sympy.org/tutorial/tutorial/index.html

 Thanks. A lot of math bored me but I see it has matrices, and I really
 liked linear algebra for some odd reason. I might fool with it again
 since this package is just basics and not some Huge graphical
 overkill.

Indeed, it's quite fun. Also, check out
https://github.com/sympy/sympy/wiki/Idioms-and-Antipatterns



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


Re: [Tutor] Python and Symbolic Math for beginners

2013-06-16 Thread Amit Saha
On Mon, Jun 17, 2013 at 1:25 PM, Jim Mooney cybervigila...@gmail.com wrote:
 On 16 June 2013 20:18, Amit Saha amitsaha...@gmail.com wrote:

 This is a new tutorial the SymPy guys are working on:
 http://docs.sympy.org/tutorial/tutorial/index.html

 Thanks. A lot of math bored me but I see it has matrices, and I really
 liked linear algebra for some odd reason. I might fool with it again
 since this package is just basics and not some Huge graphical
 overkill.

I agree with that sentiment of some Huge graphical overkill.

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


Re: [Tutor] Is there a programmatic use for keys() and values()

2013-06-16 Thread eryksun
On Sun, Jun 16, 2013 at 4:43 AM, Roel Schroeven r...@roelschroeven.net wrote:
 Jim Mooney schreef:
 I'll get to here:

 {'alpha':'beta'

 Only my cursor is to the Left of the final quote. Then I have to go
 hunt the Right Arrow or End key

In PyScripter you can just type the closing quote/brace over the
auto-inserted one.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] The Whole Tree

2013-06-16 Thread eryksun
On Sun, Jun 16, 2013 at 3:17 PM, Steven D'Aprano st...@pearwood.info wrote:

 plus some more exotic built-ins, which I haven't shown.

Some types that didn't make it into Steven's list:

zip
map
filter
enumerate
reversed
memoryview

slice
ellipsis, type(...)

super
classmethod
staticmethod
property

I wouldn't call 'em exotic. OK, maybe ellipsis.

Regarding abstract base classes, once you've gotten the hang of the
data model, read the docs for abc and numbers in addition to the
already-mentioned collections.abc:

http://docs.python.org/3/library/abc
http://docs.python.org/3/library/numbers

For example, sorted(numbers.Integral.__abstractmethods__) is the list
of methods that have to be implemented. Else the interpreter will just
complain that it Can't instantiate abstract class Integral with
abstract methods .
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor