Re: [Tutor] Help needed

2011-04-08 Thread Andre Engels
On Fri, Apr 8, 2011 at 3:57 AM, Aaron Brown  wrote:
> I am in an online python class and am failing badly.  I am not sure where
> the problem is here but any insight would be great.
>
> def main():
>     while (True):
>     allowed = int(input("Please enter minutes allowed between 100 and
> 700: "))
>     used = int(input("How many minutes were used: "))
>     totalOver = used - allowed
>     totalDue = (64.95 + (0.15*totalOver))
>     if(totalOver > 0):
>     print("You were over your minutes by " + str(totalOver))
>     else:
>     totalOver = 0
>     print("You were not over your minutes for the month")
>     print ("Do you want to end program? Enter yes or no:")
>     toEnd = raw_input()
>     if toEnd == "yes":
>     print("MONTHLY USE REPORT")
>     print("Minutes allowed were " + str(allowed))
>     print("Minutes used were " + str(used))
>     print("Minutes over were " + str(totalOver))
>     print("Total due is $ " + str(totalDue(totalOver))
>
> I keep getting a syntax error in a blank line at the bottom.  I have tried
> to end it with main() but it errors on the main as well?

If you get a syntax error, the problem almost always is in the line
shown or the line directly above it. A blank line at the end is not a
syntax error, so in this case it is the line above it:

print("Total due is $ " + str(totalDue(totalOver))

This line has three left brackets but only two right brackets. Add one
right bracket and your program should run (however, it will not work
correctly - in the above line you try to call totalDue, but it is a
number, not a function or method).

-- 
André Engels, andreeng...@gmail.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help needed

2011-04-08 Thread Alan Gauld


"Aaron Brown"  wrote

I am in an online python class and am failing badly.  I am not sure 
where

the problem is here but any insight would be great.


When posting always include the full error text since
it usually helps locate the precise location more clearly
than a verbal description or summary.


def main():
   while (True):


How do you intend to exit?
I don't see any return or break statements?
But thats not the immediate issue

   allowed = int(input("Please enter minutes allowed between 100 
and

700: "))
   used = int(input("How many minutes were used: "))
   totalOver = used - allowed
   totalDue = (64.95 + (0.15*totalOver))
   if(totalOver > 0):
   print("You were over your minutes by " + str(totalOver))


You don;t need to call str() because print can do that for you.
All you need is:

print("You were over your minutes by ", totalOver)


   else:
   totalOver = 0
   print("You were not over your minutes for the month")
   print ("Do you want to end program? Enter yes or no:")
   toEnd = raw_input()


Most of the code looks like Python v3 but this line is from Pyhon 
v2...

raw_input has been replaced by input() in v3.
However, that should generate a NameError not a SyntaxError.


   if toEnd == "yes":
   print("MONTHLY USE REPORT")
   print("Minutes allowed were " + str(allowed))
   print("Minutes used were " + str(used))
   print("Minutes over were " + str(totalOver))
   print("Total due is $ " + str(totalDue(totalOver))

I keep getting a syntax error in a blank line at the bottom.  I have 
tried

to end it with main() but it errors on the main as well?


The only probblem that jumps out at me is the raw_input()
but that would not be a syntax error...

HTH,


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


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


Re: [Tutor] Help needed

2011-04-08 Thread Christian Witts

On 08/04/2011 03:57, Aaron Brown wrote:
I am in an online python class and am failing badly.  I am not sure 
where the problem is here but any insight would be great.

def main():
while (True):
allowed = int(input("Please enter minutes allowed between 100 
and 700: "))

used = int(input("How many minutes were used: "))
totalOver = used - allowed
totalDue = (64.95 + (0.15*totalOver))
if(totalOver > 0):
print("You were over your minutes by " + str(totalOver))
else:
totalOver = 0
print("You were not over your minutes for the month")
print ("Do you want to end program? Enter yes or no:")
toEnd = raw_input()
if toEnd == "yes":
print("MONTHLY USE REPORT")
print("Minutes allowed were " + str(allowed))
print("Minutes used were " + str(used))
print("Minutes over were " + str(totalOver))
print("Total due is $ " + str(totalDue(totalOver))

I keep getting a syntax error in a blank line at the bottom.  I have 
tried to end it with main() but it errors on the main as well?

Help Please,
Aaron Brown


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

Your last line is missing a closing parenthesis resulting in a Syntax Error.

--
Kind Regards,
Christian Witts


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


[Tutor] Sound question

2011-04-08 Thread Jan Erik Moström
Hi,

A couple of my students need to be able to play sounds, controlling start & 
stop, play sound from files and if possible generate sinus wave sounds.

I looked around and found several packages but they all seem to have some kind 
platform restrictions. Does anyone have recommendations for what packages to 
use? I would prefer some cross-platform package for at least Windows and Mac 
but unix/linux would be a plus.

I assume that winsound is the recommended package for Windows only (I'm a Mac 
person so I don't really know myself)

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


Re: [Tutor] How to use a module when only import package

2011-04-08 Thread leechau

Steven wrote:

leechau wrote:

I wrote module1 in package1, and want to use a method named 'method1' in
module1, the caller(test.py) is like this:

import package1
package1.module1.method1()

[...]

When i run test.py, the output is:
AttributeError: 'module' object has no attribute 'module1'
File "e:\MyDoc\GODU_BVT\test.py", line 2, in 
  package1.module1.method1()

If test.py is modified to:
import package1.module1
...
then everything goes well.


Yes, that is correct, and that is a deliberate design.

What if your package had a 1000 sub-modules, each of which were big? You
wouldn't want loading the main package to automatically load all 1000
sub-modules, if you only needed 1.

You either import the sub-module by hand:

import package1.module1

and now you can use package1.module1.method1 (not really a method,
actually a function). If you want module1 to automatically be available
after importing the package, include one of these in the package1
__init__.py file:

import module1  # should work in Python 2


and now package1 will include the module1 in its namespace.


--
Steven


Thanks for Steven's exellent and patient explanations. How should I do 
if automatically import a module in Python 3? Thanks again.


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


Re: [Tutor] Sound question

2011-04-08 Thread col speed
On 8 April 2011 15:54, Jan Erik Moström  wrote:

> Hi,
>
> A couple of my students need to be able to play sounds, controlling start &
> stop, play sound from files and if possible generate sinus wave sounds.
>
> I looked around and found several packages but they all seem to have some
> kind platform restrictions. Does anyone have recommendations for what
> packages to use? I would prefer some cross-platform package for at least
> Windows and Mac but unix/linux would be a plus.
>
> I assume that winsound is the recommended package for Windows only (I'm a
> Mac person so I don't really know myself)
>
> - jem
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
Personally, I've found pygame great for playing sounds.


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


Re: [Tutor] Sound question

2011-04-08 Thread Emmanuel Ruellan
On Fri, Apr 8, 2011 at 10:54 AM, Jan Erik Moström wrote:

>
>
> A couple of my students need to be able to play sounds, controlling start &
> stop, play sound from files and if possible generate sinus wave sounds.
>

I've used Snack to generate sounds on both Windows and Linux.

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


[Tutor] NLP

2011-04-08 Thread Ranjith Kumar
Hi all,
Can anyone suggest me any best Natural Language Processing in
python other than nltk.

-- 
Cheers,
Ranjith Kumar K,
Chennai.

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


[Tutor] Evaluating program running time?

2011-04-08 Thread Cory Teshera-Sterne
Hi all,

I have a small(ish) Python program, and I need to be able to log the running
time. This isn't something I've ever really encountered, and I've been led
to believe it can be a little hairy. Are there any Python-specific
approaches to this? I found the "timeit" module, but that doesn't seem to be
quite what I'm looking for.

Thanks for any insight,
Cory

-- 
Cory Teshera-Sterne
Mount Holyoke College, 2010
www.linkedin.com/in/corytesherasterne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Evaluating program running time?

2011-04-08 Thread bob gailer

On 4/8/2011 2:29 PM, Cory Teshera-Sterne wrote:

Hi all,

I have a small(ish) Python program, and I need to be able to log the 
running time. This isn't something I've ever really encountered, and 
I've been led to believe it can be a little hairy. Are there any 
Python-specific approaches to this? I found the "timeit" module, but 
that doesn't seem to be quite what I'm looking for.


I like to use the time module

import time
start = time.time()
rest of program
print time.time() - start

I believe that gives best precisioni on *nix
On Windows use time.clock() )instead.

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

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


Re: [Tutor] Evaluating program running time?

2011-04-08 Thread Prasad, Ramit
Odd, my previous email seems to have gotten lost

Cory,
See: http://stackoverflow.com/questions/156330/get-timer-ticks-in-python
It is basically what Bob mentions, but with a few more details / alternatives.


Ramit



Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


-Original Message-
From: tutor-bounces+ramit.prasad=jpmchase@python.org 
[mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of bob 
gailer
Sent: Friday, April 08, 2011 2:49 PM
To: Cory Teshera-Sterne
Cc: tutor@python.org
Subject: Re: [Tutor] Evaluating program running time?

On 4/8/2011 2:29 PM, Cory Teshera-Sterne wrote:
> Hi all,
>
> I have a small(ish) Python program, and I need to be able to log the 
> running time. This isn't something I've ever really encountered, and 
> I've been led to believe it can be a little hairy. Are there any 
> Python-specific approaches to this? I found the "timeit" module, but 
> that doesn't seem to be quite what I'm looking for.

I like to use the time module

import time
start = time.time()
rest of program
print time.time() - start

I believe that gives best precisioni on *nix
On Windows use time.clock() )instead.

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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Evaluating program running time?

2011-04-08 Thread Prasad, Ramit
Cory,
See: http://stackoverflow.com/questions/156330/get-timer-ticks-in-python

Ramit



Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

From: tutor-bounces+ramit.prasad=jpmchase@python.org 
[mailto:tutor-bounces+ramit.prasad=jpmchase@python.org] On Behalf Of Cory 
Teshera-Sterne
Sent: Friday, April 08, 2011 1:29 PM
To: tutor@python.org
Subject: [Tutor] Evaluating program running time?

Hi all,

I have a small(ish) Python program, and I need to be able to log the running 
time. This isn't something I've ever really encountered, and I've been led to 
believe it can be a little hairy. Are there any Python-specific approaches to 
this? I found the "timeit" module, but that doesn't seem to be quite what I'm 
looking for.

Thanks for any insight,
Cory

--
Cory Teshera-Sterne
Mount Holyoke College, 2010
www.linkedin.com/in/corytesherasterne


This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to European legal entities.___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to use a module when only import package

2011-04-08 Thread Karim

On 04/08/2011 11:13 AM, leechau wrote:

Steven wrote:

leechau wrote:
I wrote module1 in package1, and want to use a method named 
'method1' in

module1, the caller(test.py) is like this:

import package1
package1.module1.method1()

[...]

When i run test.py, the output is:
AttributeError: 'module' object has no attribute 'module1'
File "e:\MyDoc\GODU_BVT\test.py", line 2, in 
  package1.module1.method1()

If test.py is modified to:
import package1.module1
...
then everything goes well.


Yes, that is correct, and that is a deliberate design.

What if your package had a 1000 sub-modules, each of which were big? You
wouldn't want loading the main package to automatically load all 1000
sub-modules, if you only needed 1.

You either import the sub-module by hand:

import package1.module1

and now you can use package1.module1.method1 (not really a method,
actually a function). If you want module1 to automatically be available
after importing the package, include one of these in the package1
__init__.py file:

import module1  # should work in Python 2


and now package1 will include the module1 in its namespace.


--
Steven


Thanks for Steven's exellent and patient explanations. How should I do 
if automatically import a module in Python 3? Thanks again.


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

Hello,

Test it simply!
You will get answer in 3 seconds.

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


Re: [Tutor] Sound question

2011-04-08 Thread Alan Gauld


"Jan Erik Moström"  wrote


A couple of my students need to be able to play sounds, ...

I looked around and found several packages but they all
seem to have some kind platform restrictions.


Sound tends to be platform specific but pygame seems
to have hidden most of that. Then again it may not offer
all the facilities the dedicated packages do, and it may
be a bit heavyweight for sound alone. But worth a look see.

Personally I've only played with it on Windows but it
claims to work across platforms...

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


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


[Tutor] Python 3.2 Install Not Responding To Python Command!!

2011-04-08 Thread Nevins Duret

Hello Everyone,

I recently installed python3.2 by building it from source and 
noticed that it may have not been

installed 100% correctly.  When I type:

python

in the Terminal in Ubuntu 10.10 Maverick, I'm noticing that get the error:

bash: /usr/bin/python: is a directory

However, when I type either:

python2.6--then python2.6 launches as before

python3.1--then python3.1 launches

python3 or python3.2--then python 3.2 launches

I just want to be sure that I have python installed correctly.  So far, 
everything seems to work, however I think this maybe leading to some 
upgrade issues that I am having with my Update Manager.



Any help on this would be greatly appreciated.

Best Regards,

Nevins Duret


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


Re: [Tutor] Sound question

2011-04-08 Thread Nick Stinemates
On Fri, Apr 8, 2011 at 5:12 PM, Alan Gauld wrote:

>
> "Jan Erik Moström"  wrote
>
>  A couple of my students need to be able to play sounds, ...
>>
>>
>> I looked around and found several packages but they all
>> seem to have some kind platform restrictions.
>>
>
> Sound tends to be platform specific but pygame seems
> to have hidden most of that. Then again it may not offer
> all the facilities the dedicated packages do, and it may
> be a bit heavyweight for sound alone. But worth a look see.
>
> Personally I've only played with it on Windows but it
> claims to work across platforms...
>

Personally I've only played with it on Linux so it seems we have it covered
:)

Nick


>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python 3.2 Install Not Responding To Python Command!!

2011-04-08 Thread Lie Ryan
On 04/09/11 11:25, Nevins Duret wrote:
> Hello Everyone,
> 
> I recently installed python3.2 by building it from source and
> noticed that it may have not been
> installed 100% correctly.  

This is probably off topic in python tutor mailing list, better asked on
the main mailing list or Ubuntu mailing list. However..

> When I type:
> 
> python
> 
> in the Terminal in Ubuntu 10.10 Maverick, I'm noticing that get the error:
> 
> bash: /usr/bin/python: is a directory

Yes, your python is not correctly installed, `python` should be a
symbolic link to the system's default python version. Try reinstalling
all python. What's the output of `whereis python` and `echo $PATH`?

> However, when I type either:
> 
> python2.6--then python2.6 launches as before
> 
> python3.1--then python3.1 launches
> 
> python3 or python3.2--then python 3.2 launches
> 
> I just want to be sure that I have python installed correctly.  So far,
> everything seems to work, however I think this maybe leading to some
> upgrade issues that I am having with my Update Manager.
> 
> 
> Any help on this would be greatly appreciated.
> 
> Best Regards,
> 
> Nevins Duret
> 
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 


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


Re: [Tutor] Evaluating program running time?

2011-04-08 Thread Lie Ryan
On 04/09/11 04:29, Cory Teshera-Sterne wrote:
> Hi all,
> 
> I have a small(ish) Python program, and I need to be able to log the
> running time. This isn't something I've ever really encountered, and
> I've been led to believe it can be a little hairy. Are there any
> Python-specific approaches to this? I found the "timeit" module, but
> that doesn't seem to be quite what I'm looking for.
> 

import cProfile
...
def main():
...

cProfile.run('main()')

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