Re: [Tutor] Tutor Digest, Vol 39, Issue 60

2007-05-23 Thread Leon Keylin

Janos, I tried the ODBC way and it worked! I was about to give up and do it
in C#
or some other language but I love Python so much I wanted it to work.

Thank you SO MUCH!

And thanks to all of you who helped as well!
You folks are the best.




Message: 6
Date: Wed, 23 May 2007 08:07:35 +0200
From: J?nos Juh?sz <[EMAIL PROTECTED]>
Subject: Re: [Tutor] MSSQL Connection
To: tutor@python.org
Message-ID:
<
[EMAIL PROTECTED]>
Content-Type: text/plain; charset="US-ASCII"

Hi Leon,


> > Hi John,
> >
> > Here's the code (I do have permissions to truncate, works manually
under
> > the same user.
> >
> >
> > import pymssql
> >
> > con = pymssql.connect
> > (host='server',user='user',password='pwd',database='DB_QA')
> > cur = con.cursor()
> >
> >
> > query="truncate TABLE bbConsolidatedMessageAcks"
> > cur.execute(query)
> > print "Deleted Records: %d" % cur.rowcount
> >

I use two alternatives to connect to mssql server.

ADODB connection via win32com.client
--
import win32com.client

cn =win32com.client.Dispatch('ADODB.connection')
cn.Provider='sqloledb'
cn.Open('Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=production;Data Source=036fefersqls001')
# The argument of cn.Open(), the connection string can be created very
easy on windows.
#  Create a conn.udl on your desktop
#  Open it with double click, and build a new connection string, test it,
save it
#  Copy and paste from your .udl

stockcode = '100701-06'
sql = "select * from stocks where stock = '%s'" % stockcode

print sql
rs = win32com.client.Dispatch('ADODB.recordset')
rs.Open(sql, cn)
print rs.Fields[0].Value
rs.Close()

cn.Close()
-

But I usually use ODBC with this kind of class.

import dbi, odbc

class myDB:
def __init__(self):
"""Open a new connection."""
self.cn =
odbc.odbc('DSN=myDB;UID=query;PWD=query;DATABASE=myDB')

def closeDB(self):
"""Close the connection."""
self.cn.close()

def Execute(self, sql):
cr = self.cn.cursor()
cr.execute(sql)
cr.close()

def Query(self, sql):
try:
cr = self.cn.cursor()
cr.execute(sql)
self.colnames = [field_prop[0] for field_prop in
cr.description]
self.result = cr.fetchall()
self.rownum = len(self.result)
return self.result
except:
self.colnames = [None]
self.result = [[None]]
self.rownum = 0
return [[None]]

test = myDB()
print(test.Query('Select * from testtable') )


Best regards,
Janos



--

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


End of Tutor Digest, Vol 39, Issue 60
*

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


Re: [Tutor] creating a buffer object from a file ?

2007-05-23 Thread Iyer
thanks, alan for your helpful response. 

in reality what is a buffer object used for ? reading
a file itself creates a string as in itself, 

file_handle = file ("path_to_file")

file_data = file_handle.read()

# file_data is a string, so why is a buffer object is
needed ?

the data in the binary file is just raw binary. 

I apologize for replying to the existing subject.
Thanks for letting me know. I shall make sure this
doesn't happen again.

thanks
iyer

--- Alan Gauld <[EMAIL PROTECTED]> wrote:

> "Iyer" <[EMAIL PROTECTED]> wrote
> 
> > How do I go about creating a buffer object from
> > a file containing binary data ? I have a function
> > that accepts only buffer objects for it's
> parameters
> 
> Can you define what you mean by a buffer object?
> Python uses duck typing so, unless the function has
> been badly coded with an explicit type check, it
> should accept any object that supports the methods
> used.
> 
> If you really do need a buffer the docs say:
> 
> -
> Buffer objects are not directly supported by Python
> syntax, but can be created by calling the builtin
> function buffer(). They don't support concatenation
> or repetition.
> -
> 
> Which was new to me. But some experimentation
> with the interpreter shows:
> 
> class buffer(object)
>  |  buffer(object [, offset[, size]])
>  |
>  |  Create a new buffer object which references the
> given object.
>  |  The buffer will reference a slice of the target
> object from the
>  |  start of the object (or at the specified
> offset). The slice will
>  |  extend to the end of the target object (or with
> the specified 
> size).
> ---
> and
> 
> >>> b = buffer('fredrica', 2,4)
> >>> b[:]
> 'edri'
> 
> 
> So we can see how to create a buffer object.
> You want to do it with a binary file. You can read
> the content
> of a binary file using the struct module. But you
> need to know
> what kind of data is in your file. To create a
> buffer you need
> a string. So do you want your buffer to process the
> raw binary
> bytes as if they were a string? Or do you want to
> convert the
> binary data and then convert it again into a string
> representation?
> 
> Either is possible but you need to decide which you
> need.
> 
> BTW Please don't post new subjects to the list by
> replying
> to an existing subject. For those using threaded
> readers it
> buries your post insife another thread, in this case
> 3 levels
> deep in one about MSSQL! I only just noticed it. Its
> better
> to start a fresh message. After all its not exactly 
> difficult to
> type tutor@python.org in the to line! :-)
> 
> HTH,
> 
> -- 
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
> 
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 



   
Luggage?
 GPS? Comic books? 
Check out fitting gifts for grads at Yahoo! Search
http://search.yahoo.com/search?fr=oni_on_mail&p=graduation+gifts&cs=bz
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] trouble with "if"

2007-05-23 Thread adam urbas
Hi all,I've been working with this new program that I wrote.  I started out 
with it on a Ti-83, which is much easier to program than python.  Now I'm 
trying to transfer the program to python but its proving to be quite difficult. 
 I'm not sure what the whole indentation thing is for.  And now I'm having 
trouble with the if statement things.  #"Circle Data Calculation Program:"print 
"Welcome to the Circle Data Calcuation Program."print#"Menu 1:"print "Pick 
a shape:"print "(NOTE: You must select the number of the shape and not the 
shape itself)"print "1 Circle"print "2 Square"print "3 Triangle"#"User's 
Choice:"shape=raw_input("> ")#"Select Given:"if shape == 1:
print "Choose the given value:"print "1 radius"print "2 
diameter"print "3 circumference"print "4 area"#"User's 
Choice:"given=raw_input("> ")if given == 1:radius=raw_input("Enter 
Radius:")diameter=(radius*2)circumference=(diameter*3.14)   
 area=(radius**2*3.14)print "Diameter:", diameterprint 
"Circumference:", circumferenceprint "Area:", areaif given == 2:
diameter=raw_input("Enter Diameter:")radius=(diameter/2)
circumference=(diameter*3.14)area=(radius**2*3.14)print 
"Radius:", radiusprint "Circumference:", circumferenceprint 
"Area:", areaif given == 3:circumference=raw_input("Enter 
Circumference:")radius=(circumference/3.14/2)
diameter=(radius*2)area=(radius**2*3.14)print "Radius:", radius 
   print "Diameter:", diameterprint "Area:", areaif given == 4: 
   area=raw_input("Enter Area:")radius=(area/3.14)  This is the 
whole program so far, because I haven't quite finished it yet.  But I tried to 
get it to display another list of options after you select a shape but it just 
does this.Pick a shape:1 Circle2 Square3 Triangle>1>1>>>I'm not sure why it 
does that but I do know that it is skipping the second list of options.Another 
of my problems is that I can't figure out how to get it to accept two different 
inputs for a selection.  Like I want it to accept both the number 1 and circle 
as circle then list the options for circle.  It won't even accept words.  I can 
only get it to accept numbers.  It's quite frustrating actually.Any advice 
would be greatly appreciated.Thanks in advance,AdamI tried to get it to display 
ano
_
Create the ultimate e-mail address book. Import your contacts to Windows Live 
Hotmail.
www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_impcont_0507___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with "if"

2007-05-23 Thread Andre Engels
The problem is with types. The outcome of raw_input is a string. But
if you give the line:

if shape == 1:

you are comparing it with a number. The text "1" is not equal to the
number 1, so this evaluates to False.

Instead you should do:

if shape == "1":

To also be able to type 'circle' instead of '1', you can do:

if shape == "1" or shape == "circle":

or alternatively:

if shape in ["1","circle"]:



Andre Engels

2007/5/23, adam urbas <[EMAIL PROTECTED]>:
>
> Hi all,
>
> I've been working with this new program that I wrote.  I started out with it
> on a Ti-83, which is much easier to program than python.  Now I'm trying to
> transfer the program to python but its proving to be quite difficult.  I'm
> not sure what the whole indentation thing is for.  And now I'm having
> trouble with the if statement things.
>
> #"Circle Data Calculation Program:"
> print "Welcome to the Circle Data Calcuation Program."
> print
>
> #"Menu 1:"
> print "Pick a shape:"
> print "(NOTE: You must select the number of the shape and not the shape
> itself)"
> print "1 Circle"
> print "2 Square"
> print "3 Triangle"
>
> #"User's Choice:"
> shape=raw_input("> ")
>
> #"Select Given:"
> if shape == 1:
> print "Choose the given value:"
> print "1 radius"
> print "2 diameter"
> print "3 circumference"
> print "4 area"
>
> #"User's Choice:"
> given=raw_input("> ")
>
> if given == 1:
> radius=raw_input("Enter Radius:")
> diameter=(radius*2)
> circumference=(diameter*3.14)
> area=(radius**2*3.14)
> print "Diameter:", diameter
> print "Circumference:", circumference
> print "Area:", area
>
> if given == 2:
> diameter=raw_input("Enter Diameter:")
> radius=(diameter/2)
> circumference=(diameter*3.14)
> area=(radius**2*3.14)
> print "Radius:", radius
> print "Circumference:", circumference
> print "Area:", area
>
> if given == 3:
> circumference=raw_input("Enter Circumference:")
> radius=(circumference/3.14/2)
> diameter=(radius*2)
> area=(radius**2*3.14)
> print "Radius:", radius
> print "Diameter:", diameter
> print "Area:", area
>
> if given == 4:
> area=raw_input("Enter Area:")
> radius=(area/3.14)
>
> This is the whole program so far, because I haven't quite finished it yet.
> But I tried to get it to display another list of options after you select a
> shape but it just does this.
>
> Pick a shape:
> 1 Circle
> 2 Square
> 3 Triangle
> >1
> >1
> >>>
>
> I'm not sure why it does that but I do know that it is skipping the second
> list of options.
>
> Another of my problems is that I can't figure out how to get it to accept
> two different inputs for a selection.  Like I want it to accept both the
> number 1 and circle as circle then list the options for circle.  It won't
> even accept words.  I can only get it to accept numbers.  It's quite
> frustrating actually.
>
> Any advice would be greatly appreciated.
> Thanks in advance,
> Adam
>
>
>
>
>
> I tried to get it to display ano
>
> 
> Add some color. Personalize your inbox with your favorite colors. Try it!
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Andre Engels, [EMAIL PROTECTED]
ICQ: 6260644  --  Skype: a_engels
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with "if"

2007-05-23 Thread Brian van den Broek
adam urbas said unto the world upon 05/23/2007 11:57 AM:
> 
> Hi all,
> 
> I've been working with this new program that I wrote.  I started out 
> with it on a Ti-83, which is much easier to program than python.  Now 
> I'm trying to transfer the program to python but its proving to be quite 
> difficult.  I'm not sure what the whole indentation thing is for.  And 
> now I'm having trouble with the if statement things. 
> 
> #"Circle Data Calculation Program:"
> print "Welcome to the Circle Data Calcuation Program."
> print
> 
> #"Menu 1:"
> print "Pick a shape:"
> print "(NOTE: You must select the number of the shape and not the shape 
> itself)"
> print "1 Circle"
> print "2 Square"
> print "3 Triangle"
> 
> #"User's Choice:"
> shape=raw_input("> ")
> 
> #"Select Given:"
> if shape == 1:
> print "Choose the given value:"
> print "1 radius"
> print "2 diameter"
> print "3 circumference"
> print "4 area"
> 
> #"User's Choice:"
> given=raw_input("> ")
> 
> if given == 1:
> radius=raw_input("Enter Radius:")
> diameter=(radius*2)
> circumference=(diameter*3.14)
> area=(radius**2*3.14)
> print "Diameter:", diameter
> print "Circumference:", circumference
> print "Area:", area
> 
> if given == 2:
> diameter=raw_input("Enter Diameter:")
> radius=(diameter/2)
> circumference=(diameter*3.14)
> area=(radius**2*3.14)
> print "Radius:", radius
> print "Circumference:", circumference
> print "Area:", area
> 
> if given == 3:
> circumference=raw_input("Enter Circumference:")
> radius=(circumference/3.14/2)
> diameter=(radius*2)
> area=(radius**2*3.14)
> print "Radius:", radius
> print "Diameter:", diameter
> print "Area:", area
> 
> if given == 4:
> area=raw_input("Enter Area:")
> radius=(area/3.14)
>  
> This is the whole program so far, because I haven't quite finished it 
> yet.  But I tried to get it to display another list of options after you 
> select a shape but it just does this.
> 
> Pick a shape:
> 1 Circle
> 2 Square
> 3 Triangle
>  >1
>  >1
>  >>>
> 
> I'm not sure why it does that but I do know that it is skipping the 
> second list of options.
> 
> Another of my problems is that I can't figure out how to get it to 
> accept two different inputs for a selection.  Like I want it to accept 
> both the number 1 and circle as circle then list the options for 
> circle.  It won't even accept words.  I can only get it to accept 
> numbers.  It's quite frustrating actually.
> 
> Any advice would be greatly appreciated.
> Thanks in advance,
> Adam
> 
> 


Adam,

Could you send plain text email rather than html, please? At least for 
me, your code's indentation is all messed up unless I take some steps 
to rectify it.

The problem is that raw_input returns a string, and you are testing 
whether given is equal to integers. See if this helps make things clear:

 >>> data = raw_input('Feed me!')
Feed me!42
 >>> type(data)

 >>> data == 42
False
 >>> int(data) == 42
True
 >>>

Best,

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


Re: [Tutor] trouble with "if"

2007-05-23 Thread Eric Walstad
adam urbas wrote:
> Hi all,
> 
> I've been working with this new program that I wrote.
...
> #"User's Choice:"
> shape=raw_input("> ")
>
> #"Select Given:"
> if shape == 1:
...


[EMAIL PROTECTED]:~$ python
Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> shape = raw_input('>')
>1
>>> type(shape)

>>> shape == 1
False
>>>


HTH,

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


Re: [Tutor] two input acceptions

2007-05-23 Thread adam urbas
Sorry, Hotmail doesn't have a turn of HTML feature or if it does, I couldn't 
find it.  I think I'm just going to take your word for it that raw_input is 
better because I find the entire concept quite confusing.  I tried typing in 
your example in IDLE and it didn't do anything, except:>>And then it told 
me that it didn't know what the >>("LOL") was.  It really disliked the >> bit.  
I understand the concept though, I think.  I have been using the raw_input 
though.  If I change it from var=raw_input()>>("LOL")to 
var=raw_input("LOL")then it displays>>>LOL>>>Not sure what that means, but 
yeah.  Well thanks anyway.Adam> Date: Sat, 19 May 2007 01:47:51 +0100> From: 
[EMAIL PROTECTED]> To: [EMAIL PROTECTED]; tutor@python.org> Subject: Re: 
[Tutor] two input acceptions> > adam urbas escreveu:> > Thanks for the help.  
I've made quite some progress since I first posted this email.  I have a 
question though, what did you mean when you were talking about the raw_input( 
)?  How can the regular input( ) be used evilly?  If you could explain in 
depth, I would be very grateful.  I have a new question related to my program 
area.py., I guess it's the same one as before.  When I run the program and 
input the rectangle option, it asks me for a radius, unless I input 1, instead 
of rectangle.  How do I program it to accept both 1 and rectangle?> Date: Sat, 
12 May 2007 18:55:20 +0100> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC: 
tutor@python.org> Subject: Re: [Tutor] (no subject)> > adam urbas escreveu:> > 
Hi,I just started python today and I would like a few pointers, if you don't 
mind.  I tried using a tutorial, but was only able to get the correct results 
for the most basic problems.  # Area calculation programprint “Welcome to the 
Area calculation program”print “––> –––”print# Print out the menu:print 
“Please select a shape:”print “1  Rectangle”print “2  Circle”# Get the user’s 
choice:shape = input(“> “)# Calculate the area:if shape == 1:height = 
input(“Please enter the height: “)width = input(“Please enter the width: “) 
   area = height*widthprint “The area is”, areaelse:radius = 
input(“Please enter the radius: “)area = 3.14*(radius**2)print “The 
area is”, areaI've been trying to get this to work.  I was on a forum on Google 
and they said to put:input("press ENTER to continue")at the end.  I did, but it 
didn't work.  It runs the program but just shuts itself off when its done and i 
don't even get to select any of the option things that i'm s> upposed to be 
able to select.  It just turns on then back off and I don't even get to see 
anything.  Could someone help me out.ThanksAdam> > 
_> > Create the 
ultimate e-mail address book. Import your cont> acts to Windows Live Hotmail.> 
> 
www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_impcont_0507>
 > > > > > 
> > > > 
___> > Tutor maillist  -  
Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor> > First, 
welcome to the world of Python. :D> Second. please give a title when you start 
a new thread on a mailing list.> Third, format your posts and code. Since 
Python uses indented code, it's > kinda hard to read it when it's all in one 
line (Don't worry, I'll paste > it indented in a file attached to this email :D 
)> > Now for the code.> > After arranging the code, the first thing I noticed 
were this characters “ ”> > I tried running the code, and if gave me a error 
there, so I just > replace then with " ", and voilá, the code worked :D . So 
the lesson > here is always use either " " or ' ' in the code.> > Oh, a> lso 
another thing. Don't use input() to get the user input, because > that command 
can run code and it may be evilly used. Always use > raw_input() instead :D .> 
> Anyway, I hope I helped you,> > > -- > _> ASCII 
ribbon campaign ( )>   - against HTML email  X>   & vCards / \> > 
_> > Create the 
ultimate e-mail address book. Import your contacts to Windows Live Hotmail.> > 
www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_impcont_0507>
 > First of all, what email client are you using?> Because the text is getting 
all weird and difficult to read (it's all in > one line, with no paragraphs and 
things like that).> > Now, the thing about input() and why it's not a good 
policy to use is > that, unlike raw_input(), what type in a input() is executed 
by Python > (in raw_input() is stored as a string).> > Example:> > var = 
raw_input()>  >> list("LOL")> > Now we have a variable called var which 
contains the string that says > 'list("LOL")'> You can confirm that by typing:> 
print var>  >> 'list("LOL")> > There, no harm

Re: [Tutor] two input acceptions

2007-05-23 Thread adam urbas
I figured out why it was asking for the radius of a square.  It was because I 
had the if shape==1: thing on there.  I was typing in rectangle and that was an 
else: function.  How do i get it to accept both 1 and circle?  I learned not to 
use else: unless I was completely sure that I could use it, to avoid problems 
like this.I put both the .py and .txt files on there, so which ever you 
prefer.Thanks,Adam> To: tutor@python.org> From: [EMAIL PROTECTED]> Date: Sat, 
19 May 2007 08:28:19 +0100> Subject: Re: [Tutor] two input acceptions> > > 
"Rolando Pereira" <[EMAIL PROTECTED]> wrote> > what did you mean when you were 
talking about the raw_input( )?  > > How can the regular input( ) be used 
evilly?  > > raw_input() is the preferred way to read input from a user.> It 
only reads the raw input as typed by the user  so it always > returns a string 
which you then need to convert to another > type (like an int) if you need to. 
This gives you more controil > over what kind of data your program receives.> > 
input() by contrast reads the string input by the user and tries > to evaluate 
it as a Python expression. Thus if the user typed> > import 
os;os.system('format c:\')> > Python would try to evaluate that as a python 
string > and it could format your C drive. (In practice it would > throw up a 
prompt and hopefully you would say no!)> It might not be something as obvious 
as that, it > could simply deactivate your firewall, or add a new > user 
account to your PC, anything that enables a > subsequent attack to do more 
damage.> > The attack might not be deliberate, sometimes > accidentally typed 
errors can result in code being > executed that you didn't want.> > But thats 
why input() is best used in very strictly > controlled environments - like at 
the >>> prompt when > you are testing/developing code. But use raw_input plus > 
a conversion function for finished code.> > > When I run the program and input 
the rectangle option, > > it asks me for a radius, > > Your code is unreadable 
and I don't have the time > or inclination to try to unpick it. Can you send as 
plain > text or as an attachment please?> > Alan G> > 
___> Tutor maillist  -  
Tutor@python.org> http://mail.python.org/mailman/listinfo/tutor
_
Create the ultimate e-mail address book. Import your contacts to Windows Live 
Hotmail.
www.windowslive-hotmail.com/learnmore/managemail2.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_impcont_0507#"Area calculation program"

print "Welcome to the Area calculation program"
print "–"
print

# "Print out the menu:"
print "Please select a shape:"
print "1,  Rectangle"
print "2,  Circle"

#"Get the user’s choice:"
shape = input("> ")

#"Calculate the area:"
if shape == 1:
height = input("Please enter the height: ")
width = input("Please enter the width: ")
area = height*width
print "The area is", area
else:
radius = input("Please enter the radius: ")
area = 3.14*(radius**2)
print "The area is", area
#"Area calculation program"

print “Welcome to the Area calculation program”
print “–”
print

# "Print out the menu:"
print “Please select a shape:”
print “1  Rectangle”
print “2  Circle”

#"Get the user’s choice:"
shape = input(“> “)

#"Calculate the area:"
if shape == 1:
height = input(“Please enter the height: “)
width = input(“Please enter the width: “)
area = height*width
print “The area is”, area
else:
radius = input(“Please enter the radius: “)
area = 3.14*(radius**2)
print “The area is”, area
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with "if"

2007-05-23 Thread adam urbas
Sorry, I forgot to attach the files.  Don't critique too much.  If you find a 
mistake in the program, then I probably haven't gotten that far, since it isn't 
complete yet.  I'm pretty much on the editing phase now.> Date: Wed, 23 May 
2007 18:08:20 +0200> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> Subject: 
Re: [Tutor] trouble with "if"> CC: tutor@python.org> > The problem is with 
types. The outcome of raw_input is a string. But> if you give the line:> > if 
shape == 1:> > you are comparing it with a number. The text "1" is not equal to 
the> number 1, so this evaluates to False.> > Instead you should do:> > if 
shape == "1":> > To also be able to type 'circle' instead of '1', you can do:> 
> if shape == "1" or shape == "circle":> > or alternatively:> > if shape in 
["1","circle"]:> > > > Andre Engels> > 2007/5/23, adam urbas <[EMAIL 
PROTECTED]>:> >> > Hi all,> >> > I've been working with this new program that I 
wrote.  I started out with it> > on a Ti-83, which is much easier to program 
than python.  Now I'm trying to> > transfer the program to python but its 
proving to be quite difficult.  I'm> > not sure what the whole indentation 
thing is for.  And now I'm having> > trouble with the if statement things.> >> 
> #"Circle Data Calculation Program:"> > print "Welcome to the Circle Data 
Calcuation Program."> > print> >> > #"Menu 1:"> > print "Pick a shape:"> > 
print "(NOTE: You must select the number of the shape and not the shape> > 
itself)"> > print "1 Circle"> > print "2 Square"> > print "3 Triangle"> >> >
 #"User's Choice:"> > shape=raw_input("> ")> >> > #"Select Given:"> > 
if shape == 1:> > print "Choose the given value:"> > print "1 
radius"> > print "2 diameter"> > print "3 circumference"> > 
print "4 area"> >> > #"User's Choice:"> > given=raw_input("> ")> >> > if 
given == 1:> > radius=raw_input("Enter Radius:")> > 
diameter=(radius*2)> > circumference=(diameter*3.14)> > 
area=(radius**2*3.14)> > print "Diameter:", diameter> > print 
"Circumference:", circumference> > print "Area:", area> >> > if given 
== 2:> > diameter=raw_input("Enter Diameter:")> > 
radius=(diameter/2)> > circumference=(diameter*3.14)> > 
area=(radius**2*3.14)> > print "Radius:", radius> > print 
"Circumference:", circumference> > print "Area:", area> >> > if given 
== 3:> > circumference=raw_input("Enter Circumference:")> > 
radius=(circumference/3.14/2)> > diameter=(radius*2)> > 
area=(radius**2*3.14)> > print "Radius:", radius> > print 
"Diameter:", diameter> > print "Area:", area> >> > if given == 4:> >
 area=raw_input("Enter Area:")> > radius=(area/3.14)> >> > This is 
the whole program so far, because I haven't quite finished it yet.> > But I 
tried to get it to display another list of options after you select a> > shape 
but it just does this.> >> > Pick a shape:> > 1 Circle> > 2 Square> > 3 
Triangle> > >1> > >1> >  >> > I'm not sure why it does that but I do know 
that it is skipping the second> > list of options.> >> > Another of my problems 
is that I can't figure out how to get it to accept> > two different inputs for 
a selection.  Like I want it to accept both the> > number 1 and circle as 
circle then list the options for circle.  It won't> > even accept words.  I can 
only get it to accept numbers.  It's quite> > frustrating actually.> >> > Any 
advice would be greatly appreciated.> > Thanks in advance,> > Adam> >> >> >> >> 
>> > I tried to get it to display ano> >> > > > 
Add some color. Personalize your inbox with your favorite colors. Try it!> > 
___> > Tutor maillist  -  
Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor> >> >> > > -- 
> Andre Engels, [EMAIL PROTECTED]> ICQ: 6260644  --  Skype: a_engels
_
Add some color. Personalize your inbox with your favorite colors.
www.windowslive-hotmail.com/learnmore/personalize.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_addcolor_0507#"Circle Data Calculation Program:"
print "Welcome to the Circle Data Calcuation Program."
print

#"Menu 1:"
print "Pick a shape:"
print "(NOTE: You must select the number of the shape and not the shape itself)"
print "1 Circle"
print "2 Square"
print "3 Triangle"

#"User's Choice:"
shape=raw_input("> ")

#"Select Given:"
if shape == "1" or shape == "circle":
print "Choose the given value:"
print "1 radius"
print "2 diameter"
print "3 circumference"
print "4 area"

#"User's Choice:"
given=raw_input("> ")

if given in["1", "radius"]:
radius=raw_input("Enter Radius:")
pi=3.14
diameter=(radius*2)
circumference=(radius*2*pi)
area=(radius**2*3.14)

Re: [Tutor] trouble with "if"

2007-05-23 Thread adam urbas
Thanks Andre.  That solved most of the problems.  Now all the lists will run 
correctly, but when I input a radius, it says:can't multiply sequence by 
non-int of type 'float'When it displays that, it is talking about 
circumference=(radius*2*3.14).  I'm guessing it doesn't want me to multiply by 
pi.  PLEASE HELP!!!thanks in advance,Adam> Date: Wed, 23 May 2007 18:08:20 
+0200> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> Subject: Re: [Tutor] 
trouble with "if"> CC: tutor@python.org> > The problem is with types. The 
outcome of raw_input is a string. But> if you give the line:> > if shape == 1:> 
> you are comparing it with a number. The text "1" is not equal to the> number 
1, so this evaluates to False.> > Instead you should do:> > if shape == "1":> > 
To also be able to type 'circle' instead of '1', you can do:> > if shape == "1" 
or shape == "circle":> > or alternatively:> > if shape in ["1","circle"]:> > > 
> Andre Engels> > 2007/5/23, adam urbas <[EMAIL PROTECTED]>:> >> > Hi all,> >> 
> I've been working with this new program that I wrote.  I started out with it> 
> on a Ti-83, which is much easier to program than python.  Now I'm trying to> 
> transfer the program to python but its proving to be quite difficult.  I'm> > 
not sure what the whole indentation thing is for.  And now I'm having> > 
trouble with the if statement things.> >> > #"Circle Data Calculation 
Program:"> > print "Welcome to the Circle Data Calcuation Program."> > print> 
>> > #"Menu 1:"> > print "Pick a shape:"> > print "(NOTE: You must select 
the number of the shape and not the shape> > itself)"> > print "1 Circle"> > 
print "2 Square"> > print "3 Triangle"> >> > #"User's Choice:"> > 
shape=raw_input("> ")> >> > #"Select Given:"> > if shape == 1:> >   
  print "Choose the given value:"> > print "1 radius"> > print 
"2 diameter"> > print "3 circumference"> > print "4 area"> >> > 
#"User's Choice:"> > given=raw_input("> ")> >> > if given == 1:> > 
radius=raw_input("Enter Radius:")> > diameter=(radius*2)> > 
circumference=(diameter*3.14)> > area=(radius**2*3.14)> > print 
"Diameter:", diameter> > print "Circumference:", circumference> >   
  print "Area:", area> >> > if given == 2:> > diameter=raw_input("Enter 
Diameter:")> > radius=(diameter/2)> > 
circumference=(diameter*3.14)> > area=(radius**2*3.14)> > print 
"Radius:", radius> > print "Circumference:", circumference> > 
print "Area:", area> >> > if given == 3:> > 
circumference=raw_input("Enter Circumference:")> > 
radius=(circumference/3.14/2)> > diameter=(radius*2)> > 
area=(radius**2*3.14)> > print "Radius:", radius> > print 
"Diameter:", diameter> > print "Area:", area> >> > if given == 4:> >
 area=raw_input("Enter Area:")> > radius=(area/3.14)> >> > This is 
the whole program so far, because I haven't quite finished it yet.> > But I 
tried to get it to display another list of options after you select a> > shape 
but it just does this.> >> > Pick a shape:> > 1 Circle> > 2 Square> > 3 
Triangle> > >1> > >1> >  >> > I'm not sure why it does that but I do know 
that it is skipping the second> > list of options.> >> > Another of my problems 
is that I can't figure out how to get it to accept> > two different inputs for 
a selection.  Like I want it to accept both the> > number 1 and circle as 
circle then list the options for circle.  It won't> > even accept words.  I can 
only get it to accept numbers.  It's quite> > frustrating actually.> >> > Any 
advice would be greatly appreciated.> > Thanks in advance,> > Adam> >> >> >> >> 
>> > I tried to get it to display ano> >> > > > 
Add some color. Personalize your inbox with your favorite colors. Try it!> > 
___> > Tutor maillist  -  
Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor> >> >> > > -- 
> Andre Engels, [EMAIL PROTECTED]> ICQ: 6260644  --  Skype: a_engels
_
Add some color. Personalize your inbox with your favorite colors.
www.windowslive-hotmail.com/learnmore/personalize.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_addcolor_0507___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] trouble with "if"

2007-05-23 Thread adam urbas
Sorry, I don't think Hotmail has turn off HTML.  If it does I havn't been able 
to find it.  I think you're going to have to explain your little bit of text 
stuff down there at the bottom.  I have no idea what most of that means.  All 
my choice things are working now though.  I think that is what you were trying 
to help me with.  What I used wasif shape in["1","circle"]:and if shape == "1" 
or shape =="circle":It works perfectly fine now.Ya that little bit o' code is 
really puzzling.  I wish I knew more about this python deal.  I understand the 
concept, but not the rules or the techniques and things of that sort.  OK... 
I've got it... the data=raw_input('Feed Me!').  Ok I now understand that bit.  
Then it says Feed Me!  and you put 42 (the ultimate answer to life the 
universe, everything).  OK, it won't accept the  bit.  it doesn't 
like the "<".  Well, I just removed that bit and it said:Feed Me!  and I put 
42, and it said >>> (I guess it's satisfied now, with the whole feeding).  Well 
if I understood what 'str' meant, then I could probably figure the rest out.  
Well I have to go do other things so I'll save the rest of this figuring out 
till later.I shall return,Adam> Date: Wed, 23 May 2007 12:12:16 -0400> From: 
[EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC: tutor@python.org> Subject: Re: 
[Tutor] trouble with "if"> > adam urbas said unto the world upon 05/23/2007 
11:57 AM:> > > > Hi all,> > > > I've been working with this new program that I 
wrote.  I started out > > with it on a Ti-83, which is much easier to program 
than python.  Now > > I'm trying to transfer the program to python but its 
proving to be quite > > difficult.  I'm not sure what the whole indentation 
thing is for.  And > > now I'm having trouble with the if statement things. > > 
> > #"Circle Data Calculation Program:"> > print "Welcome to the Circle Data 
Calcuation Program."> > print> > > > #"Menu 1:"> > print "Pick a shape:"> > 
print "(NOTE: You must select the number of the shape and not the shape > > 
itself)"> > print "1 Circle"> > print "2 Square"> > print "3 Triangle"> > > >   
  #"User's Choice:"> > shape=raw_input("> ")> > > > #"Select Given:"> > 
if shape == 1:> > print "Choose the given value:"> > print "1 
radius"> > print "2 diameter"> > print "3 circumference"> > 
print "4 area"> > > > #"User's Choice:"> > given=raw_input("> ")> > > > if 
given == 1:> > radius=raw_input("Enter Radius:")> > 
diameter=(radius*2)> > circumference=(diameter*3.14)> > 
area=(radius**2*3.14)> > print "Diameter:", diameter> > print 
"Circumference:", circumference> > print "Area:", area> > > > if given 
== 2:> > diameter=raw_input("Enter Diameter:")> > 
radius=(diameter/2)> > circumference=(diameter*3.14)> > 
area=(radius**2*3.14)> > print "Radius:", radius> > print 
"Circumference:", circumference> > print "Area:", area> > > > if given 
== 3:> > circumference=raw_input("Enter Circumference:")> > 
radius=(circumference/3.14/2)> > diameter=(radius*2)> > 
area=(radius**2*3.14)> > print "Radius:", radius> > print 
"Diameter:", diameter> > print "Area:", area> > > > if given == 4:> >   
  area=raw_input("Enter Area:")> > radius=(area/3.14)> >  > 
> This is the whole program so far, because I haven't quite finished it > > 
yet.  But I tried to get it to display another list of options after you > > 
select a shape but it just does this.> > > > Pick a shape:> > 1 Circle> > 2 
Square> > 3 Triangle> >  >1> >  >1> >   > > > I'm not sure why it does that 
but I do know that it is skipping the > > second list of options.> > > > 
Another of my problems is that I can't figure out how to get it to > > accept 
two different inputs for a selection.  Like I want it to accept > > both the 
number 1 and circle as circle then list the options for > > circle.  It won't 
even accept words.  I can only get it to accept > > numbers.  It's quite 
frustrating actually.> > > > Any advice would be greatly appreciated.> > Thanks 
in advance,> > Adam> > > > > > > Adam,> > Could you send plain text email 
rather than html, please? At least for > me, your code's indentation is all 
messed up unless I take some steps > to rectify it.> > The problem is that 
raw_input returns a string, and you are testing > whether given is equal to 
integers. See if this helps make things clear:> >  >>> data = raw_input('Feed 
me!')> Feed me!42>  >>> type(data)> >  >>> data == 42> False>  >>> 
int(data) == 42> True>   > Best,> > Brian vdB
_
Change is good. See what’s different about Windows Live Hotmail. 
http://www.windowslive-hotmail.com/learnmore/default.html?locale=en-us&ocid=RMT_TAGLM_HMWL_reten_changegood_0507
___
Tutor mail

[Tutor] tkinter arrow event location

2007-05-23 Thread Teresa Stanton
Using a mouse I could use event.x to find the current location of the mouse.
But if I have a canvas with a gif and I need the current location of the
gif, could I bind the gif to an arrow event to get the feedback of where the
gif is at any given time? If so, can someone show me how?

T


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


Re: [Tutor] trouble with "if"

2007-05-23 Thread Brian van den Broek
adam urbas said unto the world upon 05/23/2007 01:04 PM:
> Sorry, I don't think Hotmail has turn off HTML.  If it does I
> havn't been able to find it.  I think you're going to have to
> explain your little bit of text stuff down there at the bottom.  I
> have no idea what most of that means.  All my choice things are
> working now though.  I think that is what you were trying to help
> me with.  What I used wasif shape in["1","circle"]:and if shape ==
> "1" or shape =="circle":It works perfectly fine now.Ya that little
> bit o' code is really puzzling.  I wish I knew more about this
> python deal.  I understand the concept, but not the rules or the
> techniques and things of that sort.  OK... I've got it... the
> data=raw_input('Feed Me!').  Ok I now understand that bit.  Then it
> says Feed Me!  and you put 42 (the ultimate answer to life the
> universe, everything).  OK, it won't accept the  bit.
> it doesn't like the "<".  Well, I just removed that bit and it
> said:Feed Me!  and I put 42, and it said >>> (I guess it's
> satisfied now, with the whole feeding).  Well if I understood what
> 'str' meant, then I could probably figure the rest out.  Well I
> have to go do other things so I'll save the rest of this figuring
> out till later.I shall return,Adam> Date: Wed, 23 May 2007 12:12:16
> -0400> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC:
> tutor@python.org> Subject: Re: [Tutor] trouble with "if"> > adam
> urbas said unto the world upon 05/23/2007 11:57 AM:> > > > Hi all,>
> > > > I've been working with this new program that I wrote.  I
> started out > > with it on a Ti-83, which is much easier to program
> than python.  Now > > I'm trying to transfer the program to python
> but its proving to be quite > > difficult.  I'm not sure what the
> whole indentation thing is for.  And > > now I'm having trouble
> with the if statement things. > > > > #"Circle Data Calculation
> Program:"> > print "Welcome to the Circle Data Calcuation
> Program."> > print> > > > #"Menu 1:"> > print "Pick a shape:">
> > print "(NOTE: You must select the number of the shape and not the
> shape > > itself)"> > print "1 Circle"> > print "2 Square"> > print
> "3 Triangle"> > > > #"User's Choice:"> > shape=raw_input("> ")>
> > > > #"Select Given:"> > if shape == 1:> > print
> "Choose the given value:"> > print "1 radius"> >
> print "2 diameter"> > print "3 circumference"> >
> print "4 area"> > > > #"User's Choice:"> > given=raw_input("> ")> >
> > > if given == 1:> > radius=raw_input("Enter Radius:")> >
> diameter=(radius*2)> > circumference=(diameter*3.14)> >
> area=(radius**2*3.14)> > print "Diameter:", diameter> >
> print "Circumference:", circumference> > print "Area:",
> area> > > > if given == 2:> > diameter=raw_input("Enter
> Diameter:")> > radius=(diameter/2)> >
> circumference=(diameter*3.14)> > area=(radius**2*3.14)> >
> print "Radius:", radius> > print "Circumference:",
> circumference> > print "Area:", area> > > > if given == 3:>
> > circumference=raw_input("Enter Circumference:")> >
> radius=(circumference/3.14/2)> > diameter=(radius*2)> >
> area=(radius**2*3.14)> > print "Radius:", radius> >
> print "Diameter:", diameter> > print "Area:", area> > > >
> if given == 4:> > area=raw_input("Enter Area:")> >
> radius=(area/3.14)> >  > > This is the whole program so
> far, because I haven't quite finished it > > yet.  But I tried to
> get it to display another list of options after you > > select a
> shape but it just does this.> > > > Pick a shape:> > 1 Circle> > 2
> Square> > 3 Triangle> >  >1> >  >1> >   > > > I'm not sure why
> it does that but I do know that it is skipping the > > second list
> of options.> > > > Another of my problems is that I can't figure
> out how to get it to > > accept two different inputs for a
> selection.  Like I want it to accept > > both the number 1 and
> circle as circle then list the options for > > circle.  It won't
> even accept words.  I can only get it to accept > > numbers.  It's
> quite frustrating actually.> > > > Any advice would be greatly
> appreciated.> > Thanks in advance,> > Adam> > > > > > > Adam,> >
> Could you send plain text email rather than html, please? At least
> for > me, your code's indentation is all messed up unless I take
> some steps > to rectify it.> > The problem is that raw_input
> returns a string, and you are testing > whether given is equal to
> integers. See if this helps make things clear:> >  >>> data =
> raw_input('Feed me!')> Feed me!42>  >>> type(data)> >
> >>> data == 42> False>  >>> int(data) == 42> True>   > Best,> >
> Brian vdB 


Adam,

As you can see from the above, the way hotmail is formatting things 
makes the conversation a bit tricky :-) I'm only willing to spend so 
much time trying to sort through it, so I hope what follows helps.

 >>> data = raw_input("Feed me!")
F

Re: [Tutor] trouble with "if"

2007-05-23 Thread Eric Walstad
Hi Adam,

adam urbas wrote:
> when I input a radius, it says:
> 
> can't multiply sequence by non-int of type 'float'
...
> > radius=raw_input("Enter Radius:")
> > diameter=(radius*2)


After you collect the raw_input for the radius, the radius variable
contains a string, not a number (that's what '' means).
Python is calling the string a sequence in your error message.

Try converting your radius to a float type first:

radius=float(raw_input("Enter Radius:"))


As side notes: those '>>>' characters in previous responses are what the
python interactive terminal displays as its command prompt.  The
'type()' function tells you the data type of a variable.

Here's an example of using the Python interactive terminal to debug your
issue (give it a try yourself, but don't enter the '>>>' in the terminal):

[EMAIL PROTECTED]:~$ python
Python 2.5.1 (r251:54863, May  3 2007, 12:27:48)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> radius=raw_input("Enter Radius:")
Enter Radius:5
>>> radius
'5'
>>> type(radius)

>>> diameter=(radius*2)
>>> diameter
'55'   # That is, it is giving you the string '5', two times
>>> type(diameter)

>>>
>>>
>>> radius=float(raw_input("Enter Radius:"))
Enter Radius:5
>>> radius  # radius now contains a float type
5.0
>>> type(radius)

>>> diameter=(radius*2)
>>> diameter
10.0
>>> type(diameter)

>>>

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


[Tutor] smtplib howto send with a subject line

2007-05-23 Thread Daniel McQuay

Hey Guys, I'm having a problem with my script that sends out an email using
smtplib. Whats happening now is when it is send I get a (no subject) where
the subject line should be. I checked a few places such as effbot and some
other online doc but couldn't find any thing about the subject line.

Any help would be much appreciated.

###
#Created by: Daniel McQuay
#This script will send and email
#to verify if the backup was
#successful or not.
###

import smtplib
import sys

emmssg = "/tmp/backup.log"
smtpserver = 'localhost'
AUTHREQUIRED = 0
smtpuser = ''
smtppass = ''

#Recipients who will be getting the emails
RECIPIENTS = ['[EMAIL PROTECTED]']

SENDER = 'Saint_Richards'

#This does not work?
SUBJECT = 'Backup_Log'

emmssg = open('/tmp/backup.log','r').read()

session = smtplib.SMTP(smtpserver)
if AUTHREQUIRED:
   session.login(smtpuser, smtppass)
smtpresult = session.sendmail(SENDER, RECIPIENTS, SUBJECT, emmssg)

if smtpresult:
   errstr = ""
   for recip in smtpresult.keys():
   errstr = """Could not delivery mail to: %s

Server said: %s
%s

%s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
   raise smtplib.SMTPException, errstr

Thanks in advance,

--
Daniel McQuay
Jaluno.com
H: 814.825.0847
M: 814-341-9013
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtplib howto send with a subject line

2007-05-23 Thread Mike Hansen
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Daniel McQuay
> Sent: Wednesday, May 23, 2007 1:49 PM
> To: tutor@python.org
> Subject: [Tutor] smtplib howto send with a subject line
> 
> Hey Guys, I'm having a problem with my script that sends out 
> an email using smtplib. Whats happening now is when it is 
> send I get a (no subject) where the subject line should be. I 
> checked a few places such as effbot and some other online doc 
> but couldn't find any thing about the subject line. 
> 
> Any help would be much appreciated.
> 
> ###
> #Created by: Daniel McQuay  
> #This script will send and email  
> #to verify if the backup was  
> #successful or not.   
> ###
> 
> import smtplib
> import sys
> 
> emmssg = "/tmp/backup.log"
> smtpserver = 'localhost'
> AUTHREQUIRED = 0
> smtpuser = '' 
> smtppass = ''  
> 
> #Recipients who will be getting the emails
> RECIPIENTS = ['[EMAIL PROTECTED]']
> 
> SENDER = 'Saint_Richards'
> 
> #This does not work?
> SUBJECT = 'Backup_Log' 
> 
> emmssg = open('/tmp/backup.log','r').read()
> 
> session = smtplib.SMTP(smtpserver)
> if AUTHREQUIRED:
> session.login(smtpuser, smtppass)
> smtpresult = session.sendmail(SENDER, RECIPIENTS, SUBJECT, emmssg) 
> 
> if smtpresult:
> errstr = ""
> for recip in smtpresult.keys():
> errstr = """Could not delivery mail to: %s
> 
> Server said: %s
> %s
> 
> %s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr) 
> raise smtplib.SMTPException, errstr
> 
> Thanks in advance,
> 
> -- 
> Daniel McQuay
> Jaluno.com
> H: 814.825.0847
> M: 814-341-9013 
> 

It seems a little easier to use the email module along with the smtp
module to create and send a message. 

http://docs.python.org/lib/node162.html

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


Re: [Tutor] smtplib howto send with a subject line

2007-05-23 Thread Daniel McQuay

Thanks Mike, it seems that I'll be easy to incorporate that into my script
as well.

I'll give it a try. I'm still open to other suggestions, though.

On 5/23/07, Mike Hansen <[EMAIL PROTECTED]> wrote:




> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Daniel McQuay
> Sent: Wednesday, May 23, 2007 1:49 PM
> To: tutor@python.org
> Subject: [Tutor] smtplib howto send with a subject line
>
> Hey Guys, I'm having a problem with my script that sends out
> an email using smtplib. Whats happening now is when it is
> send I get a (no subject) where the subject line should be. I
> checked a few places such as effbot and some other online doc
> but couldn't find any thing about the subject line.
>
> Any help would be much appreciated.
>
> ###
> #Created by: Daniel McQuay
> #This script will send and email
> #to verify if the backup was
> #successful or not.
> ###
>
> import smtplib
> import sys
>
> emmssg = "/tmp/backup.log"
> smtpserver = 'localhost'
> AUTHREQUIRED = 0
> smtpuser = ''
> smtppass = ''
>
> #Recipients who will be getting the emails
> RECIPIENTS = ['[EMAIL PROTECTED]']
>
> SENDER = 'Saint_Richards'
>
> #This does not work?
> SUBJECT = 'Backup_Log'
>
> emmssg = open('/tmp/backup.log','r').read()
>
> session = smtplib.SMTP(smtpserver)
> if AUTHREQUIRED:
> session.login(smtpuser, smtppass)
> smtpresult = session.sendmail(SENDER, RECIPIENTS, SUBJECT, emmssg)
>
> if smtpresult:
> errstr = ""
> for recip in smtpresult.keys():
> errstr = """Could not delivery mail to: %s
>
> Server said: %s
> %s
>
> %s""" % (recip, smtpresult[recip][0], smtpresult[recip][1], errstr)
> raise smtplib.SMTPException, errstr
>
> Thanks in advance,
>
> --
> Daniel McQuay
> Jaluno.com
> H: 814.825.0847
> M: 814-341-9013
>

It seems a little easier to use the email module along with the smtp
module to create and send a message.

http://docs.python.org/lib/node162.html

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





--
Daniel McQuay
Linux Jedi
Jaluno.com
H: 814.825.0847
M: 814-341-9013
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtplib howto send with a subject line

2007-05-23 Thread Mike Hansen
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Daniel McQuay
> Sent: Wednesday, May 23, 2007 3:52 PM
> Cc: tutor@python.org
> Subject: Re: [Tutor] smtplib howto send with a subject line
> 
> Thanks Mike, it seems that I'll be easy to incorporate that 
> into my script as well. 
> 
> I'll give it a try. I'm still open to other suggestions, though.
> 

Take a look at this link again(I think you said you looked at it.)

http://effbot.org/librarybook/smtplib.htm

Notice that the body string has From:, To:, Subject: followed by the
from, to, and subject.

body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")

You might need to do something similar to get your subject line although
without the string module since the string methods are built in. 

I'm no expert on how to construct e-mail messages, so take this with a
grain of salt. I'm but a simple caveman programmer(*). 

Mike

* - Phil Hartman "I'm but a simple caveman lawyer" SNL
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] smtplib howto send with a subject line

2007-05-23 Thread Daniel McQuay

Thanks a lot Mike you have been very helpful. I gave that a try in a few
different ways but, with the same results. I'm going to try your first
example.

Best Regards,

On 5/23/07, Mike Hansen <[EMAIL PROTECTED]> wrote:




> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Daniel McQuay
> Sent: Wednesday, May 23, 2007 3:52 PM
> Cc: tutor@python.org
> Subject: Re: [Tutor] smtplib howto send with a subject line
>
> Thanks Mike, it seems that I'll be easy to incorporate that
> into my script as well.
>
> I'll give it a try. I'm still open to other suggestions, though.
>

Take a look at this link again(I think you said you looked at it.)

http://effbot.org/librarybook/smtplib.htm

Notice that the body string has From:, To:, Subject: followed by the
from, to, and subject.

body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")

You might need to do something similar to get your subject line although
without the string module since the string methods are built in.

I'm no expert on how to construct e-mail messages, so take this with a
grain of salt. I'm but a simple caveman programmer(*).

Mike

* - Phil Hartman "I'm but a simple caveman lawyer" SNL
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor





--
Daniel McQuay
Jaluno.com
H: 814.825.0847
M: 814-341-9013
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor