[Tutor] How to make to exit the loop, while typing Enter

2006-01-03 Thread John Joseph
Hi 
I am trying to write a program in which it ask for
entries for the list , But if I press Enter it  should
exit  the while loop without giving errors ,I have
problem in making it work , right now if I press enter
to exit , the program terminates showing error 
I am added my script which I wrote 
  Advice requested 
  Thanks 
   Joseph



#
#   How to exit , when user Press Enter
#   While Entering Data
#

# define array
array = []
m = 0
print Enter  to exit
m = int(raw_input(Enter the  Values for  The Array : 
))
array.append(m)
print array
while m != :
m = int(raw_input(Enter the  Values for  The
Array :  ))
array.append(m)
print array






___ 
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail 
http://uk.messenger.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with choosing books

2006-01-03 Thread Srinivas Iyyer
Hi, 
 I guess this has been discussed in detail in December
2005 (last month). 
you might want to check this thread and the replies in
deteails. 


http://mail.python.org/pipermail/tutor/2005-December/044028.html

This might help.






--- wood yee [EMAIL PROTECTED] wrote:


-

Hi! I got Foundations of Python Network Programming as
a gift but I don't know Python. My library has several
books called Beginning Python. One's by Wrox and the
other is by the author of the hacking python tutorial.
My question is how can I achieve my goal of becoming
ready for Foundations of Python Network Programming?
Which book should I start with? Is a tutorial better?
Any ideas of what syllabus(sp?) to follow? I really
want to tackle my Foundations book and I want to get
up to speed as quickly as I can. Thanks! 



 


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




__ 
Yahoo! DSL – Something to write home about. 
Just $16.99/mo. or less. 
dsl.yahoo.com 

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


Re: [Tutor] How to make to exit the loop, while typing Enter

2006-01-03 Thread Danny Yoo


 I am trying to write a program in which it ask for entries for the list
 , But if I press Enter it should exit the while loop without giving
 errors

Hi John,

Do you have ideas why it's getting an error?  Can you point at the part of
the program that's receiving the Enter?

As a related question, what result do you expect from:

int()

What does Python respond with?

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


[Tutor] How to make to exit the loop, while typing Enter

2006-01-03 Thread Adam
Woops, forgot to reply-all.-- Forwarded message --From: Adam [EMAIL PROTECTED]Date: 03-Jan-2006 15:48
Subject: Re: [Tutor] How to make to exit the loop, while typing EnterTo: John Joseph [EMAIL PROTECTED]
array = []m = 0print Enterto exitm = int(raw_input(Enter theValues forThe Array :
))array.append(m)print arraywhile m != :m = int(raw_input(Enter theValues forTheArray :))array.append(m)print array

The problem is that if a value is entered that can't be converted to an integer type, like  or a letter then an exception is raised. What you could do is use a try, except.while 1: try:
 m = int(raw_input(Enter theValues forThe Array: ))
 array.append(m) print array except ValueError: sys.exit()alternatively you could do something like this:m=raw_input(Enter theValues forThe Array: )

if m == : sys.exit()try: int(m) array.append(m) print arrayexcept ValueError: print Only integer values can be entered into the array, or press the enter key to exit.


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


[Tutor] Python code pretty-print?

2006-01-03 Thread Lance E Sloan
A colleague of mine often develops Python code under Mac OS X.  He would 
like to be able to print the code in an easily readable format.  He's found 
that kwrite on Linux does a very nice job, but it's inconvenient to copy 
his code to a Linux box just to print it out.

We've found mention (mostly in manpages) of a program called pyhtmlizer, 
but couldn't find source or binary for it.

Can anybody recommend a similar tool that we can use on Mac OS X?

Thanks!

--
Lance E Sloan, Systems Research Programmer III
U-M WATS: Web Applications, Technologies, and Solutions
Full-service web and database design, development, and hosting.
http://www.itcs.umich.edu/wats/ - Putting U on the Web

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


[Tutor] dynamic lists

2006-01-03 Thread lfiedor
Hi
im looking for very simple DES and RSA algorithms writen in python (or 
C), can anyone know where i can find them

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


Re: [Tutor] Python code pretty-print?

2006-01-03 Thread Danny Yoo


On Tue, 3 Jan 2006, Lance E Sloan wrote:

 A colleague of mine often develops Python code under Mac OS X.  He would
 like to be able to print the code in an easily readable format.  He's
 found that kwrite on Linux does a very nice job, but it's inconvenient
 to copy his code to a Linux box just to print it out.

 We've found mention (mostly in manpages) of a program called
 pyhtmlizer, but couldn't find source or binary for it.

Hi Lance,

'pyhtmlizer' is in the twisted package, under twisted.scripts:

http://twistedmatrix.com/documents/current/api/twisted.scripts.htmlizer.html

You should be able to get the source there.


Alternatively, the Python Cookbook has a good recipe for syntax
highlighting:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298


Finally, GNU Enscript might be applicable.  GNU Enscript knows how to
colorize and pretty print different programming languages, and I believe
it's already in Mac OS X.

http://www.osxfaq.com/man/1/enscript.ws

If you use the --pretty-print, --color, and -Whtml options, you should be
able to get some reasonable output with it.

Best of wishes!

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


Re: [Tutor] dynamic lists

2006-01-03 Thread Jason Massey
googled for rsa  python:

http://www.python.org/workshops/1995-05/pct.html

On 1/3/06, lfiedor [EMAIL PROTECTED] wrote:
Hiim looking for very simple DES and RSA algorithms writen in python (orC), can anyone know where i can find them___Tutor maillist-
Tutor@python.orghttp://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] DES and RSA cryptography algorithms? (Was: Re: dynamic lists)

2006-01-03 Thread Danny Yoo


On Tue, 3 Jan 2006, lfiedor wrote:

 im looking for very simple DES and RSA algorithms writen in python (or
 C), can anyone know where i can find them

I'm changing subject lines.  Please try to make your message Subject lines
descriptive enough to make it easier to find later.

Also, next time, try first searching for these modules in Python's Cheese
Shop code repository.  It's the spiritual successor to the Vaults of
Parnassus, and is steadily becoming very usable.

http://cheeseshop.python.org/pypi


Yes, there are implementations of those algorithms available.  For
example:

http://cheeseshop.python.org/pypi/pyDes/

shows a pure Python implementation of DES.


There's also a nice packaging of those algorithms in the Python
Cryptography Toolkit:

http://www.amk.ca/python/code/crypto


Good luck to you.

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


[Tutor] Syntax Errors

2006-01-03 Thread Jason Massey
I've just finished ripping out a bunch of lines in one of my wxPython programs. Testing it out I get:

C:\Python24tla2.py
 File C:\Python24\tla2.py, line 412
 self.grid.SetCellValue(0,0,Site)
 ^
SyntaxError: invalid syntax

There's nothing wrong with that line. I didn't even touch it in
the overhaul (refactoring is much too delicate of a word for the
surgery I just did). I can make the error go away by unindenting
the line, but all that happens then is the error gets passed onto the
next line down.

I've had this happen before on a smaller scale. Python wouldn't
like a certain line and I found that if I moved it up in the function
the error would go away. Unfortunately this overhaul touched on at
least three functions. Oddly enough the function where I did the
majority of the work seemed to come out fine.


Any pointers on tracing this down? In C I would expect I didn't have a set of matching braces or a missing semi-colon.

thanks,

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


[Tutor] HD/DVD/CD

2006-01-03 Thread Ron Speerstra


Hi, M-list, my name Ron Speerstra(the Netherlands)

my question: howtoo read the HD/CD/DVD serial-numbers with Python.
Volume-name, dir name, file name. no problem etc.

Gr Ron$

_
Vind alles terug op je PC: MSN Search Toolbar http://toolbar.msn.nl/

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


Re: [Tutor] How to make to exit the loop, while typing Enter

2006-01-03 Thread Alan Gauld
 entries for the list , But if I press Enter it  should
 exit  the while loop without giving errors ,I have
 problem in making it work , right now if I press enter
 to exit , the program terminates showing error 

Thats because you can't convert an empty string to an int.

If you defer the conversion until you add the mark to the 
list then it should work OK.


 m = int(raw_input(Enter the  Values for  The Array : 
 ))
 array.append(m)

array.append(int(m))

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] Help with choosing books

2006-01-03 Thread Alan Gauld
Hi,

What background do you come from? 
Can you already program in another language?

 Hi! I got Foundations of Python Network Programming 

 I really want to tackle my Foundations book and I want 
 to get up to speed as quickly as I can. Thanks! 

If you already program then just work through the Python tutor 
that comes with Python. That should be all you really need.
Ask any specific questions on this list.

If you are a complete beginner there is a web site that lists 
several tutors for non programmers (mine included) and 
the books you have should help too.
Anything you don't understand just ask here.

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] Syntax Errors

2006-01-03 Thread Danny Yoo


On Tue, 3 Jan 2006, Jason Massey wrote:

 I've just finished ripping out a bunch of lines in one of my wxPython
 programs.  Testing it out I get:

 C:\Python24tla2.py
   File C:\Python24\tla2.py, line 412
 self.grid.SetCellValue(0,0,Site)
 ^
 SyntaxError: invalid syntax

 There's nothing wrong with that line.  I didn't even touch it in the
 overhaul (refactoring is much too delicate of a word for the surgery I
 just did).  I can make the error go away by unindenting the line, but
 all that happens then is the error gets passed onto the next line down.

Hi Jason,

Can you show us the line in context?  That is, can you show us a few lines
above and below?

Also, let's make sure we're not running into a silly tab-vs-spaces issue.
Can you try running Python with the '-tt' command line option?  This will
enable Python to strictly treat mixed tabs and spaces as a bad thing.


Good luck!

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


Re: [Tutor] HD/DVD/CD

2006-01-03 Thread John Fouhy
On 04/01/06, Ron Speerstra [EMAIL PROTECTED] wrote:
 my question: howtoo read the HD/CD/DVD serial-numbers with Python.
 Volume-name, dir name, file name. no problem etc

Are you running Microsoft Windows?  If so, are any of the scripts at
http://www.microsoft.com/technet/scriptcenter/scripts/python/pyindex.mspx
useful to you?

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


Re: [Tutor] Syntax Errors

2006-01-03 Thread Jason Massey
Danny!

Thanks! It's the tab vs spaces, alright.

I use tabs for my spacing and I was touching a part of the code that a co-worker wrote. Guess what he uses? Spaces.

Thanks for that insight and I'll be sure to read up on the command line options.

On 1/3/06, Danny Yoo [EMAIL PROTECTED] wrote:
On Tue, 3 Jan 2006, Jason Massey wrote: I've just finished ripping out a bunch of lines in one of my wxPython programs.Testing it out I get: C:\Python24tla2.py File C:\Python24\tla2.py, line 412
 self.grid.SetCellValue(0,0,Site) ^ SyntaxError: invalid syntax There's nothing wrong with that line.I didn't even touch it in the overhaul (refactoring is much too delicate of a word for the surgery I
 just did).I can make the error go away by unindenting the line, but all that happens then is the error gets passed onto the next line down.Hi Jason,Can you show us the line in context?That is, can you show us a few lines
above and below?Also, let's make sure we're not running into a silly tab-vs-spaces issue.Can you try running Python with the '-tt' command line option?This willenable Python to strictly treat mixed tabs and spaces as a bad thing.
Good luck!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] dynamic lists

2006-01-03 Thread Alan Gauld
 im looking for very simple DES and RSA algorithms writen in python (or 
 C), can anyone know where i can find them

I'll be slightly surprised if you find Python versions(but not amazed! :-)
since performance is usually of high priority for cryptography.

But the RSA site should have C libraries I think.
They used to...

Note that DES is now considered minimum security since it was 
broken by brute force in DesChall a few years ago...

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld


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


Re: [Tutor] Python code pretty-print?

2006-01-03 Thread Alan Gauld
Try getting gvim for MacOS
vim includes a Python mode with syntax colouring and you can get it to print
it out using an HTML representation.

It works well IMHO (on any platform including MacOS).

http://www.vim.org/download.php

and MacOS specific versions :

http://macvim.org/

Scite does the same trick but I don't know how well it
runs on MacOS.

http://mailman.lyra.org/pipermail/scintilla-interest/2003-May/002756.html

Alan G.

- Original Message - 
From: Lance E Sloan [EMAIL PROTECTED]
To: tutor@python.org
Sent: Tuesday, January 03, 2006 2:12 PM
Subject: [Tutor] Python code pretty-print?


A colleague of mine often develops Python code under Mac OS X.  He would 
like to be able to print the code in an easily readable format.  He's found 
that kwrite on Linux does a very nice job, but it's inconvenient to copy 
his code to a Linux box just to print it out.

 We've found mention (mostly in manpages) of a program called pyhtmlizer, 
 but couldn't find source or binary for it.

 Can anybody recommend a similar tool that we can use on Mac OS X?

 Thanks!

 --
 Lance E Sloan, Systems Research Programmer III
 U-M WATS: Web Applications, Technologies, and Solutions
 Full-service web and database design, development, and hosting.
 http://www.itcs.umich.edu/wats/ - Putting U on the Web


 

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


Re: [Tutor] dynamic lists

2006-01-03 Thread Alan Gauld

 im looking for very simple DES and RSA algorithms writen in python (or
 C), can anyone know where i can find them

 I'll be slightly surprised if you find Python versions(but not amazed! :-)
 since performance is usually of high priority for cryptography.

Ok, I'm duly surprised but not amazed... ;-)

Batteries not included this time but available nonetheless,
Python never ceased to catch me out... Mind you I still doubt
I'd use Python for anything other than experimental crypto work.
(But that might just be my comms background and the need for
real-time encryption showing through...)

Alan G.

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


Re: [Tutor] HD/DVD/CD

2006-01-03 Thread Terry Carroll
On Tue, 3 Jan 2006, Ron Speerstra wrote:

 my question: howtoo read the HD/CD/DVD serial-numbers with Python.

I can take you part-way there, at least under Windows.  Hopefully 
someone can finish the job.

I'm assuming you want the same serial # that shows up when you do a 
DIR on the CD, e.g.:

  dir d:
   Volume in drive D is 050512_1752
   Volume Serial Number is 8A73-780D

Here's some code:

 import win32api
 CD_Info = win32api.GetVolumeInformation(D:/)
 serno = CD_Info[1]
 serno
-1972144115
 %X % serno
'-758C87F3'
 %X % -serno
'758C87F3'

This is as far as I can get.  the hex string, in this case 758C87F3 is the 
two's complement of the serial number that shows up when I do a dir d::

  dir d:
   Volume in drive D is 050512_1752
   Volume Serial Number is 8A73-780D

Note that:
758C 87F3
  + 8A73 780D
=
  1  

Put another way, if you flip every bit in the 758C87F3 string and add one, 
you'll get the 8A73780D serial no.

I hope someone more artful than I can show a quick and easy way to convert 
either '758C87F3' or -1972144115 to the '8A73780D'  that is your goal.

I'm betting there's something simple I'm missing.

(By the way, it occurs to me; I guess you could just do the dir and 
capture the serial number in the output; but that's inelegant and 
wasteful.)

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


Re: [Tutor] HD/DVD/CD

2006-01-03 Thread John Fouhy
On 04/01/06, Terry Carroll [EMAIL PROTECTED] wrote:
 I hope someone more artful than I can show a quick and easy way to convert
 either '758C87F3' or -1972144115 to the '8A73780D'  that is your goal.

Hmm, well,

 i = -1972144115
 '%X' % (pow(2, 32)-(~i+1))
'8A73780D'

Although my bitwise arithmetic's feeling pretty rusty..

But ---

C:\Games\Civilization III\Conquestsdir d:
 Volume in drive D is CIV3CQST
 Volume Serial Number is 49BC-31DB
...

 import win32api
 cdi = win32api.GetVolumeInformation('D:/')
 '%X' % cdi[1]
'49BC31DB'

So, on my system (ActivePython 2.4, WinXPpro) there is no need for magic.

I've got Mark Hammond's pywin32 book, but it doesn't talk about
win32api.GetVolumeInformation().

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


Re: [Tutor] HD/DVD/CD

2006-01-03 Thread Terry Carroll
On Wed, 4 Jan 2006, John Fouhy wrote:

 On 04/01/06, Terry Carroll [EMAIL PROTECTED] wrote:
  I hope someone more artful than I can show a quick and easy way to convert
  either '758C87F3' or -1972144115 to the '8A73780D'  that is your goal.
 
 Hmm, well,
 
  i = -1972144115
  '%X' % (pow(2, 32)-(~i+1))
 '8A73780D'

Aha, I also figured another way myself in the meantime:

 import win32api
 CD_Info = win32api.GetVolumeInformation(D:/)
 serno = CD_Info[1]
 serno_str = %X % (0x1+serno)
 serno_str
'8A73780D'


  cdi = win32api.GetVolumeInformation('D:/')
  '%X' % cdi[1]
 '49BC31DB'
 
 So, on my system (ActivePython 2.4, WinXPpro) there is no need for magic.

I think you just got lucky that your first digit (4) was in the range 0-7, 
and so didn't generate a negative.

But you *do* point out a fault in my approach.  I'll give an incorrect
result for a non-negative.  I think the correct way is:

 import win32api
 CD_Info = win32api.GetVolumeInformation(D:/)
 serno = CD_Info[1]
 if serno  0:
...serno_str = %X % (0x1+serno)
... else:
...serno_str = %X % serno
...
 serno_str
'8A73780D'



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


[Tutor] Programming Python, 3rd ed.??

2006-01-03 Thread Dick Moores
Several months ago I saw an item on the O'Reilly site to the effect that
the 3rd. ed. of Programming Python was in the works. I made a note to
myself to check back in January. I just did, but could find nothing at
all about a 3rd. edition. Anyone know?

Thanks,

Dick Moores

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


Re: [Tutor] How to make to exit the loop, while typing Enter

2006-01-03 Thread John Joseph
Hi All  
I was able to exit the while loop , using sys
module 
 also I was able to find the maximum no of marks
entered ,  I am adding my code , for comments and
suggestions
   Thanks for the support 
   Joseph John 

*

 This progorm was to learn
 1 How to find which is the maximum mark  in list
 2 How to exit the while loop, while typing enter




import sys
maxmark = []

counter = 0

while 1:
try:
mark = int(raw_input(Enter the  Values for 
The Array: ))
maxmark.append(mark)
print maxmark
except ValueError:
#print From Here to Where 
counter = 0
length = len(maxmark)
#print length
max = maxmark[counter]
#print max
for counter in  range(length):
if maxmark[counter]  max:
max = maxmark[counter]
# print  Ya U are in the if
loop and the maximum no is , max
#else:
#print The  , length

print At last the Maximum Marks U got is  ,
max
sys.exit()
~
~
~



--- Adam [EMAIL PROTECTED] wrote:

  array = []
  m = 0
  print Enter  to exit
  m = int(raw_input(Enter the  Values for  The
 Array :
  ))
  array.append(m)
  print array
  while m != :
  m = int(raw_input(Enter the  Values for 
 The
  Array :  ))
  array.append(m)
  print array
 
 
 The problem is that if a value is entered that can't
 be converted to an
 integer type, like  or a letter then an exception
 is raised. What you
 could do is use a try, except.
 while 1:
 try:
 m = int(raw_input(Enter the  Values for 
 The Array: ))
 array.append(m)
 print array
 except ValueError:
 sys.exit()
 
 alternatively you could do something like this:
  m=raw_input(Enter the  Values for  The Array: )
 if m == : sys.exit()
 try:
 int(m)
 array.append(m)
 print array
 except ValueError:
 print Only integer values can be entered into
 the array, or press the
 enter key to exit.
 




___ 
To help you stay safe and secure online, we've developed the all new Yahoo! 
Security Centre. http://uk.security.yahoo.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor