Re: [Tutor] SMTP Module Help

2009-01-07 Thread Ole Henning Jensen

Marco Petersen wrote:
I'm using Python 2.5.4. I wanted to try out the SMTP module. I tried to 
send an email through my Gmail account but it keeps saying that the 
connection was refused.


This is the code that I used :

import smtplib
msg = 'Test'


server = smtplib.SMTP('smtp.gmail.com')
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
server.login('marco.m.peter...@gmail.com', 'password')
server.sendmail('marco.m.peter...@gmail.com', 
'marcoleepeter...@gmail.com', msg)

server.close()

This error message keeps coming up:


Traceback (most recent call last):
 File "C:/Python25/send_mail.py", line 5, in 
   server = smtplib.SMTP('smtp.gmail.com')
 File "C:\Python25\Lib\smtplib.py", line 244, in __init__
   (code, msg) = self.connect(host, port)
 File "C:\Python25\Lib\smtplib.py", line 310, in connect
   raise socket.error, msg
error: (10061, 'Connection refused')


Can anyone help me with this?



I must admit that I know nothing of the SMTP module, but I do know that 
with gmail you need to use an SSL secure connection on port 995.


I doesn't seem to be aplied in your script as far as I can tell.

Best Regards
Ole
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] repply

2009-01-04 Thread Ole Henning Jensen

prasad rao wrote:
hi 
  I got it right.


 >>> z=[]
 >>> for x in range(1000):
if divmod(x,3)[1]==0:z.append(x)
if divmod(x,5)[1]==0:z.append(x)

 >>> sum(set(z))
233168



Instead of using the set function you could just use an elif in your for 
loop.


>>> z=[]
>>> for x in range(1000):
if divmod(x,3)[1]==0:z.append(x)
elif divmod(x,5)[1]==0:z.append(x)


>>> sum(z)
233168

or as somebody else suggested use an OR operator

>>> z=[]
>>> for x in range(1000):
if (divmod(x,3)[1]==0) or (divmod(x,5)[1]==0):
z.append(x)


>>> sum(z)
233168

just some variations... On an other wise correct anwser.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] what does the "@" operator mean?

2008-12-16 Thread Ole Henning Jensen

Marc Tompkins wrote:

By the way, (totally off-topic, of course, my apologies): what do all
y'all call the "@" operator?  Here in the States, we call it the
"at-sign", which I find boring; I believe "sleepycat" is a
Scandinavian thing (I picked it up in some long-forgotten article)


Continuing of the OT lane
I'm not sure that "sleepycat" is scandinavien, I'm Danish myself and to 
my knowledge in both Denmark and Sweden the at-sign is called "snabel-a" 
which translates to "trunk-a" (a trunk as on an elefant)

And in Norwegian I belive to be "krølle-alfa" translated means "curly-alpha"

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] hypotenuse

2008-03-15 Thread Ole Henning Jensen
bob gailer wrote:
> Robert Childers wrote:
>> I have rewritten my "hypotenuse" program as follows:>>> #This program 
>> calculates the width and diagonal of a golden rectangle
> print "Calculate the width and diagonal of a golden rectangle."
>> Calculate the width and diagonal of a golden rectangle.
> height = input ("Input height:")
>> Input height:1
> width = height*1.618
> print "Width:", width
>> Width: 1.618
> import math
> hyp_squared = height**2 + width**2
> hypotenuse = math.sqrt(hyp_squared)
> print "Diagonal:", hypotenuse
>> Diagonal: 1.90208412012
>>  
>> When I save the program then try to run the module I get an error 
>> message that it is invalid.
> 
> Please ALWAYS post the code and the traceback. Otherwise we have no way 
> to easily help you.
> 
> But I will take a guess that you saved the contents of the interactive 
> session and tried to run that. That will not work, as  the interactive 
> session is full of >>> and results of print statements.
> 
> So I suggest you edit the module to see if this is the case; if it is 
> then remove all the junk so you just have pure Python. Run that. If you 
> still get errors post the code and traceback.
> 

Yes like Bob says you most likly saved the interactive session.

What you should do is open IDLE as usual, and *before* you start typing 
you program, you should open a "new wind" from the file menu.
This should open a blank sheet, into which you can type your program, 
just as you did before (but without the >>>).

When you have done that, save the file and *remember* to add ".py" to 
the filename (without the quotes),  then press the F5 key to run the 
program.

Happy programming.

BR
Ole Jensen
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Hard time understanding classes

2008-03-12 Thread Ole Henning Jensen
Norm All wrote:
> I am learning python and so far have done pretty well, until I got to 
> the subject of classes which I have been struggling to understand for a 
> while. I have not found any easy to understand tutorial on the web or 
> looking in some books for a clear step by step example. Would  
> appreciate any help or links to read.
> 


While this is a very long discussion thread, I found it extremly helpful 
in my understanding of classes and how they should be built/designed.

http://www.nabble.com/designing-POOP-tc15290468.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help with slice

2008-03-04 Thread Ole Henning Jensen
> Could someone please explain 'slices' also for dictionaries?
> 
> basically, I'd like to know how you would call every 3rd element in a list
> of lists... 
> 
> My logic says: ThirdElems=List[:][2]
> 
What this does is, just assign the 3 value of List to the variable.
look at this way, step by step.

 >>> lst = range(10) # Generate a list
 >>> print lst[:]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 >>> lst == lst[:]
True

## So lst[:] is really (sort of) just the same list

 >>> lst[:][2]
2

# So lst[:][ is basically the same as lst[2]



> Which to me reads, for every item in List (which are lists), return the
> third item.
> but this doesn't work.


What you need to do is loop all the way through your list and then only 
do something to every third element in the list

This is an example of a for loop, that prints out every 3 element:

 >>> lst = ["hello", "sweet", "world", "goodbye", "sweet", "world"]
 >>> for index in lst:
if index % 3 == 0:
print lst[index]

hello
goodbye


Best Regards
Ole H. Jensen
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] using quotes in IDLE

2007-12-14 Thread Ole Henning Jensen

- Original Message - 
From: "Jim Morcombe" <[EMAIL PROTECTED]>
To: 
Sent: Friday, December 14, 2007 2:43 AM
Subject: [Tutor] using quotes in IDLE


A really dumb question...

When typing things into IDLE, how are quotes meant to work?

If I type"

employee.name = "Susan"

then IDLE ignores the last " and I get an error.
---

When pasting you code into IDLE i get this:

>>> employee.name = "Susan"

Traceback (most recent call last):
  File "", line 1, in 
employee.name = "Susan"
NameError: name 'employee' is not defined

which is the result of me not having a class called employee, do you have 
that?
If not, you can't use dots in variable names so in stead of 'employee.name' 
you could use employeeName or employee_name

fx
>>> employee_name = "susan"
>>> print employee_name
susan


Regards Ole Jensen 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] updating a print statement

2007-12-10 Thread Ole Henning Jensen

Sry about the previous mail.

- Original Message - 

I have a print statement in a for loop so I can watch the progress

for line in file(file):
the_line = line.split()
if the_line:
print ("Index = %.2f") %index

Is there a way that only one line will be output and the variable is updated
rather than one line for every index.
-

Now I'm still only in the learning process, but couldn't you do something 
like this:

for line in file(file):
the_line = line.split()
if the_line:
Index = "%.2f" %index # This line might have to be
# adjusted to do what it is 
you want
print "Index= " + Index


BR
Ole

PS heres to hoping the code is indented properbly. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] updating a print statement

2007-12-10 Thread Ole Henning Jensen

  I have a print statement in a for loop so I can watch the progress

  for line in file(file):
  the_line = line.split()
  if the_line:
  print ("Index = %.2f") %index

  Is there a way that only one line will be output and the variable is updated 
rather than one line for every index.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor