Re: [Tutor] Question about Python being object oriented

2010-05-08 Thread Lie Ryan
On 05/09/10 02:19, Tino Dai wrote:
> Hi Everybody,
> 
>  My friend and I were having a disagreement about Python. Has Python
> always been an OO language or was it at one point a procedural language like
> C? Thanks!

AFAIK Python has always been a mixed paradigm language. You can write
fully OO code if you want, as well as procedural-style or
imperative-style code (especially handy for quickie-scripts[1]). But as
Bob Gailer pointed out, most OOP languages are build on top of
procedural base, which is itself is build on top of imperative base.


[1] compare to Java, a simple "hello world" must contain a class
declaration, then a 'public stupi^B^B^Batic main', etc. Even C must have
"public main".

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


Re: [Tutor] Question about Python being object oriented

2010-05-08 Thread bob gailer

On 5/8/2010 12:19 PM, Tino Dai wrote:

Hi Everybody,

 My friend and I were having a disagreement about Python. Has 
Python always been an OO language or was it at one point a procedural 
language like C? Thanks!


OO and procedural are not mutually exclusive!

From http://en.wikipedia.org/wiki/Imperative_programming:
"Procedural programming is imperative programming in which the program 
is built from one or more procedures (also known as subroutines or 
functions). The terms are often used as synonyms, but the use of 
procedures has a dramatic effect on how imperative programs appear and 
how they are constructed. Heavily procedural programming, in which state 
changes are localized to procedures or restricted to explicit arguments 
and returns from procedures, is known as structured programming. From 
the 1960s onwards, structured programming and modular programming in 
general, have been promoted as techniques to improve the maintainability 
and overall quality of imperative programs. Object-oriented programming 
extends this approach."


--
Bob Gailer
919-636-4239
Chapel Hill NC

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


Re: [Tutor] Question about Python being object oriented

2010-05-08 Thread Eike Welk
On Saturday May 8 2010 18:19:53 Tino Dai wrote:
> Hi Everybody,
> 
>  My friend and I were having a disagreement about Python. Has Python
> always been an OO language or was it at one point a procedural language
>  like C? Thanks!

The Wikipedia article states: Yes, it was always an object oriented language.
http://en.wikipedia.org/wiki/History_of_Python

However Python has a predecessor, the ABC language, which is not object 
oriented.
http://en.wikipedia.org/wiki/ABC_programming_language


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


[Tutor] Question about Python being object oriented

2010-05-08 Thread Tino Dai
Hi Everybody,

 My friend and I were having a disagreement about Python. Has Python
always been an OO language or was it at one point a procedural language like
C? Thanks!

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


Re: [Tutor] QUESTION REGARDING STATUS OF MY SUBSCRIPTION FW: Auto-response for your message to the "Tutor" mailing list

2010-04-16 Thread Dave Angel

Peter Meagher wrote:

GREETINGS,

THIS EMAIL WOULD INDICATE THAT I AM ON THE SUBSCRIPTION
LIST.

HOWEVER, I GOT ANOTHER EMAIL, THAT CAME IN AT PRECISELY THE
SAME TIME AS THE ORIGINAL MESSAGE THAT I AM FORWARDING YOU.
THAT INDICATES THAT THERE WAS AN ISSUE ADDING ME TO THE
LIST. I'VE PASTED IT IN THE BLOCK OF TEXT BELOW, BUT ABOVE
THE EMAIL THAT I AM FORWARDING YOU.

THANK YOU FOR YOUR ATTENTION.
Peter Meagher



If you do not wish to be subscribed to this list, please

simply
disregard this message.  If you think you are being
maliciously
subscribed to the list, or have any other questions,
send
them to
tutor-ow...@python.org.


  
That explains where you go with subscription questions.  The address is 
NOT the same as the one used for posting on the list.  I suspect you 
didn't correctly reply to the original message.


Your other message is an independent point.  It has nothing to do with 
whether you're subscribed or not, but simply is an acknowledgement that 
you're a new poster to the list, and includes some suggestions.  In 
fact, I get that message sometimes, even though I was 3rd highest poster 
here last year.  It's perfectly legal to post without being a 
subscriber, as you could be browing the messages online.


BTW, all upper-case is considered shouting.  It makes a message much 
harder to read, and more likely to be ignored.


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


[Tutor] QUESTION REGARDING STATUS OF MY SUBSCRIPTION FW: Auto-response for your message to the "Tutor" mailing list

2010-04-16 Thread Peter Meagher
GREETINGS,

THIS EMAIL WOULD INDICATE THAT I AM ON THE SUBSCRIPTION
LIST.

HOWEVER, I GOT ANOTHER EMAIL, THAT CAME IN AT PRECISELY THE
SAME TIME AS THE ORIGINAL MESSAGE THAT I AM FORWARDING YOU.
THAT INDICATES THAT THERE WAS AN ISSUE ADDING ME TO THE
LIST. I'VE PASTED IT IN THE BLOCK OF TEXT BELOW, BUT ABOVE
THE EMAIL THAT I AM FORWARDING YOU.

THANK YOU FOR YOUR ATTENTION.
Peter Meagher



---EMAIL INDICATING ISSUE PASTED BELOW

The results of your email command are provided below.
Attached is your original message.

- Results:
Invalid confirmation string.  Note that confirmation
strings expire approximately 3 days after the initial
subscription request.  If your confirmation has expired,
please try to re-submit your original request or message.

- Unprocessed:
RE: Your confirmation is required to join the Tutor
mailing list
Thank you
-Original Message-
From: tutor-bounces+ppmeagher=gmail@python.org
[mailto:tutor-bounces+ppmeagher=gmail@python.org] On
Behalf Of
 
tutor-confirm+fe41d06d04b6e46925e0b5da4b2e115760b4f...@pytho
n.org
Sent: Friday, April 16, 2010 12:35 AM
To: ppmeag...@gmail.com
Subject: Your confirmation is required to join the Tutor
mailing list
Mailing list subscription confirmation notice for
mailing
list Tutor
We have received a request from 96.224.37.102 for
subscription of your
email address, "ppmeag...@gmail.com", to the
tutor@python.org mailing
list.  To confirm that you want to be added to this
mailing
list,
simply reply to this message, keeping the Subject:
header
intact.  Or
visit this web page:

- Ignored:

 
 
http://mail.python.org/mailman/confirm/tutor/fe41d06d04b6e46
925e0b5da4b2e115760b4f2bd


Or include the following line -- and only the following
line
-- in a
message to tutor-requ...@python.org:

confirm fe41d06d04b6e46925e0b5da4b2e115760b4f2bd

Note that simply sending a `reply' to this message
should
work from
most mail readers, since that usually leaves the
Subject:
line in the
right form (additional "Re:" text in the Subject: is
okay).

If you do not wish to be subscribed to this list, please
simply
disregard this message.  If you think you are being
maliciously
subscribed to the list, or have any other questions,
send
them to
tutor-ow...@python.org.


- Done.


---END EMAIL INDICATING ISSUE PASTED ABOVE



-Original Message-
From: tutor-bounces+ppmeagher=gmail@python.org
[mailto:tutor-bounces+ppmeagher=gmail@python.org] On
Behalf Of tutor-boun...@python.org
Sent: Friday, April 16, 2010 1:34 AM
To: ppmeag...@gmail.com
Subject: Auto-response for your message to the "Tutor"
mailing list

Your message for tutor@python.org, the Python programming
tutor list,
has been received and is being delivered.  This automated
response is
sent to those of you new to the Tutor list, to point out a
few
resources that can help with answering your own questions,
or improve
the chances of getting a useful answer from the other
subscribers.

If your question is something akin to:

"I've just heard about Python, and it sounds great!
Where can I
 find out more on how to program with Python?"

  or:

 "What's Python?"

please read section 1 below.

On the other hand, if your question is:
  
"I've heard that Python is good for hacking -- I want to
know
more!"

  or

"Can you teach me how to break into a computer with
Python?"

please read section 2 at the bottom of this email.

Section 1: --

The most comprehensive overview of python.org help resources
is at

  http://www.python.org/Help.html

The Python FAQ is available at

  http://www.python.org/doc/FAQ.html 

and it has answers to many questions that people ask,
possibly
including your question.  Another wealth of information and
experience
can be found via the python.org searches, at

  http://www.python.org/search/

There you'll find comprehensive, easy-to-use searches over
the
python.org web site and the Python newsgroup,
comp.lang.python.

Python has an online tutorial, available freely from

  http://www.python.org/doc/current/tutorial/index.html

Finally, when you do send email to the Tutor list, be as
clear as you
can about the problem, including, when relevant, details
like:

 - Precise error messages, including complete tracebacks
 - The hardware platform (available in the Python sys module
as
sys.platform)
 - The python version (sys.version) 
 - The python search path (sys.path)

In general, be specific about what was going on connected
with the
problem or what specific concept you're having difficulties
with.  The
better the info you provide, the more likely the helpers
will be able
to glean the answer...

There's a HOWTO that shows how to ask "smart" questions to
technical
folks:

http://catb.org/~esr/faqs/smart-questions.html

Although it is p

Re: [Tutor] Question about importing

2010-02-02 Thread Alan Gauld


"Grigor Kolev"  wrote 


Can I use something like this
#--
import sys
sys.path.append("/home/user/other")
import module
#-


Yes but if you have a lot of modules in there that you might 
want to use in other programs you might prefer to add the 
folder to your PYTHONPATH environment variable. That 
way Python will always look in that folder for your modules.


Thats what I do - I gave a folder whee I put all my reusable 
modules. This folder is not under my Python install folder 
so that when I install a new Python and delete the old I 
don't lose my code... And the PYTHONPATH variable 
works with the new Python.


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

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


Re: [Tutor] Question about importing

2010-02-02 Thread Dave Angel

Eike Welk wrote:

On Tuesday February 2 2010 20:28:03 Grigor Kolev wrote:
  

Can I use something like this
#--
import sys
sys.path.append("/home/user/other")
import module
#-




Yes I think so. I just tried something similar:
--


IPython 0.10 -- An enhanced Interactive Python.

<--- snip >

In [1]: import sys

In [2]: 
sys.path.append("/home/eike/codedir/freeode/trunk/freeode_py/freeode/")


<--- snip >
<--- The next line is a special command of IPython: >

In [8]: !ls /home/eike/codedir/freeode/trunk/freeode_py/freeode/
ast.py   pygenerator.pyctest_1_interpreter.pyc   
test_pygenerator.pyc
ast.pyc  simlcompiler.pytest_2_interpreter.py  
test_simlcompiler.py
__init__.py  simlcompiler.pyc   test_2_interpreter.pyc 

<--- snip >



In [9]: import simlcompiler
---
ImportError   Traceback (most recent call last)

/home/eike/ in ()

/home/eike/codedir/freeode/trunk/freeode_py/freeode/simlcompiler.py in 
()

 36 import stat
 37 from subprocess import Popen #, PIPE, STDOUT
---> 38 import pyparsing
 39 import freeode.simlparser as simlparser
 40 import freeode.interpreter as interpreter

ImportError: No module named pyparsing


--
Well... the import fails, but it finds the module and starts to import it. 



HTH,
Eike.



  
I have no idea what freode looks like, but I have a guess, based on your 
error messages.


I'd guess that you want to append without the freeode directory:


sys.path.append("/home/eike/codedir/freeode/trunk/freeode_py/")

and import with it.  That's because freeode is a package name, not a 
directory name (I can tell because __init__.py is present)

 import freeode.simlcompiler

See if that works any better.

DaveA

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


Re: [Tutor] Question about importing

2010-02-02 Thread David Hutto

--- On Tue, 2/2/10, Grigor 
Kolev 
 wrote:

From: Grigor Kolev 

Subject: Re: [Tutor] Question about 
importing
To: "David Hutto" 
Cc: 
"Python Tutor" 
Date:
 Tuesday, February 2,
 2010, 2:54 PM

В 11:47 -0800 на 02.02.2010
 (вт), David Hutto написа:
> 
> 
> --- On Tue, 2/2/10,
 Grigor Kolev  
wrote:
>         
>         From: Grigor Kolev 
>         Subject: 
Re: [Tutor] Question about importing
>         To: "David Hutto" 

>         Cc:
 "Python Tutor" 
>   
      Date: Tuesday, February 2, 2010, 2:28 PM
>         
> 
        В 10:33 -0800 на 02.02.2010 (вт), David Hutto написа:
>   
      > 
>         > 
>         >
 --- On Tue, 2/2/10, Григор 
 wrote:
>         >         
>         >         From:
 Григор 
>     
    >         Subject: [Tutor] Question about importing
>      
   >         To: "Python Tutor" 
> 
        >         Date: Tuesday, February 2, 2010, 12:07
 PM
>         >         
>         >         Hi all.
> 
        >         How can I import a module which is located in the
> 
        upper
>         >         directory.
>      
   >         
>         >         
>         >     
    I think the following might be what you're looking
>      
   for:
>         >         
>   
      >
>            http://docs.python.org/tutorial/modules.html#the-module-search-path
> 
        >         
>         > 
>         Can I use 
something like this
>      
   #--
>      
   import sys
>         sys.path.append("/home/user/other")
> 
        import module
>      
   #-
>         --
 
>         Grigor Kolev
 
>          
> 
        
>         That's exactly what it says to do, but I 
haven't figured out
>         the path to append to mine yet.
> 
        
> 


Thanks for your help

It wasn't that 
much help, and I was about to do something similar anyway.. So if it 
makes you feel better, now we both know that's how it works.
-- 
Grigor
 Kolev 





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


Re: [Tutor] Question about importing

2010-02-02 Thread Eike Welk
On Tuesday February 2 2010 20:28:03 Grigor Kolev wrote:
> Can I use something like this
> #--
> import sys
> sys.path.append("/home/user/other")
> import module
> #-
> 

Yes I think so. I just tried something similar:
--


IPython 0.10 -- An enhanced Interactive Python.

<--- snip >

In [1]: import sys

In [2]: 
sys.path.append("/home/eike/codedir/freeode/trunk/freeode_py/freeode/")

<--- snip >
<--- The next line is a special command of IPython: >

In [8]: !ls /home/eike/codedir/freeode/trunk/freeode_py/freeode/
ast.py   pygenerator.pyctest_1_interpreter.pyc  
 
test_pygenerator.pyc
ast.pyc  simlcompiler.pytest_2_interpreter.py  
test_simlcompiler.py
__init__.py  simlcompiler.pyc   test_2_interpreter.pyc 

<--- snip >


In [9]: import simlcompiler
---
ImportError   Traceback (most recent call last)

/home/eike/ in ()

/home/eike/codedir/freeode/trunk/freeode_py/freeode/simlcompiler.py in 
()
 36 import stat
 37 from subprocess import Popen #, PIPE, STDOUT
---> 38 import pyparsing
 39 import freeode.simlparser as simlparser
 40 import freeode.interpreter as interpreter

ImportError: No module named pyparsing


--
Well... the import fails, but it finds the module and starts to import it. 


HTH,
Eike.


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


Re: [Tutor] Question about importing

2010-02-02 Thread Grigor Kolev
В 11:47 -0800 на 02.02.2010 (вт), David Hutto написа:
> 
> 
> --- On Tue, 2/2/10, Grigor Kolev  wrote:
> 
> From: Grigor Kolev 
> Subject: Re: [Tutor] Question about importing
> To: "David Hutto" 
> Cc: "Python Tutor" 
> Date: Tuesday, February 2, 2010, 2:28 PM
> 
> В 10:33 -0800 на 02.02.2010 (вт), David Hutto написа:
> > 
> > 
> > --- On Tue, 2/2/10, Григор  wrote:
> >     
> > From: Григор 
> > Subject: [Tutor] Question about importing
> > To: "Python Tutor" 
> > Date: Tuesday, February 2, 2010, 12:07 PM
> > 
> > Hi all.
> > How can I import a module which is located in the
> upper
> > directory.
> > 
> > 
> > I think the following might be what you're looking
> for:
> > 
> >
>http://docs.python.org/tutorial/modules.html#the-module-search-path
> > 
> > 
> Can I use something like this
> #--
> import sys
> sys.path.append("/home/user/other")
> import module
> #-
> -- 
> Grigor Kolev 
>  
> 
> That's exactly what it says to do, but I haven't figured out
> the path to append to mine yet.
> 
> 


Thanks for your help

-- 
Grigor Kolev 

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


Re: [Tutor] Question about importing

2010-02-02 Thread David Hutto


--- On Tue, 2/2/10, Grigor Kolev  wrote:

From: Grigor Kolev 
Subject: Re: [Tutor] Question about importing
To: "David Hutto" 
Cc: "Python Tutor" 
Date: Tuesday, February 2, 2010, 2:28 PM

В 10:33 -0800 на 02.02.2010 (вт), David Hutto написа:
> 
> 
> --- On Tue, 2/2/10, Григор  wrote:
>         
>         From: Григор 
>         Subject: [Tutor] Question about importing
>         To: "Python Tutor" 
>         Date: Tuesday, February 2, 2010, 12:07 PM
>         
>         Hi all.
>         How can I import a module which is located in the upper
>         directory.
>         
>         
>         I think the following might be what you're looking for:
>         
>         http://docs.python.org/tutorial/modules.html#the-module-search-path
>         
> 
Can I use something like this
#--
import sys
sys.path.append("/home/user/other")
import module
#-
-- 
Grigor Kolev 
 

That's exactly what it says to do, but I haven't figured out the path to append 
to mine yet.



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


Re: [Tutor] Question about importing

2010-02-02 Thread Grigor Kolev
В 10:33 -0800 на 02.02.2010 (вт), David Hutto написа:
> 
> 
> --- On Tue, 2/2/10, Григор  wrote:
> 
> From: Григор 
>     Subject: [Tutor] Question about importing
> To: "Python Tutor" 
> Date: Tuesday, February 2, 2010, 12:07 PM
> 
> Hi all.
> How can I import a module which is located in the upper
> directory.
> 
> 
> I think the following might be what you're looking for:
> 
> http://docs.python.org/tutorial/modules.html#the-module-search-path
> 
> 
Can I use something like this
#--
import sys
sys.path.append("/home/user/other")
import module
#-
-- 
Grigor Kolev 

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


Re: [Tutor] Question about importing

2010-02-02 Thread David Hutto


--- On Tue, 2/2/10, Григор  wrote:

From: Григор 
Subject: [Tutor] Question about importing
To: "Python Tutor" 
Date: Tuesday, February 2, 2010, 12:07 PM

Hi all.
How can I import a module which is located in the upper directory.


I think the following might be what you're looking for:

http://docs.python.org/tutorial/modules.html#the-module-search-path



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


[Tutor] Question about importing

2010-02-02 Thread Григор
Hi all.
How can I import a module which is located in the upper directory.


-- 
Криле имат само тия, дето дето сърцето им иска да лети !
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-10 Thread Kent Johnson
On Sat, Jan 9, 2010 at 3:50 AM, spir  wrote:
> Lie Ryan dixit:
>
>> only use "from module import *" if the
>> module was designed for such use
>
> In most cases, this translates to: the imported module defines __names__, 
> which holds the list of names (of the objects) to be exported. Check it.
> Below, a,b,c,f,g,X,Y are defined, but only c,g,Y are exported. This means 
> "from mod import *" will only import these names. Without __names__ defined, 
> it would import all.\

That should be __all__, not __names__

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


Re: [Tutor] question about function inside of function

2010-01-10 Thread Kent Johnson
On Sat, Jan 9, 2010 at 8:03 AM, spir  wrote:

> Do you realize the inner func will be redefined before each call? Meaning in 
> your case n calls x n outer loops x n inner loops.
>   def f() ...
> is actually a kind of masked assignment
>   f = function()...

That's true, but it is pretty inexpensive. The heavy lifting is at
compile time when a code object is created. Wrapping this as a
function is fast.

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


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-10 Thread Eric Pavey
On Sat, Jan 9, 2010 at 9:08 PM, Lie Ryan  wrote:

> On 1/10/2010 11:23 AM, Eric Pavey wrote:
>
>> I should add (that as I understand it), when you do a 'from foo import
>> blah', or 'from foo import *', this is doing a /copy/ (effectively) of
>> that module's attributes into the current namespace.  Doing "import foo"
>> or "import foo as goo" is keeping a /reference /to the imported module
>> rather than a copy.
>>
>
> No, that's a roundabout way to look at it. Python's variable holds
> references to objects[1] and never the object themselves; name assignment
> statement in python never makes a copy of the object, but always makes a new
> reference to the same object. "Assignment statements" in python includes the
> '=', 'from import', and regular 'import' [2].
>
> [1] this is call-by-object http://effbot.org/zone/python-objects.htm
> http://effbot.org/zone/call-by-object.htm
> [2] there are other more obscure statements that is an 'assignment
> statement' as well, such as "with ... as ...", "agumented assignment
> operators", dictionary/list assignment, etc. The list is non-exhaustive.
>
>
>  If you use the 'from import' system, changes made to attrs of the
>> imported module /won't/ be seen by any other module that imported it.
>> If you do just an 'import' on a module (or 'import ... as ...'), then
>> changes made to attrs on the imported module /will /be seen by othe
>> modules that import it as well.  I hope that is somewhat clear. ;)
>>
>
> Read both links to effbot's article, they should make it clear why the
> current behavior is the way it is.
>

See, I figured I'd get straightened out myself by posting that.  Those
concepts help me out as well ;)  Always learning...
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-09 Thread Lie Ryan

On 1/10/2010 11:23 AM, Eric Pavey wrote:

I should add (that as I understand it), when you do a 'from foo import
blah', or 'from foo import *', this is doing a /copy/ (effectively) of
that module's attributes into the current namespace.  Doing "import foo"
or "import foo as goo" is keeping a /reference /to the imported module
rather than a copy.


No, that's a roundabout way to look at it. Python's variable holds 
references to objects[1] and never the object themselves; name 
assignment statement in python never makes a copy of the object, but 
always makes a new reference to the same object. "Assignment statements" 
in python includes the '=', 'from import', and regular 'import' [2].


[1] this is call-by-object http://effbot.org/zone/python-objects.htm 
http://effbot.org/zone/call-by-object.htm
[2] there are other more obscure statements that is an 'assignment 
statement' as well, such as "with ... as ...", "agumented assignment 
operators", dictionary/list assignment, etc. The list is non-exhaustive.



If you use the 'from import' system, changes made to attrs of the
imported module /won't/ be seen by any other module that imported it.
If you do just an 'import' on a module (or 'import ... as ...'), then
changes made to attrs on the imported module /will /be seen by othe
modules that import it as well.  I hope that is somewhat clear. ;)


Read both links to effbot's article, they should make it clear why the 
current behavior is the way it is.


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


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-09 Thread bob gailer

Eric Pavey wrote:
I should add (that as I understand it), when you do a 'from foo import 
blah', or 'from foo import *', this is doing a /copy/ (effectively) of 
that module's attributes into the current namespace.
Not a copy (which means duplicating the attribute) but a new reference 
to the original attribute. Example

>>> import sys
>>> from sys import modules
>>> sys.modules is modules
True
>>> m = dict(sys.modules) # create a copy
>>> m is modules
False

--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-09 Thread Eric Pavey
I should add (that as I understand it), when you do a 'from foo import
blah', or 'from foo import *', this is doing a *copy* (effectively) of that
module's attributes into the current namespace.  Doing "import foo" or
"import foo as goo" is keeping a *reference *to the imported module rather
than a copy.

If you use the 'from import' system, changes made to attrs of the imported
module *won't* be seen by any other module that imported it.
If you do just an 'import' on a module (or 'import ... as ...'), then
changes made to attrs on the imported module *will *be seen by othe modules
that import it as well.  I hope that is somewhat clear. ;)

On Sat, Jan 9, 2010 at 8:35 AM, Lowell Tackett wrote:

> If I might offer one small comment...
>
> It seems to me that this argument also goes to a code readability issue;
> ergo, if you choose "from foobar..." as opposed to "import foobar", then
> from that point on you only need employ foobar's methods in your code, and
> they are not alway easily recognizable.  i.e, by importing foobar, you will
> always prefix a method with its' parent module name, which [I think] makes
> the code more understandable.
>
> From the virtual desk of Lowell Tackett
>
>
> --- On *Sat, 1/9/10, Alan Gauld * wrote:
>
>
> From: Alan Gauld 
> Subject: Re: [Tutor] Question on "import foobar" vs "from foobar import *"
> To: tutor@python.org
> Date: Saturday, January 9, 2010, 10:21 AM
>
>
>
> "Rob Cherry" http://mc/compose?to=pythontu...@lxrb.com>>
> wrote
>
> > Extending on this advice somewhat - is it *ever* correct to "import
> foobar".
>
> Yes, it is *usually* correct to "import foobar" and rarely correct to "from
> foobar".
> The exception being if you only need one or two names from foobar, but
> usually you need a lot more, in which case use import foobar.
>
> To save typing you can give foobar a shorter name:
>
> import foobar as fb
>
> For some reason that convenience feature doesn't get mentioned
> all that often but I use it a lot.
>
> HTH,
>
>
> -- Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about function inside of function

2010-01-09 Thread Richard D. Moores
On Sat, Jan 9, 2010 at 07:28, Alan Gauld  wrote:
>
> "Richard D. Moores"  wrote
>>
>> to be put in a function. For convenience sake, I've put this new
>> function inside the one that calls it.
>>
>> Question 1: Is this bad practice? It works fine that way, but..
>
> No, but there are some issues to consider.
> Denis has addressed some but one other is...
>
> Reuse: by hiding the function inside the outer one it means it can only ever
> be used inside that function.

That's OK. It's very specific to the enclosing function.

> It may be better to have it as a module level
> function - even if you use the _prefix to limit its use outside the module.
>
>> Question 2: If the answer to Q1 is no, is there a standard place to
>> put a function inside of another function? Is it standard to have it
>> the first line of the function? I've put mine at the point where it
>> would be called, mainly as a reminder to myself.
>
> Top of the function is best because as Denis says it only gets defined once
> per function call. If you are really paranoid and the function only gets
> used in exceptional cases then you could define it at the point of use but
> in that case you probably don't need a function at all!

I moved it to the top. But since writing it I debugged and edited the
script so that the small function is used in only one case. So you're
right, I don't need it as a function at all.

Thanks, Alan. Right on as usual.

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


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-09 Thread Lowell Tackett
If I might offer one small comment...

It seems to me that this argument also goes to a code readability issue; ergo, 
if you choose "from foobar..." as opposed to "import foobar", then from that 
point on you only need employ foobar's methods in your code, and they are not 
alway easily recognizable.  i.e, by importing foobar, you will always prefix a 
method with its' parent module name, which [I think] makes the code more 
understandable.

>From the virtual desk of Lowell Tackett  


--- On Sat, 1/9/10, Alan Gauld  wrote:

From: Alan Gauld 
Subject: Re: [Tutor] Question on "import foobar" vs "from foobar import *"
To: tutor@python.org
Date: Saturday, January 9, 2010, 10:21 AM


"Rob Cherry"  wrote

> Extending on this advice somewhat - is it *ever* correct to "import foobar".

Yes, it is *usually* correct to "import foobar" and rarely correct to "from 
foobar".
The exception being if you only need one or two names from foobar, but
usually you need a lot more, in which case use import foobar.

To save typing you can give foobar a shorter name:

import foobar as fb

For some reason that convenience feature doesn't get mentioned
all that often but I use it a lot.

HTH,


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

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



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


Re: [Tutor] question about function inside of function

2010-01-09 Thread Alan Gauld


"Richard D. Moores"  wrote 


to be put in a function. For convenience sake, I've put this new
function inside the one that calls it.

Question 1: Is this bad practice? It works fine that way, but..


No, but there are some issues to consider.
Denis has addressed some but one other is...

Reuse: by hiding the function inside the outer one it means it 
can only ever be used inside that function. It may be better to 
have it as a module level function - even if you use the _prefix 
to limit its use outside the module.



Question 2: If the answer to Q1 is no, is there a standard place to
put a function inside of another function? Is it standard to have it
the first line of the function? I've put mine at the point where it
would be called, mainly as a reminder to myself.


Top of the function is best because as Denis says it only gets 
defined once per function call. If you are really paranoid and 
the function only gets used in exceptional cases then you could 
define it at the point of use but in that case you probably don't 
need a function at all!


HTH,


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

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


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-09 Thread Alan Gauld


"Rob Cherry"  wrote

Extending on this advice somewhat - is it *ever* correct to "import 
foobar".


Yes, it is *usually* correct to "import foobar" and rarely correct to "from 
foobar".

The exception being if you only need one or two names from foobar, but
usually you need a lot more, in which case use import foobar.

To save typing you can give foobar a shorter name:

import foobar as fb

For some reason that convenience feature doesn't get mentioned
all that often but I use it a lot.

HTH,


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



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


Re: [Tutor] question about function inside of function

2010-01-09 Thread Richard D. Moores
On Sat, Jan 9, 2010 at 05:03, spir  wrote:

> Do you realize the inner func will be redefined before each call?

Oh, I forgot about that. Thanks!

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


Re: [Tutor] question about function inside of function

2010-01-09 Thread spir
Richard D. Moores dixit:

> I'm working on a function that seems to cry out for some of its code
> to be put in a function. For convenience sake, I've put this new
> function inside the one that calls it.
> 
> Question 1: Is this bad practice? It works fine that way, but..
> 
> Question 2: If the answer to Q1 is no, is there a standard place to
> put a function inside of another function? Is it standard to have it
> the first line of the function? I've put mine at the point where it
> would be called, mainly as a reminder to myself.
> 
> An outline of the big function is:
> 
> if:
> else:
>  for loop
>  for loop
>  if
>  elif
>  the function
>  call the function
>  else
> 
> Thanks,

Do you realize the inner func will be redefined before each call? Meaning in 
your case n calls x n outer loops x n inner loops.
   def f() ...
is actually a kind of masked assignment
   f = function()...

To avoid polluting the global namespace (if it's what you mean), you can 
assiattach the inner func as an attribute of the outer: "g.f = f". 
Unfortunately, it's not possible (I guess), to define it directly using "def 
g.f()".
Also, if a func logically is an attribute of another, then probably you're 
close to defined an object, possibly with other attributes. Think at the design 
of the application.

I may be wrong, but I guess the only common case where you should (and must) 
define a func inside another is the one of a func factory, ie a func that 
defines (and returns) a new func:

def makeAdder(val):
def adder(x):
return x + adder.val
adder.val = val
return adder
add3 = makeAdder(3)
print add3(2)   # --> 5

Denis


la vita e estrany

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


[Tutor] question about function inside of function

2010-01-09 Thread Richard D. Moores
I'm working on a function that seems to cry out for some of its code
to be put in a function. For convenience sake, I've put this new
function inside the one that calls it.

Question 1: Is this bad practice? It works fine that way, but..

Question 2: If the answer to Q1 is no, is there a standard place to
put a function inside of another function? Is it standard to have it
the first line of the function? I've put mine at the point where it
would be called, mainly as a reminder to myself.

An outline of the big function is:

if:
else:
 for loop
 for loop
 if
 elif
 the function
 call the function
 else

Thanks,

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


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-09 Thread spir
Lie Ryan dixit:

> only use "from module import *" if the 
> module was designed for such use 

In most cases, this translates to: the imported module defines __names__, which 
holds the list of names (of the objects) to be exported. Check it.
Below, a,b,c,f,g,X,Y are defined, but only c,g,Y are exported. This means "from 
mod import *" will only import these names. Without __names__ defined, it would 
import all.

### module mod.py ###

__names__ = ['c','g','Y']

a = ...
b = ...
c = ...

def f():
...
def g():
...

class X(object):
...
class Y(object):
...


Denis


la vita e estrany

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


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-08 Thread Lie Ryan

On 1/9/2010 6:39 AM, Rob Cherry wrote:

Extending on this advice somewhat - is it *ever* correct to "import foobar".

There are countless examples of

import os,sys


The rule of thumb is:
Use the "from module import something" if you're only going to use one 
or two functions from the module; only use "from module import *" if the 
module was designed for such use (e.g. Tkconstants, pygame.constants) or 
if you're in the interactive interpreter. When in doubt, use the "import 
module" form.




etc,etc.  Strictly speaking should we always be using "from" to only
get what we know we need?


Not necessarily, the "from module..." actually does a full "import 
module" in the back; you don't actually save anything by 
micro-controlling. In fact, it is quite a work to update the from-list 
every time you want to access another class/function in the module. 
However, the "from module import *" form is considered a bad form 
because it introduces namespace pollution.


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


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-08 Thread Kent Johnson
On Fri, Jan 8, 2010 at 2:39 PM, Rob Cherry  wrote:
> Extending on this advice somewhat - is it *ever* correct to "import foobar".
>
> There are countless examples of
>
> import os,sys
>
> etc,etc.  Strictly speaking should we always be using "from" to only
> get what we know we need?

No, the plain import is fine.

import sys
adds just the single name 'sys' to your global namespace, you then
have to access the items in it via sys.version, etc.

from sys import version
imports just the name 'version' into your global namespace.

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


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-08 Thread Wayne Werner
On Fri, Jan 8, 2010 at 1:21 PM, Rob Cherry  wrote:

> Still trying to get the hang of some python intricacies, but this one
> has come up a few times.  Beyond the obvious syntactic niceties what
> is the difference between importing with and without the "from"
> syntax?
>
> Its nice for example to do this -
>
> from socket import *
> googleip = gethostbyname("www.google.com")
>
> vs
>
> import socket
> googleip = socket.gethostbyname("www.google.com")
>
> Is there any difference between these concepts?  Is there an easy
> google search term for me to research the difference to death?
>

Namespace is a term you might want to look for. (Google "Python Namespace"
or something to that effect)

What the first one does is import all of the variables, classes, functions,
and anything inside the socket library into the local namespace.

This can lead to some pretty unpredictable behavior and is usually
discouraged. It's better to import socket (or whatever module you want to
import). But if you know you just want one function or class, you can use
the "from" syntax to import it.

HTH,
Wayne


-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-08 Thread Luke Paireepinart
Yes, it depends how the library was designed.  Some are designed so that you
can import some of the library into your global namespace.  For example, in
Pygame library, it's accepted to do
import pygame
from pygame.locals import *


This keeps the methods like
pygame.init()
pygame.display.set_mode()

etc.
but it lets you avoid having to do
for event in pygame.event.get():
if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:


instead you can do

for event in pygame.event.get():
if event.type == KEYDOWN and event.key == K_UP:


But I don't know of any case where it's preferable to use the "from" syntax,
it's mostly just a laziness thing.

-Luke


On Fri, Jan 8, 2010 at 1:39 PM, Rob Cherry  wrote:

> Extending on this advice somewhat - is it *ever* correct to "import
> foobar".
>
> There are countless examples of
>
> import os,sys
>
> etc,etc.  Strictly speaking should we always be using "from" to only
> get what we know we need?
>
> Thanks,
>
> Rob
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-08 Thread Rob Cherry
Extending on this advice somewhat - is it *ever* correct to "import foobar".

There are countless examples of

import os,sys

etc,etc.  Strictly speaking should we always be using "from" to only
get what we know we need?

Thanks,

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


Re: [Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-08 Thread Luke Paireepinart
The difference is a term called "namespace pollution".
the "from socket import *" will place a whole lot of methods into your
global namespace, possibly colliding with other methods / variables you've
defined yourself.  For example, if your file contained

x = 5
from foobar import *


and foobar contained
x = 6

then x would be 6.  This is a potential side-effect that's pretty
undesirable.  If you did the other import style, then x would not get
overwritten.

The reason the 'from' syntax was designed was so you could only import
certain methods into your global namespace, but you'd be aware of which you
were importing.
So in your example you'd want to do
from socket import gethostbyname

so you're sure you know what you're importing into your namespace and you
can avoid polluting it.

HTH,
-Luke



On Fri, Jan 8, 2010 at 1:21 PM, Rob Cherry  wrote:

> Still trying to get the hang of some python intricacies, but this one
> has come up a few times.  Beyond the obvious syntactic niceties what
> is the difference between importing with and without the "from"
> syntax?
>
> Its nice for example to do this -
>
> from socket import *
> googleip = gethostbyname("www.google.com")
>
> vs
>
> import socket
> googleip = socket.gethostbyname("www.google.com")
>
> Is there any difference between these concepts?  Is there an easy
> google search term for me to research the difference to death?
>
> Thanks in advance!
>
> Rob
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question on "import foobar" vs "from foobar import *"

2010-01-08 Thread Rob Cherry
Still trying to get the hang of some python intricacies, but this one
has come up a few times.  Beyond the obvious syntactic niceties what
is the difference between importing with and without the "from"
syntax?

Its nice for example to do this -

from socket import *
googleip = gethostbyname("www.google.com")

vs

import socket
googleip = socket.gethostbyname("www.google.com")

Is there any difference between these concepts?  Is there an easy
google search term for me to research the difference to death?

Thanks in advance!

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


[Tutor] question about for loops

2010-01-07 Thread Richard D. Moores
On Thu, Jan 7, 2010 at 05:03, Alan Plum  wrote:

> Variable unpacking works like this:
>
> points = [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)]
>
> for (x,y) in points:
>    print 'x: %d, y: %d' % (x, y)
>
> Without unpacking:
>
> for point in points:
>    print 'x: %d, y: %d' % (point[0], point[1]) # point is a tuple
>
> Similarly consider this expression:
>
> (a, b) = (50, 100) # a = 50, b = 100
> c = (a, b) # c[0] = a, c[1] = b
>
> It's a really useful language feature if you're ever dealing with tuples
> that carry certain semantics (e.g. x, y and z coordinates in a point
> tuple) but don't want to create a new type.
>
>
> Hope that helps,

Certainly does. Thank you.

I did something like your 3rd example, in these lines from the script
I posted yesterday in the thread about the fractions module.

f = str(Fraction(str(r)).limit_denominator(100))
n, d = f.split('/')
num, denom = int(n), int(d)
fraction = num/denom


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


Re: [Tutor] question about for loops

2010-01-07 Thread Richard D. Moores
Now I have a nice collection of examples, which to me are worth more
than the sometimes inscrutable docs.

My thanks to you three for taking the time to create the examples, and
accompany them with understandable explanations.

BTW I like Summerfield's book a lot, but he let me down on p.162.

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


Re: [Tutor] question about for loops

2010-01-07 Thread taserian
On Thu, Jan 7, 2010 at 7:43 AM, Richard D. Moores wrote:

> On p. 162 of "Programming In Python", 2nd ed., by Summerfield, the
> section entitled "for Loops" begins:
>
> =
> for expression in iterable:
> for_suite
> else:
> else_suite
>
> The expression is normally either a single variable or a sequence of
> variables, usually in the form of a tuple. If a tuple or list is used
> for the expression, each item is unpacked into the expression's items.
> ==
>
> I thought I was quite familiar with for loops, but I don't understand
> how the expression can be a sequence of variables, nor what  unpacking
> into the expression's items means. Could someone explain this,
> preferably with an example?
>
> Thanks,
>
> Dick Moores
>
>
As an example, think of a list of tuples, similar to the following:

tuplelist = [ (1, "a"), (2, "b"), (3, "c") ]

To process them and handle each tuples elements individually, you can have
the for statement:

for (a, b) in tuplelist:
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about for loops

2010-01-07 Thread Eike Welk
Hello Richard!

On Thursday January 7 2010 13:43:26 Richard D. Moores wrote:
> On p. 162 of "Programming In Python", 2nd ed., by Summerfield, the
> section entitled "for Loops" begins:
> 
> =
> for expression in iterable:
>  for_suite
> else:
>  else_suite
> 
> The expression is normally either a single variable or a sequence of
> variables, usually in the form of a tuple. If a tuple or list is used
> for the expression, each item is unpacked into the expression's items.
> ==
> 
> I thought I was quite familiar with for loops, but I don't understand
> how the expression can be a sequence of variables, nor what  unpacking
> into the expression's items means. Could someone explain this,
> preferably with an example?

Your book seems to be a bit sloppy with the terms it chooses for describing 
the syntax. Look at the official syntax description section 7.3:
http://docs.python.org/reference/compound_stmts.html#the-for-statement

After the for statement there is no expression, but something called 
target_list. This target_list normally contains unknown variables, which are 
illegal in expressions. 

The whole complicated wording refers to this case:
>>> for a,b,c in ((1,2,3), (4,5,6), (10,20,30)):
... print a,b,c
...
1 2 3
4 5 6
10 20 30


Unpacking is the operation done in:
a,b,b = (2,4,5)

The "a,b,c" on the left side of the assignment operator is also a target list. 
See section 6.2:
http://docs.python.org/reference/simple_stmts.html#assignment-statements


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


[Tutor] question about for loops

2010-01-07 Thread Richard D. Moores
On p. 162 of "Programming In Python", 2nd ed., by Summerfield, the
section entitled "for Loops" begins:

=
for expression in iterable:
 for_suite
else:
 else_suite

The expression is normally either a single variable or a sequence of
variables, usually in the form of a tuple. If a tuple or list is used
for the expression, each item is unpacked into the expression's items.
==

I thought I was quite familiar with for loops, but I don't understand
how the expression can be a sequence of variables, nor what  unpacking
into the expression's items means. Could someone explain this,
preferably with an example?

Thanks,

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


Re: [Tutor] Question : Creating cribbage game

2009-12-07 Thread spir
Christopher schueler  dixit:

> 
> My name is Chris Schueler and i am having some troubles with my Python 
> programming
> 
>  
> 
> Our current project is to create the game of cribbage from scratch.
> 
> The only problem is we are not allowed to use classes, only user-defind 
> functions and arrays. I was wondering if anybody could give me tips or 
> pointers on adding codes or modifying some of my program


>From my limited experience in coding games. You have to model several distinct 
>aspects:
* Constant data about the game, such as a card set.
* The game logic, mirroring the (real) game rules, ie what players can do, and 
what comes out of their actions.
* The game state, what's the situation at a given point in time, constantly 
modified by the above actions.
* Possibly some AI if the computer plays a role.
Note that first 2 points are predefined aspects (constants in the plain sense 
of the word).

Forbidding OO is a very bad thing because game modelling is precisely a 
programming domain in which this paradigm applies very naturally : every 
element in the game (state) is an "object" that can be modified through methods 
representing game rules.
Python dicts offer a powerful tool to represent kinds of objects, when used as 
records (lookup in wikipedia if you don't see what I mean). Moreover, python 
functions beeing "namable" objects, you can even attach relevant funcs to 
records so as to simulate methods. All you miss then is typical OO syntactic 
sugar where 'self' is automagically inserted as first argument of a method 
call. Instead of
   hand.popCard(card)
you need to write
   hand.popCard(hand, card)

Some more comments below in  your code.

> Here is my Program so far
> 
> I will also include a .py file of it incase this doesnt look legible
> 
>  
> 
> from random import*
> 
>  
> 
> 
> def DisplayTitle():
> print
> print "Welcome to Tech-Sauve Cribbage"
> print ""
> print "   Insctructions"
> print ""
> print "1) Only played with two players (for now)   "
> print "2) The program starts with a full deck of 52 cards"
> print "3) Deals out 6 cards to each player with a Suit letter"
> print "4) Then asks each player what 2 cards they want to discard to the 
> crib"
> print "5) Then the program saves the crib in a temporary deck"
> print "6) Players start showing cards to get an ammount equal to 31"
> print "7) Once all the cards have been played, program counts the score"
> print "8) Then the program will count all possible scores in each hand"
> print "   And it will add the players points to their total score"
> print "9) First player to reach a score of 121 wins the game"

This is a single string to write. Use multiline strings inside triple quotes 
"""...""" and write in a single instruction. No need for a func.

> #Gets players names
> def GetPlayer1():
> print
> Player1 = str(raw_input("Player 1's name "))
> return Player1
> def GetPlayer2():
> print
> Player2 = str(raw_input("Player 2's name "))
> return Player2

This is twice the same func. Write a single one with a parameter representing a 
player, then call it twice. You'd better use a dict for each player because 
doubt the only relevant info is their name. Why not attach their hand, score, 
or whatever to the structures representing players?
player1 = {name:None, more:foo}
player2 = {name:None, more:foo}
def getPlayerName(player):
   # (raw_input already returns a string)
   player["name"] = raw_input("Player 1's name ")
getPlayerName(player1)
getPlayerName(player2)

> #Building the deck
> def Build_Deck():
> for R in range (0,52):
> cardnumb = numbers[R]
> cardsuit = suits[R]
> card = str(numbers[R])+str(suits[R])
> Deck.append(card)
> return Deck,numbers,suits,card,cardnumb,cardsuit

This func should only return Deck. Card cardnum, cardsuit are local variables 
used obly in the func, suits and numbers are input instead:

def Build_Deck(suits, number, card_count):
# 52 is also a predefined constant, namely here called card_count
for R in range (0,card_count):
cardnumb = numbers[R]
cardsuit = suits[R]
card = str(numbers[R])+str(suits[R])
Deck.append(card)
return Deck
... define constants about card: card_count, suits and numbers ...
Deck = Build_Deck(suits, number)

You'd better represent each card with a pair {"suit":suit, "number":number} so 
as to be able to compare their strength (unless this is irrelevant for this 
game).

> #Variables Needed
> numbers = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"]*4
> suits = ["H","C","S","D"]*13
> suits.sort()
> Deck = []
> P1hand = []
> P2hand = []
> Crib = []
> Cribcard = []
> Cribsuit = []
> P1_score = 0
> P2_score = 0
> Winner = 121
> ele = 52

All non-null things above are constants that define 

Re: [Tutor] Question : Creating cribbage game

2009-12-07 Thread Tim Goddard
> Message: 2
> Date: Mon, 7 Dec 2009 02:30:30 -0400
> From: Christopher schueler 
> To: 
> Subject: [Tutor] Question : Creating cribbage game
> Message-ID: 
> Content-Type: text/plain; charset="iso-8859-1"
>
>
> My name is Chris Schueler and i am having some troubles with my Python 
> programming
>
>
>
> Our current project is to create the game of cribbage from scratch.
>
> The only problem is we are not allowed to use classes, only user-defind 
> functions and arrays. I was wondering if anybody could give me tips or 
> pointers on adding codes or modifying some of my program
>
>
>
> Here is my Program so far
>
> I will also include a .py file of it incase this doesnt look legible
>
>
>
> from random import*
>
>
>
>
> def DisplayTitle():
>    print
>    print "Welcome to Tech-Sauve Cribbage"
>    print ""
>    print "               Insctructions                "
>    print ""
>    print "1) Only played with two players (for now)   "
>    print "2) The program starts with a full deck of 52 cards"
>    print "3) Deals out 6 cards to each player with a Suit letter"
>    print "4) Then asks each player what 2 cards they want to discard to the 
> crib"
>    print "5) Then the program saves the crib in a temporary deck"
>    print "6) Players start showing cards to get an ammount equal to 31"
>    print "7) Once all the cards have been played, program counts the score"
>    print "8) Then the program will count all possible scores in each hand"
>    print "   And it will add the players points to their total score"
>    print "9) First player to reach a score of 121 wins the game"
> #Gets players names
> def GetPlayer1():
>    print
>    Player1 = str(raw_input("Player 1's name "))
>    return Player1
> def GetPlayer2():
>    print
>    Player2 = str(raw_input("Player 2's name "))
>    return Player2
> #Building the deck
> def Build_Deck():
>    for R in range (0,52):
>        cardnumb = numbers[R]
>        cardsuit = suits[R]
>        card = str(numbers[R])+str(suits[R])
>        Deck.append(card)
>    return Deck,numbers,suits,card,cardnumb,cardsuit
>
>
> #Variables Needed
> numbers = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"]*4
> suits = ["H","C","S","D"]*13
> suits.sort()
> Deck = []
> P1hand = []
> P2hand = []
> Crib = []
> Cribcard = []
> Cribsuit = []
> P1_score = 0
> P2_score = 0
> Winner = 121
> ele = 52
> Deck,numbers,suits,card,cardnumb,cardsuit = Build_Deck()
> for X in range(0,6):
>    Y = randint(0,ele)
>    draw = Deck[Y]
>    P1hand.append(draw)
>    Deck.pop(Y)
>    ele -= 1
> for X2 in range (0,6):
>    Y1 = randint(0,ele)
>    draw2 = Deck[Y1]
>    P2hand.append(draw2)
>    Deck.pop(Y1)
>    ele -= 1
> print
> Top = randint(0,47)
> Topcard = Deck[Top]
> print
> for count in range(0,2):
>    print P1hand
>    print
>    option = str(raw_input("Player 1,what CARD would you like to add to the 
> crib?  CARDS 1 thru 6 "))
>    if option == "1":
>        Crib.append(P1hand[0])
>        P1hand.pop(0)
>    elif option == "2":
>        Crib.append(P1hand[1])
>        P1hand.pop(1)
>    elif option == "3":
>        Crib.append(P1hand[2])
>        P1hand.pop(2)
>    elif option == "4":
>        Crib.append(P1hand[3])
>        P1hand.pop(3)
>    elif option == "5":
>        Crib.append(P1hand[4])
>        P1hand.pop(4)
>    elif option == "6":
>        Crib.append(P1hand[5])
>        P1hand.pop(5)
> print
> for c2 in range(0,2):
>    print P2hand
>    print
>    option1 = str(raw_input("Player 2, what CARD would you like to add to the 
> crib?  CARDS 1 thru 6 "))
>    if option1 == "1":
>        Crib.append(P2hand[0])
>        P2hand.pop(0)
>    elif option1 == "2":
>        Crib.append(P2hand[1])
>        P2hand.pop(1)
>    elif option1 == "3":
>        Crib.append(P2hand[2])
>        P2hand.pop(2)
>    elif option1 == "4":
>        Crib.append(P2hand[3])
>        P2hand.pop(3)
>    elif option1 == "5":
>        Crib.append(P2hand[4])
>        P2hand.pop(4)
>    elif option1 == "6":
>      

[Tutor] Question : Creating cribbage game

2009-12-07 Thread Christopher schueler

My name is Chris Schueler and i am having some troubles with my Python 
programming

 

Our current project is to create the game of cribbage from scratch.

The only problem is we are not allowed to use classes, only user-defind 
functions and arrays. I was wondering if anybody could give me tips or pointers 
on adding codes or modifying some of my program

 

Here is my Program so far

I will also include a .py file of it incase this doesnt look legible

 

from random import*

 


def DisplayTitle():
print
print "Welcome to Tech-Sauve Cribbage"
print ""
print "   Insctructions"
print ""
print "1) Only played with two players (for now)   "
print "2) The program starts with a full deck of 52 cards"
print "3) Deals out 6 cards to each player with a Suit letter"
print "4) Then asks each player what 2 cards they want to discard to the 
crib"
print "5) Then the program saves the crib in a temporary deck"
print "6) Players start showing cards to get an ammount equal to 31"
print "7) Once all the cards have been played, program counts the score"
print "8) Then the program will count all possible scores in each hand"
print "   And it will add the players points to their total score"
print "9) First player to reach a score of 121 wins the game"
#Gets players names
def GetPlayer1():
print
Player1 = str(raw_input("Player 1's name "))
return Player1
def GetPlayer2():
print
Player2 = str(raw_input("Player 2's name "))
return Player2
#Building the deck
def Build_Deck():
for R in range (0,52):
cardnumb = numbers[R]
cardsuit = suits[R]
card = str(numbers[R])+str(suits[R])
Deck.append(card)
return Deck,numbers,suits,card,cardnumb,cardsuit


#Variables Needed
numbers = ["A","2","3","4","5","6","7","8","9","10","J","Q","K"]*4
suits = ["H","C","S","D"]*13
suits.sort()
Deck = []
P1hand = []
P2hand = []
Crib = []
Cribcard = []
Cribsuit = []
P1_score = 0
P2_score = 0
Winner = 121
ele = 52
Deck,numbers,suits,card,cardnumb,cardsuit = Build_Deck()
for X in range(0,6):
Y = randint(0,ele)
draw = Deck[Y]
P1hand.append(draw)
Deck.pop(Y)
ele -= 1
for X2 in range (0,6):
Y1 = randint(0,ele)
draw2 = Deck[Y1]
P2hand.append(draw2)
Deck.pop(Y1)
ele -= 1
print
Top = randint(0,47)
Topcard = Deck[Top]
print
for count in range(0,2):
print P1hand
print
option = str(raw_input("Player 1,what CARD would you like to add to the 
crib?  CARDS 1 thru 6 "))
if option == "1":
Crib.append(P1hand[0])
P1hand.pop(0)
elif option == "2":
Crib.append(P1hand[1])
P1hand.pop(1)
elif option == "3":
Crib.append(P1hand[2])
P1hand.pop(2)
elif option == "4":
Crib.append(P1hand[3])
P1hand.pop(3)
elif option == "5":
Crib.append(P1hand[4])
P1hand.pop(4)
elif option == "6":
Crib.append(P1hand[5])
P1hand.pop(5)
print
for c2 in range(0,2):
print P2hand
print
option1 = str(raw_input("Player 2, what CARD would you like to add to the 
crib?  CARDS 1 thru 6 "))
if option1 == "1":
Crib.append(P2hand[0])
P2hand.pop(0)
elif option1 == "2":
Crib.append(P2hand[1])
P2hand.pop(1)
elif option1 == "3":
Crib.append(P2hand[2])
P2hand.pop(2)
elif option1 == "4":
Crib.append(P2hand[3])
P2hand.pop(3)
elif option1 == "5":
Crib.append(P2hand[4])
P2hand.pop(4)
elif option1 == "6":
Crib.append(P2hand[5])
P2hand.pop(5)

print Deck
print "The TOP CARD is ",Topcard
print "Player 1's Hand is ",P1hand
print "Player 2's Hand is ",P2hand
print "The 4 cards in the Crib are ",Crib
  
_
Ready. Set. Get a great deal on Windows 7. See fantastic deals on Windows 7 now
http://go.microsoft.com/?linkid=9691818from random import*

def DisplayTitle():
print
print "Welcome to Tech-Sauve Cribbage"
print ""
print "   Insctructions"
print ""
print "1) Only played with two players (for now)   "
print "2) The program starts with a full deck of 52 cards"
print "3) Deals out 6 cards to each player with a Suit letter"
print "4) Then asks each player what 2 cards they want to discard to the 
crib"
print "5) Then the program saves the crib in a temporary deck"
print "6) Players start showing cards to get an ammount equal to 31"
print "7) Once all the cards have been played, program counts the score"
print "8) Then the program will count all possible scores in each hand"
print "   And it will add the players points to the

Re: [Tutor] Question re: hangman.py

2009-11-13 Thread biboy mendz

thanks a lot for the clarification Alan and all.

--
Regards,
bibs M.

Host/Kernel/OS  "cc02695" running Linux 2.6.31-5.slh.4-sidux-686 
[sidux 2009-02 Αιθήρ - kde-full - (200907141427) ]

www.sidux.com



Alan Gauld wrote:


"biboy mendz"  wrote


chapter 8: hangman.py

expression is: print(letter, end=' ')

it explained:
end keyword argument in print() call makes the print() function put a 
space

character at the end of the string instead of a newline.

however when run it gives error: SyntaxError: invalid syntax.

What gives? This is the first time i saw such expression inside print
function. Is this version-specific of python? I'm running version 2.5.4.


Your tutorial is using version 3.
In 2.6 simply put a comma after the string:

print letter,

to do the same thing.

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


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


Re: [Tutor] Question re: hangman.py

2009-11-13 Thread Alan Gauld


"Hugo Arts"  wrote 


print letter, ' ',



You don't need the space, Python automatically inserts 
a space instead of the newline when you use the comma.



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

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


Re: [Tutor] Question re: hangman.py

2009-11-13 Thread Alan Gauld


"biboy mendz"  wrote


chapter 8: hangman.py

expression is: print(letter, end=' ')

it explained:
end keyword argument in print() call makes the print() function put a 
space

character at the end of the string instead of a newline.

however when run it gives error: SyntaxError: invalid syntax.

What gives? This is the first time i saw such expression inside print
function. Is this version-specific of python? I'm running version 2.5.4.


Your tutorial is using version 3.
In 2.6 simply put a comma after the string:

print letter,

to do the same thing. 



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


Re: [Tutor] Question re: hangman.py

2009-11-13 Thread Hugo Arts
On Fri, Nov 13, 2009 at 2:17 PM, biboy mendz  wrote:
> http://inventwithpython.com
>
> chapter 8: hangman.py
>
> expression is: print(letter, end=' ')
>
> it explained:
> end keyword argument in print() call makes the print() function put a space
> character at the end of the string instead of a newline.
>
> however when run it gives error: SyntaxError: invalid syntax.
>
> What gives? This is the first time i saw such expression inside print
> function. Is this version-specific of python? I'm running version 2.5.4.
>

Yes, the print function is a new feature of python 3. The equivalent
statement in python 2.5 is probably something like this:

print letter, ' ',

The print function is a statement in python before 3.0. It takes a
comma-separated list of things to print. The trailing comma prevents
python from appending a newline.

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


[Tutor] Question re: hangman.py

2009-11-13 Thread biboy mendz

http://inventwithpython.com

chapter 8: hangman.py

expression is: print(letter, end=' ')

it explained:
end keyword argument in print() call makes the print() function put a space
character at the end of the string instead of a newline.

however when run it gives error: SyntaxError: invalid syntax.

What gives? This is the first time i saw such expression inside print
function. Is this version-specific of python? I'm running version 2.5.4.

--
Regards,
bibs M.

Host/Kernel/OS  "cc02695" running Linux 2.6.31-5.slh.4-sidux-686 
[sidux 2009-02 Αιθήρ - kde-full - (200907141427) ]

www.sidux.com

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


Re: [Tutor] Question about time.gmtime

2009-11-02 Thread Eduardo Vieira
On Tue, Sep 29, 2009 at 8:11 AM, Eduardo Vieira  wrote:
> Hello, I had a problem with a script yesterday that made me puzzled.
> My time zone is US Mountain Time. This script was running nice last
> week, but yesterday it reported the date of today instead
> So, yesterday at 5:20pm this line:
> hoje = time.strftime("%a, %b %d, %Y", time.gmtime())
>
> Gave me this: "Tue, Sep 29, 2009" instead of "Mon, Sep 28, 2009"
> What's going on?
> Minutes ago, while I was investigating this I had this output:
>
 time.gmtime()
> time.struct_time(tm_year=2009, tm_mon=9, tm_mday=29, tm_hour=14,
> tm_min=48, tm_sec=49, tm_wday=1, tm_yday=272, tm_isdst=0)
 time.localtime()
> time.struct_time(tm_year=2009, tm_mon=9, tm_mday=29, tm_hour=8,
> tm_min=50, tm_sec=28, tm_wday=1, tm_yday=272, tm_isdst=1)
>
> I see there are 6 hours difference, but I'm sure the script ran before 6pm
> Should I simply modify my code to use localtime, instead? Why did it
> happen only yesterday?
>
> I'm using Windows XP Professional, and my clock says it's Tuesday,
> Sept. 29, 2009 and 9:10 AM
>
> Regards,
>
> Eduardo
>

Some time ago I experienced that. And today again. I wonder if it's
not related to the fact that I did some system restore operations
today?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question about time.gmtime

2009-09-29 Thread Eduardo Vieira
Hello, I had a problem with a script yesterday that made me puzzled.
My time zone is US Mountain Time. This script was running nice last
week, but yesterday it reported the date of today instead
So, yesterday at 5:20pm this line:
hoje = time.strftime("%a, %b %d, %Y", time.gmtime())

Gave me this: "Tue, Sep 29, 2009" instead of "Mon, Sep 28, 2009"
What's going on?
Minutes ago, while I was investigating this I had this output:

>>> time.gmtime()
time.struct_time(tm_year=2009, tm_mon=9, tm_mday=29, tm_hour=14,
tm_min=48, tm_sec=49, tm_wday=1, tm_yday=272, tm_isdst=0)
>>> time.localtime()
time.struct_time(tm_year=2009, tm_mon=9, tm_mday=29, tm_hour=8,
tm_min=50, tm_sec=28, tm_wday=1, tm_yday=272, tm_isdst=1)

I see there are 6 hours difference, but I'm sure the script ran before 6pm
Should I simply modify my code to use localtime, instead? Why did it
happen only yesterday?

I'm using Windows XP Professional, and my clock says it's Tuesday,
Sept. 29, 2009 and 9:10 AM

Regards,

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


Re: [Tutor] Question if my reasoning is right

2009-08-19 Thread Kent Johnson
On Wed, Aug 19, 2009 at 1:52 AM, Darth Kaboda wrote:
> I'm questioning my reason for why the follwoing code doesn't behave as I
> thought it would upon first coding a project.
>
> m = 8
> n = 10
> cb = [[[0, None]] * (n + 1)] * (m + 1)
> cb[3][2][0] = 10
>
> This last statement causes the every first element in the list to update. Is
> this becuase this method of initializing a list is just a copy of the same
> list in memory?

Not literally a copy, but pointing to the same list. The correct term
is that each element of the list is a reference, or alias, to the same
list.

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


Re: [Tutor] Question if my reasoning is right

2009-08-19 Thread Alan Gauld


"Darth Kaboda"  wrote


cb = [[[0, None]] * (n + 1)] * (m + 1)
cb[3][2][0] = 10

This last statement causes the every first element in the list to update.
Is this becuase this method of initializing a list is just a copy


Yes exactly.



To get around this I'm now doing the folowing:
cb = [[[0,None] for x in range(n+1)] for y in range(m+1)]


Yes, that's what list comprehensions are for, to create lists.


Is this an acceptable practice?


Absolutely. It is one of the most common uses for comprehensions.


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



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


[Tutor] Question if my reasoning is right

2009-08-18 Thread Darth Kaboda

I'm questioning my reason for why the follwoing code doesn't behave as I 
thought it would upon first coding a project.

 

m = 8
n = 10
cb = [[[0, None]] * (n + 1)] * (m + 1)
cb[3][2][0] = 10

 

This last statement causes the every first element in the list to update. Is 
this becuase this method of initializing a list is just a copy of the same list 
in memory?

 

To get around this I'm now doing the folowing:

 

m = 8
n = 10
cb = [[[0,None] for x in range(n+1)] for y in range(m+1)]
cb[3][2][0] = 10


This is working by updating only the one list as I want it to. Is this an 
acceptable practice? Or should I use the standard nested for loops like you'd 
do in most other languages?

 

Any insight would be greatly appreciated.

 

Thanks,

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


Re: [Tutor] Question about the FONT in Tkinter

2009-08-03 Thread Kent Johnson
On Sat, Aug 1, 2009 at 12:12 PM, Mohannad
Mohammad wrote:

> Kindly refer to the attached photo.
> There are two sentences appearing when the user checked two checkbutton, I
> make it as a practice.
> ok
> I want to change the font of these two sentences. how?

>     self.box = Text(self, width = 400, height = 10, wrap = WORD)

Add a font= parameter, for example
self.box = Text(self, width = 400, height = 10, wrap = WORD,
font=("Helvetica", 10, "bold italic")

http://www.pythonware.com/library/tkinter/introduction/x444-fonts.htm

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


[Tutor] Question about the FONT in Tkinter

2009-08-01 Thread Mohannad Mohammad


Hello all,

Kindly refer to the attached photo.
There are two sentences appearing when the user checked two checkbutton, I make 
it as a practice.
ok
I want to change the font of these two sentences. how?


This is the code I use to make this simple application:

from Tkinter import *

class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
self.font = ("tahoma", 10)

def create_widgets(self):
self.lbl1 = Label(self, text = "Choose your favorite movie types")
self.lbl1.grid(row = 0, column = 0, columnspan = 2, sticky = W)

self.lbl2 = Label(self, text = "Select all that apply:")
self.lbl2.grid(row = 1, column = 0, columnspan = 2, sticky = W)

self.likes_drama = BooleanVar()
Checkbutton(self, text = "Drama", variable = self.likes_drama, command 
= self.update_text).grid(row = 2, column = 0, sticky = W)

self.likes_comedy = BooleanVar()
Checkbutton(self, text = "Comedy", variable = self.likes_comedy, 
command = self.update_text).grid(row = 3, column = 0, sticky = W)

self.likes_sport = BooleanVar()
Checkbutton(self, text = "Sport", variable = self.likes_sport, command 
= self.update_text).grid(row = 4, column = 0, sticky = W)

self.box = Text(self, width = 400, height = 10, wrap = WORD)
self.box.grid(row = 5, column = 0, columnspan = 2, sticky = W)

def update_text(self):
likes = ""

if self.likes_drama.get():
likes += "You like Drama movies\n"
if self.likes_comedy.get():
likes += "You like Comedy movies\n"
if self.likes_sport.get():
likes += "You like Sport movies\n"

self.box.delete(0.0, END)
self.box.insert(0.0, likes)

win = Tk()
win.title("Choose any one..")
win.geometry("400x300")
app = Application(win)
win.mainloop()



_
Celebrate a decade of Messenger with free winks, emoticons, display pics, and 
more.
http://clk.atdmt.com/UKM/go/157562755/direct/01/<>___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question from a newbie (thank you)

2009-07-23 Thread fiberfolly
 
 
 
WoW!  You all have given me lots to look at, think about, and play with. 
Thank you one and all for your answers!
 
 <><><>___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question from a newbie

2009-07-22 Thread John
On Tuesday 21 July 2009 11:12:23 am Deb wrote:
> My son suggested I play around with Python.  I was wondering if anybody has
> any real life applications?  It appears to be able to do quite a lot, but
> is anybody really doing it with Python?  I am very curious about this
> language. I used to be a Clipper programmer in another life (dBASE
> compiler), and got sick when I was just entering the OOP world via Visual
> Basic and had to quit I just recently got my brain back, thanks to medical
> science, and would like to learn all I can about what it out there these
> days.
>
> Thanks,

Then you'll love Dabo (www.dabodev.com) which is built on python, wxPython, 
and supports databases like Postgres, MsSQL, MySQL, Firebird, and SQLite.  
The thinking is very similar to Visual FoxPro.  Classes are close and the 
coding is close.  If you ever used any of the VFP (clipper) frameworks then 
it will be old hat.


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


Re: [Tutor] Question from a newbie

2009-07-22 Thread Glen Zangirolami
Deb,
For starters most of the Google enterprise runs on python.
Google App Engin e is for developers to
develop web applications on Google

There are many applications ranging from web frameworks to math modules.
Web frameworks: Django , Repoze
BFG,
Pylons , Turbo Gears ,
CherryPy 
NumPy  for math/physics.
Plone  is a content management system used by many
schools and governments.

Python website has lots of information to learn python.
Documents,
Python Enhancement Proposals ,
Communityand the Python
Package Index .

It is a beautiful language! Good Luck :)


On Tue, Jul 21, 2009 at 1:12 PM, Deb  wrote:

> My son suggested I play around with Python.  I was wondering if
> anybody has any real life applications?  It appears to be able to do quite a
> lot, but is anybody really doing it with Python?  I am very curious about
> this language.  I used to be a Clipper programmer in another life (dBASE
> compiler), and got sick when I was just entering the OOP world via Visual
> Basic and had to quit.  I just recently got my brain back, thanks to medical
> science, and would like to learn all I can about what it out there these
> days.
>
>  Thanks,
>
>
> ___
> 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] Question from a newbie

2009-07-21 Thread Alan Gauld
"Deb"  wrote 
My son suggested I play around with Python.  


Hi, welcome to the tutor list.

I was wondering if anybody has any real life applications?  


There are several folks on the list who make a liiving writing Python.
Others, like myself, use it in their day job but its not the main or end 
product (I use it for prototyping ideas that our Indian developers 
eventually turn into Java)


Some organisations - Google is the best known - use Python 
for writing their test harnesses and admin tools etc. Several 
Linux  distruibutions have used Python to create their admin 
tools for adding users etc. HP did the same on Windows for 
a while.


Blender is a well kinown open source graphics tool that uses 
embedded Python as its macro language, as do a few others.


Check out the Python web site for more success stories to see 
how widespread it is. Look at the links top right on the home page...


And of course it is also a great scripting language to replace 
DOS batch files, Unix shell scripts and awk/sed/perl/Tcl etc etc


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

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


Re: [Tutor] Question from a newbie

2009-07-21 Thread Kent Johnson
On Tue, Jul 21, 2009 at 2:12 PM, Deb wrote:
> My son suggested I play around with Python.  I was wondering if anybody has
> any real life applications?  It appears to be able to do quite a lot, but is
> anybody really doing it with Python?

Yes, Python is used in a wide variety of real-life applications. For
some examples, see
http://python.org/about/success/

Is there a particular application area you are interested in?

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


[Tutor] Question from a newbie

2009-07-21 Thread Deb
My son suggested I play around with Python.  I was wondering if anybody has
any real life applications?  It appears to be able to do quite a lot, but is
anybody really doing it with Python?  I am very curious about this language.
 I used to be a Clipper programmer in another life (dBASE compiler), and got
sick when I was just entering the OOP world via Visual Basic and had to quit
  I just recently got my brain back, thanks to medical science, and would
like to learn all I can about what it out there these days.
 
Thanks,

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


Re: [Tutor] question about class

2009-06-10 Thread Lie Ryan
Vincent Davis wrote:
> Thanks again for the help, A little followup.
> For my applicant class I have a few initial values that need to be set
> but I what to choose the value (actually the calculation to set the
> value) for each applicant (instance?)
> Here is the start of my Applicant Class
> 
> class Applicant(object):
>   "quality is refers to the quality of the Applicant
>   observe refers to the accuracy of which they assess the
> quality of the school"
>   def __init__(self, quality = 0, observe = 0):
>   self. quality = quality
>   self. observe = observe
>   def Quality(self, mean, sd):
>   print self,
>   self.quality = normalvariate(mean, sd)
>   print "--> %s" % self
>  def Observe(self, mean, sd):
>   print self,
>   self. observe = normalvariate(mean, sd)
>   print "--> %s" % self

The problem with that approach is that repeated calls to Quality and
Observe would change the value of self.quality and self.observe and it
will be therefore unnecessary (and dangerous) to call
self.Quality/Observe again in the future

Usually I'd go with something like this:

class Applicant(object):
def __init__(self, quality, observe):
self.quality = quality
self.observe = observe
def norm_quality(self, mean, sd):
return normalvariate(mean, sd, self.quality)
def norm_observe(self, mean, sd):
return normalvariate(mean, sd, self.observe)

Additionally-- although it is a matter of style --instead of passing
mean and sd to norm_quality, I'd use functools.partial with
normalvariate, mean, and sd. Then since they now don't take parameters
they can then be easily turned into property using decorator.

> Or I could I guess do it this way, Is this better? I will only be
> setting the quality and observe values once for each instance.
> 
> class Applicant(object):
>   "quality is refers to the quality of the Applicant
>  observe refers to the accuracy of which they assess the
> quality of the school"
>   def __init__(self, mquality = 0, sdquality = 0, mobserve = 0,
> sdobserve = 0):
>   self. quality = normalvariate(mquality, sdquality)
>   self. observe = normalvariate(mobserve, sdobserve)

That approach is fine as well, however it wouldn't be much different
than using a tuple.

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


Re: [Tutor] question about class

2009-06-09 Thread Alan Gauld


"Vincent Davis"  wrote 


Here is the start of my Applicant Class


class Applicant(object):
 "quality is refers to the quality of the Applicant
 observe refers to the accuracy of which they assess the
quality of the school"

I guess you intended those to be triple quotes?

 def __init__(self, quality = 0, observe = 0):
 self. quality = quality
 self. observe = observe
 def Quality(self, mean, sd):
 print self,
 self.quality = normalvariate(mean, sd)
 print "--> %s" % self

Its normal to use lowercase letters to start a method name. 
ot needed but convention. But of course you'd need to change 
the name to avoid conflicts with the attribute.


Do you really want to priont self? That will say something 
like ""


You could however provide a __str__ method that will print out 
what you do want to see.


  def Observe(self, mean, sd):
 print self,
 self. observe = normalvariate(mean, sd)
 print "--> %s" % self


Or I could I guess do it this way, Is this better? I will only be
setting the quality and observe values once for each instance.


This is a class with only an __init__ method, that's usually a 
suspicious sign. What does the class do?


BTW its also unusual to have verbs as attributes. (Unless 
they are boolean flags and even then its better to make it 
a question eg. doesObserve. Should your self.observe be

self.observation say?


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

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


Re: [Tutor] question about class

2009-06-09 Thread Vincent Davis
Thanks again for the help, A little followup.
For my applicant class I have a few initial values that need to be set
but I what to choose the value (actually the calculation to set the
value) for each applicant (instance?)
Here is the start of my Applicant Class

class Applicant(object):
  "quality is refers to the quality of the Applicant
  observe refers to the accuracy of which they assess the
quality of the school"
  def __init__(self, quality = 0, observe = 0):
  self. quality = quality
  self. observe = observe
  def Quality(self, mean, sd):
  print self,
  self.quality = normalvariate(mean, sd)
  print "--> %s" % self
 def Observe(self, mean, sd):
  print self,
  self. observe = normalvariate(mean, sd)
  print "--> %s" % self

Or I could I guess do it this way, Is this better? I will only be
setting the quality and observe values once for each instance.

class Applicant(object):
  "quality is refers to the quality of the Applicant
 observe refers to the accuracy of which they assess the
quality of the school"
  def __init__(self, mquality = 0, sdquality = 0, mobserve = 0,
sdobserve = 0):
  self. quality = normalvariate(mquality, sdquality)
  self. observe = normalvariate(mobserve, sdobserve)


Thanks
Vincent Davis
720-301-3003




On Tue, Jun 9, 2009 at 7:02 AM, Vincent Davis wrote:
> Thanks for the help and comments, I think my questions have been
> answered, I will know if I understand when I try to implement them.
> The Match algorithm. algorithm is described in the link below. The
> Applicant and School rankings will be (Attributes ?) of the Applicant
> and School class, and I simulate this ranking process by considering
> Applicants and Schools attributes, but basically similar qualities get
> mutually ranked. (I go go on if someone is interested but I thought it
> best to keep the discution on what I am trying to learn about classes)
>
> http://www.nrmp.org/res_match/about_res/algorithms.html
>
> Thanks Again
> Vincent Davis
>
>
>
>
> On Tue, Jun 9, 2009 at 1:12 AM, spir wrote:
>> Le Mon, 8 Jun 2009 17:31:23 -0600,
>> Vincent Davis  s'exprima ainsi:
>>
>>> Accidentally sent I have added the rest
>>> (by the way I refrain from using the terms attribute, method, as I
>>> will likely miss use them)
>>>
>>> > I am reading several tutorials about classes and trying to figure out
>>> > how to apply it to my project. I have a working program that basically
>>> > matches up applicants and schools. Schools and applicants have and
>>> > "true" quality and an "observed" quality. Then there is an algorithm
>>> > that matches them up. Right now I do this all with lists which works
>>> > ok but I would like to try using classes.
>>
>>> > Questions
>>> > 1, does it make seens to have a applicant and a schools class (based
>>> > on this brief explanation)
>>
>> Based on your explanations, I don't really understand the problem you're 
>> trying to solve, nore the algorithm. Still, probably it makes sense to use 
>> Applicant and School classes for the simple reason these notions in your 
>> program represent "objects": there are single, identified, things ; as 
>> opposed to "values" (in the ordinary sense of the term) that represent 
>> qualities or information such as color, position, number, or "true" and 
>> "observed" above.
>> (By the way, don't use 'true', it's too misleading. Maybe 'truth' instead.)
>>
>> This notion of object identity would allow you, for instance, to match an 
>> applicant to a school by letting the applicant's attribute 'matched_school' 
>> directly point to a school itself, instead of a number that indirectly 
>> represents the school.
>>
>> Also, you've got a collection of schools and applicants, which probably 
>> means they will be stored in a set or a list. Once you have a type for them, 
>> it's easier to safely manipulate them in a unified manner. Even if they have 
>> only one single data attribute, I would do it: this also brings a 
>> centralised place to expose the object type's structure and behaviour.
>>
>>> > 2, is it possible to have a class for the algorithm that will modify
>>> > values in the applicant and schools class
>>> for example applicant.matched = 4 and school.matched = 343 meaning
>>> applicant 343 is matched to school 4
>>
>> No, if I understand what you mean. You won't have a separate "class" only to 
>> store actions (python is not java), but instead you should precisely 
>> attribute these as methods to the Applicant or School types.
>>
>>> 3, is I have a value set in a class applicant.foo = 5 and I what to
>>> use a (method?) in the class to change this, what is the right way to
>>> do this?
>>
>> Below an example:
>>
>> 
>> class Point(object):
>>        def __init__(self, x=0,y=0):
>>                self.x = x
>>                self.y = y
>>        def move(self, dx,dy

Re: [Tutor] question about class

2009-06-09 Thread Vincent Davis
Thanks for the help and comments, I think my questions have been
answered, I will know if I understand when I try to implement them.
The Match algorithm. algorithm is described in the link below. The
Applicant and School rankings will be (Attributes ?) of the Applicant
and School class, and I simulate this ranking process by considering
Applicants and Schools attributes, but basically similar qualities get
mutually ranked. (I go go on if someone is interested but I thought it
best to keep the discution on what I am trying to learn about classes)

http://www.nrmp.org/res_match/about_res/algorithms.html

Thanks Again
Vincent Davis




On Tue, Jun 9, 2009 at 1:12 AM, spir wrote:
> Le Mon, 8 Jun 2009 17:31:23 -0600,
> Vincent Davis  s'exprima ainsi:
>
>> Accidentally sent I have added the rest
>> (by the way I refrain from using the terms attribute, method, as I
>> will likely miss use them)
>>
>> > I am reading several tutorials about classes and trying to figure out
>> > how to apply it to my project. I have a working program that basically
>> > matches up applicants and schools. Schools and applicants have and
>> > "true" quality and an "observed" quality. Then there is an algorithm
>> > that matches them up. Right now I do this all with lists which works
>> > ok but I would like to try using classes.
>
>> > Questions
>> > 1, does it make seens to have a applicant and a schools class (based
>> > on this brief explanation)
>
> Based on your explanations, I don't really understand the problem you're 
> trying to solve, nore the algorithm. Still, probably it makes sense to use 
> Applicant and School classes for the simple reason these notions in your 
> program represent "objects": there are single, identified, things ; as 
> opposed to "values" (in the ordinary sense of the term) that represent 
> qualities or information such as color, position, number, or "true" and 
> "observed" above.
> (By the way, don't use 'true', it's too misleading. Maybe 'truth' instead.)
>
> This notion of object identity would allow you, for instance, to match an 
> applicant to a school by letting the applicant's attribute 'matched_school' 
> directly point to a school itself, instead of a number that indirectly 
> represents the school.
>
> Also, you've got a collection of schools and applicants, which probably means 
> they will be stored in a set or a list. Once you have a type for them, it's 
> easier to safely manipulate them in a unified manner. Even if they have only 
> one single data attribute, I would do it: this also brings a centralised 
> place to expose the object type's structure and behaviour.
>
>> > 2, is it possible to have a class for the algorithm that will modify
>> > values in the applicant and schools class
>> for example applicant.matched = 4 and school.matched = 343 meaning
>> applicant 343 is matched to school 4
>
> No, if I understand what you mean. You won't have a separate "class" only to 
> store actions (python is not java), but instead you should precisely 
> attribute these as methods to the Applicant or School types.
>
>> 3, is I have a value set in a class applicant.foo = 5 and I what to
>> use a (method?) in the class to change this, what is the right way to
>> do this?
>
> Below an example:
>
> 
> class Point(object):
>        def __init__(self, x=0,y=0):
>                self.x = x
>                self.y = y
>        def move(self, dx,dy):
>                print self,
>                self.x += dx
>                self.y += dy
>                print "--> %s" % self
>        def __str__(self):
>                return "Point (%s,%s)" % (self.x,self.y)
>
> p0 = Point() ; print p0
> p = Point(9,8) ; print p
> p.move(-11,11)
> 
> ==>
> 
> Point (0,0)
> Point (9,8)
> Point (9,8) --> Point (-2,19)
> 
>
> Denis
> --
> la vita e estrany
> ___
> Tutor maillist  -  tu...@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about class

2009-06-09 Thread Alan Gauld

"Vincent Davis"  wrote


I am reading several tutorials about classes and trying to figure out
how to apply it to my project. I have a working program that basically
matches up applicants and schools. Schools and applicants have and
"true" quality and an "observed" quality. Then there is an algorithm
that matches them up. Right now I do this all with lists which works
ok but I would like to try using classes.


OK, The algorithm, is one of the key things that will likely change
in your program. When converting procedural code to use objects
it is often the case that algorithms (ie functions) get split up to put
part of the code in one object and part in another.

Thus in your case (depending on the actual algorithm,) you may
move some testing code into the school object (to determine if the
school wants the pupil!) and/or some into the applicant object (to
determine if the pupil wants the school). Finally you might retain
an application level function that simply iterates over each pupil
finding them a school by asking each school if they will accept the
pupil. Or you might iterate over the schools finding out if the pupil
wants that school (which way is most appropriate depends on
the app!).  The point is each object only knows about part of
the solution. The ownershp of the matching process probably
stays outside - maybe in another object - who/what wants to
do the matching for example?


Questions
1, does it make seens to have a applicant and a schools class (based
on this brief explanation)


Yes, almost certainly


2, is it possible to have a class for the algorithm that will modify
values in the applicant and schools class

for example applicant.matched = 4 and school.matched = 343 meaning
applicant 343 is matched to school 4


Its very bad practice to have an algorithm outside a class modifying 
attributes

classes/objects should "do it to themselves". In some languages its
common to implement a bunch of get/set methods to acces attributes and
people think this meets the "DIY" principle but it doesn't really. The 
point

is the attributes should be supporting a higher level operation and that
operation is what should change the data. Some get/set methods may
be appropriate if they are truly what the class is for, but they should be
the minority. (And in Python we generally just use direct access to
attributes rather than writing one-liner get/set methods!)

So in your case you may determine that pupil A should go to school B.
You probably want to have an enrolPupil method of school or a joinSchool
method of applicant (again depends on the perspective of the application)
That method will be responsible for adding the pupil to the list of 
enrolled

pupils and/or assigning the schoool to the pupil.


3, is I have a value set in a class applicant.foo = 5 and I what to
use a (method?) in the class to change this, what is the right way to
do this?


As mentioned above you could write a get/set method, but in Python
we usually just use direct access. But in general it's best to call a 
higher

level method of the class and let it make the change!

Remember to ask yourself what is this class's responsibilities, what
do I want it to do for me? Think about behaviours first, data second.

HTH,

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



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


Re: [Tutor] question about class

2009-06-09 Thread A.T.Hofkamp

Vincent Davis wrote:

Accidentally sent I have added the rest
(by the way I refrain from using the terms attribute, method, as I
will likely miss use them)


I am reading several tutorials about classes and trying to figure out
how to apply it to my project. I have a working program that basically
matches up applicants and schools. Schools and applicants have and
"true" quality and an "observed" quality. Then there is an algorithm
that matches them up. Right now I do this all with lists which works
ok but I would like to try using classes.


sounds like a good plan.


Questions
1, does it make seens to have a applicant and a schools class (based
on this brief explanation)


Most likely, yes.


2, is it possible to have a class for the algorithm that will modify
values in the applicant and schools class

for example applicant.matched = 4 and school.matched = 343 meaning
applicant 343 is matched to school 4


I don't understand the example, but that may not matter.

Yes it is possible to make an object of your algorithm.
However, if you have exactly one such algorithm, there is little point imho to 
wrap it into a class.


You may also want to wrap the result in an object.
(but your approach of modifying the applicant or school objects is fine too!)



3, is I have a value set in a class applicant.foo = 5 and I what to
use a (method?) in the class to change this, what is the right way to
do this?


If you want to make a setter, below is an example.

class X(object):
  """
  Example class with a value.

  @ivar v: Value of the object.
  """
  def __init__(self, v):
self.v = v

  def set_v(self, new_v):
self.v = new_v

my_x = X(5)
my_x.set_v(4)

is the way to use a method for setting a value.

However, Python discourages the use of such methods, since you are mostly 
adding boiler plate code without gaining anything.



So instead, I'd suggest to forget about getters and setters, drop the 
X.set_v() method, and do


my_x = X(5)
my_x.v = 4

which is cleaner and equally precise in your intention.


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


Re: [Tutor] question about class

2009-06-09 Thread spir
Le Mon, 8 Jun 2009 17:31:23 -0600,
Vincent Davis  s'exprima ainsi:

> Accidentally sent I have added the rest
> (by the way I refrain from using the terms attribute, method, as I
> will likely miss use them)
> 
> > I am reading several tutorials about classes and trying to figure out
> > how to apply it to my project. I have a working program that basically
> > matches up applicants and schools. Schools and applicants have and
> > "true" quality and an "observed" quality. Then there is an algorithm
> > that matches them up. Right now I do this all with lists which works
> > ok but I would like to try using classes.

> > Questions
> > 1, does it make seens to have a applicant and a schools class (based
> > on this brief explanation)

Based on your explanations, I don't really understand the problem you're trying 
to solve, nore the algorithm. Still, probably it makes sense to use Applicant 
and School classes for the simple reason these notions in your program 
represent "objects": there are single, identified, things ; as opposed to 
"values" (in the ordinary sense of the term) that represent qualities or 
information such as color, position, number, or "true" and "observed" above.
(By the way, don't use 'true', it's too misleading. Maybe 'truth' instead.)

This notion of object identity would allow you, for instance, to match an 
applicant to a school by letting the applicant's attribute 'matched_school' 
directly point to a school itself, instead of a number that indirectly 
represents the school.

Also, you've got a collection of schools and applicants, which probably means 
they will be stored in a set or a list. Once you have a type for them, it's 
easier to safely manipulate them in a unified manner. Even if they have only 
one single data attribute, I would do it: this also brings a centralised place 
to expose the object type's structure and behaviour.

> > 2, is it possible to have a class for the algorithm that will modify
> > values in the applicant and schools class
> for example applicant.matched = 4 and school.matched = 343 meaning
> applicant 343 is matched to school 4

No, if I understand what you mean. You won't have a separate "class" only to 
store actions (python is not java), but instead you should precisely attribute 
these as methods to the Applicant or School types.

> 3, is I have a value set in a class applicant.foo = 5 and I what to
> use a (method?) in the class to change this, what is the right way to
> do this?

Below an example:


class Point(object):
def __init__(self, x=0,y=0):
self.x = x
self.y = y
def move(self, dx,dy):
print self,
self.x += dx
self.y += dy
print "--> %s" % self
def __str__(self):
return "Point (%s,%s)" % (self.x,self.y)

p0 = Point() ; print p0
p = Point(9,8) ; print p
p.move(-11,11)

==>

Point (0,0)
Point (9,8)
Point (9,8) --> Point (-2,19)


Denis
--
la vita e estrany
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about class

2009-06-08 Thread Vincent Davis
Accidentally sent I have added the rest
(by the way I refrain from using the terms attribute, method, as I
will likely miss use them)

> I am reading several tutorials about classes and trying to figure out
> how to apply it to my project. I have a working program that basically
> matches up applicants and schools. Schools and applicants have and
> "true" quality and an "observed" quality. Then there is an algorithm
> that matches them up. Right now I do this all with lists which works
> ok but I would like to try using classes.
>
> Questions
> 1, does it make seens to have a applicant and a schools class (based
> on this brief explanation)
> 2, is it possible to have a class for the algorithm that will modify
> values in the applicant and schools class
for example applicant.matched = 4 and school.matched = 343 meaning
applicant 343 is matched to school 4

3, is I have a value set in a class applicant.foo = 5 and I what to
use a (method?) in the class to change this, what is the right way to
do this?

Ok that's all for now
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question about class

2009-06-08 Thread Vincent Davis
I am reading several tutorials about classes and trying to figure out
how to apply it to my project. I have a working program that basically
matches up applicants and schools. Schools and applicants have and
"true" quality and an "observed" quality. Then there is an algorithm
that matches them up. Right now I do this all with lists which works
ok but I would like to try using classes.

Questions
1, does it make seens to have a applicant and a schools class (based
on this brief explanation)
2, is it possible to have a class for the algorithim that will modify
values in the applicant and schools class

Thanks
Vincent Davis
720-301-3003
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about Python.

2009-03-25 Thread Alan Gauld


"T"  wrote


I'm working on Paper, Rock, Scissors in Python.
I need to make it a loop, and test the values 
(1, 2, 3, /Rock/Paper/Scissors) yet, but i'm kind 
of stuck. Could you help me?


What exactly puzzles you? You know you need 
a loop so you presumably realize that you need 
to repeat some part of your program.


What bit needs to be repeated? 
Is it the bit that you ask the platyer to choose a value? 
Or where the computer calculates a value? 
Or where you work out the result? Or all of these?


And how many times, or until what condition, should it repeat?
How will you detect that value?

If you answer those questions you might start to see 
what needs to be done?


There are a few commens on the code below:

def main():  #First function.
   print 'Lets play Paper Rock Scissors!\n'
   print '1 For Rock\n2 For Paper\n3 For Scissors\n4 To Quit'
   number=raw_input ('What do you choose? ') #Gets users input.

number sems a bit vague, this is actually the players choice.
So call it PlayersChoice or some such descriptive name.
Even just pc maybe - see below...

   pc = ComputerChoice()

And pc seems an odd name to choose for ComputersChoice()
Why not cc?

   PlayerChoice(number, pc)

And this function doesn't actually return the players choice, 
it displays the result. So maybe DisplayResult wouldbe a 
better name?


def ComputerChoice(): #Compuers function
   ComputerChoice = random.randrange(1, 4) #Computers random range.
   return ComputerChoice

Its not a good idea to use a variable name the same as the function. 
This will prevent you using recursion (which you might not know 
about yet but is important later!) You could simply use 'choice', its 
shorter to type too!


def PlayerChoice(number, CC): #Uses the users input & compares 
   number = int(number) #With the computers.


Its probably better to convert the number where you read it from 
the user - that way you can tell them they made a mistake and 
get a better response before you call this function. And the function 
can just expect a number as input.



   print "\n"
   if CC == 1 and number == 3:
   print 'Computer wins: Rock beats Scissors'
   elif CC == 1 and number == 2:
   print 'Player wins: Paper beats Rock'
   elif CC == 2 and number == 3:
   print 'Player wins: Scissors beat paper'
   elif CC == 3 and number == 1:
   print 'Player wins: Rock beats scissors'
   elif CC == 2 and number == 1:
   print 'Computer wins: Paper beats rock'
   elif CC == number:
   print '''Draw!''' #Trying it with 3
   elif CC == 3 and number == 2:
   print 'Computer wins: Scissors beats rock'
   elif number == 4:
   print 'Goodbye'

OK, This is stuff you probably want to take out and put 
beside the code for reading the user input. Its not really 
part of the game. In fact this might be what you use to 
terminate your loop?


   else:
   print CC
   print number
   if number != 4:  
   print '\n'

   main()

Looks like you discovered recursion already, although 
I suspect you don't know it yet? :-)



#Start of program
main()


HTH,


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

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


Re: [Tutor] Question about Python.

2009-03-25 Thread A.T.Hofkamp

T wrote:

Hi.
I'm working on Paper, Rock, Scissors in Python.
I need to make it a loop, and test the values (1, 2, 3, /Rock/Paper/Scissors) 
yet, but i'm kind of stuck. Could you help me?


import random  #Imports the random modual from the library.

def main():  #First function.
print 'Lets play Paper Rock Scissors!\n'
print '1 For Rock\n2 For Paper\n3 For Scissors\n4 To Quit'
number=raw_input ('What do you choose? ') #Gets users input.
pc = ComputerChoice()
PlayerChoice(number, pc)

def ComputerChoice(): #Compuers function
ComputerChoice = random.randrange(1, 4) #Computers random range.
return ComputerChoice


def PlayerChoice(number, CC): #Uses the users input & compares 


In ComputerChoice(), you obtain the choice of the computer.
In PlayerChoice() however, you do not obtain the player choice, but instead 
decide on the result.


I would suggest to modify PlayerChoice() to just obtain the player choice 
(code which you now have in main()).


Next write a new function that takes the computer choice and the player 
choice, and decides on the outcome.

(that function should have 3 possible return values).

Then in the main loop combine all three functions.
The construct you should investigate seems the 'while' statement.
(while the game is not decided, call the functions)


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


[Tutor] Question about Python.

2009-03-25 Thread T

Hi.
I'm working on Paper, Rock, Scissors in Python.
I need to make it a loop, and test the values (1, 2, 3, /Rock/Paper/Scissors) 
yet, but i'm kind of stuck. Could you help me?


import random  #Imports the random modual from the library.

def main():  #First function.
print 'Lets play Paper Rock Scissors!\n'
print '1 For Rock\n2 For Paper\n3 For Scissors\n4 To Quit'
number=raw_input ('What do you choose? ') #Gets users input.
pc = ComputerChoice()
PlayerChoice(number, pc)

def ComputerChoice(): #Compuers function
ComputerChoice = random.randrange(1, 4) #Computers random range.
return ComputerChoice


def PlayerChoice(number, CC): #Uses the users input & compares 
number = int(number) #With the computers.
print "\n"
if CC == 1 and number == 3:
print 'Computer wins: Rock beats Scissors'
elif CC == 1 and number == 2:
print 'Player wins: Paper beats Rock'
elif CC == 2 and number == 3:
print 'Player wins: Scissors beat paper'
elif CC == 3 and number == 1:
print 'Player wins: Rock beats scissors'
elif CC == 2 and number == 1:
print 'Computer wins: Paper beats rock'
elif CC == number:
print '''Draw!''' #Trying it with 3
elif CC == 3 and number == 2:
print 'Computer wins: Scissors beats rock'
elif number == 4:
print 'Goodbye'
else:
print CC
print number
if number != 4:  
print '\n'
main()



#Start of program
main()

_
Windows Live™ SkyDrive: Get 25 GB of free online storage.
http://windowslive.com/online/skydrive?ocid=TXT_TAGLM_WL_skydrive_032009___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question on how to open other programs and files

2009-02-08 Thread Alan Gauld


"Hi"  wrote

I have a question regarding how to open other programs and files in 
Python
code. I am creating a simple interface and I want it to be able to 
open

other files, such as a text file or a pdf file.


OK, lets clarify something first.
When you say open do you mean you want to open the file in Python
such that you can read the data into your python program? Or do
you mean you want to open the file in the default application on
your computer. In other words for a pdf file do you want to read
the data in the file or do you want to launch Acrobat on the file?

usually associated with other programs - for instance, gedit for 
text and
document viewer for pdf (I am using Ubuntu 8.10). What syntax or 
commands do

I need in order to do so.


The "official" approach to laumnching applications is to
use the subprocess module. This replaces several other
mechanisms which are now considred obsolete.


I've used os.popen in Windows XP and it works
fine, but the same code does not work in Ubuntu.


It should work but subprocess replaces popen.


def openfile(self, event):
result =  os.popen("home/user/textfile.txt")

In the terminal it simply says, sh: home/user/textfile.txt: not 
found.


I suspect your path is wrong. Notice you are not using
an absolute path but a relative path, so unless you have
a directory called home in your current directory it will fail.

But this is not opening the text file this is trying to execute
the text file and that is unlikely to work on Ubuntu. (In Windows
it will launch the default app - probably Notepad) So back to
the original question: do you want to open the t5extfile in
Python or do you want to launch gedit from Python?

Untiol you resolve that conundrum we can't really help
much more.

HTH,

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



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


[Tutor] Question on how to open other programs and files

2009-02-07 Thread Hi
I have a question regarding how to open other programs and files in Python
code. I am creating a simple interface and I want it to be able to open
other files, such as a text file or a pdf file. However, those files are
usually associated with other programs - for instance, gedit for text and
document viewer for pdf (I am using Ubuntu 8.10). What syntax or commands do
I need in order to do so. I've used os.popen in Windows XP and it works
fine, but the same code does not work in Ubuntu. This is the part of my code
that deals with opening files/programs:

def openfile(self, event):
 result =  os.popen("home/user/textfile.txt")

In the terminal it simply says, sh: home/user/textfile.txt: not found. And I
have already set permissions via chmod +x on the files of my choosing. Any
help would be greatly appreciated.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question about mpmath product expression

2009-02-02 Thread Bernd Prager
Does anybody know if there is a precision difference when I use mpmath and
take an expression:

from mpmath import *
mp.dps = 100
mu0 = [mpf('4') * pi * power(10, -7)

rather then:

mu0 = fprod([mpf('4'), pi, power(10, -7)])

?

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


Re: [Tutor] Question about pygame/tkinter interaction

2009-01-20 Thread Lie Ryan
On Tue, 2009-01-20 at 08:04 -0800, Steve Willoughby wrote:
> 
> In this case, that might be enough. I just need to show a video clip
> in 
> an otherwise fairly simple GUI.  A decorationless, borderless window
> popped up on the screen over the Tk stuff would probably work.  Thanks
> for the advice, I'll play with this a bit.

I've never used decoration-less pygame window, but I suspect it'd be
much easier/better to popup a fully decorated window with a separate
control panel (like mplayer). I think a lot of problems might arise with
decorator-less window, such as minimizing/resizing/moving Tk window
doesn't minimize/resize/move pygame's.

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


Re: [Tutor] Question about pygame/tkinter interaction

2009-01-20 Thread Lie Ryan
On Mon, 19 Jan 2009 15:46:27 -0800, Steve Willoughby wrote:

> On Mon, Jan 19, 2009 at 05:30:01PM -0500, Kent Johnson wrote:
>> My guess is that pygame and Tkinter are both going to want to control
>> the event loop. Googling 'pygame tkinter' gives both hints that it
>> might be possible and hints of trouble...
> 
> Yeah, I was thinking that, but since what I saw up until the point I
> asked the list was that for pygame you seem to write your own event
> loop, like
> 
> while True:
>   handle_event_myself(pygame.event.get())
> 
> whereas Tkinter wants you to just hand it control and let your program
> flow disappear into that black box entirely, until it pokes callbacks at
> you, I thought... "Well, maybe..."

I guess it shouldn't be too difficult if what you're intending is to have 
one window controlled by Tkinter and the other by pygame, it's just a 
matter of having Tkinter calling pygame's event handler once in a while 
(so instead of
while True: 
handle_pygame_event()

insert an event that makes Tkinter calls handle_pygame_event() every once 
in a while.
)

What I don't know is whether it is possible to "embed" a pygame-
controlled frame into Tkinter-controlled window.

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


Re: [Tutor] Question about pygame/tkinter interaction

2009-01-19 Thread Chris Fuller
On Monday 19 January 2009 12:05, Steve Willoughby wrote:
> I have a game I'm porting to Python which is currently written
> using TCL/Tk.  Now it would be fairly easy to make it work in
> Python with Tkinter, of course, since the way the GUI would be
> organized and implemented would be essentially the same.
>
> However, I'd also like to implement some fancier (but minor)
> animated effects and embed video and audio clips.  So I was
> thinking that pygame (or pymedia) would be reasonable choices,
> but I've never used either of those before.
>
> Is it reasonable to expect that I could use Tkinter for
> everything else, but use pygame/pymedia to handle things like
> creating a video playback window on the screen, or is pygame
> going to want to run the whole GUI event loop and screen updates
> in competition with Tkinter?
>
> Any general nudges in the right direction would be appreciated.
> Thanks,
> steve

I have successfully run dual GUI managers at once (Tkinter and wxPython) by 
suspending the mainloop of one and starting the other.  You might be able to 
setup a timeout in one GUI to service pending events in the other if this 
approach would be difficult.

GUIs tend to want to be in the main thread.  Certainly any GUI functions 
called from other threads must be via locks.  You could try experimenting 
with having a thread for each GUI, but I would expect problems.  Another 
solution would be to have two separate Python instances with some form of 
interprocess communications.  This doesn't have to be all that difficult, if 
you are careful with the design.  You can use pickle to convert complex 
objects into strings, for instance.

Cheers


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


Re: [Tutor] Question about pygame/tkinter interaction

2009-01-19 Thread Steve Willoughby
On Mon, Jan 19, 2009 at 05:30:01PM -0500, Kent Johnson wrote:
> My guess is that pygame and Tkinter are both going to want to control
> the event loop. Googling 'pygame tkinter' gives both hints that it
> might be possible and hints of trouble...

Yeah, I was thinking that, but since what I saw up until the point
I asked the list was that for pygame you seem to write your own
event loop, like

while True:
  handle_event_myself(pygame.event.get())

whereas Tkinter wants you to just hand it control and let your
program flow disappear into that black box entirely, until it
pokes callbacks at you, I thought... "Well, maybe..."

-- 
Steve Willoughby|  Using billion-dollar satellites
st...@alchemy.com   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about pygame/tkinter interaction

2009-01-19 Thread Kent Johnson
On Mon, Jan 19, 2009 at 1:05 PM, Steve Willoughby  wrote:

> Is it reasonable to expect that I could use Tkinter for
> everything else, but use pygame/pymedia to handle things like
> creating a video playback window on the screen, or is pygame
> going to want to run the whole GUI event loop and screen updates
> in competition with Tkinter?

My guess is that pygame and Tkinter are both going to want to control
the event loop. Googling 'pygame tkinter' gives both hints that it
might be possible and hints of trouble...

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


Re: [Tutor] Question about pygame/tkinter interaction

2009-01-19 Thread Eike Welk
You could use Qt and PyQt (bindings) for your application. QT is a 
library for buttons and similar things; it can show images, play 
video and play sound. They should both be part of every big Linux 
distribution. They are also available for Windows and Mac OS. 
 
http://doc.trolltech.com/4.4/index.html
http://www.riverbankcomputing.co.uk/news

List of tutorials:
http://www.diotavelli.net/PyQtWiki/Tutorials

Kind regards,
Eike.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about pygame/tkinter interaction

2009-01-19 Thread W W
On Mon, Jan 19, 2009 at 12:05 PM, Steve Willoughby wrote:

> Is it reasonable to expect that I could use Tkinter for
> everything else, but use pygame/pymedia to handle things like
> creating a video playback window on the screen, or is pygame
> going to want to run the whole GUI event loop and screen updates
> in competition with Tkinter?
>
> Any general nudges in the right direction would be appreciated.
> Thanks,
> steve
>

As far as I know it would be a fairly reasonable expectation - you would
simply hide the Tkinter screen when you show the pygame/pymedia window.
However, I'm not nearly as versed on any of the above as a lot of folks
here, so they may be able to confirm/contradict my advice.

But with my limited knowledge, that's probably how I'd do it (unless you
have a burning desire to learn pygame).

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


[Tutor] Question about pygame/tkinter interaction

2009-01-19 Thread Steve Willoughby
I have a game I'm porting to Python which is currently written
using TCL/Tk.  Now it would be fairly easy to make it work in
Python with Tkinter, of course, since the way the GUI would be
organized and implemented would be essentially the same.

However, I'd also like to implement some fancier (but minor)
animated effects and embed video and audio clips.  So I was
thinking that pygame (or pymedia) would be reasonable choices,
but I've never used either of those before.  

Is it reasonable to expect that I could use Tkinter for 
everything else, but use pygame/pymedia to handle things like
creating a video playback window on the screen, or is pygame
going to want to run the whole GUI event loop and screen updates
in competition with Tkinter?

Any general nudges in the right direction would be appreciated.
Thanks,
steve
-- 
Steve Willoughby|  Using billion-dollar satellites
st...@alchemy.com   |  to hunt for Tupperware.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question regarding win32com getting ldap object

2009-01-05 Thread vishwajeet singh
Thanks for the help.
It worked for me.

On Tue, Jan 6, 2009 at 1:28 AM, Jervis Whitley  wrote:

>
>
> On Mon, Jan 5, 2009 at 8:04 PM, vishwajeet singh wrote:
>
>> Hi List,
>>
>> I am running following code to get ldap com object but the result I am
>> getting is unknown
>> I am using Python 25 and win32 bindings available at
>> http://downloads.sourceforge.net/pywin32/pywin32-212.win32-py2.2.exe?modtime=1217535908&big_mirror=0
>>
>> *adsi = win32com.client.Dispatch('ADsNameSpaces')
>> print adsi
>> ldap = adsi.getobject('', 'LDAP:')
>> print ldap*
>>
>> OutPut:
>> 
>> >
>>
>> Any ideas what I am doing wrong ?
>>
>> --
>> Cheers,
>> Vishwajeet
>> http://www.singhvishwajeet.com
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>> Hi,
> try the following from the archive:
>
> http://mail.python.org/pipermail/python-list/1999-December/018594.html
>
> Cheers,
>
> Jervis
>



-- 
Cheers,
Vishwajeet
http://www.singhvishwajeet.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question regarding win32com getting ldap object

2009-01-05 Thread Jervis Whitley
On Mon, Jan 5, 2009 at 8:04 PM, vishwajeet singh wrote:

> Hi List,
>
> I am running following code to get ldap com object but the result I am
> getting is unknown
> I am using Python 25 and win32 bindings available at
> http://downloads.sourceforge.net/pywin32/pywin32-212.win32-py2.2.exe?modtime=1217535908&big_mirror=0
>
> *adsi = win32com.client.Dispatch('ADsNameSpaces')
> print adsi
> ldap = adsi.getobject('', 'LDAP:')
> print ldap*
>
> OutPut:
> 
> >
>
> Any ideas what I am doing wrong ?
>
> --
> Cheers,
> Vishwajeet
> http://www.singhvishwajeet.com
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
> Hi,
try the following from the archive:

http://mail.python.org/pipermail/python-list/1999-December/018594.html

Cheers,

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


[Tutor] Question regarding win32com getting ldap object

2009-01-05 Thread vishwajeet singh
Hi List,

I am running following code to get ldap com object but the result I am
getting is unknown
I am using Python 25 and win32 bindings available at
http://downloads.sourceforge.net/pywin32/pywin32-212.win32-py2.2.exe?modtime=1217535908&big_mirror=0

*adsi = win32com.client.Dispatch('ADsNameSpaces')
print adsi
ldap = adsi.getobject('', 'LDAP:')
print ldap*

OutPut:

>

Any ideas what I am doing wrong ?

-- 
Cheers,
Vishwajeet
http://www.singhvishwajeet.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question

2008-11-10 Thread Kent Johnson
On Mon, Nov 10, 2008 at 11:07 AM, Michael Connors <[EMAIL PROTECTED]> wrote:

> My guess is that, if you want to provide instructions to someone with no
> linux/unix experience. e.g. to edit a config file, you can safely tell them
> to: nano myfile.conf and expect them to be able to save the file and return
> to the command line. If you want to give the same instructions using vim or
> emacs, you would also need to specify how to save and exit. I imagine this
> to be the reason it is popular in tutorials, and if all the tutorials you
> use, use nano, you will probably use it too.

Yes. I don't use vim or emacs. When I need a terminal-based editor I
use nano because I can figure it out.

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


Re: [Tutor] Question

2008-11-10 Thread Alan Gauld

"Python Nutter" <[EMAIL PROTECTED]> wrote


On the Mac I just linked ipython in the config file to nano
On the iPhone 3G I just linked ipython in the config file to nano
On the Linux/Ubuntu box I also linked to nano...

hmmm looks like I use nano a lot more than I though ;-)


Nothing to do with Python directly, but I'm curious...

nano is a very popular editor in Unix/Linux circles but I 
confess I never could figure out why? Is there something 
I'm missing?


What does nano do that vi (or emacs) doesn't? Given that vi 
is the "standard" editor on *nix ity would seem the obvious 
choice. But everyone seems to be using nano? Why?



PS. I should explain that I used to use Unix a lot but it was 
before nano appeared to proliferate so I never used it. Now 
I only use *nix occasionally but nano is everywhere it seems.


Alan G.

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


Re: [Tutor] Question

2008-11-10 Thread Michael Connors
2008/11/10 W W <[EMAIL PROTECTED]>

> On Mon, Nov 10, 2008 at 9:40 AM, Alan Gauld <[EMAIL PROTECTED]>wrote:
>
>> 
>
> What does nano do that vi (or emacs) doesn't? Given that vi is the
>> "standard" editor on *nix ity would seem the obvious choice. But everyone
>> seems to be using nano? Why?
>
>
> AFAIK, it's a little smaller/faster than emacs... but since I'm a vi(m)
> fan, I'm probably the wrong person for the question ;)
>
>
>
My guess is that, if you want to provide instructions to someone with no
linux/unix experience. e.g. to edit a config file, you can safely tell them
to: nano myfile.conf and expect them to be able to save the file and return
to the command line. If you want to give the same instructions using vim or
emacs, you would also need to specify how to save and exit. I imagine this
to be the reason it is popular in tutorials, and if all the tutorials you
use, use nano, you will probably use it too.

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


Re: [Tutor] Question

2008-11-10 Thread W W
On Mon, Nov 10, 2008 at 9:40 AM, Alan Gauld <[EMAIL PROTECTED]>wrote:

> 

What does nano do that vi (or emacs) doesn't? Given that vi is the
> "standard" editor on *nix ity would seem the obvious choice. But everyone
> seems to be using nano? Why?


AFAIK, it's a little smaller/faster than emacs... but since I'm a vi(m) fan,
I'm probably the wrong person for the question ;)

-Wayne


>
> PS. I should explain that I used to use Unix a lot but it was before nano
> appeared to proliferate so I never used it. Now I only use *nix occasionally
> but nano is everywhere it seems.
>
> Alan G.
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question

2008-11-10 Thread Python Nutter
I use Notepad++ on my Windows box for Python, but my feeling about it
is a bit "Blah..." but thats my feeling with Windows in general ;-)

I think I'm one of the rare ones who do not like its choice of Syntax
Highlighting colours. But too lazy to change them since I don't do
much development on my Windows box to warrant it now that I got a Mac
on the desk as well.

I use ipython a lot and linked to Notepad++ in it so on Windows just typing
>>>edit somefile.py

will auto launch Notepad++ and let me code then when I save/exit it
will load the file automatically back into ipython and start
interpreting it.

On the Mac I just linked ipython in the config file to nano
On the iPhone 3G I just linked ipython in the config file to nano
On the Linux/Ubuntu box I also linked to nano...

hmmm looks like I use nano a lot more than I though ;-)

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


Re: [Tutor] Question

2008-11-09 Thread Rich Lovely
All you really need for python is a basic text editor, and the  
interpretter. Everything else is icing. Notepad++ has syntax  
highlighting support for python, and sounds as if it has brace and  
bracket completion. Most people here will tell you that auto- 
completion in python is a complex issue (most objects can have dynamic  
attributes defined at runtime that most auto-complete engines will  
miss). Notepad++ also supports auto-indentation, which is probably the  
most useful feature of any editor used for python.


Note I've never used it myself, just took a quick look through it's  
website.


---
Richard "Roadie Rich" Lovely
Part of the JNP|UK Famille
www.theJNP.com

(Sent from my iPod - please allow me a few typos: it's a very small  
keyboard)


On 9 Nov 2008, at 03:22 AM, Bap <[EMAIL PROTECTED]> wrote:


Can I use notepad++ for Python?

Thank you! ;-)

___
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] Question

2008-11-08 Thread Nick Scholtes
Last I checked, Notepad ++ works with Python. I've never used it for Python,
so I don't know how it works.
Nick



On Sat, Nov 8, 2008 at 9:22 PM, Bap <[EMAIL PROTECTED]> wrote:

> Can I use notepad++ for Python?
>
> Thank you! ;-)
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Art: http://www.coroflot.com/bellsoffreedom
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question

2008-11-08 Thread Bap

Can I use notepad++ for Python?

Thank you! ;-)

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


[Tutor] Question on DOMImplementation Objects

2008-09-30 Thread Chris Babcock
Does the DOMImplementation interface support schemas? 

I'm tweaking an example from a book to process a flat file registration
database:

from xml.dom import implementation

class RegistrationParser:
  def parseFile(self, fileAsString):

# Create DocType Declaration
doctype = implementation.createDocumentType('registrations', '',
'archive.xsd')

# Create empty DOM Document and get root element
doc = implementation.createDocument('', 'registrations', doctype)
elemDoc = doc.documentElement

. . . 


If I leave archive.xsd out of createDocumentType will it just generate
an XML document without validation?

Chris

-- 


Make a difference in the world and support more Diplomacy projects and
services then you can shake a dagger at, please read:

http://members.bluegoosenews.com/diplomacy/blog/2008/09/24/a_special_note_for_diplomacy_players
 - or - 
http://tinyurl.com/3wx6lb 

Blue Goose is willing to give me $250 to support various services and
projects in the Diplomacy hobby. The blog post above will tell you why
they are doing this, what I will do with the money, and what you can do
to help me get it.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] question about socket status

2008-07-24 Thread Monika Jisswel
if networking code is inside of the kernel then its from the kernel that you
can get network information & nowhere else.
(http://www.linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html)

I would just add that to see what netstat does simply use "strace netstat"
it will probably tell you the interesting files it reads when run.


2008/7/23 arsyed <[EMAIL PROTECTED]>:

> On Mon, Jul 21, 2008 at 1:25 PM, Rupp, Romaine <[EMAIL PROTECTED]>
> wrote:
> > Hello,
> >
> > I am new to programming with python and sockets.
> >
> > I would like to determine the status of a socket as it  is returned when
> you
> > do 'netstat –a | grep '.  I would like  to know if the socket
> state
> > is ESTABLISHED, LISTEN , CLOSE_WAIT, etc.
> >
> > Is there a way to get this information through a socket call?
> >
> > I've tried using socket.getperrname() function, but that only tells if
> there
> > is a connection.
> >
> > Is there a way to get more information on the state of the socket
> > connection?
> >
>
>
> If you're on linux, you could try poking around /proc/net. See, for
> example:
>
> http://www.linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html
>
> But I think invoking netstat and parsing the output from python might
> work well enough.
> ___
> 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] question about socket status

2008-07-22 Thread arsyed
On Mon, Jul 21, 2008 at 1:25 PM, Rupp, Romaine <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I am new to programming with python and sockets.
>
> I would like to determine the status of a socket as it  is returned when you
> do 'netstat –a | grep '.  I would like  to know if the socket state
> is ESTABLISHED, LISTEN , CLOSE_WAIT, etc.
>
> Is there a way to get this information through a socket call?
>
> I've tried using socket.getperrname() function, but that only tells if there
> is a connection.
>
> Is there a way to get more information on the state of the socket
> connection?
>


If you're on linux, you could try poking around /proc/net. See, for example:

http://www.linuxdevcenter.com/pub/a/linux/2000/11/16/LinuxAdmin.html

But I think invoking netstat and parsing the output from python might
work well enough.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] question about socket status

2008-07-21 Thread Rupp, Romaine
Hello,
I am new to programming with python and sockets.
I would like to determine the status of a socket as it  is returned when you do 
'netstat -a | grep '.  I would like  to know if the socket state is 
ESTABLISHED, LISTEN , CLOSE_WAIT, etc.
Is there a way to get this information through a socket call?
I've tried using socket.getperrname() function, but that only tells if there is 
a connection.
Is there a way to get more information on the state of the socket connection?
Thanks,
rrupp
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


<    1   2   3   4   5   6   7   8   9   10   >