[Tutor] User input

2006-05-22 Thread MATATA EMMANUEL

Hi there,
Can anyone tell me how I'm having trouble executing this piece of code: 
mpg = raw_input (" Enter your mileage:")distance = raw_input ("Enter your distance:")galon_price = raw_input ("Enter you cost per gallon:")make = "Honda"model = "Accord"##print make, model, "mileage is", mpg, "miles per gallon"print "Total trip cost is US$", distance / (mpg * gallon_price)
I get this error when I run it:
print "Total trip cost is US$", distance / (mpg * gallon_price)TypeError: unsupported operand type(s) for *

Matt

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


Re: [Tutor] User input

2006-05-22 Thread Ewald Ertl
MATATA EMMANUEL wrote:
> Hi there,
> 
> Can anyone tell me how I'm having trouble executing this piece of code:
> 
> mpg = raw_input (" Enter your mileage:")
> distance = raw_input ("Enter your distance:")
> galon_price = raw_input ("Enter you cost per gallon:")
> make = "Honda"
> model = "Accord"
> ##
> print make, model, "mileage is", mpg, "miles per gallon"
> print "Total trip cost is US$", distance / (mpg * gallon_price)
> 
> I get this error when I run it:
> 
> print "Total trip cost is US$", distance / (mpg * gallon_price)
> TypeError: unsupported operand type(s) for *
> 
The type which raw_input() returns is a string, so '120'*'5' multiplies
two strings.
Perhaps you can convert your input to a type you need. ( e.g. float ), but you
have to check for a ValueError-Exception if the conversion fails.

HTH Ewald

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


Re: [Tutor] User input

2006-05-22 Thread Kelly Vincent
raw_input reads in the value as a string, so you need
to convert it at some point to a number. You can
either do this at the point where you read the value
in, or when you do the calculation/print. 

To convert it at the input stage (probably the most
logical), add float() such as
mpg = float(raw_input (" Enter your mileage:"))
instead of
mpg = raw_input (" Enter your mileage:")

Or you can do it in the print statement:
print "Total trip cost is US$", float(distance) /
(float(mpg) * float(galon_price))

HTH



--- MATATA EMMANUEL <[EMAIL PROTECTED]> wrote:

-

Hi there,

Can anyone tell me how I'm having trouble executing
this piece of code: 

mpg = raw_input (" Enter your mileage:")
distance = raw_input ("Enter your distance:")
galon_price = raw_input ("Enter you cost per gallon:")
make = "Honda"
model = "Accord"
##
print make, model, "mileage is", mpg, "miles per
gallon"
print "Total trip cost is US$", distance / (mpg *
gallon_price)


I get this error when I run it:

print "Total trip cost is US$", distance / (mpg *
gallon_price)
TypeError: unsupported operand type(s) for *




Matt

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

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


Re: [Tutor] User input

2006-05-22 Thread URBAN LANDREMAN
You had a typo with the variable 'gallon_price' and your formula for the 
total cost was incorrect.  Adding float() for the raw_input helps.

This code gets you closer:

mpg = float(raw_input ("Enter your mileage:"))
distance = float(raw_input ("Enter your distance:"))
gallon_price = float(raw_input ("Enter you cost per gallon:"))
make = "Honda"
model = "Accord"

##
print make, model, "mileage is", mpg, "miles per gallon"
print "Total trip cost is US$" , distance * gallon_price/mpg

Others who are more experienced may have suggestions for more elegant code.

Urban Landreman




>From: "MATATA EMMANUEL" <[EMAIL PROTECTED]>
>To: Tutor@python.org
>Subject: [Tutor] User input
>Date: Mon, 22 May 2006 09:58:04 -0400
>MIME-Version: 1.0
>X-Originating-IP: [199.90.217.113]
>X-Originating-Email: [EMAIL PROTECTED]
>X-Sender: [EMAIL PROTECTED]
>Received: from bay0-mc9-f10.bay0.hotmail.com ([65.54.245.18]) by 
>bay0-imc2-s36.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 
>22 May 2006 07:01:58 -0700
>Received: from smtp-vbr15.xs4all.nl ([194.109.24.35]) by 
>bay0-mc9-f10.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.1830); Mon, 
>22 May 2006 07:01:48 -0700
>Received: from bag.python.org (bag.python.org [194.109.207.14])by 
>smtp-vbr15.xs4all.nl (8.13.6/8.13.6) with ESMTP id k4MDwC09055356;Mon, 22 
>May 2006 15:58:12 +0200 (CEST)(envelope-from [EMAIL PROTECTED])
>Received: from bag.python.org (bag [127.0.0.1])by bag.python.org (Postfix) 
>with ESMTP id 803111E4016;Mon, 22 May 2006 15:58:11 +0200 (CEST)
>Received: from bag.python.org (bag [127.0.0.1])by bag.python.org (Postfix) 
>with ESMTP id A42201E4007for ; Mon, 22 May 2006 15:58:09 
>+0200 (CEST)
>Received: from bag (HELO bag.python.org) (127.0.0.1)by bag.python.org with 
>SMTP; 22 May 2006 15:58:09 +0200
>Received: from hotmail.com (bay107-f11.bay107.hotmail.com [64.4.51.21])by 
>bag.python.org (Postfix) with ESMTPfor ; Mon, 22 May 2006 
>15:58:08 +0200 (CEST)
>Received: from mail pickup service by hotmail.com with Microsoft 
>SMTPSVC;Mon, 22 May 2006 06:58:07 -0700
>Received: from 64.4.51.220 by by107fd.bay107.hotmail.msn.com with HTTP;Mon, 
>22 May 2006 13:58:04 GMT
>X-Message-Info: LsUYwwHHNt1YS4l5TKo3dHnFdM1dcnJLvFKeEzvkf14=
>X-Original-To: Tutor@python.org
>Delivered-To: [EMAIL PROTECTED]
>X-Spam-Status: OK 0.075
>X-OriginalArrivalTime: 22 May 2006 13:58:07.0284 
>(UTC)FILETIME=[C0B69740:01C67DA7]
>X-BeenThere: tutor@python.org
>X-Mailman-Version: 2.1.7
>Precedence: list
>List-Id: Discussion for learning programming with Python 
>List-Unsubscribe: 
>,
>List-Archive: 
>List-Post: 
>List-Help: 
>List-Subscribe: 
>,
>Errors-To: [EMAIL PROTECTED]
>X-Virus-Scanned: by XS4ALL Virus Scanner
>Return-Path: [EMAIL PROTECTED]
>
>
>
>Hi there,
>
>Can anyone tell me how I'm having trouble executing this piece of code:
>
>mpg = raw_input (" Enter your mileage:")
>distance = raw_input ("Enter your distance:")
>galon_price = raw_input ("Enter you cost per gallon:")
>make = "Honda"
>model = "Accord"
>##
>print make, model, "mileage is", mpg, "miles per gallon"
>print "Total trip cost is US$", distance / (mpg * gallon_price)
>
>
>I get this error when I run it:
>
>print "Total trip cost is US$", distance / (mpg * gallon_price)
>TypeError: unsupported operand type(s) for *
>
>
>
>Matt
>


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


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


Re: [Tutor] User input

2006-05-22 Thread MATATA EMMANUEL

Thanks Kelly.
The second version works. 
print "Total trip cost is US$", float(distance) /(float(mpg) * float(galon_price))Matt
 




From:  Kelly Vincent <[EMAIL PROTECTED]>To:  MATATA EMMANUEL <[EMAIL PROTECTED]>, Tutor@python.orgSubject:  Re: [Tutor] User inputDate:  Mon, 22 May 2006 15:19:12 +0100 (BST)>raw_input reads in the value as a string, so you need>to convert it at some point to a number. You can>either do this at the point where you read the value>in, or when you do the calculation/print.>>To convert it at the input stage (probably the most>logical), add float() such as>mpg = float(raw_input (" Enter your mileage:"))>instead of>mpg = raw_input (" Enter your mileage:")>>Or you can do it in the print statement:>print "Total trip cost is US$", float(distance) />(float(mpg) * 
float(galon_price))>>HTH--- MATATA EMMANUEL <[EMAIL PROTECTED]> wrote:>>->>Hi there,>>Can anyone tell me how I'm having trouble executing>this piece of code:>>mpg = raw_input (" Enter your mileage:")>distance = raw_input ("Enter your distance:")>galon_price = raw_input ("Enter you cost per gallon:")>make = "Honda">model = "Accord">##>print make, model, "mileage is", mpg, "miles per>gallon">print "Total trip cost is US$", distance / (mpg *>gallon_price)>>>I get this error when I run it:>>print "Total trip cost is US$", distance / (mpg *>gallon_price)>TypeError: unsupported operand type(s) for 
*>Matt>> > ___> > Tutor maillist  -  Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor> >>

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


Re: [Tutor] User input

2006-05-22 Thread Danny Yoo
> The second version works.
> 
> print "Total trip cost is US$", float(distance) /
> (float(mpg) * float(galon_price))

Hi Matt,

Although this works, we'll probably want to do the type conversions as 
early as possible.  We can write a function input_float() that wraps up 
the float(raw_input()) stuff:

###
def input_float(prompt):
 return float(raw_input(prompt))
###

If we have this as a helper function, then we don't have to worry about 
sprinkling float() conversions all over the place.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problem with a class

2006-05-22 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Everyone,

I am getting an odd traceback when using a class.

The class I am using is

class TriggerMessage:

def __init__(self,data):
"""
Unpacks the passed binary data based on the MQTCM2

format dictated in
the MQ Application Programming Reference
"""

self.data=data
self.structid=None
self.version=None
self.qname=None
self.procname=None
self.trigdata=None
self.appltype=None
self.applid=None
self.envdata=None
self.userdata=None
Self.qmgr=None


def decode(self):
format='4s 4s 48s 48s 64s 4s 256s 128s 128s 48s'
size=struct.calcsize(format)

self.structid, self.version, self.qname, self.processname,  
 \
self.triggerdata, self.appltype, self.applid,   
 \
self.envdata, self.userdata, self.qmgr  
 \
= struct.unpack(format,self.data)


When I try to reference the class with the following statement:

test = TriggerMessage.decode(data)

I get the following traceback

Traceback (most recent call last):
  File "m:\mq\mq\scripts\receiver.py", line 238, in ?
test = TriggerMessage.decode(data)
TypeError: unbound method decode() must be called by TriggerMessage
instance as first argument (got str instance instead)

Does this make any sense?

The variable data passed to the class is valid and is used elsewhere
correctly.


- --
Thank you,
Andrew Robert
Systems Architect
Information Technologies
MFS Investment Management
Phone:   617-954-5882

E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFEcfV4Dvn/4H0LjDwRAo9XAJ4viu2SxR50Mgl4DWucJs0+l84r+gCgkcMy
xs+li5sUfKpz1fgAPw5PhuE=
=9IHp
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Problem with a class

2006-05-22 Thread Terry Carroll
On Mon, 22 May 2006, Andrew Robert wrote:

> class TriggerMessage:
>   
>   def __init__(self,data):


This suggests that it's to be invoked along the lines of:

  foo = TriggerMessage(data)

>   def decode(self):

And this as:

 bar = foo.decode() 

> test = TriggerMessage.decode(data)

I think you wanted something like:

  test1 = TriggerMessage(data)
  test2 = test1.decode()

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


[Tutor] Download file from the web and store it locally.

2006-05-22 Thread MATATA EMMANUEL

I need help on this script. I'm trying to download zip file from the web and store it to my local drive: It is printing info, but doesn't download any thing. Can anyone assist here?
import urllibimport sys# Get a file-like object from the web and store it locally.url = ""http://www.esri.com">"f = urllib.urlopen(url)# connect to the remotetry:    remote = urllib.urlopen(url)except:    print "Connot open URL"    sys.exit()# Read from the object, storing the page's contents in 's' --> want to download parcels.zip.s = f.read(Parcels.zip)m = "D\\Temp\\file"print remote.info()m = urllib.urlretrieveprint "Download Done"f.close()
Thanks



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


[Tutor] help...newbie

2006-05-22 Thread Joe F
Hello, I am pretty sure I am sending this to the right email address.  But anyway I need help.  I started learning python, and I wanna know how to make a simple program, that displays text and when the user presses enter more text is displayed.  And so and so until the end.  Thank you, joe.
		Love cheap thrills? Enjoy PC-to-Phone  calls to 30+ countries for just 2¢/min with Yahoo! Messenger with Voice.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Download file from the web and store it locally.

2006-05-22 Thread Danny Yoo


On Mon, 22 May 2006, MATATA EMMANUEL wrote:

> import urllib
> import sys
> # Get a file-like object from the web and store it locally.
> url = "http://www.co.rowan.nc.us/enviroservs/downloads.htm";
> f = urllib.urlopen(url)
> # connect to the remote
> try:
> remote = urllib.urlopen(url)
> except:
> print "Connot open URL"
> sys.exit()

Don't do this kind of exception handling: it hides information about the 
exception.

If something bad happens, we want to see something other than "Cannot open 
URL".  So instead, let the exception fall through:

###
url = "http://www.co.rowan.nc.us/enviroservs/downloads.htm";
f = urllib.urlopen(url)
remote = urllib.urlopen(url)
###

Or at the very least, modify the exception handler to print out more 
informative error messages other than "An error happened".  We can use the 
'traceback' module in the Standard Library to get us more informative 
error messages.

While you're writing simple programs, I'd recommend avoiding exception 
handlers, just because if something bad happens, we need to preserve all 
the debugging information we can get.



> # Read from the object, storing the page's contents in 's' --> want to
> download parcels.zip.
> s = f.read(Parcels.zip)

What is parcels.zip?  I don't understand what this is trying to do yet.


At this point, 'f' is a file whose contents contains the stuff in

 http://www.co.rowan.nc.us/enviroservs/downloads.htm


I get the feeling you're thinking like a web browser, in the sense that 
you need to first visit the page before downloading the file.

If so, that's not it.  *grin*

If the file you're trying to download has a URL like:

 http://www.co.rowan.nc.us/enviroservs/Parcels.zip

then there is no reason to have Python visit the downloads.htm page first: 
you can go ahead and grab Parcels.zip first, unless the content provider 
has done something weird to their web server.


One other comment:

##
m = urllib.urlretrieve
##

This won't fire off.  In Python, functions that take no arguments still 
need parens to be called.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] problem with class - get message that self is not defined

2006-05-22 Thread Andrew Robert
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi Everyone,


When I try to use the class listed below, I get the statement that self
is not defined.

test=TriggerMessage(data)
var = test.decode(self.qname)

I would have thought that self would have carried forward when I grabbed
an instance of TriggerMessage.

Any ideas on this?



The class in question is:


class TriggerMessage(object):

def __init__(self,data):
"""
Unpacks the passed binary data based on the MQTCM2 format 
dictated in
the MQ Application Programming Reference
"""

self.data=data
self.structid=None
self.version=None
self.qname=None
self.procname=None
self.trigdata=None
self.appltype=None
self.applid=None
self.envdata=None
self.userdata=None
self.qmgr=None


def decode(self):
import struct
format='4s 4s 48s 48s 64s 4s 256s 128s 128s 48s'
size=struct.calcsize(format)
self.data=data  
self.structid, self.version, self.qname, self.processname,  
 \
self.triggerdata, self.appltype, self.applid,   
 \
self.envdata, self.userdata, self.qmgr  
 \
= struct.unpack(format,self.data)



- --
Thank you,
Andrew Robert
Systems Architect
Information Technologies
MFS Investment Management
Phone:   617-954-5882

E-mail:  [EMAIL PROTECTED]
Linux User Number: #201204
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFEcgK6Dvn/4H0LjDwRArwJAKCVdcpLC7IcUzDaMN+L/hVFv8CToQCaA6hP
0KteYe8olY5/72+uktGRCco=
=ToBq
-END PGP SIGNATURE-
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: any good newsgroup or other forum for MP3 internals discussions?

2006-05-22 Thread Hugo González Monteverde
Terry Carroll wrote:
> I apologize for this off-topic question -- the only real connection to 
> Python is that I'm using Python as my programming language.
> 
> I'm writing a program to analyze an MP3 file's contents.  I need to 
> find a newsgroup or other forum to ask some questions about file 
> format internals.  Nothing's jumping out at me, looking through the 
> list of usenet newsgroups.
> 
> I've found dozens of sites with relevant specifications, but am looking at
> one or two rogue files where either I'm misunderstanding the specs, or the
> file is nonconformant (but some MP3 programs can read them, so I'm betting
> it's me).

Are you using any kind of prefabricated Python module for this? Maybe 
their implementation of MP3 tagging is enlightening to you.

Remember that ID3 in MP3 was a dirty hack at the beginning, so it is 
likely that may files are nonconformant or that many different programs 
simply follow their gut, as there was no specification.

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


Re: [Tutor] Download file from the web and store it locally.

2006-05-22 Thread MATATA EMMANUEL

Danny,
I just made some changes, but I still can't get my file saved on my local drive:
here is the new version of the code:
++
import urllibimport sys
# Get a file-like object from the web and store it locally.
url = ""http://www.co.rowan.nc.us/enviroservs/planning_data/countyline.zip">http://www.co.rowan.nc.us/enviroservs/planning_data/countyline.zip"f = urllib.urlopen(url)# connect to the remotetry:    remote = urllib.urlopen(url)except:    print "Connot open URL"    sys.exit()# Read from the object, storing the page's contents in 's'.s = f.read()m = "D\\Temp\\file"print remote.info()m = urllib.urlretrieveprint "Content:"print sprint "Download Done"f.close()
++
It looks like it is almost doing it but I don't know how to correct so far.
--Matt:)
 
 




From:  Danny Yoo <[EMAIL PROTECTED]>To:  MATATA EMMANUEL <[EMAIL PROTECTED]>CC:  Tutor@python.orgSubject:  Re: [Tutor] Download file from the web and store it locally.Date:  Mon, 22 May 2006 11:29:50 -0700 (PDT)>>>On Mon, 22 May 2006, MATATA EMMANUEL wrote:>>>import urllib>>import sys>># Get a file-like object from the web and store it locally.>>url = "">>f = urllib.urlopen(url)>># connect to the remote>>try:>> remote = urllib.urlopen(url)>>except:>> print "Connot open URL">> 
sys.exit()>>Don't do this kind of exception handling: it hides information about >the exception.>>If something bad happens, we want to see something other than >"Cannot open URL".  So instead, let the exception fall through:>>###>url = "">f = urllib.urlopen(url)>remote = urllib.urlopen(url)>###>>Or at the very least, modify the exception handler to print out more >informative error messages other than "An error happened".  We can >use the 'traceback' module in the Standard Library to get us more >informative error messages.>>While you're writing simple programs, I'd recommend 
avoiding >exception handlers, just because if something bad happens, we need >to preserve all the debugging information we can get.># Read from the object, storing the page's contents in 's' --> want >>to>>download parcels.zip.>>s = f.read(Parcels.zip)>>What is parcels.zip?  I don't understand what this is trying to do >yet.>>>At this point, 'f' is a file whose contents contains the stuff in>> http://www.co.rowan.nc.us/enviroservs/downloads.htm>>>I get the feeling you're thinking like a web browser, in the sense >that you need to first visit the page before downloading the file.>>If so, that's not it.  *grin*>>If the file you're trying to download has a 
URL like:>> http://www.co.rowan.nc.us/enviroservs/Parcels.zip>>then there is no reason to have Python visit the downloads.htm page >first: you can go ahead and grab Parcels.zip first, unless the >content provider has done something weird to their web server.>>>One other comment:>>##>m = urllib.urlretrieve>##>>This won't fire off.  In Python, functions that take no arguments >still need parens to be called.

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


Re: [Tutor] problem with class - get message that self is not defined

2006-05-22 Thread Python
On Mon, 2006-05-22 at 14:28 -0400, Andrew Robert wrote:
> When I try to use the class listed below, I get the statement that
> self
> is not defined.
> 
> test=TriggerMessage(data)
> var = test.decode(self.qname)

Perhaps
var = test.decode()

would do what you want.  

It is not clear why you are trying to use a "qname" argument when
decode's only argument is self.  test.decode will bind self to the test
object.

Alan Gauld's web site has a useful discussion of OOP programming.
http://www.freenetpages.co.uk/hp/alan.gauld

-- 
Lloyd Kvam
Venix Corp

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


Re: [Tutor] help...newbie

2006-05-22 Thread Alan Gauld
Hi Joe,

> Hello, I am pretty sure I am sending this to the right email 
> address.

Looks like it :-)

> But anyway I need help.  I started learning python,

How are you learning? Have you found a tutorial yet?
If you already know how to program in another language
the official tutorial on the python web site is quite good.

If you are a complete beginner then the python web site has
a page of suggested tutoriuals, including mine.

> and I wanna know how to make a simple program, that
> displays text and when the user presses enter more text
> is displayed.  And so and so until the end.  Thank you, joe.

Any particular text? Or just random letters?
Do you mean a paging program like more on Unix? (or type in DOS)
Thats a fairly easy project and most of the tutorials should help
you write that. nHave a go and if you get stuck tell us what you
tried, what went wrong (including any error messages) and we'll
try to help out.

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


Re: [Tutor] Download file from the web and store it locally.

2006-05-22 Thread Alan Gauld
> I need help on this script. I'm trying to download zip file from the 
> web and store it to my local drive: It is printing info, but doesn't 
> download any thing.

Looks like you are a wee bit confused on what you are trying to do.

> import urllib
> import sys
> # Get a file-like object from the web and store it locally.
> url = "http://www.co.rowan.nc.us/enviroservs/downloads.htm";
> f = urllib.urlopen(url)

Here you open a link to the url

> # connect to the remote
> try:
>remote = urllib.urlopen(url)

and here you open another to the same url - do you need 2?

> # Read from the object, storing the page's contents in 's' --> want 
> to download parcels.zip.
> s = f.read(Parcels.zip)

But now you are trying to read from the url, but you pass a variable 
name
(Parcels.zip) which is probably not recognised? If it was a filename 
it would
have quotres around it. But read() doesn't take filenames so thatsd 
not
right either.

read() will read the p[age contents of your url back as a string.

If the page has a link to Parcels.zip you will have to find it and 
extract
the url for the file - you will probably find it esier to use your 
browser
to do this, with View->source if necessary

Then use the actual url to the zip file instead of the html file 
above.

Assuming I've understood what you are trying to do correctly.

HTH,

Alan G. 


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


Re: [Tutor] problem with class - get message that self is not defined

2006-05-22 Thread Python
(usually best to click reply-All so that the reply goes to the list)

On Mon, 2006-05-22 at 15:08 -0400, Andrew Robert wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> Well.. inside the class is the decode function.

The decode method depends on "data" which is referenced as a global.
Perhaps data should be passed into decode as a second argument.  My
edited version:

def decode(self, data):
   ^^
import struct
format='4s 4s 48s 48s 64s 4s 256s 128s 128s 48s'
size=struct.calcsize(format)
#self.data=data  # not needed
^   ^^
self.structid, self.version, self.qname, self.processname,  
 \
self.triggerdata, self.appltype, self.applid,   
 \
self.envdata, self.userdata, self.qmgr  
 \
= struct.unpack(format,data)
   ^ (removed self.)

> 
> In that function, several variables are defined from a struct unpack.

I am suggesting that the data to be unpacked gets passed into the decode
method as an argument:
test.decode(data)
I changed the struct.unpack call to use the data argument.

Some additional suggestions:
size is never used.  perhaps you want:
assert size = 
import struct
could be moved to the top of the script and imported once

Hopefully this helps.

> 
> What I need is to get those values out.
> 
> How to do that, I am not exactly clear.
> 
> 
> Andy
> 
> 
> Python wrote:
> > On Mon, 2006-05-22 at 14:28 -0400, Andrew Robert wrote:
> >> When I try to use the class listed below, I get the statement that
> >> self
> >> is not defined.
> >> 
> >> test=TriggerMessage(data)
> >> var = test.decode(self.qname)
> > 
> > Perhaps
> > var = test.decode()
> > 
> > would do what you want.  
> > 
> > It is not clear why you are trying to use a "qname" argument when
> > decode's only argument is self.  test.decode will bind self to the test
> > object.
> > 
> > Alan Gauld's web site has a useful discussion of OOP programming.
> > http://www.freenetpages.co.uk/hp/alan.gauld
> > 
> 
> - --
> Thank you,
> Andrew Robert
> Systems Architect
> Information Technologies
> MFS Investment Management
> Phone:   617-954-5882
> 
> E-mail:  [EMAIL PROTECTED]
> Linux User Number: #201204
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.3 (MingW32)
> 
> iD8DBQFEcgwoDvn/4H0LjDwRAsUuAJ94rHJbBQVxgHyLYlmi1pAhJzkE1QCfR1xK
> sZlx+dHtvaZOOwRpC8tuN6o=
> =2Nsp
> -END PGP SIGNATURE-
-- 
Lloyd Kvam
Venix Corp

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


Re: [Tutor] Download file from the web and store it locally.

2006-05-22 Thread Danny Yoo


On Mon, 22 May 2006, MATATA EMMANUEL wrote:

> I just made some changes, but I still can't get my file saved on my local
> drive:

Ok.  Up to what part of the program works?

Don't just say it doesn't work: can you try isolating what parts are 
working as expected, and what parts aren't working as expected?  Can you 
at least point at what you see wrong?

I do see something weird here, but I want to make sure you can see it too.

I guess I'm trying to say: don't use us on Tutor as a simple program or 
syntax checker.  *grin* You should try figuring things out to the best of 
your abilities too, so that you can learn how to get better.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Download file from the web and store it locally.

2006-05-22 Thread MATATA EMMANUEL

Alan,
I have changed the code as following but it still printing the contains as something I don't know what it is instead of saving locally! If you click the link in this code, you will see the type of file I would like to be able to download in this script. 
import urllibimport sys
# Get a file-like object from the web and store it locally.
url = ""http://www.co.rowan.nc.us/enviroservs/planning_data/countyline.zip">http://www.co.rowan.nc.us/enviroservs/planning_data/countyline.zip"
# connect to the remotetry:    remote = urllib.urlopen(url)except:    print "Connot open URL"    sys.exit()# Read from the object, storing the page's contents in 's'.s = f.read()m = "D\\Temp\\file"print remote.info()m = urllib.urlretrieveprint "Content:"print sprint "Download Done"f.close()




From:  "Alan Gauld" <[EMAIL PROTECTED]>To:  "MATATA EMMANUEL" <[EMAIL PROTECTED]>,Subject:  Re: [Tutor] Download file from the web and store it locally.Date:  Mon, 22 May 2006 20:30:47 +0100>>I need help on this script. I'm trying to download zip file from >>the web and store it to my local drive: It is printing info, but >>doesn't download any thing.>>Looks like you are a wee bit confused on what you are trying to do.>>>import urllib>>import sys>># Get a file-like object from the web and store it locally.>>url = "">>f = urllib.urlopen(url)>>Here you open a link to the 
url>>># connect to the remote>>try:>>remote = urllib.urlopen(url)>>and here you open another to the same url - do you need 2?>>># Read from the object, storing the page's contents in 's' --> want >>to download parcels.zip.>>s = f.read(Parcels.zip)>>But now you are trying to read from the url, but you pass a variable >name>(Parcels.zip) which is probably not recognised? If it was a filename >it would>have quotres around it. But read() doesn't take filenames so thatsd >not>right either.>>read() will read the p[age contents of your url back as a string.>>If the page has a link to Parcels.zip you will have to find it and >extract>the url for the file - you will probably find it 
esier to use your >browser>to do this, with View->source if necessary>>Then use the actual url to the zip file instead of the html file >above.>>Assuming I've understood what you are trying to do correctly.>>HTH,>>Alan G.>>

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


Re: [Tutor] Download file from the web and store it locally.

2006-05-22 Thread MATATA EMMANUEL

Danny,
This script has to do two things:
1) Hit a site where I would like to download something
2) Read it what the file 
3) Download it locally.
I'm a beginner, but according to what it is printing I'm thinking it is opening and is able to read the site (I'm wrong since I have been studying Python for the past two weeks).
import urllibimport sys
# Get a file-like object from the web and store it locally.
url = ""http://www.co.rowan.nc.us/enviroservs/planning_data/countyline.zip">http://www.co.rowan.nc.us/enviroservs/planning_data/countyline.zip"# connect to the remotetry:    remote = urllib.urlopen(url)except:    print "Connot open URL"    sys.exit()# Read from the object, storing the page's contents in 's'.s = f.read()
I'm thinking that up to this level, the script is fine.=
m = "D\\Temp\\file"print remote.info()m = urllib.urlretrieve  ==> Not sure here print "Content:"print sprint "Download Done"f.close()
Matt
 
 




From:  Danny Yoo <[EMAIL PROTECTED]>To:  MATATA EMMANUEL <[EMAIL PROTECTED]>CC:  Tutor@python.orgSubject:  Re: [Tutor] Download file from the web and store it locally.Date:  Mon, 22 May 2006 13:05:13 -0700 (PDT)>>>On Mon, 22 May 2006, MATATA EMMANUEL wrote:>>>I just made some changes, but I still can't get my file saved on my >>local>>drive:>>Ok.  Up to what part of the program works?>>Don't just say it doesn't work: can you try isolating what parts are >working as expected, and what parts aren't working as expected?  Can >you at least point at what you see wrong?>>I do see something weird here, but I want to make sure you 
can see >it too.>>I guess I'm trying to say: don't use us on Tutor as a simple program >or syntax checker.  *grin* You should try figuring things out to the >best of your abilities too, so that you can learn how to get better.

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


Re: [Tutor] Download file from the web and store it locally.

2006-05-22 Thread Alan Gauld
> I have changed the code as following but it still printing the 
> contains as something I don't know what it is instead of saving 
> locally!

You need to step back a bit and get a better understanding of 
variables
and functions and how to use them. You are trying to run before you
can walk.

> import urllib
> import sys
>
> # Get a file-like object from the web and store it locally.
>
> url = 
> "http://www.co.rowan.nc.us/enviroservs/planning_data/countyline.zip";
>
>
> # connect to the remote
> try:
>remote = urllib.urlopen(url)
> except:
>print "Connot open URL"
>sys.exit()

At this stage you have a connection to the zip file.

> # Read from the object, storing the page's contents in 's'.
> s = f.read()

But here you are trying to read from f which doesn't exist!

> m = "D\\Temp\\file"

And here you assign a filename to m (except the filename
is invalid because it doesn't have a colon after the D)

> print remote.info()

Now this should print some info about your connection

> m = urllib.urlretrieve

Now you replace the filename with a function from the urllib module.

> print "Content:"
> print s
> print "Download Done"

You print out the contents of s which probanly are invalid
since f didn't exist.

> f.close()

And you close f which still doesn't exist.

You need to sit down and work through which variables you need
and which functions of urllib you need.

I suspect you only need to use urllib.urlretrieve() and your total
code should only be 3 or 4 lines long.

Alan G.


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


Re: [Tutor] help...newbie

2006-05-22 Thread Alan Gauld
> Hey Alan, I have indeed found a tutorial.  "A Byte Of Python"

Yes, that should be fine for you.

> So far it's really good.  I'm down around functions, and is this far 
> enough?

I'm not sure which order it covers things but somewhere soon
you should find the stuff about reading text from files and you
should already know about how to read input from a user and
write output to the screen.

The next step is to try actually writing the program and see how it 
goes.
It probably won;t work first time, but try to woprk out why and fix 
it.
If you get stuck send a note to the tutor list and someone will help 
out.

> So is that enough to use the python tutorial?

A C background would be fine, but since you already have a Byte of
Python then stick with it...

Alan G.

> Alan Gauld <[EMAIL PROTECTED]> wrote: Hi Joe,
>
>> Hello, I am pretty sure I am sending this to the right email
>> address.
>
> Looks like it :-)
>
>> But anyway I need help.  I started learning python,
>
> How are you learning? Have you found a tutorial yet?
> If you already know how to program in another language
> the official tutorial on the python web site is quite good.
>
> If you are a complete beginner then the python web site has
> a page of suggested tutoriuals, including mine.
>
>> and I wanna know how to make a simple program, that
>> displays text and when the user presses enter more text
>> is displayed.  And so and so until the end.  Thank you, joe.
>
> Any particular text? Or just random letters?
> Do you mean a paging program like more on Unix? (or type in DOS)
> Thats a fairly easy project and most of the tutorials should help
> you write that. nHave a go and if you get stuck tell us what you
> tried, what went wrong (including any error messages) and we'll
> try to help out.
>
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
>
>
>
> -
> Be a chatter box. Enjoy free PC-to-PC calls  with Yahoo! Messenger 
> with Voice. 


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


Re: [Tutor] problem with class - get message that self is not defined

2006-05-22 Thread Alan Gauld
> When I try to use the class listed below, I get the statement that 
> self
> is not defined.
>
> test=TriggerMessage(data)
> var = test.decode(self.qname)
>
> I would have thought that self would have carried forward when I 
> grabbed
> an instance of TriggerMessage.

self is a special varianble that is only defined inside of a
method of an object. It refers to the object itself (hence the name!)
Thus you cannot pass self.qname into a method unless you are
already inside another object's method.

You can read about this in more edetail in the OOP topic
of my tutor but I'll try to illustrate here:

class C:
def method(self,x):
 self.var = x
def g(self, anObj):
 anObj.f(self.var)

class D:
def f(self, val):
   print val

c = C()
c.method(42)

creates an object called c and executes its method with a
value of 42. This executes the function

C.method(c,42)

where self takes the values c and x 42
The end result is that object c has a data member
called var with the value 42

d = D()
c.g(d)

creates a new object d
calls the g method of c passing object d as argument
executes the function

C.g(c,d)

where self takes on the value c and anObj takes on d
C.g() then calls d.f(self.var) which executes

D.f(d,c.var)

that is, the self in D.f() is d and the self in C.g() = c

I hope that makes sense.

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


[Tutor] IDLE: configuration

2006-05-22 Thread Cecilia Alm
Hi,

How can I set tab as default indendation for the file editor window in
IDLE? I tried to change this in "Configuration Window" and "Apply", but
still get 4 spaces. What does work is setting indentation to "8" and
then enabling toggle tabs when I open a new window. 

Thanks,
Cecilia

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


[Tutor] Calendar Module

2006-05-22 Thread Shuai Jiang
Hello, I just got Python In a Nutshell and decided to play around with the time section. While playing with the calendar module, I encountered a problem:>>> import calendar>>> calendar.calendar
(2006)'  2006\n\n  January   February   March\nMo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su\n   1 1  2  3  4  5 1  2  3  4  5\n 2  3  4  5  6  7  8   6  7  8  9 10 11 12   6  7  8  9 10 11 12\n 9 10 11 12 13 14 15  13 14 15 16 17 18 19  13 14 15 16 17 18 19\n16 17 18 19 20 21 22  20 21 22 23 24 25 26  20 21 22 23 24 25 26\n23 24 25 26 27 28 29  27 28 27 28 29 30 31\n30 31\n\n   April  May   June\nMo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su\n    1  2   1  2  3  4  5  6  7    1  2  3  4\n 3  4  5  6  7  8  9   8  9 10 11 12 13 14   5  6  7  8  9 10 11\n10 11 12 13 14 15 16  15 16 17 18 19 20 21  12 13 14 15 16 17 18\n17 18 19 20 21 22 23  22 23 24 25 26 27 28  19 20 21 22 23 24 25\n24 25 26 27 28 29 30  29 30 31  26 27 28 29 30\n\n    July August  September\nMo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su\n    1  2  1  2  3  4  5  6   1  2  3\n 3  4  5  6  7  8  9   7  8  9 10 11 12 13   4  5  6  7  8  9 10\n10 11 12 13 14 15 16  14 15 16 17 18 19 20  11 12 13 14 15 16 17\n17 18 19 20 21 22 23  21 22 23 24 25 26 27  18 19 20 21 22 23 24\n24 25 26 27 28 29 30  28 29 30 31   25 26 27 28 29 30\n31\n\n  October   November  December\nMo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su\n   1 1  2  3  4  5   1  2  3\n 2  3  4  5  6  7  8   6  7  8  9 10 11 12   4  5  6  7  8  9 10\n 9 10 11 12 13 14 15  13 14 15 16 17 18 19  11 12 13 14 15 16 17\n16 17 18 19 20 21 22  20 21 22 23 24 25 26  18 19 20 21 22 23 24\n23 24 25 26 27 28 29  27 28 29 30   25 26 27 28 29 30 31\n30 31\n'
>>> I can't seem to figure out how to make it look prettierThanks in advanceMarshall Jiang-- Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Rick Cook, The Wizardry Compiled
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calendar Module

2006-05-22 Thread John Fouhy
On 23/05/06, Shuai Jiang <[EMAIL PROTECTED]> wrote:
> Hello,
> I just got Python In a Nutshell and decided to play around with the time
> section. While playing with the calendar module, I encountered a problem:
>
> >>> import calendar
> >>> calendar.calendar (2006)
> '  2006\n\n  January
>February   March\nMo Tu We Th Fr Sa Su
> Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su\n   1
> 1  2  3  4  5 1  2  3  4  5\n 2  3  4  5  6  7  8   6  7
[...]
> I can't seem to figure out how to make it look prettier
> Thanks in advance

See those '\n' characters? They mean "start a new line" in some
contexts (such as text output and graphical editors). You can make
python interpret them by asking it to print the output.  For example:

>>> s = 'Hello\n   World!\n-\n --- \n  -  \n'
>>> s
'Hello\n   World!\n-\n --- \n  -  \n'
>>> print s
Hello
   World!
-
 ---
  -

>>>

Or, you could try typing "print calendar.calendar(2006)" into your console :-)

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


[Tutor] StringIO

2006-05-22 Thread kakada
Hello list,

I want to use the module StringIO as read and write strings as files, I
looked into document but cannot understand.
Could anyone give me a simple example?

something like:
from StringIO import *
fin = StringIO("abc")
.
How can I used fin?

Thanks,

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


[Tutor] (no subject)

2006-05-22 Thread jenw
I am looking for Matthew White.  How can I reach him.
Jen

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


Re: [Tutor] StringIO

2006-05-22 Thread Danny Yoo
> I want to use the module StringIO as read and write strings as files, I 
> looked into document but cannot understand. Could anyone give me a 
> simple example?
>
> something like:
> from StringIO import *
> fin = StringIO("abc")
> .
> How can I used fin?

'fin' is a file-like object at this point, so you can do things 
like:

 fin.read(1)

to get a single byte.  The list of things we can do with file-like objects 
is here:

 http://www.python.org/doc/lib/bltin-file-objects.html


Does this help?  Good luck!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] (no subject)

2006-05-22 Thread Danny Yoo


On Mon, 22 May 2006, [EMAIL PROTECTED] wrote:

> I am looking for Matthew White.  How can I reach him.

Hi Jennifer,

We probably can not help you much with this.  It would help very much if 
you could somehow explain why you posted this question here on Tutor.  It 
is not obvious how this is related to Python, learning, or programming.

This doesn't mean that your question is irrelevant altogether, but only 
that we don't have much expertise to track this person down for you from 
the whole entire world.  At a whim, I did a google search for "matthew 
white python".  There is a Matthew White that has been answering on 
Python-Tutor.  See:

 http://aspn.activestate.com/ASPN/Mail/Message/python-Tutor/3115167

I really don't know if this is who you are referring to, but this is the 
best I can do with my assumptions.  Next time, please provide more context 
here.

Good luck to you.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calendar Module

2006-05-22 Thread Alan Gauld
use print!

print calendart.calendar(2006)

Alan G.

- Original Message - 
From: "Shuai Jiang" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, May 23, 2006 2:09 AM
Subject: [Tutor] Calendar Module


Hello,
I just got Python In a Nutshell and decided to play around with the 
time
section. While playing with the calendar module, I encountered a 
problem:

>>> import calendar
>>> calendar.calendar(2006)
'  2006\n\n  January
February   March\nMo Tu We Th Fr Sa Su  Mo Tu We 
Th Fr
Sa Su  Mo Tu We Th Fr Sa Su\n   1 1  2 
3
4  5 1  2  3  4  5\n 2  3  4  5  6  7  8   6  7  8  9 
10 11
12   6  7  8  9 10 11 12\n 9 10 11 12 13 14 15  13 14 15 16 17 
18
19  13 14 15 16 17 18 19\n16 17 18 19 20 21 22  20 21 22 23 24 
25
26  20 21 22 23 24 25 26\n23 24 25 26 27 28 29  27
28 27 28 29 30 31\n30 31\n\n
April  May   June\nMo Tu We Th 
Fr Sa
Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su\n 
1
2   1  2  3  4  5  6  71  2  3  4\n 3  4  5  6  7 
8
9   8  9 10 11 12 13 14   5  6  7  8  9 10 11\n10 11 12 13 14 
15
16  15 16 17 18 19 20 21  12 13 14 15 16 17 18\n17 18 19 20 21 
22
23  22 23 24 25 26 27 28  19 20 21 22 23 24 25\n24 25 26 27 28 
29
30  29 30 31  26 27 28 29 30\n\n
July August  September\nMo Tu We 
Th Fr
Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su\n
1  2  1  2  3  4  5  6   1  2  3\n 3  4  5  6 
7  8
9   7  8  9 10 11 12 13   4  5  6  7  8  9 10\n10 11 12 13 14 
15
16  14 15 16 17 18 19 20  11 12 13 14 15 16 17\n17 18 19 20 21 
22
23  21 22 23 24 25 26 27  18 19 20 21 22 23 24\n24 25 26 27 28 
29
30  28 29 30 31   25 26 27 28 29 30\n31\n\n
October   November  December\nMo Tu We 
Th Fr
Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa
Su\n   1 1  2  3  4  5   1 
2
3\n 2  3  4  5  6  7  8   6  7  8  9 10 11 12   4  5  6  7  8 
9
10\n 9 10 11 12 13 14 15  13 14 15 16 17 18 19  11 12 13 14 15 
16
17\n16 17 18 19 20 21 22  20 21 22 23 24 25 26  18 19 20 21 22 
23
24\n23 24 25 26 27 28 29  27 28 29 30   25 26 27 28 29 
30
31\n30 31\n'
>>>

I can't seem to figure out how to make it look prettier
Thanks in advance

Marshall Jiang
-- 
Programming today is a race between software engineers striving to 
build
bigger and better idiot-proof programs, and the Universe trying to 
produce
bigger and better idiots. So far, the Universe is winning.
Rick Cook, The Wizardry Compiled


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


Re: [Tutor] StringIO

2006-05-22 Thread kakada
Danny Yoo wrote:
>> I want to use the module StringIO as read and write strings as files,
>> I looked into document but cannot understand. Could anyone give me a
>> simple example?
>>
>> something like:
>> from StringIO import *
>> fin = StringIO("abc")
>> .
>> How can I used fin?
>
> 'fin' is a file-like object at this point, so you can do things like:
>
> fin.read(1)
>
> to get a single byte.  The list of things we can do with file-like
> objects is here:
>
> http://www.python.org/doc/lib/bltin-file-objects.html
>
>
> Does this help?  Good luck!
Actually, what I want is creating a kind of file that is just located in
memory not file system.
I want to have a filename for my convert(inputFileName, outputFileName)
How can I get filename?
doing:
fin.name() is impossible!

All above, I want to test it in unittest.
>
>

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