[Tutor] what does the "@" operator mean?

2008-12-17 Thread Daniele
> From: "Alan Gauld" 
> Subject: Re: [Tutor] what does the "@" operator mean?

Thinking it's quite funny, I'll keep on with italian words:
the @ is called "chiocciola" which means snail,
while # is called "cancelletto" which is a small gate

As you see italian words are quite close to the sign shape,
like in Denmark i guess (trunk-a for @ is fantastic! :-P )
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sys.path.append

2008-12-17 Thread ppaarrkk

I can do this :

>>> sys.path.append ( 'C:\dump1' )

but not :

>>> x = 'C:\dir1'
>>> sys.path.append(x)

or :


but not :

>>> x = ['C:\dir1']
>>> sys.path.append(x)

Can I append variables to the path, rather than explicit strings ?

-- 
View this message in context: 
http://www.nabble.com/sys.path.append-tp21054555p21054555.html
Sent from the Python - tutor mailing list archive at Nabble.com.

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


Re: [Tutor] sys.path.append

2008-12-17 Thread Kent Johnson
On Wed, Dec 17, 2008 at 10:20 AM, ppaarrkk  wrote:
>
> I can do this :
>
 sys.path.append ( 'C:\dump1' )

Note you should use raw strings r'C:\dump1' or double backslash
'C:\\dump1' because the \ is a string escape character.

> but not :
>
 x = 'C:\dir1'
 sys.path.append(x)

That should work fine (other than the single \). What happens when you try it?

> or :

??

> but not :

 x = ['C:\dir1']
 sys.path.append(x)

Here you are appending a list of strings to sys.path, that will not do
what you want.

> Can I append variables to the path, rather than explicit strings ?

Sure.

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


Re: [Tutor] Lucky Boy Sudhir wants to chat

2008-12-17 Thread Williams, Thomas (DSHS/RDA)
Thank you

Tom
-Original Message-
From: Kent Johnson [mailto:ken...@tds.net] 
Sent: Wednesday, December 17, 2008 6:52 AM
To: Lucky Boy Sudhir
Cc: tutor@python.org
Subject: Re: [Tutor] Lucky Boy Sudhir wants to chat

I have unsubscribed Lucky Boy from the list as he is just spamming it.

Kent

On Wed, Dec 17, 2008 at 7:01 AM, Lucky Boy Sudhir
 wrote:
>
---
>
> Lucky Boy Sudhir  wants to stay in better touch using some of Google's
> coolest new
> products.
>
> If you already have Gmail or Google Talk, visit:
> http://mail.google.com/mail/b-4696b4693-d5d69810df-aafd3a6b94976b5f
> You'll need to click this link to be able to chat with Lucky Boy
Sudhir .
>
> To get Gmail - a free email account from Google with over 2,800
megabytes of
> storage - and chat with Lucky Boy Sudhir , visit:
> http://mail.google.com/mail/a-4696b4693-d5d69810df-ee3cdf55e5
>
> Gmail offers:
> - Instant messaging right inside Gmail
> - Powerful spam protection
> - Built-in search for finding your messages and a helpful way of
organizing
>  emails into "conversations"
> - No pop-up ads or untargeted banners - just text ads and related
information
>  that are relevant to the content of your messages
>
> All this, and its yours for free. But wait, there's more! By opening a
Gmail
> account, you also get access to Google Talk, Google's instant
messaging
> service:
>
> http://www.google.com/talk/
>
> Google Talk offers:
> - Web-based chat that you can use anywhere, without a download
> - A contact list that's synchronized with your Gmail account
> - Free, high quality PC-to-PC voice calls when you download the Google
Talk
>  client
>
> Gmail and Google Talk are still in beta. We're working hard to add new
features
> and make improvements, so we might also ask for your comments and
suggestions
> periodically. We appreciate your help in making our products even
better!
>
> Thanks,
> The Google Team
>
> To learn more about Gmail and Google Talk, visit:
> http://mail.google.com/mail/help/about.html
> http://www.google.com/talk/about.html
>
> (If clicking the URLs in this message does not work, copy and paste
them into
> the address bar of your browser).
> ___
> 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] what does the "@" operator mean?

2008-12-17 Thread Lie Ryan
On Tue, 16 Dec 2008 01:03:55 +, Alan Gauld wrote:

> "Marc Tompkins"  wrote
> 
>> If you're just starting out in Python, decorators can be hard to get
>> your head around...
> 
> I've been using Python for oover 10 years and still find decorators hard
> to get my head around! :-)
> 
> I confess I'm not a fan, they go against the Python spirit of explicit
> is best in my opinion. If I'm calling a function I like to know I'm
> calling a function... I know they make the code look pretty but IMHO
> they are a pain to debug and I'm never totally convinced I've got it
> exactly right.

I usually think about decorator as a tag or marker instead of function 
calling. When I put the property decorator, I'll be thinking about 
attaching a property tag to the function so the interpreter would handle 
the function as if it is a property. This way, I don't think of it as 
implicit function calling but as an explicit tag (how the tag system 
works is a detail I need not to care).

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


Re: [Tutor] what does the "@" operator mean?

2008-12-17 Thread Wolfram Kraus

Am 16.12.2008 02:03, Alan Gauld schrieb:


"Marc Tompkins"  wrote


If you're just starting out in Python, decorators can be hard to get
your head around...


I've been using Python for oover 10 years and still find decorators
hard to get my head around! :-)

I confess I'm not a fan, they go against the Python spirit of
explicit is best in my opinion. If I'm calling a function I like to
know I'm calling a function... I know they make the code look
pretty but IMHO they are a pain to debug and I'm never totally
convinced I've got it exactly right.

Alan G


Just found this via dzone.org: 
http://gumuz.nl/weblog/simple-python-decorator-classes/


Very interesting read.

HTH,
Wolfram

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


Re: [Tutor] Lucky Boy Sudhir wants to chat

2008-12-17 Thread Kent Johnson
I have unsubscribed Lucky Boy from the list as he is just spamming it.

Kent

On Wed, Dec 17, 2008 at 7:01 AM, Lucky Boy Sudhir
 wrote:
> ---
>
> Lucky Boy Sudhir  wants to stay in better touch using some of Google's
> coolest new
> products.
>
> If you already have Gmail or Google Talk, visit:
> http://mail.google.com/mail/b-4696b4693-d5d69810df-aafd3a6b94976b5f
> You'll need to click this link to be able to chat with Lucky Boy Sudhir .
>
> To get Gmail - a free email account from Google with over 2,800 megabytes of
> storage - and chat with Lucky Boy Sudhir , visit:
> http://mail.google.com/mail/a-4696b4693-d5d69810df-ee3cdf55e5
>
> Gmail offers:
> - Instant messaging right inside Gmail
> - Powerful spam protection
> - Built-in search for finding your messages and a helpful way of organizing
>  emails into "conversations"
> - No pop-up ads or untargeted banners - just text ads and related information
>  that are relevant to the content of your messages
>
> All this, and its yours for free. But wait, there's more! By opening a Gmail
> account, you also get access to Google Talk, Google's instant messaging
> service:
>
> http://www.google.com/talk/
>
> Google Talk offers:
> - Web-based chat that you can use anywhere, without a download
> - A contact list that's synchronized with your Gmail account
> - Free, high quality PC-to-PC voice calls when you download the Google Talk
>  client
>
> Gmail and Google Talk are still in beta. We're working hard to add new 
> features
> and make improvements, so we might also ask for your comments and suggestions
> periodically. We appreciate your help in making our products even better!
>
> Thanks,
> The Google Team
>
> To learn more about Gmail and Google Talk, visit:
> http://mail.google.com/mail/help/about.html
> http://www.google.com/talk/about.html
>
> (If clicking the URLs in this message does not work, copy and paste them into
> the address bar of your browser).
> ___
> 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] Lucky Boy Sudhir has invited you to open a Google mail account

2008-12-17 Thread Lucky Boy Sudhir
I've been using Gmail and thought you might like to try it out. Here's
an invitation to create an account.

---

Lucky Boy Sudhir  has invited you to open a free Gmail account.

To accept this invitation and register for your account, visit
http://mail.google.com/mail/a-4696b4693-1006ddb730-25c77422c3

Once you create your account, Lucky Boy Sudhir  will be notified with
your new email address so you can stay in touch with Gmail!

If you haven't already heard about Gmail, it's a new search-based webmail
service that offers:

- Over 2,700 megabytes (two gigabytes) of free storage
- Built-in Google search that instantly finds any message you want
- Automatic arrangement of messages and related replies into
  "conversations"
- Powerful spam protection using innovative Google technology
- No large, annoying ads--just small text ads and related pages that are
  relevant to the content of your messages

To learn more about Gmail before registering, visit:
http://mail.google.com/mail/help/benefits.html

And, to see how easy it can be to switch to a new email service, check
out our new switch guide: http://mail.google.com/mail/help/switch/

We're still working every day to improve Gmail, so we might ask for your
comments and suggestions periodically.  We hope you'll like Gmail.  We
do.  And, it's only going to get better.

Thanks,

The Gmail Team

(If clicking the URLs in this message does not work, copy and paste them
into the address bar of your browser).
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Lucky Boy Sudhir wants to chat

2008-12-17 Thread Lucky Boy Sudhir
---

Lucky Boy Sudhir  wants to stay in better touch using some of Google's
coolest new
products.

If you already have Gmail or Google Talk, visit:
http://mail.google.com/mail/b-4696b4693-d5d69810df-aafd3a6b94976b5f
You'll need to click this link to be able to chat with Lucky Boy Sudhir .

To get Gmail - a free email account from Google with over 2,800 megabytes of
storage - and chat with Lucky Boy Sudhir , visit:
http://mail.google.com/mail/a-4696b4693-d5d69810df-ee3cdf55e5

Gmail offers:
- Instant messaging right inside Gmail
- Powerful spam protection
- Built-in search for finding your messages and a helpful way of organizing
  emails into "conversations"
- No pop-up ads or untargeted banners - just text ads and related information
  that are relevant to the content of your messages

All this, and its yours for free. But wait, there's more! By opening a Gmail
account, you also get access to Google Talk, Google's instant messaging
service:

http://www.google.com/talk/

Google Talk offers:
- Web-based chat that you can use anywhere, without a download
- A contact list that's synchronized with your Gmail account
- Free, high quality PC-to-PC voice calls when you download the Google Talk
  client

Gmail and Google Talk are still in beta. We're working hard to add new features
and make improvements, so we might also ask for your comments and suggestions
periodically. We appreciate your help in making our products even better!

Thanks,
The Google Team

To learn more about Gmail and Google Talk, visit:
http://mail.google.com/mail/help/about.html
http://www.google.com/talk/about.html

(If clicking the URLs in this message does not work, copy and paste them into
the address bar of your browser).
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to exit program without sys.exit()

2008-12-17 Thread David

Hi,
I make these silly programs to learn from examples I find on the list. I 
put a couple together just to practice. I have heard it is not a good 
idea to use sys.exit() but I can not figure out how to do it. Also any 
and all comments are welcome. Thanks


#!/usr/bin/python
import sys
_count = 0

def getinfo():
answer = yesno("Enter y to continue, n to exit: y/n >> ")
if answer == "y":
getnumber()
else:
sys.exit()

def counter():
global _count
_count += 1
return _count

def yesno(question):
responce = None
while responce not in ("y", "n"):
responce = raw_input(question).lower()
return responce

def getnumber():
try:
num = int(raw_input("Enter a number between 25 and 75: "))
if 25 < num < 75:
print "WOW you are smart ", sayit()
except ValueError:
print "Please Enter a number!", getnumber()


def sayit():
print "Your total correct answers is", counter()
again()


def again():
onemore = raw_input("Again? y/n >> " )
if onemore.lower() == "y":
getnumber()
elif onemore.lower() == "n":
getinfo()
else:
sys.exit


def main():
getinfo()

if __name__=="__main__":
main()



--
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
pgp.mit.edu

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


Re: [Tutor] How to exit program without sys.exit()

2008-12-17 Thread wesley chun
> I make these silly programs to learn from examples I find on the list. I put
> a couple together just to practice. I have heard it is not a good idea to
> use sys.exit() but I can not figure out how to do it. Also any and all
> comments are welcome. Thanks


david,

welcome to Python!  it's definitely a good thing to read this list and
even more importantly, to practice. as far as your inquiry goes, you
don't need *any* sys.exit() calls in your code. just remove them plus
the else statement above each, as in:

> #!/usr/bin/python
> import sys
> _count = 0
>
> def getinfo():
>answer = yesno("Enter y to continue, n to exit: y/n >> ")
>if answer == "y":
>getnumber()
>
> def counter():
>global _count
>_count += 1
>return _count
>
> def yesno(question):
>responce = None
>while responce not in ("y", "n"):
>responce = raw_input(question).lower()
>return responce
>
> def getnumber():
>try:
>num = int(raw_input("Enter a number between 25 and 75: "))
>if 25 < num < 75:
>print "WOW you are smart ", sayit()
>except ValueError:
>print "Please Enter a number!", getnumber()
>
>
> def sayit():
>print "Your total correct answers is", counter()
>again()
>
>
> def again():
>onemore = raw_input("Again? y/n >> " )
>if onemore.lower() == "y":
>getnumber()
>elif onemore.lower() == "n":
>getinfo()
>
> def main():
>getinfo()
>
> if __name__=="__main__":
>main()

it should still work the same as before.  your functions will return
to the caller, and they will exit in the same way. finally, when
main() is done, your app is automatically exits.

one other suggestion... you have a lot of functions. it's possible to
reduce the total number, esp. since they're pretty much all one-offs.
generally, you want to employ functions for code that is used more
than once during a single execution of your code.  with your app, you
can probably get away with not having any functions at all.

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to exit program without sys.exit()

2008-12-17 Thread Alan Gauld

"David"  wrote

put a couple together just to practice. I have heard it is not a 
good idea to use sys.exit()


sys.exit is there to exit from a program so there is absolutely 
nothing

wrong with using it. However the way you are using it is not optimal.
A program will terminate or exit by itself if you allow it to "run off 
the end".

So you can remove most of your sys.exit() calls.

Where you want to use sys.exit() is where something happens that
would leave your program running but in a state where it might then do
some damage or produce a wriong result. You can then force a
premature exit with sys.exit. However even in these cases it's often
possible to restructure your code so that an explicit call to sys.exit
is not needed.

So to answer your question, using sys.exit is not bad or wrong,
but mostly you don't need to. It's better to reserve its use for 
occasions
where the program has to be forced to exit early. The other place 
where

you should use sys.exit() is where you want to return a specific error
code to the Operating System - usually for other scripts to use to 
detect

errors by your program.

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] How to exit program without sys.exit()

2008-12-17 Thread David

one other suggestion... you have a lot of functions. it's possible to
reduce the total number, esp. since they're pretty much all one-offs.
generally, you want to employ functions for code that is used more
than once during a single execution of your code.  with your app, you
can probably get away with not having any functions at all.

cheers,
-- wesley


I was practicing how to use a global counter and trying to understand 
how functions can interact with each other. I can understand if I can 
see the error's when I run the program. I know my terminology may be 
hard to follow. Also I like your book :)




So to answer your question, using sys.exit is not bad or wrong,
but mostly you don't need to. It's better to reserve its use for occasions
where the program has to be forced to exit early. The other place where
you should use sys.exit() is where you want to return a specific error
code to the Operating System - usually for other scripts to use to detect
errors by your program.

HTH,

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


Thanks, That does HAL (help a lot). Also thanks for the tutorial/book I 
have it bookmarked :)


-david


--
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
pgp.mit.edu

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


Re: [Tutor] How to exit program without sys.exit()

2008-12-17 Thread wesley chun
> I was practicing how to use a global counter and trying to understand
> how functions can interact with each other. I can understand if I can
> see the error's when I run the program. I know my terminology may be
> hard to follow. Also I like your book :)


you are well read since you already have seen places where it is
suggested that using sys.exit() is not the best choice.  as alan has
said, there isn't anything really "evil" about it... it just not
necessary, and you can write applications without using it at all.

another thing you'll read about is how it's "not good" to have global
variables. as with sys.exit() it is possible to have a universal
counter without using a global variable. they are a bit worse than
sys.exit() because they take up extra memory, there is less control --
they can be updated in multiple places in an application; such access
may result in race conditions and unexpected behavior if modified by
concurrent threads, etc.

to find a suitable replacement will depend on what you're counting,
and where a better place may be to store the counter. for example, you
can use a static member of a class, a closure, etc. if you have
specific application requirements, just post them to the list, and
folks will be glad to help you get around using global counters.

glad you enjoy the book! pssst... there is a DVD version of it coming
out at the end of this month called "Python Fundamentals"... keep an
eye out for it! ;-)

best regards,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor