Re: [Tutor] input with default value option

2006-04-10 Thread Danny Yoo


> With raw_input(), it allows to input value. Can it be used to input 
> value with default value option?

Hi Phon,

We can build your own function to do this.  Bob showed how to set up code 
so that the default's taken if the user just presses enter in his reply. 
Let's take a look at it again:

###
response = raw_input("Enter some data:")
if not response: response = "default value"
###


We can capture this as a function that takes in a question and a default 
answer:

##
def ask(question, default):
 response = raw_input(question)
 if not response:
 response = default
 return response
##


And now we have something that acts like raw_input(), but also gives the 
user the ability to get a default:

##
>>> ask("favorite color?", "Blue.  No yellow -- aaaugh!")
favorite color?red
'red'
>>> ask("favorite color?", "Blue.  No yellow -- aaaugh!")
favorite color?
'Blue.  No yellow -- aaaugh!'
>>> 
##

(In the second call to ask(), I just pressed enter.)


Does this make sense?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] input with default value option

2006-04-10 Thread Bob Gailer
Keo Sophon wrote:
> Hi,
>
> With raw_input(), it allows to input value. Can it be used to input value 
> with default value option?
>   
response = raw_input("Enter some data:")
if not response: response = "default value"

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


[Tutor] input with default value option

2006-04-10 Thread Keo Sophon
Hi,

With raw_input(), it allows to input value. Can it be used to input value with 
default value option?

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


Re: [Tutor] failing to learn python

2006-04-10 Thread Greg Lindstrom
Paypal-

I do a lot of system admin type work with Python.  If you'd like,
drop me a line and let me know what you're interested in
learning...perhaps I could help you work through a project or two.

Greg Lindstrom
[EMAIL PROTECTED]

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


[Tutor] Python for sysadmins (Was: failing to learn python)

2006-04-10 Thread Carroll, Barry
Payal:

I agree with Kent: the Python Cookbook is an excellent resource.  And,
it has a whole section on System Administration. try this URL:

 http://aspn.activestate.com/ASPN/Cookbook/Python?kwd=System

You can also try Google.  I entered 'Python sysadmin'.  Here are just a
few potentially interesting sites that came back:

 http://www.samag.com/documents/s=8964/sam0312a/0312a.htm
 http://www.unixreview.com/documents/s=8989/sam0401d/
 
http://www.linuxdevcenter.com/pub/a/linux/2002/05/09/sysadminguide.html

Look through these and other resources, choose an example function that
relates to one of your tasks and try it out.  Post questions and
problems here.  Good luck

Regards,
 
Barry
[EMAIL PROTECTED]
541-302-1107

We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed

> -Original Message-
> Message: 5
> Date: Mon, 10 Apr 2006 13:22:19 -0400
> From: Kent Johnson <[EMAIL PROTECTED]>
> Subject: Re: [Tutor] failing to learn python
> Cc: tutor@python.org
> Message-ID: <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Payal Rathod wrote:
> >> What kind of real life problems are you interested in? You might
like
> >
> > I am a parttime sys admin so I want system admin problem which
usually I
> > do through shell scripts like parsing logs, generating reports,
greping
> > with regexes etc.
> > The only thing I don't want is silly problems like generate
fibonnacci
> > series, add numbers frm 0-n etc. non required silly stuff.
> 
> Take a look at the Python Cookbook:
> http://aspn.activestate.com/ASPN/Cookbook/Python
> 
> Dive into Python is not targeted at beginners but it is available
online
> and does have real-world examples:
> http://diveintopython.org/
> 
> Kent

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


Re: [Tutor] failing to learn python

2006-04-10 Thread Danny Yoo
> I am a parttime sys admin so I want system admin problem which usually I 
> do through shell scripts like parsing logs, generating reports, greping 
> with regexes etc.

Hi Payal,

You might also find David Mertz's book "Text Processing With Python" to be 
useful for you:

 http://gnosis.cx/TPiP/

I agree with the other recommendation on "Dive into Python": it provides a 
lot of good practical programming knowledge.

 http://diveintopython.org/



> The only thing I don't want is silly problems like generate fibonnacci 
> series, add numbers from 0-n etc. non required silly stuff.

Just as a counterpoint: some of those silly things aren't useful in their 
own right, but they're finger exercises to help one really get mastery 
over the language.  Recursion is one of those things that are core 
concepts, and most Python tutorials try to cover it by talking about 
factorials.

It's very unfortunate that fibonacci numbers are one of the "classical" 
examples of recursion, since they are useless to most people.  But don't 
discount recursion altogether.

We can look at concrete example of recursion that might be more 
applicable.  One common system administration question that pops up every 
once in a while is: "How do I do [some_action] to every file in my 
directory?"

We can either know magically that os.walk() will do the hard work for us, 
or we can use a combination of os.listdir() and os.path.isdir():

#
### pseudocode
def my_walk(some_action, dir_or_file):
 if os.path.isfile(dir_or_file):
 some_action(dir_or_file)
 else:
 for thing in os.listdir(dir_or_file):
 my_walk(some_action, thing)
#

in which there's a specific "base" case for handling regular files, and an 
"inductive" case for handling directories.

Another example of this kind of processing involves things like XML or 
HTML processing.  If we wanted to get all the anchor link elements in an 
HTML document, how would we do this?  We again break it into two cases: 
one to handle anchor elements, and another to handle anything else:

##
## Pseudocode
def get_anchors(element):
 if element is an anchor:
 return [element]
 else:
 anchors = []
 for child in element.children:
 anchors.extend(get_anchors(child))
 return anchors
##

We're in a slightly different domain, but if we look at this with a 
critical eye, we should see that the code structure is similar to the 
directory-walking example.  There's a case for handling really simple 
problems, and another case for handling slightly harder problems.


That's the key insight you should have been getting.  If the tutorials 
that you're reading haven't been delving into this, that means that those 
tutorials aren't doing a good job.  The fact that factorial() looks like:


def factorial(n):
 if n == 0:
 return 1
 else:
 return n * factorial(n-1)


is pretty darn worthless in itself.  But the idea that we can break things 
down into two categories (simple cases, slightly complex cases) and handle 
them in some structured way is a valuable concept.


If you see something that's looks trivially un-useful when you're reading 
a tutorial, bring it up on this list.  They're bound to be some kind of 
real application for it.  *grin* And if you have any other questions, feel 
free to ask.


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


Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- Matthew White <[EMAIL PROTECTED]> wrote:

> Hi Hoffman,
> 
> It is often useful to use the "for" construct to
> process items in a list.
> e.g.:
> 
> >>> list1 =  [ 'spam!', 2, ['Ted', 'Rock']]
> >>> for item in list:
> ...print item
> spam!
> 2
> ['Ted', 'Rock']
> 
> If you pass a list to the len() function, it will
> return the number of
> elenents in the list. e.g.:
> 
> >>> x = ['a', 'b', 'c']
> >>> len(x)
> 3
> 
> Now if you pass len() a string it will return the
> length of a string:
> >>> y = 'hello'
> >>> len(y)
> 5
> 
> Given your list below, len() will return what you're
> looking for when it
> encounters the third element of the list, but won't
> for the first and
> second elements.  One way to solve this problem is
> to use the type()
> function to figure out if your item is a string or
> list and use len()
> as appropriate.  I hope this provides enough of a
> hint.
> 
> -mtw
> 
> 
> On Mon, Apr 10, 2006 at 03:29:23PM -0700, Hoffmann
> ([EMAIL PROTECTED]) wrote:
> > Hello,
> > 
> > I have a list: list1 =  [ 'spam!', 2, ['Ted',
> 'Rock']
> > ]
> > and I wrote the script below:
> > 
> > i = 0
> > while i < len(list1):
> > print list1[i]
> > i += 1
> > 
> > Ok. This script will generate as the output each
> > element of the original list, one per line:
> > 
> > spam!
> > 2
> > ['Ted', 'Rock']
> > 
> > I also would like to print the length of each
> element
> > of that list:
> > 
> > spam! = 1 element
> > 2 = 1 element
> > ['Ted', 'Rock'] = 2 elements
> > 
> > Could anyone, please, give me some hints?
> > Thanks,
> > Hoffmann
> > 
> > 
> > __
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> > http://mail.yahoo.com 
> > ___
> > Tutor maillist  -  Tutor@python.org
> > http://mail.python.org/mailman/listinfo/tutor
> 
> -- 
> Matthew White - District Systems Administrator
> Tigard/Tualatin School District
> 503.431.4128
> 
> "The greatest thing in this world is not so much
> where we are, but in
> what direction we are moving."   -Oliver Wendell
> Holmes
> 
> 

Hi Matthew,

Thanks for the nice information!
I am learning a lot with all of the hints you guys are
sending to me.
Hoffmann

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- Terry Carroll <[EMAIL PROTECTED]> wrote:

> On Mon, 10 Apr 2006, Hoffmann wrote:
> 
> > Hello,
> > 
> > I have a list: list1 =  [ 'spam!', 2, ['Ted',
> 'Rock']
> > ]
> > and I wrote the script below:
> > 
> > i = 0
> > while i < len(list1):
> > print list1[i]
> > i += 1
> > 
> > Ok. This script will generate as the output each
> > element of the original list, one per line:
> > 
> > spam!
> > 2
> > ['Ted', 'Rock']
> > 
> > I also would like to print the length of each
> element
> > of that list:
> > 
> > spam! = 1 element
> > 2 = 1 element
> > ['Ted', 'Rock'] = 2 elements
> 
> Well, the length of "spam!" is 5.  Lengths of
> strings express the number
> of characters.
> 
> You could check to see if it's a grouping-type of
> element -- i.e., a list, 
> tuple or set -- but I think your better approach is
> that, if this is 
> something you need, make all of the elements lists,
> some of which are 
> single-item lists; for example, instead of:
> 
>  list1 =  [ 'spam!', 2, ['Ted', 'Rock'] ]
> 
> use:
>  list1 =  [ ['spam!'], [2], ['Ted', 'Rock'] ]
> 
> >>> list1 =  [ ['spam!'], [2], ['Ted', 'Rock'] ]
> >>> for item in list1:
> ...  print item, len(item)
> ...
> ['spam!'] 1
> [2] 1
> ['Ted', 'Rock'] 2
> 
> If your heart is set on the other approach, though,
> it can be done:
> 
> >>> list1 =  [ 'spam!', 2, ['Ted', 'Rock'] ]
> >>> for item in list1:
> ...   if isinstance(item,(list, tuple, set)):
> ... print item, len(item)
> ...   else:
> ... print item, 1
> ...
> spam! 1
> 2 1
> ['Ted', 'Rock'] 2
> >>>
> 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

Hi Terry,

Your aproaches (mainly the last one!) answered my
question. After following your last approach, I got
what I was looking for.
Up to the page I am (page 84 of "How to think like a
computer scientist - learning with Python"), I didn't
see that nice approach.
Thanks!
Hoffmann

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about list

2006-04-10 Thread Danny Yoo


On Mon, 10 Apr 2006, Hoffmann wrote:

> I also would like to print the length of each element
> of that list:
>
> spam! = 1 element
> 2 = 1 element
> ['Ted', 'Rock'] = 2 elements
>
> Could anyone, please, give me some hints?


The problem is slightly weird, just because you need to clarify what it 
means to take the length of a non-list.  From the examples above, it 
sounds like we'd like to define the "length" of a non-list to be one.  Is 
that right?


Can you write a function called length() that takes a thing and returns 
the "length" of that thing?

##
def length(something):
 ... ## fill me in
##


For example, we'd like to see:

 length("spam!") ==> 1
 length(2) ==> 1
 length(['Ted', 'Rock']) ==> 2

If you can define this you should be able to use this to solve your 
problem.


When you're defining length(), you may find the built-in function "type()" 
useful.  For example:

##
>>> type(5)

>>> type([1, 2, 3])

##


Good luck!

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


Re: [Tutor] Question about list

2006-04-10 Thread Terry Carroll
On Mon, 10 Apr 2006, Hoffmann wrote:

> Hello,
> 
> I have a list: list1 =  [ 'spam!', 2, ['Ted', 'Rock']
> ]
> and I wrote the script below:
> 
> i = 0
> while i < len(list1):
> print list1[i]
> i += 1
> 
> Ok. This script will generate as the output each
> element of the original list, one per line:
> 
> spam!
> 2
> ['Ted', 'Rock']
> 
> I also would like to print the length of each element
> of that list:
> 
> spam! = 1 element
> 2 = 1 element
> ['Ted', 'Rock'] = 2 elements

Well, the length of "spam!" is 5.  Lengths of strings express the number
of characters.

You could check to see if it's a grouping-type of element -- i.e., a list, 
tuple or set -- but I think your better approach is that, if this is 
something you need, make all of the elements lists, some of which are 
single-item lists; for example, instead of:

 list1 =  [ 'spam!', 2, ['Ted', 'Rock'] ]

use:
 list1 =  [ ['spam!'], [2], ['Ted', 'Rock'] ]

>>> list1 =  [ ['spam!'], [2], ['Ted', 'Rock'] ]
>>> for item in list1:
...  print item, len(item)
...
['spam!'] 1
[2] 1
['Ted', 'Rock'] 2

If your heart is set on the other approach, though, it can be done:

>>> list1 =  [ 'spam!', 2, ['Ted', 'Rock'] ]
>>> for item in list1:
...   if isinstance(item,(list, tuple, set)):
... print item, len(item)
...   else:
... print item, 1
...
spam! 1
2 1
['Ted', 'Rock'] 2
>>>

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


Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- John Fouhy <[EMAIL PROTECTED]> wrote:

> Hi Hoffmann,
> 
> On 11/04/06, Hoffmann <[EMAIL PROTECTED]> wrote:
> > I have a list: list1 =  [ 'spam!', 2, ['Ted',
> 'Rock'] ]
> > and I wrote the script below:
> >
> > i = 0
> > while i < len(list1):
> > print list1[i]
> > i += 1
> 
> Have you read about "for" loops?  The pythonic way
> of looping through
> a list is to do something like this:
> 
> for item in list1:
> print item
> 
> This will produce the same output as your code
> above, but is much
> nicer to read :-)
> 
> > I also would like to print the length of each
> element
> > of that list:
> >
> > spam! = 1 element
> > 2 = 1 element
> > ['Ted', 'Rock'] = 2 elements
> 
> The challenge here is that your list contains a
> mixture of different types.
> 
> For example, the len() function will tell us that
> ['Ted', 'Rock'] has
> two elements.  But it would also tell us that
> 'spam!' has five
> elements, and it would raise an exception if we
> tried to find the
> length of 2.
> 
> So you will need to ask python about the type of
> element you're
> looking at.  One possibility that might work for you
> is this:
> 
> for item in list1:
> if isinstance(item, (tuple, list)):
> print len(item)
> else:
> print 1
> 
> May I ask why you're doing this?  This feels like a
> situation where
> you need to think clearly what your goals are before
> you go diving
> towards a solution :-)
> 
> --
> John.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

Hi John,

This is just a version of a book exercise (How to
think like a computer scientist - learning with
python, by Downey, Elkner, and Meyers), page 84.

Thanks,
Hoffmann

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about list

2006-04-10 Thread Matthew White
Hi Hoffman,

It is often useful to use the "for" construct to process items in a list.
e.g.:

>>> list1 =  [ 'spam!', 2, ['Ted', 'Rock']]
>>> for item in list:
...print item
spam!
2
['Ted', 'Rock']

If you pass a list to the len() function, it will return the number of
elenents in the list. e.g.:

>>> x = ['a', 'b', 'c']
>>> len(x)
3

Now if you pass len() a string it will return the length of a string:
>>> y = 'hello'
>>> len(y)
5

Given your list below, len() will return what you're looking for when it
encounters the third element of the list, but won't for the first and
second elements.  One way to solve this problem is to use the type()
function to figure out if your item is a string or list and use len()
as appropriate.  I hope this provides enough of a hint.

-mtw


On Mon, Apr 10, 2006 at 03:29:23PM -0700, Hoffmann ([EMAIL PROTECTED]) wrote:
> Hello,
> 
> I have a list: list1 =  [ 'spam!', 2, ['Ted', 'Rock']
> ]
> and I wrote the script below:
> 
> i = 0
> while i < len(list1):
> print list1[i]
> i += 1
> 
> Ok. This script will generate as the output each
> element of the original list, one per line:
> 
> spam!
> 2
> ['Ted', 'Rock']
> 
> I also would like to print the length of each element
> of that list:
> 
> spam! = 1 element
> 2 = 1 element
> ['Ted', 'Rock'] = 2 elements
> 
> Could anyone, please, give me some hints?
> Thanks,
> Hoffmann
> 
> 
> __
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Matthew White - District Systems Administrator
Tigard/Tualatin School District
503.431.4128

"The greatest thing in this world is not so much where we are, but in
what direction we are moving."   -Oliver Wendell Holmes

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


Re: [Tutor] Question about list

2006-04-10 Thread Hoffmann
--- Adam <[EMAIL PROTECTED]> wrote:

> On 10/04/06, Hoffmann <[EMAIL PROTECTED]> wrote:
> > Hello,
> >
> > I have a list: list1 =  [ 'spam!', 2, ['Ted',
> 'Rock']
> > ]
> > and I wrote the script below:
> >
> > i = 0
> > while i < len(list1):
> > print list1[i]
> > i += 1
> >
> > Ok. This script will generate as the output each
> > element of the original list, one per line:
> >
> > spam!
> > 2
> > ['Ted', 'Rock']
> >
> > I also would like to print the length of each
> element
> > of that list:
> >
> > spam! = 1 element
> > 2 = 1 element
> > ['Ted', 'Rock'] = 2 elements
> >
> > Could anyone, please, give me some hints?
> > Thanks,
> > Hoffmann
> 
> instead of just print list1[i] you could use print
> list1[i], len(list1[i]).
> I'd like to point out that the usual way to iterate
> through objects in
> a list like that would be using a for loop like so.
> 
> for item in list1:
> print item, len(item)
> 
> as you can see this is much easier to understand and
> is also a lot shorter.
> HTH.
> 

Hi Adam, 

In the previous email, I forgot to mention that I have
already tried:

i = 0
while i < len(list1):
print list1[i], len(list1[i])
i += 1

However, I got:

soam! 5
1
Traceback (most recent call last):
  File "list1.py", line 11, in ?
print list1[i], len(list1[i])
TypeError: len() of unsized object

Could I hear from you again?
Hoffmann




__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about list

2006-04-10 Thread Adam
On 10/04/06, Hoffmann <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have a list: list1 =  [ 'spam!', 2, ['Ted', 'Rock']
> ]
> and I wrote the script below:
>
> i = 0
> while i < len(list1):
> print list1[i]
> i += 1
>
> Ok. This script will generate as the output each
> element of the original list, one per line:
>
> spam!
> 2
> ['Ted', 'Rock']
>
> I also would like to print the length of each element
> of that list:
>
> spam! = 1 element
> 2 = 1 element
> ['Ted', 'Rock'] = 2 elements
>
> Could anyone, please, give me some hints?
> Thanks,
> Hoffmann

instead of just print list1[i] you could use print list1[i], len(list1[i]).
I'd like to point out that the usual way to iterate through objects in
a list like that would be using a for loop like so.

for item in list1:
print item, len(item)

as you can see this is much easier to understand and is also a lot shorter.
HTH.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about list

2006-04-10 Thread John Fouhy
Hi Hoffmann,

On 11/04/06, Hoffmann <[EMAIL PROTECTED]> wrote:
> I have a list: list1 =  [ 'spam!', 2, ['Ted', 'Rock'] ]
> and I wrote the script below:
>
> i = 0
> while i < len(list1):
> print list1[i]
> i += 1

Have you read about "for" loops?  The pythonic way of looping through
a list is to do something like this:

for item in list1:
print item

This will produce the same output as your code above, but is much
nicer to read :-)

> I also would like to print the length of each element
> of that list:
>
> spam! = 1 element
> 2 = 1 element
> ['Ted', 'Rock'] = 2 elements

The challenge here is that your list contains a mixture of different types.

For example, the len() function will tell us that ['Ted', 'Rock'] has
two elements.  But it would also tell us that 'spam!' has five
elements, and it would raise an exception if we tried to find the
length of 2.

So you will need to ask python about the type of element you're
looking at.  One possibility that might work for you is this:

for item in list1:
if isinstance(item, (tuple, list)):
print len(item)
else:
print 1

May I ask why you're doing this?  This feels like a situation where
you need to think clearly what your goals are before you go diving
towards a solution :-)

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


[Tutor] Question about list

2006-04-10 Thread Hoffmann
Hello,

I have a list: list1 =  [ 'spam!', 2, ['Ted', 'Rock']
]
and I wrote the script below:

i = 0
while i < len(list1):
print list1[i]
i += 1

Ok. This script will generate as the output each
element of the original list, one per line:

spam!
2
['Ted', 'Rock']

I also would like to print the length of each element
of that list:

spam! = 1 element
2 = 1 element
['Ted', 'Rock'] = 2 elements

Could anyone, please, give me some hints?
Thanks,
Hoffmann


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Decorators

2006-04-10 Thread Kent Johnson
Greg Lindstrom wrote:
> Hello-
> 
> For some reason I have decided to learn about decorators; I heard them 
> talked up at  Pycon the past two years and want to know what all the 
> fuss is about.  I might even use them in my code :-)
> 
> My problem, and this is after reading PEP 318 and other items found when 
> I "Googled" for decorators, is that I can't figure out the practical use 
> for them.  This surely means that I do not understand the concept 
> because Python does not waste my time or energy.  Can any of you gurus 
> either explain what all the excitement is about or point me to examples 
> of how/why I would want to use decorators?

http://wiki.python.org/moin/PythonDecoratorLibrary

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


[Tutor] Decorators

2006-04-10 Thread Greg Lindstrom
Hello-For some reason I have decided to learn about decorators; I heard them talked up at  Pycon the past two years and want to know what all the fuss is about.  I might even use them in my code :-)My problem, and this is after reading PEP 318 and other items found when I "Googled" for decorators, is that I can't figure out the practical use for them.  This surely means that I do not understand the concept because Python does not waste my time or energy.  Can any of you gurus either explain what all the excitement is about or point me to examples of how/why I would want to use decorators?
Thanks for your attention...
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] failing to learn python

2006-04-10 Thread Kent Johnson
Payal Rathod wrote:
>> What kind of real life problems are you interested in? You might like 
> 
> I am a parttime sys admin so I want system admin problem which usually I 
> do through shell scripts like parsing logs, generating reports, greping 
> with regexes etc.
> The only thing I don't want is silly problems like generate fibonnacci 
> series, add numbers frm 0-n etc. non required silly stuff.

Take a look at the Python Cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python

Dive into Python is not targeted at beginners but it is available online 
and does have real-world examples:
http://diveintopython.org/

Kent

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


Re: [Tutor] failing to learn python

2006-04-10 Thread Bob Gailer
Payal Rathod wrote:
> On Mon, Apr 10, 2006 at 10:05:45AM -0400, Kent Johnson wrote:
>   
>> You might like to look at "Python Programming for the absolute 
>> beginner". It is oriented to beginners and has many examples and 
>> exercises.
>> 
>
> I might not be able to afford another book, due to high dollar-to-ruppee 
> rate.
>
>   
>> What kind of real life problems are you interested in? You might like 
>> 
>
> I am a parttime sys admin so I want system admin problem which usually I 
> do through shell scripts like parsing logs, generating reports, greping 
> with regexes etc.
> The only thing I don't want is silly problems like generate fibonnacci 
> series, add numbers frm 0-n etc. non required silly stuff.
When I hear the word "silly" I assume that you are comfortable with 
programming in Python, and do not need the examples that are useful to 
beginners, and want access to libraries of code for doing the tasks you 
described.

So I suggest you look at Python's remarkable set of modules. In the docs 
you'll find Global Module Index. Start with re for regular expressions, 
glob & shutil for some file management, os for more file and process 
management. Some of these have some example code. Select ONE task of 
interest to you, make your best stab at writing a Python program using 
the module, then come back with the program and tell us how we can help 
you with it.

If my assumption is inaccurate, and you do need help with the 
fundamentals of Python, then I suggest you tackle some of the 
assignments in the references you have *as a way of becoming comfortable 
with Python*, then tackle the modules I mentioned.

Someone else on this list may point you to online learning resources 
that will meet your need for more information at low-to-no cost.

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


Re: [Tutor] failing to learn python

2006-04-10 Thread Payal Rathod
On Mon, Apr 10, 2006 at 10:05:45AM -0400, Kent Johnson wrote:
> You might like to look at "Python Programming for the absolute 
> beginner". It is oriented to beginners and has many examples and 
> exercises.

I might not be able to afford another book, due to high dollar-to-ruppee 
rate.

> What kind of real life problems are you interested in? You might like 

I am a parttime sys admin so I want system admin problem which usually I 
do through shell scripts like parsing logs, generating reports, greping 
with regexes etc.
The only thing I don't want is silly problems like generate fibonnacci 
series, add numbers frm 0-n etc. non required silly stuff.

With warm regards,
-Payal
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] failing to learn python

2006-04-10 Thread Kent Johnson
Payal Rathod wrote:
> Hi,
> I am trying to learn Python seriously for almost 2 months but have not 
> gotten far at all. Infact, it seems I have not understood even the basic 
> concepts itself. I know some shell, sed and awk programming.
> I have tried reading Learning Python - Mark Lutz
> Think C Spy
> A byte of Python 
> Non-Programmers Tutorial For Python
> etc.
> But I have not got anything from them. I am feeling that they are 
> superficial and do not touch real life problems. Also, not enough 
> examples are provided which can help newbies like me.

Hi Payal,

Beginner's material teaches the basics of the language. These are the 
building blocks you will use to solve your problems. You need to 
understand the basics like loops, functions, lists and dictionaries to 
solve most real-world problems.

When you have questions about basic concepts you can ask for help on 
this list.

You might like to look at "Python Programming for the absolute 
beginner". It is oriented to beginners and has many examples and exercises.
http://premierpressbooks.com/ptr_detail.cfm?group=Programming&subcat=Other%20Programming&isbn=1%2D59863%2D112%2D8

What kind of real life problems are you interested in? You might like 
"Beginning Python", it has several real-life projects.
http://apress.com/book/bookDisplay.html?bID=10013

When you have questions about basic concepts you can ask for help on 
this list. We do best with questions that are very specific.

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


[Tutor] failing to learn python

2006-04-10 Thread Payal Rathod
Hi,
I am trying to learn Python seriously for almost 2 months but have not 
gotten far at all. Infact, it seems I have not understood even the basic 
concepts itself. I know some shell, sed and awk programming.
I have tried reading Learning Python - Mark Lutz
Think C Spy
A byte of Python 
Non-Programmers Tutorial For Python
etc.
But I have not got anything from them. I am feeling that they are 
superficial and do not touch real life problems. Also, not enough 
examples are provided which can help newbies like me.

Can anyone help me, it is pretty pretty frustating thing for last couple 
of months?

With warm regards,
-Payal

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