Re: [Tutor] Thanks (was Random Number Generator)

2007-12-05 Thread bhaaluu
On Dec 4, 2007 7:21 PM, earlylight publishing
<[EMAIL PROTECTED]> wrote:
> Thank you everyone for your help!  I have no idea why it never occured to me
> to Google it.  Thanks for the code.  Now let's see if I can get this sucker
> to work!
>

1) Wikipedia  <-- learn a basic vocabulary so you can enter keywords into
2) Google  <-- Feeling Lucky? If that doesn't work, sort through the other 200K
3) Python Tutorials  <-- Get up and going quickly, saving the hard parts for
4) Python Documentation and Books

And then there's the Python Tutor list! 8^D

Best of luck getting your program working.
If you get stuck, show us your code, and error messages, we'll try to help.
(It also helps to add system info as well as Python version, etc.)
Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Random Number Generator

2007-12-05 Thread Dick Moores


At 02:41 PM 12/4/2007, bhaaluu wrote:
I'm running the Python 2.4.3
interactive interpreter
in a Konsole at a bash prompt:
$ python
>>> help
Type help() for interactive help, or help(object) for help about
object.
But look what I get with Python 2.5.1 and Win XP:
=
>>> help('topics')
Here is a list of available topics.  Enter any topic name to get
more help.
ASSERTION  
DEBUGGING  
LITERALS   
SEQUENCEMETHODS2
ASSIGNMENT 
DELETION   
LOOPING
SEQUENCES
ATTRIBUTEMETHODS   
DICTIONARIES   
MAPPINGMETHODS  SHIFTING
ATTRIBUTES 
DICTIONARYLITERALS 
MAPPINGS   
SLICINGS
AUGMENTEDASSIGNMENT DYNAMICFEATURES
METHODS
SPECIALATTRIBUTES
BACKQUOTES 
ELLIPSIS   
MODULES
SPECIALIDENTIFIERS
BASICMETHODS   
EXCEPTIONS 
NAMESPACES 
SPECIALMETHODS
BINARY 
EXECUTION  
NONE   
STRINGMETHODS
BITWISE
EXPRESSIONS
NUMBERMETHODS   STRINGS
BOOLEAN
FILES  
NUMBERS
SUBSCRIPTS
CALLABLEMETHODS
FLOAT  
OBJECTS
TRACEBACKS
CALLS  
FORMATTING 
OPERATORS  
TRUTHVALUE
CLASSES
FRAMEOBJECTS   
PACKAGES   
TUPLELITERALS
CODEOBJECTS
FRAMES 
POWER  
TUPLES
COERCIONS  
FUNCTIONS  
PRECEDENCE 
TYPEOBJECTS
COMPARISON 
IDENTIFIERS
PRINTING   
TYPES
COMPLEX
IMPORTING  
PRIVATENAMES    UNARY
CONDITIONAL
INTEGER
RETURNING  
UNICODE
CONTEXTMANAGERS
LISTLITERALS   
SCOPING

CONVERSIONS
LISTS  
SEQUENCEMETHODS1    
>>> help('power')
no Python documentation found for 'power'
>>> help('lists')
no Python documentation found for 'lists'
>>> help('classes')
no Python documentation found for 'classes'
>>> help('modules')
Please wait a moment while I gather a list of all available
modules...

Traceback (most recent call last):
  File "", line 1, in 
    help('modules')
  File "E:\Python25\lib\site.py", line 346, in
__call__
    return pydoc.help(*args, **kwds)
  File "E:\Python25\lib\pydoc.py", line 1645, in
__call__
    self.help(request)
  File "E:\Python25\lib\pydoc.py", line 1682, in help
    elif request == 'modules': self.listmodules()
  File "E:\Python25\lib\pydoc.py", line 1803, in
listmodules
    ModuleScanner().run(callback)
  File "E:\Python25\lib\pydoc.py", line 1854, in run
    for importer, modname, ispkg in
pkgutil.walk_packages():
  File "E:\Python25\lib\pkgutil.py", line 110, in
walk_packages
    __import__(name)
  File
"E:\Python25\lib\site-packages\dmath-0.9-py2.5.egg\dmath\__init__.py",
line 343, in 
NameError: name 'context' is not defined
>>> 

However, getting help for things like random, random.uniform, math, list,
tuple, works fine.
For example,

>>> help('random.uniform')
Help on method uniform in random:
random.uniform = uniform(self, a, b) method of random.Random
instance
    Get a random number in the range [a, b).
>>>
==
Dick Moores



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


[Tutor] This is the online help utility [tutorial].

2007-12-05 Thread bhaaluu
Greetings,
Recently a thread about Python's online help utility was buried
within another thread with a different Subject. So I thought I'd
try to summarize that thread within a thread in a thread of its own.
It would be helpful for those running different versions of Python
on differnet systems to contribute their online help experiences
if they differ from what I'm posting. I'm running Python 2.4.3 in
bash, in a Konsole (KDE) running on the Linux 2.6.15 kernel.

1) Starting the Python Interactive Interpreter:

$ python
Python 2.4.3 (#2, Oct  6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

It says to type "help", so that's what I type:

>>> "help"
'help'

Oops! That doesn't work very well now, does it?

>>> help
Type help() for interactive help, or help(object) for help about object.

A! That's better. If I'm new to Python, I probably won't know what
'object' means
in help(object), so maybe 'help()' will be a good start?

 >>> help()

Welcome to Python 2.4!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://www.python.org/doc/tut/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help>

OK! The first thing I notice is that the interactive prompt has changed from
'>>>' to 'help>'.  There is some VERY USEFUL INFORMATION in the splash
text. For example, to get out of the help utility, and return to the
interpreter,
I need to type "quit" <-- it can be typed WITHOUT the quotes!

Three other words are suggested for use here: modules, keywords, and topics.
So now I have four words I can use at the 'help>' prompt to get help:
quit, topics, modules, and keywords.

help> keywords
Here is a list of the Python keywords.  Enter any keyword to get more help.

and elseimport  raise
assert  except  in  return
break   execis  try
class   finally lambda  while
continuefor not yield
def fromor
del global  pass
elifif  print

help> pass


  6.4 The pass statement

pass_stmt::= "pass"

  Download entire grammar as text.[1]
[snip]

On my machine, when the help has ended, END is displayed, and I must
type a "q" to get back to the help prompt.

help> modules

Please wait a moment while I gather a list of all available modules...

ArgImagePlugin  UserListfpectl  qtxml
ArrayPrinterUserString  fpformatquopri
BaseHTTPServer  WalImageFileftplib  random
[snip]
Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".

help> modules random

Here is a list of matching modules.  Enter any module name to get more help.

random - Random variable generators.
whrandom - Wichman-Hill random number generator.
_random
RNG (package) - x=CreateGenerator(seed) creates an random number
generator stream
RandomArray

Here again, when at the help> prompt, no quotes are necessary around
the words entered.

help> topics
 topics

Here is a list of available topics.  Enter any topic name to get more help.

ASSERTION   DELETIONLOOPING SEQUENCES
ASSIGNMENT  DICTIONARIESMAPPINGMETHODS  SHIFTING
ATTRIBUTEMETHODSDICTIONARYLITERALS  MAPPINGSSLICINGS
ATTRIBUTES  DYNAMICFEATURES METHODS SPECIALATTRIBUTES
[snip]

help> POWER


  5.4 The power operator

  The power operator binds more tightly than unary operators on its left;
  it binds less tightly than unary operators on its right. The syntax is:

power::= primary[1] ["**" u_expr[2]]

  Download entire grammar as text.[3]
[snip]
:

The colon means I can type SPACE for another page, or ARROW key to move a line.
At the end, or at any time, I can type a "q" to return to the help> prompt.

help> quit

You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as 

Re: [Tutor] lstrip removes '/' unexpectedly

2007-12-05 Thread Tim Johnson
On Monday 03 December 2007, Tiger12506 wrote:
> >> ##
> >>
> > s = '/home/test/'
> > s1 = s.lstrip('/ehmo')
> > s1
> >>
> >> 'test/'
> >> ##
I've been having some problems posting to this list,
so this is also a kind of test:
I just wrote a global lstring
def lstrip(S,chars):
if S.startswith(chars):
return S[len(chars):]
else: return S

It begs for a extension of the string object I guess,
but this (and a corollary rstrip) works for me.
Tim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] info, help, guidence,...

2007-12-05 Thread Kent Johnson
jeff witt wrote:

> here are a few questions that go through my head...
>  how does python get applied to a GUI?  

There are many possibilities, see
http://wiki.python.org/moin/CategoryPyGUI

Also you can use native window toolkits on Windows and Mac.

> is 
> it accepted in the world of programming professionally?  ( i am 
> interested in a career too, as well as a new hobby),.

Yes.
http://jobsearch.monster.com/Search.aspx?q=python&fn=&lid=&re=130&cy=us&brd=1&JSNONREG=1

>   i use linux, and python seems to be everywhere for linux,.. and i read 
> that it works on windows too but is it accepted in "those" circles? 

Yes

> what is pythons strengths and weaknesses, IE. web/Internet, or program 
> development, operating system things,... 

Pretty much anything except operating systems, device drivers and 
real-time programs:
http://www.python.org/about/apps/

>  what would you (or you guys) 
> recomend for the first language?  or like my brother says, "just learn 
> something and stop asking me questions"

Python, of course!

> if python was released in 1991 how long will it remain a current or a 
> applicable language? or i guess i am asking, what is the normal life of 
> a programming language before it is obsolete?

Python popularity is increasing, by some measures at least:
http://www.tiobe.com/tpci.htm
http://radar.oreilly.com/archives/2007/05/state_of_the_co_10.html

> well, like i mentioned, any help or info would be greatly appreciated,   
> i have been to some of the beginner sites and tried the whole "hello 
> world" thing, and i unfortunately realize i am years from actually 
> contributing to any open source project,  (especially since i am still 
> struggling with the file system in linux [only been using it for 8or9 
> months])

There are quite a few good Python tutorials for non-programmers:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

A good book for a beginner is Dawson's "Python Programming for the 
absolute beginner".

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


Re: [Tutor] lstrip removes '/' unexpectedly

2007-12-05 Thread Tim Johnson
On Monday 03 December 2007, Tiger12506 wrote:
> >> ##
> >>
> > s = '/home/test/'
> > s1 = s.lstrip('/ehmo')
> > s1
> >>
> >> 'test/'
> >> ##
I've been having some problems posting to this list,
so this is also a kind of test:
I just wrote a global lstring
def lstrip(S,chars):
if S.startswith(chars):
return S[len(chars):]
else: return S

It begs for a extension of the string object I guess,
but this (and a corollary rstrip) works for me.
Tim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] info, help, guidence,...

2007-12-05 Thread Brian Wisti
Hi Jeff,

On Dec 5, 2007 7:30 AM, jeff witt <[EMAIL PROTECTED]> wrote:
>
> Hello,
> i have some questions about programming in general and python,..

Welcome! You have a lot of great questions. Tell your brother to relax.

First off, Python is a great first language because it was written
with an eye towards being consistent and easy to learn. It is also a
very powerful language that will continue to be useful for you as your
needs and knowledge expand. I've been using Python since 2000 and it
is still an important part of my development toolkit.

Now for your questions ...

> here are a few questions that go through my head...
>  how does python get applied to a GUI?

Python itself is just a language, and uses libraries for GUI applications.

* Tkinter [http://www.pythonware.com/library/tkinter/introduction/]
comes with the standard Python distribution, which makes it the
official GUI library.
* WxPython [http://www.wxpython.org] is a very popular
cross-platform GUI library. It's an extra download, and maybe a little
advanced for somebody who is *just* starting out with programming. But
hey, don't let that stop you.
* IronPython
[http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython] is
actually a different version of Python written specifically for the
.NET environment. Most of the language features are the same as
CPython (the standard Python you would get from python.org), and in
addition it has full access to the .NET framework including Windows
Forms. It's very powerful, and I've had a lot of fun with it.
* Jython [http://jython.org] is a version of Python written in
Java. It's a little behind CPython on features, but has full access to
the Java API including Swing.

IronPython and Jython require a bit of setup to get started with, so
they might not be the best choices for your first day. Play with
Tkinter and maybe WxPython for the moment, the other two will be there
when you're interested.

> why dont universities teach it?

They do. MIT is a high profile example. They recently incorporated
Python into their courses.

> is there an online class i can take for it?

Probably, but save your money and go to Google with the phrase "Python
tutorial". You'll be overwhelmed with the amount of instructional
material. Python is fun to write about.

> training certificates?

Yes, but I am not aware of any organizations that care about Python
certification. I've always been asked to show what I know, but never
about certification.

> is it accepted in the world of programming professionally?  ( i am interested 
> in a
> career too, as well as a new hobby),.

Oh my yes. Python is used by companies all over the world. Google and
NASA are especially impressive-sounding examples of organizations that
use Python. Check http://www.python.org/about/success/ for a very long
list of organizations using Python.

>   i use linux, and python seems to be everywhere for linux,.. and i read
> that it works on windows too but is it accepted in "those" circles?

Absolutely. The set of Python users crosses a huge number of operating
systems, including Windows.

> what is pythons strengths and weaknesses, IE. web/Internet, or program
> development, operating system things,...

Python is a very high level language with great library support, and
has been useful for me in every problem domain. A Python application
normally runs slower than an application built in C/C++, so it usually
isn't the first choice for time-critical applications where somebody
could *die*. There are many ways to speed up your Python applications,
though, and it can be used by a knowledgeable developer to create
those time-critical apps.

> what would you (or you guys) recomend for the first language?

Perl! No, that was just a joke. You are asking the Python tutor list
about the best starting language. I think you can guess what the
answer is going to be.

> or like my brother says, "just learn something and stop asking me questions"

Man, tell that guy to switch to decaf. I'd say "just learn something
and keep asking questions"

> if python was released in 1991 how long will it remain a current or a 
> applicable language? or i guess i am asking, what is the normal life of a 
> programming language before it is obsolete?

For a very long time indeed. C is over 30 years old and still being
used for creating new applications. COBOL is about 4 million years old
(give or take a few million) and people still make good money using
it. The Python team has done an excellent job of keeping pace with the
needs of the day, and I don't think Python is going away any time
soon.

>
> well, like i mentioned, any help or info would be greatly appreciated,   i
> have been to some of the beginner sites and tried the whole "hello world"
> thing, and i unfortunately realize i am years from actually contributing to
> any open source project,  (especially since i am still struggling with the
> file system in linux [only been using it for 8or9 months])


Re: [Tutor] info, help, guidence,...

2007-12-05 Thread taserian
Sorry if this isn't the right place for it, but today's xkcd comic strip is
very apropos for the newly illuminated in all things Python.

http://www.xkcd.com/

Tony R.

On Dec 5, 2007 12:00 PM, bhaaluu <[EMAIL PROTECTED]> wrote:

> Greetings,
>
> On Dec 5, 2007 10:30 AM, jeff witt <[EMAIL PROTECTED]> wrote:
> >
> > Hello,
> > i have some questions about programming in general and python,..
> > my brother (who is a programmer) guides me to ".net" languages,  and i
> am
> > not too sure why, however, he is getting sick of me pestering him with
> my
> > questions,..
> > i like the little i know about python, it seems to be user friendly,
> > however, i am not finding clear answers about what it does compared to
> > ".net" for example.
> >  I really know nothing about programming (which i am sure is obvious) so
> ANY
> > info would be helpful, ...
> >
> > here are a few questions that go through my head...
> >  how does python get applied to a GUI?
>
> http://wiki.python.org/moin/GuiProgramming
> TkInter is Python's "standard" GUI library
>
> > why dont universities teach it? is
> > there an online class i can take for it?  training certificates?   is it
> > accepted in the world of programming professionally?  ( i am interested
> in a
> > career too, as well as a new hobby),.
>
> Some universities do use Python to teach Computer Science topics.
> There are several online tutorials to get you started, for example:
> http://docs.python.org/tut/
> is the 'official' Python tutorial
>
> >   i use linux, and python seems to be everywhere for linux,.. and i read
> > that it works on windows too but is it accepted in "those" circles?
> > what is pythons strengths and weaknesses, IE. web/Internet, or program
> > development, operating system things,...   what would you (or you guys)
> > recomend for the first language?  or like my brother says, "just learn
> > something and stop asking me questions"
>
> Python is an excellent first programming language.
> The Tutor list is for learning Python as a first programming language.
> There seem to be an equal number of Tutors who use Linux or Windows.
>
> > if python was released in 1991 how long will it remain a current or a
> > applicable language? or i guess i am asking, what is the normal life of
> a
> > programming language before it is obsolete?
>
> That's a good question!
>
> >
> > well, like i mentioned, any help or info would be greatly appreciated,
> i
> > have been to some of the beginner sites and tried the whole "hello
> world"
> > thing, and i unfortunately realize i am years from actually contributing
> to
> > any open source project,  (especially since i am still struggling with
> the
> > file system in linux [only been using it for 8or9 months])
> >
> > God bless you  guys, and thank you for your site and willingness to
> share
> > and help!
> >
> > jeff
>
> There are several excellent tutorials and books online for free.
> You'll have to check them out and see which ones 'click' for you.
> Each person learns stuff differently, and each writer has a different
> 'style' of writing, so you might find two tutorials that cover the same
> things, but you'll like one better than the other.
>
> This is a good place to ask questions!
> Happy Programming!
> --
> b h a a l u u at g m a i l dot c o m
> http://www.geocities.com/ek.bhaaluu/python/index.html
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how to accept an integer?

2007-12-05 Thread Mahesh N
I dun understand the mistake. My aim is to accept an integer number. The
python lookup in IDLE asks for a string object but the interpreter returns
with the following error message. Some one pls explain.
Thank You

PS : I understand that i can do type conversion after getting input thru
raw_input(). But how does input() function work?

>>> prompt="temme a number\n"
>>> speed =input(prompt)

Traceback (most recent call last):
  File "", line 1, in 
speed =input(prompt)
TypeError: 'str' object is not callable
>>> speed =input("temme a number\n")

Traceback (most recent call last):
  File "", line 1, in 
speed =input("temme a number\n")
TypeError: 'str' object is not callable
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to accept an integer?

2007-12-05 Thread Kent Johnson
Mahesh N wrote:
> I dun understand the mistake. My aim is to accept an integer number. The 
> python lookup in IDLE asks for a string object but the interpreter 
> returns with the following error message. Some one pls explain.
> Thank You
> 
> PS : I understand that i can do type conversion after getting input thru 
> raw_input(). But how does input() function work?
> 
>  >>> prompt="temme a number\n"
>  >>> speed =input(prompt)
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> speed =input(prompt)
> TypeError: 'str' object is not callable
>  >>> speed =input("temme a number\n")

It looks like you have named a string 'input'; this hides the built-in 
'input' function and causes the error you are seeing. Restart IDLE and 
input() should work correctly.

A safer way to accept an integer is to use raw_input() and convert the 
result yourself:

try:
   speed = int(raw_input(prompt))
except ValueError:
   print 'You did not enter an integer'

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


Re: [Tutor] lstrip removes '/' unexpectedly

2007-12-05 Thread Tim Johnson
On Friday 30 November 2007, Eric Brunson wrote:
> Tim Johnson wrote:
> > Hello:
> > I'm seeing some strange behavior with lstrip operating
> > on string representations of *nix-style file paths
> >
> > Example:
>  s = '/home/test/'
>  s1 = s.lstrip('/home')
>  s1
> >
> > 'test/'   ## '/test/' was expected! '/' was unexpectedly removed
>
 Hi Folks:
 I actually resent this as a test because I've had problems contacting
 this list. The understanding of it percolated up to my wee little brain
 shortly after the first send (which didn't arrive).
I wrote the following as a solution:
def lstrip(S,chars):
if S.startswith(chars):
return S[len(chars):]
else: return S
and a global rstrip would be an easy corrolary.
Thanks
(and thanks also to Danny and Kent for clearing up the email problem)
Tim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] lstrip removes '/' unexpectedly

2007-12-05 Thread Tim Johnson
Trying this again. This list has not be receiving all
of my emails..
==
On Friday 30 November 2007, Eric Brunson wrote:
> Tim Johnson wrote:
> > Hello:
> > I'm seeing some strange behavior with lstrip operating
> > on string representations of *nix-style file paths
> >
> > Example:
>  s = '/home/test/'
>  s1 = s.lstrip('/home')
>  s1
> >
> > 'test/'   ## '/test/' was expected! '/' was unexpectedly removed
>
 Hi Folks:
 I actually resent this as a test because I've had problems contacting
 this list. The understanding of it percolated up to my wee little brain
 shortly after the first send (which didn't arrive).
I wrote the following as a solution:
def lstrip(S,chars):
if S.startswith(chars):
return S[len(chars):]
else: return S
and a global rstrip would be an easy corrolary.
Thanks
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to accept an integer?

2007-12-05 Thread Eric Brunson
Mahesh N wrote:
> I dun understand the mistake. My aim is to accept an integer number. 
> The python lookup in IDLE asks for a string object but the interpreter 
> returns with the following error message. Some one pls explain.
> Thank You
>
> PS : I understand that i can do type conversion after getting input 
> thru raw_input(). But how does input() function work?

Did you read this?

http://docs.python.org/lib/built-in-funcs.html#l2h-40

What do you not understand about it?

>
> >>> prompt="temme a number\n"
> >>> speed =input(prompt)
>
> Traceback (most recent call last):
>   File "", line 1, in 
> speed =input(prompt)
> TypeError: 'str' object is not callable
> >>> speed =input("temme a number\n")
>
> Traceback (most recent call last):
>   File "", line 1, in 
> speed =input("temme a number\n")
> TypeError: 'str' object is not callable
>
>
>
> 
>
> ___
> 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] Problems with List Server?

2007-12-05 Thread Tim Johnson
On Monday 03 December 2007, Tim Johnson wrote:
> I appear to be having a weird problem with the List Server.
> At first, email sent to this address did not appear at
> all.
> After contacting the ML maintainers only one email from
> me to this address go through. When I replied to the
> thread which the email started, it was not delivered.
>
> This is a very frustrating turn of events and I am hoping
> that it will be corrected soon. I wonder if anyone else is
> having similar problems?
>
> I suspect that this email will be delivered, but I might not
> be able to send another on the same thread.
>
> Any ideas?
> tim
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

If this is not delivered to the ML, then the problem
persists.
thanks
Tim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] info, help, guidence,...

2007-12-05 Thread bhaaluu
Greetings,

On Dec 5, 2007 10:30 AM, jeff witt <[EMAIL PROTECTED]> wrote:
>
> Hello,
> i have some questions about programming in general and python,..
> my brother (who is a programmer) guides me to ".net" languages,  and i am
> not too sure why, however, he is getting sick of me pestering him with my
> questions,..
> i like the little i know about python, it seems to be user friendly,
> however, i am not finding clear answers about what it does compared to
> ".net" for example.
>  I really know nothing about programming (which i am sure is obvious) so ANY
> info would be helpful, ...
>
> here are a few questions that go through my head...
>  how does python get applied to a GUI?

http://wiki.python.org/moin/GuiProgramming
TkInter is Python's "standard" GUI library

> why dont universities teach it? is
> there an online class i can take for it?  training certificates?   is it
> accepted in the world of programming professionally?  ( i am interested in a
> career too, as well as a new hobby),.

Some universities do use Python to teach Computer Science topics.
There are several online tutorials to get you started, for example:
http://docs.python.org/tut/
is the 'official' Python tutorial

>   i use linux, and python seems to be everywhere for linux,.. and i read
> that it works on windows too but is it accepted in "those" circles?
> what is pythons strengths and weaknesses, IE. web/Internet, or program
> development, operating system things,...   what would you (or you guys)
> recomend for the first language?  or like my brother says, "just learn
> something and stop asking me questions"

Python is an excellent first programming language.
The Tutor list is for learning Python as a first programming language.
There seem to be an equal number of Tutors who use Linux or Windows.

> if python was released in 1991 how long will it remain a current or a
> applicable language? or i guess i am asking, what is the normal life of a
> programming language before it is obsolete?

That's a good question!

>
> well, like i mentioned, any help or info would be greatly appreciated,   i
> have been to some of the beginner sites and tried the whole "hello world"
> thing, and i unfortunately realize i am years from actually contributing to
> any open source project,  (especially since i am still struggling with the
> file system in linux [only been using it for 8or9 months])
>
> God bless you  guys, and thank you for your site and willingness to share
> and help!
>
> jeff

There are several excellent tutorials and books online for free.
You'll have to check them out and see which ones 'click' for you.
Each person learns stuff differently, and each writer has a different
'style' of writing, so you might find two tutorials that cover the same
things, but you'll like one better than the other.

This is a good place to ask questions!
Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
http://www.geocities.com/ek.bhaaluu/python/index.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to accept an integer?

2007-12-05 Thread Mahesh N
On Dec 6, 2007 2:31 AM, Mahesh N <[EMAIL PROTECTED]> wrote:

> I dun understand the mistake. My aim is to accept an integer number. The
> python lookup in IDLE asks for a string object but the interpreter returns
> with the following error message. Some one pls explain.
> Thank You
>
> PS : I understand that i can do type conversion after getting input thru
> raw_input(). But how does input() function work?
>
> >>> prompt="temme a number\n"
> >>> speed =input(prompt)
>
> Traceback (most recent call last):
>   File "", line 1, in 
> speed =input(prompt)
> TypeError: 'str' object is not callable
> >>> speed =input("temme a number\n")
>
> Traceback (most recent call last):
>   File "", line 1, in 
> speed =input("temme a number\n")
> TypeError: 'str' object is not callable
>
>
>
>
absolutely, i went up the shell and found out that i had declared a variable
named input and it was shadowing the input() function. i restarted the shell
and now everything's fine.
Thanks Everyone.




-- 
The Place where I Come from,
We Face our Enemies,
If our enemy is Unarmed,
We Offer our SWORD!!!


Courtesy "Warrior Within"
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to accept an integer?

2007-12-05 Thread Mahesh N
On Dec 6, 2007 2:37 AM, Eric Brunson <[EMAIL PROTECTED]> wrote:

> Mahesh N wrote:
> > I dun understand the mistake. My aim is to accept an integer number.
> > The python lookup in IDLE asks for a string object but the interpreter
> > returns with the following error message. Some one pls explain.
> > Thank You
> >
> > PS : I understand that i can do type conversion after getting input
> > thru raw_input(). But how does input() function work?
>
> Did you read this?
>
> http://docs.python.org/lib/built-in-funcs.html#l2h-40
>
> What do you not understand about it?
>
> >
> > >>> prompt="temme a number\n"
> > >>> speed =input(prompt)
> >
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > speed =input(prompt)
> > TypeError: 'str' object is not callable
> > >>> speed =input("temme a number\n")
> >
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > speed =input("temme a number\n")
> > TypeError: 'str' object is not callable
> >
> >
> >
> > 
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
sorry i dint go thru the docs. i thought i will delve into it once i felt
comfortable with the language.
is the new line character not allowed in input() statement ???
cuz i tried it without the new line character and it works fine.
More over i find python to be a little sluggish after having worked with C
and Java. But one thing's for sure. Its damn powerful and a lovely language.
can someone temme where python is most applicable?
server side scripting? am i guessing it right?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Selecting a browser

2007-12-05 Thread Kent Johnson
Ricardo Aráoz wrote:
> The other way to handle it would be to include in the documentation that
> windows paths should have '/' or '' instead of '\\'.
> The choice would depend on whether the authors consider there is a use
> for the escape character, and what value that escape character might have.

Yes, without any docs it's hard to know whether this is a bug or a feature.

> I've registered in the issue tracker, but got scared and didn't post
> anything. Can I be certain the blokes maintaining this module will see
> it, or should and try contact them directly?

The issue tracker is the best way I know to contact the maintainers.

You might want to post two issues - one for the lack of documentation 
and one for the problem with \. It's very helpful to include any 
suggested fix.

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


[Tutor] Best way of learning

2007-12-05 Thread andy
Dear Pythonistas

Over a year ago I dabbled in learning Python, working my way through a 
few tutorials, the Deitel's  "How to program in Python" and Hetland's 
"Practical Python", until I came across the OOP sections. My mind just 
froze up, and I found myself wondering if I had really understood 
anything at all. In addition to which I didn't have any "itch" that I 
needed to scratch so was trying to learn something without any purpose. 
So I stopped.

In the interim however I did have a few occasions to write programs and 
scripts for my GNU/Linux system to do the odd thing here and there, a 
few conversion programs and calculators. I found myself going back to 
the books and trying to figure it out again, and am proud to say that I 
have a few programs now that are probably not elegant nor the most 
efficient or stylish, but do the job.

This has re-awakened my interest in programming and as I am going back 
to basics again I am conscious that I want to approach the matter 
differently. I *don't* work in a programming environment, nor am I 
likely to ever get into development, although would be interested in 
learning ethical hacking (the idea just interests me - too many 
espionage movies as a kid I guess).

I am happy to read, and have done a fair amount, but am concerned about 
getting too overwhelmed and confused again. I acknowledge and realise 
the value of practising by scripting programs and enjoy the intellectual 
challenge of the debugging process, and trying to think through the 
trick of a particular way of cracking a problem.

So, after this long-winded introduction, I was hoping to pick the wisdom 
of this list to get some pointers of what to do/not to do to make the 
most effective use of the few hours I have to learn how to program using 
Python. So, any advice for someone in their mid-40s who would like to 
learn Python in a more methodical and effective manner?

Thanks in anticipation.

Andy


-- 

"If they can get you asking the wrong questions, they don't have to worry about 
the answers." - Thomas Pynchon, "Gravity's Rainbow"

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


Re: [Tutor] Random Number Generator

2007-12-05 Thread bhaaluu
$ python
>>> help()
help> 'topics'
[snip]
CODEOBJECTS FRAMES  POWER   TUPLES
[snip]
help> 'POWER'


  5.4 The power operator

  The power operator binds more tightly than unary operators on its left;
  it binds less tightly than unary operators on its right. The syntax is:

power::= primary[1] ["**" u_expr[2]]

  Download entire grammar as text.[3]
:

It seems to be case-sensitive Mr. Moores!
When I entered 'power' (like you did), I also got:
help> 'power'
no Python documentation found for 'power'

Try entering: 'POWER'  (all caps, just like in the output).

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m


On Dec 5, 2007 6:31 AM, Dick Moores <[EMAIL PROTECTED]> wrote:
>
>  At 02:41 PM 12/4/2007, bhaaluu wrote:
>
> I'm running the Python 2.4.3 interactive interpreter
>  in a Konsole at a bash prompt:
>
>  $ python
>
>  >>> help
>  Type help() for interactive help, or help(object) for help about object.
>  But look what I get with Python 2.5.1 and Win XP:
>
>  =
>  >>> help('topics')
>
>  Here is a list of available topics.  Enter any topic name to get more help.
>
>  ASSERTION   DEBUGGING   LITERALS
> SEQUENCEMETHODS2
>  ASSIGNMENT  DELETIONLOOPING SEQUENCES
>  ATTRIBUTEMETHODSDICTIONARIESMAPPINGMETHODS  SHIFTING
>  ATTRIBUTES  DICTIONARYLITERALS  MAPPINGSSLICINGS
>  AUGMENTEDASSIGNMENT DYNAMICFEATURES METHODS
> SPECIALATTRIBUTES
>  BACKQUOTES  ELLIPSISMODULES
> SPECIALIDENTIFIERS
>  BASICMETHODSEXCEPTIONS  NAMESPACES  SPECIALMETHODS
>  BINARY  EXECUTION   NONESTRINGMETHODS
>  BITWISE EXPRESSIONS NUMBERMETHODS   STRINGS
>  BOOLEAN FILES   NUMBERS SUBSCRIPTS
>  CALLABLEMETHODS FLOAT   OBJECTS TRACEBACKS
>  CALLS   FORMATTING  OPERATORS   TRUTHVALUE
>  CLASSES FRAMEOBJECTSPACKAGESTUPLELITERALS
>  CODEOBJECTS FRAMES  POWER   TUPLES
>  COERCIONS   FUNCTIONS   PRECEDENCE  TYPEOBJECTS
>  COMPARISON  IDENTIFIERS PRINTINGTYPES
>  COMPLEX IMPORTING   PRIVATENAMESUNARY
>  CONDITIONAL INTEGER RETURNING   UNICODE
>  CONTEXTMANAGERS LISTLITERALSSCOPING
>  CONVERSIONS LISTS   SEQUENCEMETHODS1
>
>  >>> help('power')
>  no Python documentation found for 'power'
>
>  >>> help('lists')
>  no Python documentation found for 'lists'
>
>  >>> help('classes')
>  no Python documentation found for 'classes'
>
>  >>> help('modules')
>
>  Please wait a moment while I gather a list of all available modules...
>
>
>  Traceback (most recent call last):
>File "", line 1, in 
>  help('modules')
>File "E:\Python25\lib\site.py", line 346, in __call__
>  return pydoc.help(*args, **kwds)
>File "E:\Python25\lib\pydoc.py", line 1645, in __call__
>  self.help(request)
>File "E:\Python25\lib\pydoc.py", line 1682, in help
>  elif request == 'modules': self.listmodules()
>File "E:\Python25\lib\pydoc.py", line 1803, in listmodules
>  ModuleScanner().run(callback)
>File "E:\Python25\lib\pydoc.py", line 1854, in run
>  for importer, modname, ispkg in pkgutil.walk_packages():
>File "E:\Python25\lib\pkgutil.py", line 110, in walk_packages
>  __import__(name)
>File
> "E:\Python25\lib\site-packages\dmath-0.9-py2.5.egg\dmath\__init__.py", line
> 343, in 
>  NameError: name 'context' is not defined
>  >>>
>  
>  However, getting help for things like random, random.uniform, math, list,
> tuple, works fine.
>
>  For example,
>
>  
>  >>> help('random.uniform')
>  Help on method uniform in random:
>
>  random.uniform = uniform(self, a, b) method of random.Random instance
>  Get a random number in the range [a, b).
>  >>>
>  ==
>
>  Dick Moores
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] xkcd on Python

2007-12-05 Thread Kent Johnson
http://xkcd.com/353/

:-)

Kent

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


Re: [Tutor] lstrip removes '/' unexpectedly

2007-12-05 Thread Tim Johnson
Gentlemen:
There appears to still be a problem.
The email below was also sent, but I do not see
that it has been received. Send time was about
2 hours previous to this. 
(09:27:42 Alaska Standard Time)
tim
--
On Friday 30 November 2007, Eric Brunson wrote:
> Tim Johnson wrote:
> > Hello:
> > I'm seeing some strange behavior with lstrip operating
> > on string representations of *nix-style file paths
> >
> > Example:
>  s = '/home/test/'
>  s1 = s.lstrip('/home')
>  s1
> >
> > 'test/'   ## '/test/' was expected! '/' was unexpectedly removed
>
 Hi Folks:
 I actually resent this as a test because I've had problems contacting
 this list. The understanding of it percolated up to my wee little brain
 shortly after the first send (which didn't arrive).
I wrote the following as a solution:
def lstrip(S,chars):
if S.startswith(chars):
return S[len(chars):]
else: return S
and a global rstrip would be an easy corrolary.
Thanks
(and thanks also to Danny and Kent for clearing up the email problem)
Tim
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] info, help, guidence,...

2007-12-05 Thread jeff witt
Hello, 
i have some questions about programming in general and python,.. 
my brother (who is a programmer) guides me to ".net" languages,  and i am not 
too sure why, however, he is getting sick of me pestering him with my 
questions,..
i like the little i know about python, it seems to be user friendly, however,  
i am not finding clear answers about what it does compared to ".net" for 
example. 
 I really know nothing about programming (which i am sure is obvious) so ANY 
info would be helpful, ... 

here are a few questions that go through my head...
 how does python get applied to a GUI?  why dont universities teach it? is 
there an online class i can take for it?  training certificates?   is it 
accepted in the world of programming professionally?  ( i am interested in a 
career too, as well as a new hobby),.
  i use linux, and python seems to be everywhere for linux,.. and i read that 
it works on windows too but is it accepted in "those" circles?  
what is pythons strengths and weaknesses, IE. web/Internet, or program 
development, operating system things,...   what would you (or you guys) 
recomend for the first language?  or like my brother says, "just learn 
something and stop asking me questions"
if python was released in 1991 how long will it remain a current or a 
applicable language? or i guess i am asking, what is the normal life of a 
programming language before it is obsolete?

well, like i mentioned, any help or info would be greatly appreciated,   i have 
been to some of the beginner sites and tried the whole "hello world" thing, and 
i unfortunately realize i am years from actually contributing to any open 
source project,  (especially since i am still struggling with the file system 
in linux [only been using it for 8or9 months])

God bless you  guys, and thank you for your site and willingness to share and 
help!

jeff






  

Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to accept an integer?

2007-12-05 Thread Jerry Hill
On Dec 5, 2007 4:01 PM, Mahesh N <[EMAIL PROTECTED]> wrote:
> I dun understand the mistake. My aim is to accept an integer number. The
> python lookup in IDLE asks for a string object but the interpreter returns
> with the following error message. Some one pls explain.
> Thank You
>
>  PS : I understand that i can do type conversion after getting input thru
> raw_input(). But how does input() function work?
>
> >>> prompt="temme a number\n"
> >>> speed =input(prompt)
>
>  Traceback (most recent call last):
>   File "", line 1, in 
> speed =input(prompt)
> TypeError: 'str' object is not callable

You have code that you haven't shown us.  My crystal ball tells me
that somewhere above this point you did input = "Some String", thus
shadowing the builtin input function.  Start a new interpreter and try
again and you should find that it works as expected.

As I'm sure you'll hear from others, it really is best to use
raw_input instead.  If you want an integer instead of a string, do
something like this:

speed = int(raw_input(prompt))

That way whatever the user types isn't run as python code, just read
in as a string and then converted into an integer.

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


Re: [Tutor] how to accept an integer?

2007-12-05 Thread Kent Johnson
Bryan Fodness wrote:
> speed = int(raw_input(prompt))
> 
>  
> Is this how ALL known integers should be input?

Yes, with probably a try/except block and a while loop around it to 
handle invalid input.

There are two good reasons for doing this instead of using input:
- it guarantees that the input is in fact an integer (raises ValueError 
otherwise)
- it protects against malicious input (you can do a lot of damage in an 
input(), whatever you type is eval'ed)

For input of unknown integers, you are on your own, Python does not have 
anything built-in for that ;-)

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


Re: [Tutor] how to accept an integer?

2007-12-05 Thread Jerry Hill
On Dec 5, 2007 4:46 PM, Bryan Fodness <[EMAIL PROTECTED]> wrote:
> On Dec 5, 2007 4:16 PM, Jerry Hill <[EMAIL PROTECTED]> wrote:
> > speed = int(raw_input(prompt))
>
>
> Is this how ALL known integers should be input?

I don't think I understand the question.  If you are prompting your
user to enter an integer from the console, then yes, this is the
general way you should do it, probably wrapped in a try/except block.

You certainly don't have to do it all in one line like that.  Instead,
you could split it up into component parts, like this:

prompt = "Please enter a number between 1 and 10:\n"
user_input = raw_input(prompt)
try:
user_number = int(user_input)
except ValueError:
print "You did not enter a number."

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


Re: [Tutor] info, help, guidence,...

2007-12-05 Thread Alan Gauld
"jeff witt" <[EMAIL PROTECTED]> wrote

> my brother (who is a programmer) guides me to ".net" languages,

OK, Python is a .NET language too.

> and i am not too sure why,

.NET is the new Microsoft standard and their counter attack on Java.
It offers a language neutral runtime environment that allows you to
write the GUI(user interface) in VB.Net, the database intrerface in
Managed C++ and the algorithms in C# and then link them all
together in a single program. That used to be very hard to do.
.NET offers some other bits too but thats the main advantage IMHO.
(Wikipedia is your friend for all things IT related - try looking up
.NET there)

> i like the little i know about python, it seems to be user friendly,
> however,  i am not finding clear answers about what it does
> compared to ".net" for example.

They are two different things. .NET is an environment for running
programs, rather like a virtual operating system, that runs on the
Windows platform. You can use multiple programming languages
within .NET, including Python.

> here are a few questions that go through my head...
> how does python get applied to a GUI?

Thee are several GUI toolkits, the standard one(ie comes with python)
is Tkinter which in turn is a Python wrapper around the long standing
Tc;/Tk GUI toolkit (Tk=Toolkit). But there are others including the
.NET GUI and Java GUIs(via Jython).

> why dont universities teach it?

Several do, and even more colleges and high schools.
Universities tend to prefer Java because it is more like classical
programming languages and enforces a stricter style of programming
which fits (arguably) better to the University curriculum.

> is there an online class i can take for it?

There are many online tutorials (including mine) and you will find
a list of links on the Python web site under the Non programmers
section.

> training certificates?

Not sure on that one, maybe...

> is it accepted in the world of programming professionally?

Yes there are many companies who use Python - see the python
web site for examples. Google is perhaps the best known but there
are plenty others. It falls under the general heading of scripting
languages and is considered to be on a par with Perl, Tcl, JavaScript,
Lisp and others.

> ( i am interested in a career too, as well as a new hobby),.

Several of the people on this list use Python in their day jobs.
And for some Python is their day job!

>  i use linux, and python seems to be everywhere for linux,..
> and i read that it works on windows too

Yes, Python workls on a multitude of platforms incliuding
the "big three": Unix, Windows, MacOS but also on VAX VMS,
MVS, and several more obscure OS.

> but is it accepted in "those" circles?

Yes, especially by the people who use it there! :-)

> what is pythons strengths and weaknesses,

It is a general purpose scripting language that is easy to learn
and easy to maintain and yet extensible and powerful. Read
the Python web site for a fuller story.

> IE. web/Internet, or program development, operating system
> things,...

I wouldn't write an OS nor anything too close to the hardware
(graphics driver say), but otherwise it can do all of those things
and if you read the archives of this group you will find relative
novices doing all of them.

> what would you (or you guys) recomend for the first language?

Python obviously! :-)

> or like my brother says, "just learn something and stop
> asking me questions"

And to some extent he is right. Once you learn any programming
language its relatively easy to convert to another. The hard bit is
the concepts involved in programming not the details of any
one language.

> if python was released in 1991 how long will it remain a current
> or a applicable language? or i guess i am asking, what is the
> normal life of a programming language before it is obsolete?

COBOL, Lisp, BASIC and ForTran were all invented before 1963
and are all still in regular use. Smalltalk started in 1973 and 
"finalised"
in 1980 and is still a highly influential language. C was invented in
the mid 70's and is still king of OS programming. Java was 1994(?)
and is the current "mainstream" leader.

But I could point to many languages which have come and gone
in the same period: CHILL, Coral, Snoball, PL/1, Modula2, Oberon.
You can still get tools for all of  these but the job market is
vanishingly small. Yet in their day all were mainstream or seen as
rising stars.

So how long depends on how good the language is, how well
it is marketed, and fashion amongst other factors.

> i am years from actually contributing to any open source
> project,

You probably could contribute as a tester or documentation
writer within a few weeks or months. You could be at the stage
of fixing bugs in less than a year. It depends on how much time
you commit...

HTH,


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


___
Tutor maillist

Re: [Tutor] Random Number Generator

2007-12-05 Thread Dick Moores
At 04:35 AM 12/5/2007, bhaaluu wrote:
>It seems to be case-sensitive Mr. Moores!
>When I entered 'power' (like you did), I also got:
>help> 'power'
>no Python documentation found for 'power'
>
>Try entering: 'POWER'  (all caps, just like in the output).

Thanks! I should have tried that.

Dick Moores


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


Re: [Tutor] Time module

2007-12-05 Thread Tim Golden
Kent Johnson wrote:
> Norman Khine wrote:
>> Hello,
>> I am having difficulties in converting the following to display the 
>> difference that has passed in hours and seconds in a nice way.
>>
>> from datetime import datetime
>> now = datetime.now()
>> posted = date
>> difference = now - posted
>>
>> namespace['date'] = date
>> namespace['posted'] = difference
> 
> It would help if you would show complete code - what is date? what is 
> namespace? Anyway, guessing that posted is a datetime.datetime, then 
> difference is a datetime.timedelta.
> 
>> when I look at the 'posted' namespace I get
>>
>> 23:08:31.454767
>>
>> What is the best way to split this so that it will show
>>
>> '23h 08m 31s' ago
> 
> You will have to do some work yourself. difference has attributes days, 
> seconds and microseconds. You can split the seconds into hours, minutes 
> and seconds using % or divmod().
> 
> Kent

Not a 100% match, but to show the kind of thing... have a look at this
code fragment (which I posted a while back to c.l.py).

http://groups.google.com/group/comp.lang.python/msg/40a87d00875f2958

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


Re: [Tutor] how to accept an integer?

2007-12-05 Thread Alan Gauld

"Mahesh N" <[EMAIL PROTECTED]> wrote


> PS : I understand that i can do type conversion after getting input 
> thru
> raw_input(). But how does input() function work?
>
 prompt="temme a number\n"
 speed =input(prompt)
>
> Traceback (most recent call last):
>  File "", line 1, in 
>speed =input(prompt)
> TypeError: 'str' object is not callable

This suggests that you have a variable somewhere called input
that is hiding the function. Try doing del(input)
and try it again.

As to what input does; it evaluates whatever string you give
to it so if your user types in some malicious Python code
input will execute it. For that reason input is usually frowned
on as a security risk and int(raw_input()) is preferred.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 


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


Re: [Tutor] Best way of learning

2007-12-05 Thread bhaaluu
On Dec 5, 2007 5:43 PM, andy <[EMAIL PROTECTED]> wrote:
> Dear Pythonistas
>
[snip]
>
> So, after this long-winded introduction, I was hoping to pick the wisdom
> of this list to get some pointers of what to do/not to do to make the
> most effective use of the few hours I have to learn how to program using
> Python. So, any advice for someone in their mid-40s who would like to
> learn Python in a more methodical and effective manner?
>
> Thanks in anticipation.
>
> Andy

It sounds to me like a good book or two would be just the thing for you.
May I suggest:
Learning Python by Mark Lutz
and
Programming Python Third Edition by the same author.

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
http://www.geocities.com/ek.bhaaluu/python/index.html
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to accept an integer?

2007-12-05 Thread Alan Gauld
"Mahesh N" <[EMAIL PROTECTED]> wrote

> More over i find python to be a little sluggish after having worked 
> with C
> and Java.

If you translate C or Java code into python you will usually
get a less than optimal implementation. Python should be
barely slower than Java and often faster. Compared to
C - yes there is a slow-down.

But even in C you can use tools like Psycho and Pyrex to
speed up critical sections to near C speeds if the problem fits.
Or rewrite the critical section in C and wrap it as a module
using SWIG. Thats how most of the performance ritical modules
in the library are written. Where the major bottleneck is I/O
work like database disk access or GUI or network sockets
then you should find Python fast enough.

> can someone temme where python is most applicable?
> server side scripting? am i guessing it right?

Python has been used in almost every form of programming
from image processing and database manipulation to games
programming and web server development. Do a search on
Source Forge for projects using Python for an example of
the variety.

I'd avoid operating systems, device drivers and hard real-time
applications though.


-- 
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] how to accept an integer?

2007-12-05 Thread Bryan Fodness
On Dec 5, 2007 4:16 PM, Jerry Hill <[EMAIL PROTECTED]> wrote:

> On Dec 5, 2007 4:01 PM, Mahesh N <[EMAIL PROTECTED]> wrote:
> > I dun understand the mistake. My aim is to accept an integer number. The
> > python lookup in IDLE asks for a string object but the interpreter
> returns
> > with the following error message. Some one pls explain.
> > Thank You
> >
> >  PS : I understand that i can do type conversion after getting input
> thru
> > raw_input(). But how does input() function work?
> >
> > >>> prompt="temme a number\n"
> > >>> speed =input(prompt)
> >
> >  Traceback (most recent call last):
> >   File "", line 1, in 
> > speed =input(prompt)
> > TypeError: 'str' object is not callable
>
> You have code that you haven't shown us.  My crystal ball tells me
> that somewhere above this point you did input = "Some String", thus
> shadowing the builtin input function.  Start a new interpreter and try
> again and you should find that it works as expected.
>
> As I'm sure you'll hear from others, it really is best to use
> raw_input instead.  If you want an integer instead of a string, do
> something like this:
>
> speed = int(raw_input(prompt))


Is this how ALL known integers should be input?


>
>
> That way whatever the user types isn't run as python code, just read
> in as a string and then converted into an integer.
>
> --
> Jerry
>  ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
"The game of science can accurately be described as a never-ending insult to
human intelligence." - João Magueijo
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Mail? What's that?

2007-12-05 Thread Ricardo Aráoz
So I eventually got to sending mail with python.
Some articles, trying and google led me to this script:

import smtplib
import time

date = time.ctime(time.time( ))
>From = '[EMAIL PROTECTED]'
To = ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]']
Subj = 'Hi'
text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n\n'
 % (From, ';'.join(To), date, Subj))

s = smtplib.SMTP('smtp.gmail.com')
s.set_debuglevel(1)
s.ehlo()
s.starttls()
s.ehlo()
s.login('foo', 'bar')
s.sendmail(From, To, text)
s.close()


So, if there's someone who really knows this stuff in the neighborhood
I'd like to ask a couple of questions.
What is ehlo and why do I have to call it twice? And set_debuglevel?
If I where to connect through other smtp server the sequence would be
the exactly the same, say yahoo or hotmail?
Are From: To: Date: and Subject: mandatory in the contents of the
email(text)?  Do I have to put "real" address in  From when calling
sendmail()? And in the contents?
Ok, if someone can answer these I'll be grateful.

TIA

Ricardo


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


Re: [Tutor] Button 1 Motion Event

2007-12-05 Thread Luke Paireepinart
Johnston Jiaa wrote:
>
>> Just don't distinguish between quick and slow drags.  Just keep a 
>> temporary variable that has the previous mouse position, and draw 
>> ovals from there to the current mouse position every time your 
>> function is called.
>
> I now have the variable with the previous mouse position.  How would I 
> draw ovals from the current mouse position to that previous mouse 
> position?  I tried reasoning it out with a for-loop, but I couldn't 
> figure out how to do it.
Well, try reasoning it out with mathematics.
Suppose we have the points (0,0) and (100,100).
What's the slope between these two points?
well, delta-Y is 100 and delta-X is 100, and 100/100 == 1.
This is also the same as 1/1.
Therefore, for every new point we want to get, we'll add 1 to the x 
value and 1 to the y value.

Now assume we have the points (23, 45) and (45, 80).
This slope would be:
80 - 45
-
45 - 23
or  35 / 22.
So as you can see, the number on the top is larger than the number on 
the bottom, so our Y-value is increasing more quickly.
But it doesn't really matter which value is bigger, the numerator or the 
denominator.
All we care about is the slope.  Because slope tells us: this is the 
change in Y for every change in X.
The reason slope tells us this is because slope is the ratio between the 
change in Y between our 2 points
and the change in X between our 2 points.
Because it's a ratio, it can be applied to any measure, even to 
deltaX=1, which gives us what deltaY is.
Since we don't care about any X-coordinates between integers, we don't 
care about any other deltaX measurement.

So you'd do something like this:
x = 23.0 # our first points
y = 45.0 # they're float so we can add partial amounts to them.
slope = 35/22.0 # this is float to force float division.
for deltax in range(23, 45):
x += deltax
y += slope

So in this case, each time through the loop, X will move 1 over, and Y 
will move slightly more than 1 up.

This still has a problem if the slope is very great in the Y-direction.
Given the case of the points (0,0) and (1,100),
we get a slope of 100.  Thus, we will draw points at 0,0 and at 1,100 
and none in-between,
when realistically we'd like at least a vertical line between them, or 
preferably one that shifts one pixel over halfway-up.

Note that the poitns (0,0) and (100, 1) would not create a problem.  
This is because our delta-x is changing at a set rate,
and our deltay is a smaller number.  It would work in this case.

What's creating the problem is that our slope is greater than 1, and 
we're using delta-x as a fixed amount.
If we add the condition that we affix delta-x to the value 1 for slopes 
less than 1, and delta-y to 1 when slopes are greater than 1,
then everything should work out perfectly.  The case of slope == 1 will 
be correctly handled in either case, just make sure to include it in one 
of them.

Thusly, our code would look something like this:

point1x, point1y = raw_input("please input the first pair of coordinates 
separated by a space: ").split(' ')
point2x, point2y = raw_input("please input the second pair of 
coordinates separated by a space: ").split(' ')

slope = (point2y - point1y) / (float(point2x - point1x))
if slope > 1:
deltax = 1 / slope # i assume we invert slope here?
deltay = 1
else:
deltax = 1
deltay = slope

currentx = float(point1x)
currenty = float(point1y)
for x in range(max((point2y - point1y), (point2x - point1x)) ):
#we choose our range as the larger of the two lengths.
#thus if delta-x is only 1px and delta-y is 100px, we'll
#still draw all those points in between.

# ..
#  draw the currentx, currenty point here
# .
currentx += deltax
currenty += deltay

# and draw the point one more time here, to get your ending point.




Note that I don't profess that either my code or my math is correct; I 
didn't test any of this, it's more to give you an idea of how to 
approach Computer Science problems.

>
> Also, I need to be able to save the canvas drawing.  Would it be 
> possible to write some sort of data to a file that could be used to 
> load the previously saved drawing back onto the canvas?
You can just keep a cache of all points and redraw them on load, or you 
can dump it out to an image file.  I believe TKInter supports that, but 
I haven't used that library in a long time.

Again, _please reply on-list_ unless you want a discussion to be 
private, in which case specify in the e-mail so we know it wasn't an 
accident.
-Luke

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


[Tutor] While Loops and Modules

2007-12-05 Thread earlylight publishing
Hello again to all the wonderfully helpful folks on this list.  Today I did my 
Google homework and I found this neat bit of code for a countdown timer.
   
  import time
import threading
class Timer(threading.Thread):
def __init__(self, seconds):
self.runTime = seconds
threading.Thread.__init__(self)
def run(self):
time.sleep(self.runTime)
print "Buzzz!!! Time's up!"
  t = Timer(30)
t.start()
   
  I don't understand large chunks of it (don't know what threading, self, or 
__init__ mean) but that's not important at the moment.  It works and I will 
learn the vocab eventually.
   
  I also wrote this bit of code for a math challenge which comes in the next 
part of my game.
   
  import random
startNum = random.choice(range(1, 9))
newNum = startNum + 7
score = 0
print 'Start with the number ', startNum, '.  Then continuously add 7 to that 
number until the timer runs out.  You have 30 seconds.'

answer = int(raw_input('Enter your answer: '))
  if newNum == answer:
print 'That is correct!  Keep going.'
score = score + 5
print 'Your score is ', score
else:
print 'That is incorrect.  Please try again.'
   
  I understand this part just fine 'cause I actually wrote it myself.  
   
  What I need to do now is put these two parts together so that the player will 
keep adding 7 to the starting number for 30 seconds then the loop breaks.  I 
know I need a loop of some sort and I'm guessing it's a 'while' sort of thing.  
I couldn't find what I was looking for when I Googled.  I'm not even sure I 
knew the right search terms.  Does anyone know how I'd combine these two 
modules to make it work?

   
-
Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mail? What's that?

2007-12-05 Thread Luke Paireepinart
Ricardo Aráoz wrote:
> So I eventually got to sending mail with python.
> Some articles, trying and google led me to this script:
>
> import smtplib
> import time
>
> date = time.ctime(time.time( ))
> >From = '[EMAIL PROTECTED]'
> To = ['[EMAIL PROTECTED]', '[EMAIL PROTECTED]']
> Subj = 'Hi'
> text = ('From: %s\nTo: %s\nDate: %s\nSubject: %s\n\n'
>  % (From, ';'.join(To), date, Subj))
>
> s = smtplib.SMTP('smtp.gmail.com')
> s.set_debuglevel(1)
> s.ehlo()
> s.starttls()
> s.ehlo()
> s.login('foo', 'bar')
> s.sendmail(From, To, text)
> s.close()
>
>
> So, if there's someone who really knows this stuff in the neighborhood
> I'd like to ask a couple of questions.
> What is ehlo and why do I have to call it twice? And set_debuglevel?
> If I where to connect through other smtp server the sequence would be
> the exactly the same, say yahoo or hotmail?
> Are From: To: Date: and Subject: mandatory in the contents of the
> email(text)?  Do I have to put "real" address in  From when calling
> sendmail()? And in the contents?
> Ok, if someone can answer these I'll be grateful.
>
> TIA
>
> Ricardo
>   
Ricardo -
I say this in the nicest way possible, but did you RTFM? :)
Python has built-in help support on modules.
You should start there, do some Googling, and if you're stumped, get 
some help.  Not for any other reason than it'll probably get you 1) more 
experience at navigating the docs, and 2) a quicker, probably more 
detailed response.

So using Help, we get:


 >>> import smtplib
 >>> help(smtplib)
Help on module smtplib:

NAME
smtplib - SMTP/ESMTP client class.

FILE
c:\python24\lib\smtplib.py

[snip 10 pages of documentation]


 >>> help(smtplib.SMTP.set_debuglevel)
Help on method set_debuglevel in module smtplib:

set_debuglevel(self, debuglevel) unbound smtplib.SMTP method
Set the debug output level.
   
A non-false value results in debug messages for connection and for all
messages sent to and received from the server.

 >>> help(smtplib.SMTP.ehlo)
Help on method ehlo in module smtplib:

ehlo(self, name='') unbound smtplib.SMTP method
SMTP 'ehlo' command.
Hostname to send for this command defaults to the FQDN of the local
host.

 >>> help(smtplib.SMTP.sendmail)
Help on method sendmail in module smtplib:

sendmail(self, from_addr, to_addrs, msg, mail_options=[], 
rcpt_options=[]) unbound smtplib.SMTP method
This command performs an entire mail transaction.
   
The arguments are:
- from_addr: The address sending this mail.
- to_addrs : A list of addresses to send this mail to.  A bare
 string will be treated as a list with 1 address.
- msg  : The message to send.
- mail_options : List of ESMTP options (such as 8bitmime) for the
 mail command.
- rcpt_options : List of ESMTP options (such as DSN commands) for
 all the rcpt commands.
   
If there has been no previous EHLO or HELO command this session, this
method tries ESMTP EHLO first.  If the server does ESMTP, message size
and each of the specified options will be passed to it.  If EHLO
fails, HELO will be tried and ESMTP options suppressed.
   
This method will return normally if the mail is accepted for at least
one recipient.  It returns a dictionary, with one entry for each
recipient that was refused.  Each entry contains a tuple of the SMTP
error code and the accompanying error message sent by the server.
   
This method may raise the following exceptions:
   
 SMTPHeloError  The server didn't reply properly to
the helo greeting.
 SMTPRecipientsRefused  The server rejected ALL recipients
(no mail was sent).
 SMTPSenderRefused  The server didn't accept the from_addr.
 SMTPDataError  The server replied with an unexpected
error code (other than a refusal of
a recipient).
   
Note: the connection will be open even after an exception is raised.
   
Example:
   
 >>> import smtplib
 >>> s=smtplib.SMTP("localhost")
 >>> 
tolist=["[EMAIL PROTECTED]","[EMAIL PROTECTED]","[EMAIL PROTECTED]","[EMAIL 
PROTECTED]"]
 >>> msg = '''\
 ... From: [EMAIL PROTECTED]
 ... Subject: testin'...
 ...
 ... This is a test '''
 >>> s.sendmail("[EMAIL PROTECTED]",tolist,msg)
 { "[EMAIL PROTECTED]" : ( 550 ,"User unknown" ) }
 >>> s.quit()
   
In the above example, the message was accepted for delivery to three
of the four addresses, and one was rejected, with the error code
550.  If all addresses are accepted, then the method will return an
empty dictionary.

 >>>




So mess around in the built-in docs, then check python.org's docs, and 
let us know what you find :)
Also, try experimenting! pass it stuff that you don't think will work 
just to s