[Tutor] noob

2010-11-29 Thread Mary
Dear Tutors:

Thank you for your time.I am trying to do first assignment (ps1a+b) onMIT open 
study, finding the 1000th prime in part a and doing something with import.math 
and logs in part b, but I'm not there yet. The little build i did to find 
primes does fine until, for some reason, 95 shows up, and later other multiples 
of 5 jump into the mix without being invited.I end up almost 200 primes off by 
the 1000 count. Is it me? Have uninstalled and reinstalled 2.7 twice. Here is 
code:

per = 25
num = 3
yep = 0

while per  0:

for den in range(2, num):

if num % den == 0:
num = num + 2

else: yep = (num)


print yep

per = per - 1


num = num  + 2


thank you again, 
M___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Temperature Scales

2010-11-29 Thread Alan Gauld


Andre Jeyarajan andrejeyara...@rogers.com wrote


Write two functions that will convert temperatures
back and forth from the Celsius and Fahrenheit temperature
scales (using raw_input)


If we ignore the raw_input bit you have done what you were asked.


def C_F(x):
   y = (x-32)*(5.0/9)
   print y


Although as a stylistic point it is better to return values from
functions rather than print the values inside the functions.
You can then print the result of the function like this:

print C_F(x)


def F_C(x):
y = (x*9.0/5)+32
print y


I have created the two functions but I don’t know what to do from 
here.


I suspect the assignment expects you to provide some code
that uses them, to show they work. Given the raw_input hint I'd
surmise they want you to ask the user for a temperature in C or F
and use your functions to print the corresponding temperature
in the other scale.

You will need to convert the raw_input value to an integer for
the functions to work. Can you do that?

--
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] noob

2010-11-29 Thread Alan Gauld


Mary sharky5...@comcast.net wrote


finding the 1000th prime


The little build i did to find primes does fine until, for some 
reason,

95 shows up, and later other multiples of 5 .Is it me?
Have uninstalled and reinstalled 2.7 twice.


It is always tempting when you start programming to assume
there must be something wrong with the tool. Sadly, it is virtually
never the case, it is the programmer at fault. :-)

I've added some questions/comments below...


per = 25 # not sure why you start at 25...
num = 3 # I'm assuming this is the number under test?
yep = 0  # and this is the count of primes?

while per  0:
   for den in range(2, num):  # den is denominator maybe?
   if num % den == 0: # this bit puzzles me.
num = num + 2
   else: yep = (num)  # what do you think the 
parentheses do here?

   print yep
   per = per - 1
   num = num  + 2


I confess I don't follow the algorithm here, I'm not sure where the
primes are being stored, I don't know how you detect when you
have reached the 1000th. I'm not even sure there is a valid test
for a prime.

Try searching wikipedia, there are easier ways to find primes
and there are also easier ways to find a specific prime.
Getting the algorithm right is the first challenge, coding it
is the easy bit.

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] noob

2010-11-29 Thread Andre Engels
On Mon, Nov 29, 2010 at 6:57 AM, Mary sharky5...@comcast.net wrote:
 Dear Tutors:

 Thank you for your time.I am trying to do first assignment (ps1a+b) onMIT
 open study, finding the 1000th prime in part a and doing something with
 import.math and logs in part b, but I'm not there yet. The little build i
 did to find primes does fine until, for some reason, 95 shows up, and later
 other multiples of 5 jump into the mix without being invited.I end up almost
 200 primes off by the 1000 count. Is it me? Have uninstalled and reinstalled
 2.7 twice. Here is code:

Your primality tester is incorrect. When you find a divisor you go on
to check the number that is 2 more, but you start with the same
divisor. If the new number you check is not a prime number, but only
has divisors smaller than the checked divisor, your program will
falsely recognize it as prime.

To make it more clear what I mean, I will show how your program finds
95 to be prime:

89 was a prime, and next the program checks 91.
91 is not divisible by 2.
91 is not divisible by 3.
91 is not divisible by 4.
91 is not divisible by 5.
91 is not divisible by 6.
91 is divisible by 7 - not prime! check 93 instead
93 is not divisible by 7.
93 is not divisible by 8.
...
93 is not divisible by 30.
93 is divisible by 31 - not prime! check 95 instead
95 is not divisible by 31.
...
95 is not divisible by 90.
Checked all numbers smaller than 91, so 95 is prime.




-- 
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] Python Exercise

2010-11-29 Thread Evans Anyokwu
Providing trial section alone will not make much difference. You should
consider removing the need to sign in as well and focus on providing great
tutorial content.

Good luck

On Sun, Nov 28, 2010 at 2:43 AM, Kok Cheng Tan tkokc...@gmail.com wrote:

 Hi,

 Thanks for the feedback.
 I will add a trial section that doesn't require login so that new visitors
 are able to give the website a try.

 Regards,
 Kok Cheng

 -- Forwarded message --
 From: tutor-requ...@python.org
 Date: Sun, Nov 28, 2010 at 2:41 AM
 Subject: Tutor Digest, Vol 81, Issue 105
 To: tutor@python.org


 Send Tutor mailing list submissions to
tutor@python.org

 To subscribe or unsubscribe via the World Wide Web, visit

http://mail.python.org/mailman/listinfo/tutor
 or, via email, send a message with subject or body 'help' to
tutor-requ...@python.org

 You can reach the person managing the list at
tutor-ow...@python.org

 When replying, please edit your Subject line so it is more specific
 than Re: Contents of Tutor digest...


 Today's Topics:

   1. Python Exercise (Kok Cheng Tan)
   2. Reload() in v3?  WAS Re: IDEs (Alan Gauld)
   3. Re: Reload() in v3?  WAS Re: IDEs (Alan Gauld)
   4. Re: Python Exercise (Mac Ryan)
   5. Re: normalize an array (Eike Welk)
   6. Python Exercise (pa...@cruzio.com)
   7. Re: Python Exercise (Joel Schwartz)
   8. Re: normalize an array (John)


 --

 Message: 1
 Date: Sat, 27 Nov 2010 22:00:03 +0800
 From: Kok Cheng Tan tkokc...@gmail.com
 To: tutor@python.org
 Subject: [Tutor] Python Exercise
 Message-ID:
aanlkti=efho9tvndsejh=xw2=ca3t7kzrrk51-ph-...@mail.gmail.com
 Content-Type: text/plain; charset=ISO-8859-1

 Hi,


 I created this website for practising python online:
 http://www.pyschools.com.
 Hope to gather feedback from people here who are interesting in
 teaching and learning python.

 Regards,
 Kok Cheng


 --

 Message: 2
 Date: Sat, 27 Nov 2010 15:04:57 -
 From: Alan Gauld alan.ga...@btinternet.com
 To: tutor@python.org
 Subject: [Tutor] Reload() in v3?  WAS Re: IDEs
 Message-ID: icr6ml$ob...@dough.gmane.org
 Content-Type: text/plain; format=flowed; charset=iso-8859-1;
reply-type=response


 Steven D'Aprano st...@pearwood.info wrote

  The other nine times out of ten *wink* I need to do debugging, and I
  swap tabs and work in my interactive Python interpreter.
 
  import filename  # first time only
  reload(filename)  # all subsequent times

 I'm working on the v3 version of my tutor and while testing some
 module code I tried to reload the module in IDLE... I got an error:

  import os
  reload(os)
 Traceback (most recent call last):
  File pyshell#65, line 1, in module
reload(os)
 NameError: name 'reload' is not defined
 

 Has reload been removed in V3?
 Whats the alternative? Does a repeated import auto-reload?

 I'm surprised and confused...

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




 --

 Message: 3
 Date: Sat, 27 Nov 2010 15:11:53 -
 From: Alan Gauld alan.ga...@btinternet.com
 To: tutor@python.org
 Subject: Re: [Tutor] Reload() in v3?  WAS Re: IDEs
 Message-ID: icr73l$q2...@dough.gmane.org
 Content-Type: text/plain; format=flowed; charset=iso-8859-1;
reply-type=response


 Alan Gauld alan.ga...@btinternet.com wrote
  Has reload been removed in V3?
  Whats the alternative? Does a repeated import auto-reload?
 
  I'm surprised and confused...

 Found it, its been moved into the imp module.

 You need to import imp and then do

 imp.reload(foo)

  import os
  reload(os)
 Traceback (most recent call last):
  File pyshell#65, line 1, in module
reload(os)
 NameError: name 'reload' is not defined
  import imp
  imp.reload(os)
 module 'os' from 'C:\Python31\lib\os.py'
 

 I wonder why that was considered a good idea?

 Alan G.



 --

 Message: 4
 Date: Sat, 27 Nov 2010 18:12:59 +0100
 From: Mac Ryan quasipe...@gmail.com
 To: tutor@python.org
 Subject: Re: [Tutor] Python Exercise
 Message-ID: 20101127181259.770ea...@jabbar
 Content-Type: text/plain; charset=US-ASCII


 On Sat, 27 Nov 2010 22:00:03 +0800
 Kok Cheng Tan tkokc...@gmail.com wrote:

  I created this website for practising python online:
  http://www.pyschools.com. Hope to gather feedback from people here
  who are interesting in teaching and learning python.

 Here you go with the first suggestion: remove the need to log in!
 (Haven't really watched at the site content, given that I - like 99% of
 the Internet users - wouldn't bother to login just to roam around a
 site).

 Mac.


 --

 Message: 5
 Date: Sat, 27 Nov 2010 18:44:25 +0100
 From: Eike Welk eike.w...@gmx.net
 To: tutor@python.org
 Subject: Re: [Tutor] normalize an array
 Message-ID: 201011271845.38868.eike.w...@gmx.net
 Content-Type: Text/Plain;  

Re: [Tutor] temporarily modifying sys.path

2010-11-29 Thread Steven D'Aprano

Alan Gauld wrote:


Tim Johnson t...@johnsons-web.com wrote


Just curious, but could the imp module help you? imp.find_module



 I'll be darned. I never even heard of that module, but I just
 did an import and looked at the docs. I *will* give that a try.


I think its new in Python v3...


Nah, it's been around forever:

[st...@sylar ~]$ python1.5
Python 1.5.2 (#1, Apr  1 2009, 22:55:54)  [GCC 4.1.2 20070925 (Red Hat 
4.1.2-27)] on linux2

Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
 import imp
 imp.find_module('math')
(None, 'math', ('', '', 6))



--
Steven

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


[Tutor] age program

2010-11-29 Thread Andre Jeyarajan
Write a short program that will perform the following:It will ask the user for 
his age,it will then present the user with a menu, with 4 choices:Tell the user 
whether his age is an even or an odd number 
Tell the user his age squared 
Tell the user how many years until he’s 100 years old, or tell him that he’s 
alerady over 100!  If the user is exactly 100 years old, congratulate him for 
being a centurion. 
I have tried everything i can. Can you please explain it to me?___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] age program

2010-11-29 Thread Andre Engels
We will not make your homework for you. However, we may well give you hints
and perhaps solve small parts that you are unable to do yourself. For that,
however, we need to know *what* it is that you are having problems with.

Thus: You said that you have tried everything you can. What have you tried?
What part(s) of the problem are you able to solve? What part(s) of the
problem are you not able to solve?

On Mon, Nov 29, 2010 at 3:29 PM, Andre Jeyarajan
andrejeyara...@rogers.comwrote:

 Write a short program that will perform the following:

 It will ask the user for his age,

 it will then present the user with a menu, with 4 choices:

1. Tell the user whether his age is an even or an odd number
2. Tell the user his age squared
3. Tell the user how many years until he’s 100 years old, or tell him
that he’s alerady over 100!  If the user is exactly 100 years old,
congratulate him for being a centurion.


 I have tried everything i can. Can you please explain it to me?

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




-- 
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] age program

2010-11-29 Thread Alex Hall
On 11/29/10, Andre Jeyarajan andrejeyara...@rogers.com wrote:
 Write a short program that will perform the following:It will ask the user
 for his age,it will then present the user with a menu, with 4 choices:Tell
 the user whether his age is an even or an odd number
 Tell the user his age squared
 Tell the user how many years until he’s 100 years old, or tell him that he’s
 alerady over 100!  If the user is exactly 100 years old, congratulate him
 for being a centurion.
 I have tried everything i can. Can you please explain it to me?
Explain which part exactly? That is, what have you gotten to work so
far? If you have not gotten anything yet, I recommend looking up the
input() and raw_input() methods for age and menu. After that it is
just a couple math operations and some if statements inside a while
loop.


-- 
Have a great day,
Alex (msg sent from GMail website)
mehg...@gmail.com; http://www.facebook.com/mehgcap
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] temporarily modifying sys.path

2010-11-29 Thread Alan Gauld


Steven D'Aprano st...@pearwood.info wrote


I think its new in Python v3...


Nah, it's been around forever:

[st...@sylar ~]$ python1.5


Wow, I've never even noticed it before, 
let alone used it...


Its amazing what that battery pack contains :-)

Alan G

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


[Tutor] Web Harvesting AJAX/Javascript

2010-11-29 Thread Roy Hinkelman
All,

I am working on a project to automate the harvesting of a site that uses
Javascript throughout it's navigation. So, I want to follow onclick and
mouseover events that use JS functions, and capture/display the resulting
info. My script is activated by an onload event.

I just want to make sure that I am headed in the right direction, and not
missing something!. Any advise or pointers appreciated.

Researching this has led me to PAMIE and Selenium. PAMIE is giving me
problems with permissions, and the discussion group appears to be fading
away. I have not tried Selenium yet. Both open a browser instance, and PAMIE
is quite slow, and I expect Selenium to be quite slow as well.

How are you navigating around these Javascript based pages? Is there a
library or plugin that I am missing?

Thanks in advance.

-- 
Roy Hinkelman

**Few people are capable of expressing with equanimity opinions which differ
from the prejudices of their social environment. Most people are even
incapable of forming such opinions.-- Albert Einstein
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] age program

2010-11-29 Thread Alan Gauld


Andre Jeyarajan andrejeyara...@rogers.com wrote 

Write a short program that will perform the following:It will ask 
the user for his age


Since you have posted a number of what are obviously 
homework/assignment type questions it might help if you 
tell us what course you are studying, what topics you have 
covered etc? Usually assignments are designed to test 
what you have just learned. But we don't know what aspect 
of Python these are supposed to be testing!


Also, for homeworks we do expect you to post at least 
some code to show you tried to solve it yourself. Its usually 
easier for us to point out where you are going wrong and 
suggest improvements than to start with a blank sheet.
If nothing else the broken code will tell us a lot about how 
you are thinking about the problem.


Alan G.

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


[Tutor] Package loading

2010-11-29 Thread Karim


Hello every one,

I created a package with the following structure:

   * ops/
 o __init__.py
 o tcl/
   + __init__.py
   + pythontcl.py



 *python -c import sys; print sys.path; import ops.tcl.pythontcl*

['', '/usr/local/lib/python2.6/dist-packages/pyparsing-1.5.5-py2.6.egg', 
'*/home/karim/build/UML2PDK/lib/python*', '/usr/lib/python2.6', 
'/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', 
'/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', 
'/usr/lib/python2.6/dist-packages', 
'/usr/lib/python2.6/dist-packages/PIL', 
'/usr/lib/python2.6/dist-packages/gst-0.10', 
'/usr/lib/pymodules/python2.6', 
'/usr/lib/python2.6/dist-packages/gtk-2.0', 
'/usr/lib/pymodules/python2.6/gtk-2.0', 
'/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode', 
'/usr/local/lib/python2.6/dist-packages']
/*home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py:109: 
RuntimeWarning: Parent module 'pythontcl' not found while handling 
absolute import

  import unittest
/home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py:110: 
RuntimeWarning: Parent module 'pythontcl' not found while handling 
absolute import

  import sys*

At the lines I import standard modules sys and unittest I get these 
non-sense warning (my consideration) though I added the top package 
root, namely, */home/karim/build/UML2PDK/lib/python. The programesecute 
correctly but I alaways get this nerving warning.


*Any idea will be welcome!* :-)

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


Re: [Tutor] Web Harvesting AJAX/Javascript

2010-11-29 Thread Emile van Sebille

On 11/29/2010 11:42 AM Roy Hinkelman said...

All,

I am working on a project to automate the harvesting of a site that uses
Javascript throughout it's navigation. So, I want to follow onclick and
mouseover events that use JS functions, and capture/display the resulting
info. My script is activated by an onload event.

I just want to make sure that I am headed in the right direction, and not
missing something!. Any advise or pointers appreciated.

Researching this has led me to PAMIE and Selenium. PAMIE is giving me
problems with permissions, and the discussion group appears to be fading
away. I have not tried Selenium yet. Both open a browser instance, and PAMIE
is quite slow, and I expect Selenium to be quite slow as well.

How are you navigating around these Javascript based pages? Is there a
library or plugin that I am missing?



Hi Roy,

I've had a couple of these types of projects on my ToDo list for a while 
and haven't researched them yet.  I suspect you'll get better traction 
on the main python list, but I've been surprised before...


Looking forward to seeing what direction you get pointed in.

Emile


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


Re: [Tutor] Pyserial and invalid handle

2010-11-29 Thread John Smith

On 11/28/2010 8:06 PM, Walter Prins wrote:

John,

(snip stuff)

Ugh, you're probably not going to like this.  I've done some googling
and it appears this may be a 64-bit issue with the ctypes module...
apparently 64-bit ctypes can only import 64-bit libraries.  See here:
http://ur.ly/vSMQ

Then again, it also seems to be an open issue on the PySerial bug
tracker: http://ur.ly/vZNL

Note, the above ticket suggests that PySerial 2.4 works ok (impliedly
even on 64-bit XP, so I imagine also on Windows 7.)  You should be able
to try this out by downloading the 2.4 version instead and installing it
in the same way you did the 2.5 version.  In any case, it might be an
idea to post a report/add a comment to that bug report as well to maybe
help get this issue resolved.

Cheers,

Walter



Hi, Walter -

Thanks for all the research. This was my second attempt at installing 
the 2.4 version. I did it thus:


E:\Python27\pyserial-2.4..\python setup.py install
standart distutils
running install
running build
running build_py
creating build
creating build\lib
creating build\lib\serial
copying serial\serialcli.py - build\lib\serial
copying serial\serialjava.py - build\lib\serial
copying serial\serialposix.py - build\lib\serial
copying serial\serialutil.py - build\lib\serial
copying serial\serialwin32.py - build\lib\serial
copying serial\sermsdos.py - build\lib\serial
copying serial\__init__.py - build\lib\serial
running install_lib
running install_egg_info
Removing E:\Python27\Lib\site-packages\pyserial-2.4-py2.7.egg-info
Writing E:\Python27\Lib\site-packages\pyserial-2.4-py2.7.egg-info

E:\Python27\pyserial-2.4


But, when I tried it in Python, I got the same as before:


 import serial
 ser = serial.Serial(0, timeout = 1)
 ser
Serialid=0x225c240, open=True(port='COM1', baudrate=9600, bytesize=8, 
parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False, 
dsrdtr=False)

 ser.read()

Traceback (most recent call last):
  File pyshell#3, line 1, in module
ser.read()
  File E:\Python27\lib\site-packages\serial\serialwin32.py, line 236, 
in read

raise SerialException(ReadFile failed (%s) % ctypes.WinError())
SerialException: ReadFile failed ([Error 6] The handle is invalid.)



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


Re: [Tutor] Pyserial and invalid handle

2010-11-29 Thread Emile van Sebille

On 11/29/2010 1:44 PM John Smith said...

But, when I tried it in Python, I got the same as before:


  import serial
  ser = serial.Serial(0, timeout = 1)


out of curiosity, if you change the timeout above to 5


  ser
Serialid=0x225c240, open=True(port='COM1', baudrate=9600, bytesize=8,
parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False,
dsrdtr=False)
  ser.read()


... does the delay before printing the traceback below take about 5 seconds?



Traceback (most recent call last):
File pyshell#3, line 1, in module
ser.read()
File E:\Python27\lib\site-packages\serial\serialwin32.py, line 236, in
read
raise SerialException(ReadFile failed (%s) % ctypes.WinError())
SerialException: ReadFile failed ([Error 6] The handle is invalid.)
 



Emile

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


Re: [Tutor] Pyserial and invalid handle

2010-11-29 Thread John Smith


On 11/29/2010 4:20 PM, Emile van Sebille wrote:

On 11/29/2010 1:44 PM John Smith said...

But, when I tried it in Python, I got the same as before:


 import serial
 ser = serial.Serial(0, timeout = 1)


out of curiosity, if you change the timeout above to 5


 ser
Serialid=0x225c240, open=True(port='COM1', baudrate=9600, bytesize=8,
parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False,
dsrdtr=False)
 ser.read()


... does the delay before printing the traceback below take about 5
seconds?




No. There is no delay regardless of the timeout setting.

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


Re: [Tutor] Pyserial and invalid handle

2010-11-29 Thread Emile van Sebille

On 11/29/2010 3:25 PM John Smith said...


On 11/29/2010 4:20 PM, Emile van Sebille wrote:

On 11/29/2010 1:44 PM John Smith said...

But, when I tried it in Python, I got the same as before:


 import serial
 ser = serial.Serial(0, timeout = 1)


out of curiosity, if you change the timeout above to 5


 ser
Serialid=0x225c240, open=True(port='COM1', baudrate=9600, bytesize=8,
parity='N', stopbits=1, timeout=1, xonxoff=False, rtscts=False,
dsrdtr=False)
 ser.read()


... does the delay before printing the traceback below take about 5
seconds?




No. There is no delay regardless of the timeout setting.



 Traceback (most recent call last):
 File pyshell#3, line 1, in module
 ser.read()
 File E:\Python27\lib\site-packages\serial\serialwin32.py, line
 236, in read
 raise SerialException(ReadFile failed (%s) % ctypes.WinError())
 SerialException: ReadFile failed ([Error 6] The handle is invalid.)
  

Hmmm... any chance you don't have administrative rights on the account 
performing this?  I never got to Win7 (having stopped at XP) but I know 
it's got a reputation for excessive permission asking.


Otherwise, I'd take this up on the main list.  Chris Liechti, the 
[author|current maintainer|significant contributor] of pyserial monitors 
that list and would probably be interested in diagnosing what you're 
describing.  You could also ask him as per the 'send me a message' link 
on his sourceforge page at


http://sourceforge.net/sendmessage.php?touser=403744

Emile

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


Re: [Tutor] Package loading

2010-11-29 Thread Karim

On 11/29/2010 09:15 PM, Karim wrote:


Hello every one,

I created a package with the following structure:

* ops/
  o __init__.py
  o tcl/
+ __init__.py
+ pythontcl.py



 *python -c import sys; print sys.path; import ops.tcl.pythontcl*

['', 
'/usr/local/lib/python2.6/dist-packages/pyparsing-1.5.5-py2.6.egg', 
'*/home/karim/build/UML2PDK/lib/python*', '/usr/lib/python2.6', 
'/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', 
'/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', 
'/usr/lib/python2.6/dist-packages', 
'/usr/lib/python2.6/dist-packages/PIL', 
'/usr/lib/python2.6/dist-packages/gst-0.10', 
'/usr/lib/pymodules/python2.6', 
'/usr/lib/python2.6/dist-packages/gtk-2.0', 
'/usr/lib/pymodules/python2.6/gtk-2.0', 
'/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode', 
'/usr/local/lib/python2.6/dist-packages']
/*home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py:109: 
RuntimeWarning: Parent module 'pythontcl' not found while handling 
absolute import

  import unittest
/home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py:110: 
RuntimeWarning: Parent module 'pythontcl' not found while handling 
absolute import

  import sys*

At the lines I import standard modules sys and unittest I get these 
non-sense warning (my consideration) though I added the top package 
root, namely, */home/karim/build/UML2PDK/lib/python. The 
programesecute correctly but I alaways get this nerving warning.


*Any idea will be welcome!* :-)

*Regards
Karim*
* 


I believed I know why:

Traceback (most recent call last):
  File string, line 1, in module
  File /home/karim/build/UML2PDK/lib/python/ops/tcl/pythontcl.py, 
line 119, in module

print sys.modules[__package__]
KeyError: 'pythontcl'

It is due to method determine parent in class ModuleImporter.
I don't know why sys.modules has the key 'ops.tcl.pythontcl'
and this class search for the key module 'pythontcl'.

Big mess between relative path or whatever.

Any idea to fix that?

Karim

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


Re: [Tutor] Pyserial and invalid handle

2010-11-29 Thread John Smith


On 11/29/2010 5:56 PM, Emile van Sebille wrote:
(snip)

Hmmm... any chance you don't have administrative rights on the account
performing this? I never got to Win7 (having stopped at XP) but I know
it's got a reputation for excessive permission asking.


You're right about that. It's like Win7 is paranoid. But, it tells me 
when I need to supply administrative permission. Some day I'll find the 
button that tells the system that nobody else uses this computer and to 
shut up and get on with it.



Otherwise, I'd take this up on the main list. Chris Liechti, the
[author|current maintainer|significant contributor] of pyserial monitors
that list and would probably be interested in diagnosing what you're
describing. You could also ask him as per the 'send me a message' link
on his sourceforge page at

http://sourceforge.net/sendmessage.php?touser=403744

Emile


I'll consider that, Emile. First, though, I would like to hear from 
Walter again after my last post.


Thanks for your suggestions.

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


Re: [Tutor] REport Card Question

2010-11-29 Thread Robert Sjöblom
  Write a code that will take an input from a user (numerical grade) and
 convert their numerical grade into a letter grade that is accompanied by a
 ?smart? statement.

  def grade_score(grade):

     if grade =95 and grade = 100:

         print 'A+, Excellent'

     elif grade =85 and grade  95:

         print 'A, Good Work'

     elif grade =80 and grade  85:

         print 'A-, Good Work, but you could do better'
[snip]
 grade = raw_input('Put your grade here:?)


 grade_score()


 Put your grade here:77

 Traceback (most recent call last):

   File /Users/andre.jeyarajan/Documents/workspace/Chapter 5
 Problems/src/ReportCardQuestion.py, line 28, in module

     grade_score()


 This line tells you why it doesn't work:


 TypeError: grade_score() takes exactly 1 argument (0 given)


 Are you familiar with functions? When you define the function you define it
 as taking one parameter:

 def grade_score(grade):
    # Code here

 but then when you call it:

 grade_score()

 you don't give it any parameters (or arguments). The traceback tells you
 that you need to provide it 1 argument and that you gave it 0 instead.

 If you called

 grade_score(3, 150)

 you would get a similar error, only it would say (2 given) instead.

 HTH,
 Wayne

On a related note, do all functions implicitly contain return None
in them? Trying out this function (correctly) would get None added,
such as:
Enter grade:76
B, Try Harder
None

Is there a way to avoid return None without explicitly having the
function return something? Even an empty string will return a new
line.

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


Re: [Tutor] REport Card Question

2010-11-29 Thread Wayne Werner
On Mon, Nov 29, 2010 at 8:28 PM, Robert Sjöblom robert.sjob...@gmail.comwrote:

 snip

 On a related note, do all functions implicitly contain return None
 in them? Trying out this function (correctly) would get None added,
 such as:
 Enter grade:76
 B, Try Harder
 None

 Is there a way to avoid return None without explicitly having the
 function return something? Even an empty string will return a new
 line.


AFAIK, no. Nor am I sure why you would want to - None is a singleton so
there can only be once instance of it at a time. None is only printed when
you're working in the interactive interpreter - if you write the program in
a .py file and execute it you won't see the 'None' unless you print the
result (which would indeed be None!)

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


Re: [Tutor] Pyserial and invalid handle

2010-11-29 Thread Rance Hall
On Mon, Nov 29, 2010 at 8:21 PM, John Smith jocj...@verizon.net wrote:

 On 11/29/2010 5:56 PM, Emile van Sebille wrote:
 (snip)

 Hmmm... any chance you don't have administrative rights on the account
 performing this? I never got to Win7 (having stopped at XP) but I know
 it's got a reputation for excessive permission asking.

 You're right about that. It's like Win7 is paranoid. But, it tells me when I
 need to supply administrative permission. Some day I'll find the button that
 tells the system that nobody else uses this computer and to shut up and get
 on with it.


Just so you know, Its called User Account Control or UAC.  Google for
disabling UAC on Windows 7 and you can find a tutorial or two on how
to make your computer shut up and get on with it.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pyserial and invalid handle

2010-11-29 Thread John Smith

On 11/29/2010 9:41 PM, Rance Hall wrote:

On Mon, Nov 29, 2010 at 8:21 PM, John Smithjocj...@verizon.net  wrote:


On 11/29/2010 5:56 PM, Emile van Sebille wrote:
(snip)


Hmmm... any chance you don't have administrative rights on the account
performing this? I never got to Win7 (having stopped at XP) but I know
it's got a reputation for excessive permission asking.


You're right about that. It's like Win7 is paranoid. But, it tells me when I
need to supply administrative permission. Some day I'll find the button that
tells the system that nobody else uses this computer and to shut up and get
on with it.



Just so you know, Its called User Account Control or UAC.  Google for
disabling UAC on Windows 7 and you can find a tutorial or two on how
to make your computer shut up and get on with it.



Hey, thanks Rance. The info is appreciated.

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