[Tutor] The magic parentheses

2010-01-23 Thread David Hutto
Hi,

This is my first post to the list, so tell me if I'm posting incorrectly.

I'm creating a script, http://python.codepad.org/mHyqbJ2z that gives the area 
of two circles, based on their radius, and displays the difference between the 
two results.

My problem is when the results are printed, I get this:

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on 
win32
IDLE 2.6.4   No Subprocess 
>>> 
('Variable 2,', 490.0, 'is greater than', 'Variable 2,', 8.0, '.')
>>> 
('Variable 2,', 490.0, 'is greater than', 'Variable 2,', 8.0, '.')
>>> 
..
The parentheses, as well as the apostrophes and commas. I'm sure it's the way 
I'm having the results printed after it's through, but not sure how to correct 
it. 

I tried writing the 'Variable 1' and '2', as well as the 'is greater
than' within the y, and z local variables in the def return_difference_of12, 
and got the same result as when I
listed the portions of the printed result's sentence in the non-local variables 
I have now(I'm new to Python, so I'm not sure if this would be the correct 
term).

Any help would be appreciated. Thanks in advance.


David



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


Re: [Tutor] The magic parentheses

2010-01-24 Thread David Hutto
Thanks
for the solutions and the quick responses. I just removed the variable
and used print, I thought they would be considered the same whether as 
a variable, or as a direct line, guess not.

Thanks again,
David



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


Re: [Tutor] The magic parentheses

2010-01-24 Thread David Hutto
Re: [Tutor] The magic parentheses
Sunday, January 24, 2010 9:28 PM
From:
"David Hutto" 
Add sender to Contacts
To:
"Alan Gauld" 


--- On Sun, 1/24/10, Alan Gauld  wrote:

> From: Alan Gauld 
> Subject: Re: [Tutor] The magic parentheses
> To: tutor@python.org
> Date: Sunday, January 24, 2010, 8:06 PM
>
> "Lie Ryan" 
> wrote
> >> and used print, I thought they would be considered
> the same whether as a variable, or as a direct line, guess
> not.
> > what is equivalent:
> > print (a, b, c)
> >
> > and
> > x = a, b, c
> > print x
> >
> > both construct a tuple and prints a,b,c as tuple
>
> Not quite:
>
> >>> a = 1
> >>> b = 2
> >>> c = 3
> >>> x = a,b,c
> >>> print a,b,c
> 1 2 3
> >>> print x
> (1, 2, 3)
> >>>
>
> The first form prints multiple values the second prints the
> repr of a single tuple value. The output is different.
>
> Alan G.
>


So 'print a,b,c' says display the values of a,b,c in the sequence of a,b,c 
given. 'print x' says print the value of x, x grabs a's value, b's value, and 
c's value, and displays the values for print.

So the sequence becomes a tuple because it's a value of values, and it's sum 
comes back in the form of a tuple, not an actual end variable. In other words 
the second leap to find the values of a,b,c for value x, makes the result 
printed for x(x becomes an array of other data a tuple, correct?


Now if I want to turn the first values listed under x into tuples(or use the 
format function that I think was named in another reply to return the non-tuple 
version of the value for x and I'm going to try it in a few min) of the other 
two variables, like below:

g = f
a = b,c
b = a,c
c = a,g
x = a,b,c


This is off the topic I think, so I'll repost under another if necessary, but 
how do I avoid going into the loop of tuples/variables. If a is dependent on 
knowing what b,c are, and b is dependent on knowing what a and c are, and c is 
dependent on knowing what a and b are, how do I prevent from going into a 
defining loop for each.

This is just basically playing with Python's functions, I was just wondering 
how to approach such a problem where variables must come in order but might be 
dependent on a following variable who's positioning is needed to maintain the 
hierarchy of other variables it might represent.

In the above, if I want to know c it requires knowing a,g. But in order to know 
a, a needs to know b,c-so I can't list c above a or a above c, because I get 
the error that the value of the other is not known when I try to run the script.


David



  

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


Re: [Tutor] kudos to alan

2010-01-31 Thread David Hutto


--- On Sun, 1/31/10, Woodwerks  wrote:

From: Woodwerks 
Subject: [Tutor] kudos to alan
To: tutor@python.org
Date: Sunday, January 31, 2010, 2:33 PM

Message: 4
Date: Sun, 31 Jan 2010 11:01:19 -0500
From: "R. Alan Monroe"
To:tutor@python.org
Subject: Re: [Tutor] can any one help
Message-ID:<4681047264.20100131110...@columbus.rr.com>
Content-Type: text/plain; charset=us-ascii

I think the way you give hints and ideas about how to accomplish something in 
Python is excellent. I sometimes work through these problems just to build 
skills. I know it would be easy for you to provide a built solution, but this 
exercises the brain in a much better way. Kudos, Alan.

> >  1 1.1 Write a Python program with a loop that prints out a sequence
> >  of numbers as follows:15 13 11...3 1 -1
>    
Hint 1: Learn about FOR loops.

Hint 2: Learn about the RANGE command.

Hint 3: Show us some code you have written. Even if yours doesn't
work, we can probably spot WHY it doesn't work.

Alan

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






I'll second the motion.




  ___
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


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 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] python function to know the path of the program in execution

2010-02-05 Thread David Hutto


--- On Fri, 2/5/10, nikunj badjatya  wrote:

From: nikunj badjatya 
Subject: [Tutor] python function to know the path of the program in execution
To: tutor@python.org
Date: Friday, February 5, 2010, 5:08 AM

Hi ,
Is there any python function to know the path of the python program under 
execution.?
If someone executes a program , he should come to know the path of the 
program..!!
ex. suppose a user ABC is running prog.py which is in ~ directory, the user 
currently is in XYZ directory. 


[ a...@localhost XYZ ]$ python ~/prog.py 
The program's location is ~/prog.py

This should be the outcome of the program.

I tried with os.getcwd()
os.getcwd() will return /path/to/folder/XYZ.



Any suggestions?
 
Thanks,
Nikunj Badjatya
Bangalore, India


-Inline Attachment Follows-

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


I think this is what you want:

>>> import sys
>>> sys.argv[0]
'C:\\Python26\\testingscripts\\lowdir.py'
>>> 

David



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


Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread David Hutto
If you want to know the file you're script is running from then print 
sys.argv[0]

this is the script I ran from a file named lowerdir.py:
import sys
print "This is sys.path:"
print
print sys.path
print
print "This is sys.path[0], the current working directory:"
print
print sys.path[0]
print
print "This is sys.path[1], the first in the PYTHONOPATH string after the 
current directory your script is running in:"
print
print sys.path[1]
print
print "This is sys.path[-1] the last in the PYTHONPATH list:"
print
print sys.path[-1]
print
print "This is sys.argv[0] your current running scripts full path:"
print
print sys.argv[0]


This is my output:

IDLE 2.6.4  
>>>  RESTART 
>>> 
This is sys.path:

['C:\\Python26\\testingscripts\\lowerdir', 'C:\\Python26\\Lib\\idlelib', 
'C:\\Windows\\system32\\python26.zip', 'C:\\Python26\\DLLs', 
'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 
'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 
'C:\\Python26\\lib\\site-packages', 'C:\\Python26\\lib\\site-packages\\win32', 
'C:\\Python26\\lib\\site-packages\\win32\\lib', 
'C:\\Python26\\lib\\site-packages\\Pythonwin']

This is sys.path[0], the current working directory:

C:\Python26\testingscripts\lowerdir

This is sys.path[1], the first in the PYTHONOPATH string after the current 
directory your script is running in:

C:\Python26\Lib\idlelib

This is sys.path[-1] the last in the PYTHONPATH list:

C:\Python26\lib\site-packages\Pythonwin

This is sys.argv[0] your current running scripts full path:

C:\Python26\testingscripts\lowerdir\lowerdir.py
>>> 


As long as you have sys imported at somepoint, then all you have to do is print 
sys.argv[0], and that should be the exact name and location of the current 
running script,


David




--- On Fri, 2/5/10, Daniel Sarmiento  wrote:

From: Daniel Sarmiento 
Subject: Re: [Tutor] python function to know the path of the program in 
execution *
To: tutor@python.org
Date: Friday, February 5, 2010, 7:53 AM



> Date: Fri, 5 Feb 2010 17:43:37 +0530
> From: Spoorthi 
> To: "Rohit Roger$" 
> Cc: tutor 
> Subject: Re: [Tutor] python function to know the path of the program
>     in    execution *
> Message-ID:
>     <6c9f52051002050413o57bd76bax7ac5986b17304...@mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> The below data(in blue) made me converge upon sys.path[0] for this
> particular problem...I dont think it returns None if a Python script is
> used. Can anyone please correct me if I am wrong
>
> *As initialized upon program startup, the first item of this list, path[0],
> is the directory containing the script that was used to invoke the Python
> interpreter. If the script directory is not available (e.g. if the
> interpreter is invoked interactively or if the script is read from standard
> input), path[0] is the empty string, which directs Python to search modules
> in the current directory first. Notice that the script directory is inserted
> before the entries inserted as a result of PYTHONPATH.*
>
> On Fri, Feb 5, 2010 at 5:38 PM, Rohit Roger$  wrote:
>
>>
>> sys.path[0] returns none
>>
>>
>>
>> On Fri, Feb 5, 2010 at 5:36 PM, Spoorthi  wrote:
>>
>>> sys.path[0] should be serving the purpose effectively I guess
>>>
>>>
>>> On Fri, Feb 5, 2010 at 5:29 PM, Rohit Roger$ wrote:
>>>
>>>> Answer :
>>>> >>> import sys
>>>>>>> rohit = sys.argv[0]
>>>>>>> print rohit
>>>>  it returns the name of the path
>>>>
>>>> On Fri, Feb 5, 2010 at 4:13 PM, David Hutto wrote:
>>>>
>>>>>  Junk Score: 2 out of 10 (below your Auto Allow 
>>>>>threshold<https://www.boxbe.com/mail-screening>)
>>>>> | Approve sender <https://www.boxbe.com/anno?tc=1529381613_418589136> |
>>>>> Block sender<https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b>| 
>>>>> Block
>>>>> domain <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b&dom>
>>>>>
>>>>>
>>>>>
>>>>> --- On *Fri, 2/5/10, nikunj badjatya * wrote:
>>>>>
>>>>>
>>>>> From: nikunj badjatya 
>>>>> Subject: [Tutor] python function to know the path of the program in
>>>>> execution
>>>>> To: tutor@python.org
>>>>> Date: Friday, February 5, 2010, 5:08 AM
>>>>>
>&g

Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread David Hutto
If you want to know the file you're script is running from then print 
sys.argv[0]

this is the script I ran from a file named lowerdir.py:
import sys
print 
"This is sys.path:"
print
print sys.path
print
print "This 
is sys.path[0], the current working directory:"
print
print 
sys.path[0]
print
print "This is sys.path[1], the first in the 
PYTHONOPATH string after the current directory your script is running 
in:"
print
print sys.path[1]
print
print "This is 
sys.path[-1] the last in the PYTHONPATH list:"
print
print 
sys.path[-1]
print
print "This is sys.argv[0] your current running
 scripts full path:"
print
print sys.argv[0]


This is my
 output:

IDLE 2.6.4  
>>> 
 RESTART
 
>>> 
This is sys.path:

['C:\\Python26\\testingscripts\\lowerdir',
 'C:\\Python26\\Lib\\idlelib', 'C:\\Windows\\system32\\python26.zip', 
'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 
'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 
'C:\\Python26', 'C:\\Python26\\lib\\site-packages', 
'C:\\Python26\\lib\\site-packages\\win32', 
'C:\\Python26\\lib\\site-packages\\win32\\lib', 
'C:\\Python26\\lib\\site-packages\\Pythonwin']

This is 
sys.path[0], the current working directory:

C:\Python26\testingscripts\lowerdir

This
 is sys.path[1], the first in the PYTHONOPATH string after the current 
directory your script is running in:

C:\Python26\Lib\idlelib

This
 is sys.path[-1] the last in the PYTHONPATH list:

C:\Python26\lib\site-packages\Pythonwin

This
 is sys.argv[0] your current running scripts full
 path:

C:\Python26\testingscripts\lowerdir\lowerdir.py
>>>
 


As long as you have sys imported at somepoint, then all you
 have to do is print sys.argv[0], and that should be the exact name and 
location of the current running script,


David

--- On Fri, 2/5/10, Daniel Sarmiento  wrote:

From: Daniel Sarmiento 
Subject: Re: [Tutor] python function to know the path of the program in 
execution *
To: tutor@python.org
Date: Friday, February 5, 2010, 7:53 AM



> Date: Fri, 5 Feb 2010 17:43:37 +0530
> From: Spoorthi 
> To: "Rohit Roger$" 
> Cc: tutor 
> Subject: Re: [Tutor] python function to know the path of the program
>     in    execution *
> Message-ID:
>     <6c9f52051002050413o57bd76bax7ac5986b17304...@mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> The below data(in blue) made me converge upon sys.path[0] for this
> particular problem...I dont think it returns None if a Python script is
> used. Can anyone please correct me if I am wrong
>
> *As initialized upon program startup, the first item of this list, path[0],
> is the directory containing the script that was used to invoke the Python
> interpreter. If the script directory is not available (e.g. if the
> interpreter is invoked interactively or if the script is read from standard
> input), path[0] is the empty string, which directs Python to search modules
> in the current directory first. Notice that the script directory is inserted
> before the entries inserted as a result of PYTHONPATH.*
>
> On Fri, Feb 5, 2010 at 5:38 PM, Rohit Roger$  wrote:
>
>>
>> sys.path[0] returns none
>>
>>
>>
>> On Fri, Feb 5, 2010 at 5:36 PM, Spoorthi  wrote:
>>
>>> sys.path[0] should be serving the purpose effectively I guess
>>>
>>>
>>> On Fri, Feb 5, 2010 at 5:29 PM, Rohit Roger$ wrote:
>>>
>>>> Answer :
>>>> >>> import sys
>>>>>>> rohit = sys.argv[0]
>>>>>>> print rohit
>>>>  it returns the name of the path
>>>>
>>>> On Fri, Feb 5, 2010 at 4:13 PM, David Hutto wrote:
>>>>
>>>>>  Junk Score: 2 out of 10 (below your Auto Allow 
>>>>>threshold<https://www.boxbe.com/mail-screening>)
>>>>> | Approve sender <https://www.boxbe.com/anno?tc=1529381613_418589136> |
>>>>> Block sender<https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b>| 
>>>>> Block
>>>>> domain <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b&dom>
>>>>>
>>>>>
>>>>>
>>>>> --- On *Fri, 2/5/10, nikunj badjatya * wrote:
>>>>>
>>>>>
>>>>> From: nikunj badjatya 
>>>>> Subject: [Tutor] python function to know the path of the program in
>>>>> execution
>>>>> To: tutor@python.org
>>>>> Date: Friday, February 5, 2010, 5:08 AM
>>>&

Re: [Tutor] Tutor list as pair progamming plush toy

2010-02-12 Thread David Hutto


--- On Fri, 2/12/10, Hansen, Mike  wrote:

From: Hansen, Mike 
Subject: Re: [Tutor] Tutor list as pair progamming plush toy
To: tutor@python.org
Date: Friday, February 12, 2010, 11:55 AM

 

> -Original Message-
> From: tutor-bounces+mike.hansen=atmel@python.org 
> [mailto:tutor-bounces+mike.hansen=atmel@python.org] On 
> Behalf Of Mac Ryan
> Sent: Friday, February 12, 2010 8:33 AM
> To: tutor@python.org
> Subject: [Tutor] Tutor list as pair progamming plush toy
> 
> Have you ever got that piece of advice about - when you have 
> stuck on a
> bug you seem unable to track - getting a plush toy to whom you explain
> your code? (This is of course a workaround if you do not have a fellow
> developer to help you out).
> 
> Well... I found out this advice kind of works for me, with the notable
> difference that my plush toy is this mailing list. It works so
> wonderfully that indeed is several months I do not post any message:
> whenever I get stuck, I begin to write a message to the list, 
> and in the
> process of explaining what is the intended behaviour and outcome of my
> code, I systematically find the bug by myself.
> 
> I know - this is slightly OT for the list - but I thought to share as
> maybe this is a "hidden benefit" the list is bringing to a few people
> without the tutors even knowing it.
> 
> Does anybody else experience the same?
> 
> Cheers, :)
> Mac.
>
+1



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


Re: [Tutor] How to use pydoc

2010-02-26 Thread David Hutto


--- On Fri, 2/26/10, Ricardo Aráoz  wrote:

From: Ricardo Aráoz 
Subject: [Tutor] How to use pydoc
To: tutor@python.org
Date: Friday, February 26, 2010, 8:31 AM

Checked the manuals on pydoc and wanted to try it. Must certainly be
doing something wrong but I can't figure what. Here's my session :

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> pydoc sys
  File "", line 1
    pydoc sys
            ^
SyntaxError: invalid syntax
>>> import pydoc
>>> pydoc sys
  File "", line 1
    pydoc sys
            ^
SyntaxError: invalid syntax
>>> pydoc

>>> import sys
>>> pydoc sys
  File "", line 1
    pydoc sys
            ^
SyntaxError: invalid syntax
>>>

What's my mistake?

TIA


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


It looks like you're using idle, you place the command in the command 
prompt/terminal like:

python -m pydoc sys

Look here about three down it's in the page summary:

http://www.google.com/search?hl=en&client=firefox-a&rls=com.ubuntu%3Aen-US%3Aofficial&q=pydoc+sys&aq=f&aqi=g1g-s1g-sx1&aql=&oq=



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


[Tutor] Script Building

2010-03-03 Thread David Hutto
I'm new to Python, so I thought as a first project I'd create a basic script 
building wizard to help with my understanding of the flow, and for basic 
practice. The following is a outline of what I would initially like to 
accomplish. 

I've begun creating small functions, and very lightly worded pseudocode, but 
before I go further I'd like to make sure I'm building my script insertions 
correctly, and see if any one has any suggestions on how to refine the process, 
or what I might be able to use as additives to sub-levels of my insertions.

Here is a basic outline of the insertions from either raw_input or, drop down 
menu:

append paths
import modules
from modules import*
import module as x
global variables
docs
version
class
class with docs
def
instance
comment to line x


This is the initial step-by step process which the script will create:

1)Ask for existing or new project

Would you like to open an existing project or create a new one?

1a)
if create new go to step 2

1b)
if open existing project go to step 3a

***

2)Create new project or file

Would you like to created a new project, or a single file? 

2a)
if create single file go to step 4

2b)
if create a project go to step 5

***


3)Select the folder of your existing project

3a)
open project, which would be a folder, not a single file, go to step 6a

3b)
open single existing file go to step 6b

***

4)Setup for single file creation

4a)
What would you like to name your new file?

raw_input

4b) would you like to use the script wizard to
setup your new file?

if yes go to script wizard(it's a choose your own adventure book)

if no
go to step 7a
**

5)Set up for project creation

5a) Two fields to fill in

What would you like to name your new project?
raw_input

You must create a new file to go in your project folder.
What would you like to call your first file?
raw_input

got to step 7b
**
**
6)open project window, or single file, depending
on which of step 3 user is coming from, then
begins 'recording' the current sessions input, until save
or exit

projects will have multiple files, so history
for each file open within the project

6a)
Open window with selection sidepanel of all files in project folder

6b)
Window with single file, and now side panel



*


7) New file has been created, or new project has been created with blank file

7a) open new window with file, but no open project folder

7b) open edit window with blank file and project folder contents, which
at this point consist of the single blank named file
**
***


sequence of events above have terminated at the editor window with
open file


**
**


The above excludes insertions, saving, creating a file or project into the main 
project window, which will probably call on some of the code from above.

If anyone is familiar with it, I'm thinking of using the blender game 
engine(just to combine the learning process of both), but the overall code is 
python, so I'm pretty sure I'm posting this to the right list.

Any suggestions, or critiques, are welcome.


Thanks,
David



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


Re: [Tutor] Bowing out

2010-03-03 Thread David Hutto


--- On Wed, 3/3/10, Sander Sweers  wrote:

From: Sander Sweers 
Subject: Re: [Tutor] Bowing out
To: "Kent Johnson" 
Cc: Tutor@python.org
Date: Wednesday, March 3, 2010, 11:06 AM

On 3 March 2010 14:17, Kent Johnson  wrote:
> After six years of tutor posts my interest and energy have waned and
> I'm ready to move on to something new.

Let me join the other people and thank you for your contribution to
this list. Good luck with something new :-)

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


Even if you didn't give me any personal help, I thank people like you. ...I bet 
this looks great on a resume.



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


Re: [Tutor] Understanding (Complex) Modules

2010-03-03 Thread David Hutto


--- On Wed, 3/3/10, Wayne Watson  wrote:

From: Wayne Watson 
Subject: [Tutor] Understanding (Complex) Modules
To: tutor@python.org
Date: Wednesday, March 3, 2010, 8:24 PM

First a little preamble before my questions.

Most of my work in Python has required modifying a program that uses modules 
that were imported by the original program. I've made some use of modules on a 
command line like math, and have used the idea of a qualifier.  On occasion, 
I've used examples from matplotlib that required from matplotlib.image import 
AxesImage. Further, I've created some simple classes, and produced  objects 
with them. No use of inheritance though.  So far so good.  In a few places, it 
is said modules are objects. I'm slightly puzzled by that, but in some way it 
seems reasonable from the standpoint of period notation. So far I have not 
created a module.

In Lutz's and Ascher's Learning Python, ed. 2, chap. 16, they describe the 
following example, among others:

module2.py as

print "starting to load ..."
import sys
def func(): pass
class klass: pass
print "done loading."

Their description of its use is quite readable.  It shows that there is some 
more to a module than a list of defs, for example.

Here comes the questions. Recently I began to use matplotlib, scipy, and pylab, 
mostly matplotlib. I've ground out a few useful pieces of code, but I'm fairly 
baffled by the imports required to get at various elements, of say, matplotlib 
(MPL).  Some of the MPL examples use of imports make sense, but how the writer 
pulled in the necessary elements is not.  How does one go about understanding 
the capabilities of such modules? MPL seems to have a lot of lower level 
components. Some of them are laid out over numerous pages as in the form of a, 
say, English language, description. How does one decipher this stuff.  For 
example, open the module in an editor and start looking at the organization? I 
thinkthe so called MPL guide ins 900 pages long. Even the numpy guide 
(reference?), I believe borders on 1000 pages. There must be some way to 
untangle these complex modules, I would think. Some of the tutorials seem 
nothing more than a template to follow for a
 particular problem.  So far, looking at the plentiful number of examples of 
MPL, and probably some of the other modules mentioned above have not provided a 
lot of insight.

 Is there some relationship between modules and objects that I'm not seeing 
that could be of value?




--            Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

             (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
              Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

               Stop the illegal killing of dolphins and porpoises.
                     
              Wrest the control of the world's fisheries from Japan.

                    Web Page:

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

How about importing your foot into your ass, for trying to ask an educated 
question and answering it through a false addresss by yourself.



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


Re: [Tutor] Visual Python programming and decompilers?

2010-03-12 Thread David Hutto


--- On Fri, 3/12/10, spir  wrote:

> From: spir 
> Subject: Re: [Tutor] Visual Python programming and decompilers?
> To: tutor@python.org
> Date: Friday, March 12, 2010, 7:22 AM
> On Fri, 12 Mar 2010 10:19:39 +0200
> Ludolph 
> wrote:
> 
> > Hi Guys
> > 
> > I posted the following message on my local pug mailing
> list and
> > someone recommended I post it here.
> > 
> > At work I have been exposed to a Agile Platform called
> OutSystems. It
> > allows you to visually program your web applications
> > http://i.imgur.com/r2F0i.png and I find the idea very
> intriguing.
> > 
> > So I have started to play around with the idea on how
> will I be able
> > to visually represent Python code as in the above
> image and then allow
> > the programmer to change some of the flow/code/logic
> visually and then
> > get it back as python source code. I don't know if
> this have been
> > tried before and after some googling I can't find
> anything like this,
> > so maybe I'm just lacking basic googling skills or a
> python solution
> > like the above does not exist yet.
> > 
> > If anybody knows of such solution please let me know,
> so that I don't
> > spend a lot of time recreating the wheel.
> 

I was thinking of a similar project a while back using the game engine in  
blender(although I'm sure there's other software, this was something that uses 
python, and is fun to play/work with), but since there are so many ide's it 
went to the back burner.

I posted a basic outline of my idea to list a while back, I think I still have 
a copy of it, but the pseudo code is lost in the digital ether after an os 
problem.

I'd be interested in working on a project like this with you if you're 
interested.




> There has been (and probably still are) numerous projects
> around visual programming.
> 
> >  Otherwise help me out on the following problem:
> > I decided I can use byteplay3 http://pypi.python.org/pypi/byteplay/ to
> > disassemble the code to workable objects, It even
> allows me to rebuild
> > the objects to bytecode. So if I define patterns on
> how python
> > interrupts the source code to bytecode I can visually
> represent this
> > and also so convert my visual representations back to
> bytecode.
> > 
> > The only problem I have at the moment is how will I
> get this bytecode
> > back to python source code. I have googled for python
> decompiler but
> > only found old projects like unpyc, decompyle and some
> online
> > services. I would like to know if anybody know of a
> well maintained or
> > at least recent module that can help me accomplish the
> above
> > mentioned, because I'm hoping I can implement this in
> Python 3.1.
> > 
> > So any input or suggestion would be greatly
> appreciated.
> 
> Don't understand why you work at the bytecode level.
> 
> > Kind Regards,
> > 
> > --
> > Ludolph Neethling
> 
> 
> Denis
> 
> 
> la vita e estrany
> 
> spir.wikidot.com
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 


David


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


[Tutor] Command not issued until after escape from loop

2010-03-14 Thread David Hutto
In the following code, the portion I'm having a problem with is outlined in 
stars, but since the overall code was short, I included it, just in case 
something else might be hindering the process.

When I execute the script, it shows my main window, then if I press the CKEY 
it's *supposed* to call the cleanSlate() function, which grabs and deletes 
objects in the contents of another window.

My problem is, it doesn't execute cleanSlate() until I hit the ESCKEY, or the 
QKEY. In the original example code I'm using as a template(I put in the ev() 
portion of the main template below my current code, so maybe someone could see 
where I deviated from the original, and why the differences in implementing 
redraw) , it's setup in the same manner. 

Why would it not execute immediately(during the main loop) in mine, but in the 
original it does?

import Blender
from Blender.BGL import *
from Blender import Draw, Scene, Object, Mesh
R = G = 0
B = A = 1
title = "Basic Object Manipulation"
instructions = "Select an object to manipulate"
len1 = Draw.GetStringWidth(title)
len2 = Draw.GetStringWidth(instructions)

# Removes default objects in scene

def cleanSlate(scn):
for ob in scn.objects:
if ob.getType == 'Mesh' or 'Camera':
scn.objects.unlink(ob)

#defining the window
def show_win():
glClearColor(R,G,B,A)# define color used to 
clear buffers 
glClear(GL_COLOR_BUFFER_BIT) # use it to clear the 
color buffer
glColor3f(0.35,0.18,0.92)# define default color
glColor3f(.0,0.0,0.0)# change default color for 
next item
glRecti(10, 450, 20+len2, 113)   # sets a box border
glColor3f(0.2,0.2,0.2)   # change default color for 
next item
glRasterPos2i(14,435)# move cursor
Draw.Text(title) # draw this text there
glRasterPos2i(14,410)# move cursor again
Draw.Text(instructions)   # draw another msg
**  
# defining the event handling list
def ev(evt, val):
scn = Scene.getCurrent()
if evt == Draw.ESCKEY or evt == Draw.QKEY:
Draw.Exit()
elif not val:
return
elif evt == Draw.CKEY: 
cleanSlate(scn) 
else:
return
Draw.Redraw(1)
**

# build the window
Draw.Register(show_win, ev, None)  # start the main loop


#End code


This is the original ev()
**

def ev(evt, val):  # event callback for Draw.Register()
   global R,G,B,A   # ... it handles input events
   if evt == Draw.ESCKEY or evt == Draw.QKEY:
 Draw.Exit()# this quits the script
   elif not val: return
   elif evt == Draw.LEFTMOUSE: R = 1 - R
   elif evt == Draw.MIDDLEMOUSE: G = 1 - G
   elif evt == Draw.RIGHTMOUSE: B = 1 - B
   elif evt == Draw.WHEELUPMOUSE:
 R += 0.1
 if R > 1: R = 1
   elif evt == Draw.WHEELDOWNMOUSE:
 R -= 0.1
 if R < 0: R = 0
   else:
 return # don't redraw if nothing changed
   Draw.Redraw(1)


TIA,
David


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


Re: [Tutor] Command not issued until after escape from loop

2010-03-15 Thread David Hutto


--- On Mon, 3/15/10, David Hutto  wrote:

> From: David Hutto 
> Subject: Command not issued until after escape from loop
> To: tutor@python.org
> Date: Monday, March 15, 2010, 2:15 AM
> In the following code, the portion
> I'm having a problem with is outlined in stars, but since
> the overall code was short, I included it, just in case
> something else might be hindering the process.
> 
> When I execute the script, it shows my main window, then if
> I press the CKEY it's *supposed* to call the cleanSlate()
> function, which grabs and deletes objects in the contents of
> another window.
> 
> My problem is, it doesn't execute cleanSlate() until I hit
> the ESCKEY, or the QKEY. In the original example code I'm
> using as a template(I put in the ev() portion of the main
> template below my current code, so maybe someone could see
> where I deviated from the original, and why the differences
> in implementing redraw) , it's setup in the same manner. 
> 
> Why would it not execute immediately(during the main loop)
> in mine, but in the original it does?
> 
> import Blender
> from Blender.BGL import *
> from Blender import Draw, Scene, Object, Mesh
> R = G = 0
> B = A = 1
> title = "Basic Object Manipulation"
> instructions = "Select an object to manipulate"
> len1 = Draw.GetStringWidth(title)
> len2 = Draw.GetStringWidth(instructions)
> 
> # Removes default objects in scene
> 
> def cleanSlate(scn):
>         for ob in
> scn.objects:
>            
>     if ob.getType == 'Mesh' or 'Camera':
>            
>            
> scn.objects.unlink(ob)
> 
> #defining the window
> def show_win():
>        
> glClearColor(R,G,B,A)         
>       # define color used to clear buffers 
>        
> glClear(GL_COLOR_BUFFER_BIT)     
>    # use it to clear the color buffer
>        
> glColor3f(0.35,0.18,0.92)         
>   # define default color
>        
> glColor3f(.0,0.0,0.0)         
>       # change default color for next item
>         glRecti(10, 450,
> 20+len2, 113)       # sets a box
> border
>        
> glColor3f(0.2,0.2,0.2)         
>      # change default color for next
> item
>        
> glRasterPos2i(14,435)         
>       # move cursor
>        
> Draw.Text(title)           
>          # draw this text
> there
>        
> glRasterPos2i(14,410)         
>       # move cursor again
>        
> Draw.Text(instructions)   # draw another msg
> **   
>     
> # defining the event handling list
> def ev(evt, val):
>         scn =
> Scene.getCurrent()
>         if evt == Draw.ESCKEY
> or evt == Draw.QKEY:
>            
>     Draw.Exit()
>         elif not val:
>            
>     return
>         elif evt ==
> Draw.CKEY: 
>            
>     cleanSlate(scn) 
>         else:
>            
>     return
>         Draw.Redraw(1)
> **
> 
> # build the window
> Draw.Register(show_win, ev, None)      #
> start the main loop
> 
> 
> #End code
> 
> 
> This is the original ev()
> **
> 
> def ev(evt, val):           
>           # event callback for
> Draw.Register()
>    global R,G,B,A       
>            
>    # ... it handles input events
>    if evt == Draw.ESCKEY or evt ==
> Draw.QKEY:
>      Draw.Exit()     
>                
>   # this quits the script
>    elif not val: return
>    elif evt == Draw.LEFTMOUSE: R = 1 - R
>    elif evt == Draw.MIDDLEMOUSE: G = 1 - G
>    elif evt == Draw.RIGHTMOUSE: B = 1 - B
>    elif evt == Draw.WHEELUPMOUSE:
>      R += 0.1
>      if R > 1: R = 1
>    elif evt == Draw.WHEELDOWNMOUSE:
>      R -= 0.1
>      if R < 0: R = 0
>    else:
>      return       
>                
>      # don't redraw if nothing changed
>    Draw.Redraw(1)
> 
> 
> TIA,
> David
> 
> 
>       
> 

The revised question to this, after messing around a little more, is why does 
the loop hold the cleanSlate() function until ESC, or Q, but not hold on to the 
mouse events, which it executes immediately?

I know the ESC, and Q are not triggering the function call, because it doesn't 
execute on ESC, or Q if the action to call it isn't performed during the loop.


David


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


Re: [Tutor] Command not issued until after escape from loop

2010-03-15 Thread David Hutto
On Mon, Mar 15, 2010 at 4:53 AM, Alan Gauld wrote:

>
> "David Hutto"  wrote
>
> Caveat: I know zero about Blender... but...
>

I *thought* that since the code was in Python it might be the way I was
executing it. I think now it might be how the other windows are updated in
blender when the command is executed.

>
>  When I execute the script, it shows my main window, then if I
>> press the CKEY it's *supposed* to call the cleanSlate() function,
>>
>> My problem is, it doesn't execute cleanSlate() until I hit the
>> ESCKEY, or the QKEY.
>> **
>> # defining the event handling list
>> def ev(evt, val):
>> scn = Scene.getCurrent()
>> if evt == Draw.ESCKEY or evt == Draw.QKEY:
>>  Draw.Exit()
>> elif not val:
>>return
>> elif evt == Draw.CKEY:
>>   cleanSlate(scn)
>> else:
>>  return
>>
>
>
> Can you insert debvug statements to display values?
> If so I'd try printing the value of val. If it is "False" - ie empty - the
> event function will exit before reaching your code.
>
> Alternatively try moving your elif up above the test for not val.
>
> See if that helps.
>
> --
> 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


[Tutor] Class Inheritance

2010-04-22 Thread David Hutto
Hello List!

While experimenting with Tkinter(python2.6), when from Tkinter import*
is used I came across the following error:

C:\Users\ascent>c:\python26/Script3.py
Traceback (most recent call last):
  File "C:\python26\Script3.py", line 1, in 
from Tkinter import *
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 44, in 
from turtle import *
  File "C:\Python26\lib\lib-tk\turtle.py", line 374, in 
class ScrolledCanvas(Tkinter.Frame):
AttributeError: 'module' object has no attribute 'Frame'

*

Which stems from the below in turtle.py:

class ScrolledCanvas(TK.Frame)

I know that ScrolledCanvas is trying to use class TK.Frame as it's base
class to build from, and the class Frame is what is trying to be called
from the Tkinter module.

So I tried to alter the turtle.py. When I try to just 'from Tkinter
import *, such as:

from Tkinter import *
class ScrolledCanvas(Tkinter.Frame):

I get:
*
C:\Users\ascent>c:\python26/Script3.py
Traceback (most recent call last):
  File "C:\python26\Script3.py", line 1, in 
from Tkinter import *
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 44, in 
from turtle import *
  File "C:\Python26\lib\lib-tk\turtle.py", line 373, in 
class ScrolledCanvas(Tkinter.Frame):
NameError: name 'Tkinter' is not defined
***


I know pretty much what is going on there. But when I try to use:

import Tkinter
from Tkinter import *
class ScrolledCanvas(Tkinter.Frame):

It takes me back to the first error. Which means
in both instances both directly called by me, and
when called from the original turtle.py call,
it's not finding the Frame class.

>From the docs (9.5. Inheritance) it states:

"The name BaseClassName must be defined in a
scope containing the derived class definition.
In place of a base class name, other arbitrary
expressions are also allowed. This can be useful,
for example, when the base class is defined in another module:

class DerivedClassName(modname.BaseClassName)
"


So why does the above, from turtle.py, a standard module,
not allow this, or is their something
the module writer got wrong, or more likely, that I'm not
understanding about what it's doing?

As a sidenote, I ended up removing the from turtle import *
line from Tkinter which resolved the problem(the example I was using
didn't have a canvas, and I'm pretty sure Tkinter was defaulting
to the ScrolledCanvas).


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


[Tutor] Class Inheritance, Beat it into the Ground

2010-04-23 Thread David Hutto
In previous post I asked about  turtle module importing from tkinter.
But what I don't understand is why does Tkinter default it's casnvas
to ScrolledCanvas in turtle.py, and then as a 'metaclass' for
ScrolledCanvas in turtle it calls TK.Frame, which could have
been set as a default within Tkinter itself?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Is there a better way to use scientific notation in an equation?

2010-05-02 Thread David Hutto
In the following code I'm trying to do basic calculations with coulumb's law

#Coulombs Law
'''
F = (9*(10**9)) * (Q1*Q2) / (d**2)
'''
base = 10
Q1mult = raw_input('First enter multiplier of base 10 charge/coloumb(Q1):')
Q1exp = raw_input('Now enter exponent of base 10(Q1):')
Q1 = int(Q1mult)*(10**int(Q1exp))
Q2mult = raw_input('First enter multiplier of base 10 charge/coloumb(Q2):')
Q2exp = raw_input('Now enter exponent of base 10(Q2):')
Q2 = int(Q2mult)*(10**int(Q2exp))
d = raw_input('Enter distance of charges/coulumbs from Q1 to Q2:')



a = (9*(10**9))*((int(Q1))*(int(Q2)))/((int(d))**2)
print a
**

Q1 and Q2 are to be entered as base ten scientific notation.
When I try to input Q1 as raw input, entering in ((2*(10**7)), I get:

ValueError: invalid literal for int() with base 10: '((2)*(10**7))'

Which is why I broke it down into it's sub-components(i.e. what to
multiply the base 10 by[Q1mult] and what exponent to use with the base
10[Q1exp]).

Is there a better way to write this, and what would be the best way to
insert the
scientific notation if not this way. I know there is probably a
module, but this is
for my own practice.

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


Re: [Tutor] Question

2010-06-19 Thread David Hutto
On Sat, Jun 19, 2010 at 7:24 AM, ALAN GAULD  wrote:
>
>
>> belt, then go ahead and learn anything else you like. But even then, if you 
>> have
>> to learn two new ones at the same time, I'd recommend they be very unlike.
>> So you could learn Lisp or Forth at the same time as you were learning Ruby, 
>> but
>> I'd not try to learn Perl and Python at the same time.
>
> Actually that's a point. I favour learning two languages that are semantically
> similar buut syntactically different. Thats why I chose JavaScript and 
> VBScript
> as my tutorial languages, because the syntax of each is so different you are
> less likely to get confused, but the underlying programming model is very
> similar in each case.
>
> So with Bob's illustration of the Harley in mind I'll withdraw the suggestion 
> to
> learn Python and Ruby - because the syntax is very similar - but keep the
> Python/Lisp/Object Pascal ccombinations.
>
> Having said that I stll recommend that most folks learn one at a time. Unless
> you are the kind of person that actively prefers comparative study it will
> be better to keep to one language.
>
> Alan G
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Being an independent learner/hobbyist scholar myself, I have to wonder
what the motivation is for wanting to learn two languages. Is it just
for satisfaction to bring the dead, curious cat back, or maybe to
impress friends,, or to accomplish some task, or to understand the
technology you use better...or...

In other words, what's the reason behind your goal? Mine, for
instance, is that once I started to learn the languages, I also had a
curiosity towards the inner workings, so it seemed that the obvious
path is to move towards the lower level languages from a programming
stand point, but it also makes since to learn from the power plant
through the outlet.

I enjoy communicating with the electrons, so I want to go at it from
both ends, so if better understanding technology is your motivation,
then I say take the most well rounded, comprehensive approach to what
you want to know more about.

So, I think, the question isn't should I learn two languages, but what
is the ultimate goal of my understanding, and what is the more well
rounded means to meet this end desire.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question

2010-06-19 Thread David Hutto
On Sat, Jun 19, 2010 at 4:56 AM, Steven D'Aprano  wrote:
> On Sat, 19 Jun 2010 01:55:05 pm Independent Learner wrote:
>
>> ~I was wondering if I should try to learn 2 programming languages at
>> once, Python and C++.
>
> I don't know. That depends on you.
>
> How much time do you have to spend on learning the languages? If it's
> one hour a week, you'll have trouble learning *one* language, never
> mind two.
>
> It really depends on you, and since we don't know you, we can't answer
> that.
>
> Alan has said "No" because Python and C++ have radically different
> programming models, and suggested that you should consider two
> languages that are much more similar such as Python and Ruby. I don't
> know about that... I think I'd much rather learn two different
> languages, so that I could compartmentalise "these are Python rules"
> and "these are C++ rules", rather constantly mixing up Python and Ruby
> syntax and idioms and getting them confused. But your mileage may
> vary -- maybe you're more like Alan than me.
>
>
>> Yea I took an intro to comp sci class(like 2 years ago) and a
>> computer programming logic class(also like 2 years ago) both
>> using pseudocode
>
> Good grief! How do they teach a class in computer programming using
> pseudocode??? That's like teaching somebody to cook by handing them
> Playdough and a toy oven that doesn't even get warm!
>
>
>> and have since dabbled in C(I started a programming
>> class for school but dropped out twice after about 1/3 of  the
>> semester, for two consecutive semesters about 9 months ago) So here I
>> am, a computer engineering major failure who had to change my major
>> to Physics so I wouldn't have to take all those dammed comp sci
>> classes Figured I could just teach myself. I mention this because I
>> want to make clear I have the logic and critical thinking skills
>> down, and in my opinion the aptitude as well.
>
> I don't mean to be negative, but if you've dropped out of a programming
> course *twice*, and then changed your major to avoid programming,
> perhaps you're not cut out for programming?

I see your point, but I place quitting learning as synonymous with
quiting smoking, the higher the rate at which you go back to
something, means you have a desire to achieve the activity, so the
repetition of attempts means they have the desire, and will have a
higher 'receptive potential' than those that are forced to learn.

Obviously I don't know you,
> maybe you have good reasons for dropping out unrelated to your ability
> and intelligence, but speaking as a stranger, when you say "Hey guys, I
> have a history of dropping out of a basic programming courses, but
> don't worry, I've got the aptitude to be a programmer", it doesn't
> really fill me with confidence. Perhaps that's something you should
> keep more to yourself until *after* you've proven you do have the
> chops?
>
>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  tu...@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] Running external commands from Python

2010-06-25 Thread David Hutto
On Fri, Jun 25, 2010 at 8:16 PM, Steven D'Aprano  wrote:
> On Sat, 26 Jun 2010 08:46:17 am Randy Kao wrote:
>> Hi all,
>>
>> I'm a newbie to Python (switching from Perl) and had a question about
>> the best way to run external commands in Python.
> [...]
>> through: os.popen, os.popen2, os.popen3, os.system,
>> commands.getoutput()
>
>
> os.system is the oldest way, and it's pretty much obsolete.


Not to hijack  this thread, but why would accessing, what I(newbie
++1) know as the direct interface from python to the machine you're
on, be obsolete? Isn't this the direct way to access your machine
through the python 'application', if I'm using this term right?



Only use it
> for quick-and-dirty scripts when you're too lazy to do the right thing
> and don't care who knows it. It doesn't capture either stdin or stdout,
> only the return value.
>
> os.popen, popen2 and popen3 are probably closer to what you're used to
> in Perl. They basically differ in how many file handles they return:
>
> popen returns the external command's stdout as a file handle.
> popen2 returns (stdin, stdout)
> popen3 returns (stdin, stdout, stderr)
>
> The commands module is meant as an easier to use front end to the popen*
> functions, for times where popen* are too much and system is too
> little. If all you want is the output (stdout + stderr) of an external
> command:
>
> import commands
> output = commands.getoutput('ls -l foo*')
>
> will do the trick.
>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  tu...@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] Running external commands from Python

2010-06-25 Thread David Hutto
On Fri, Jun 25, 2010 at 9:37 PM, Randy Kao  wrote:
> Thanks for the great and quick feedback from everyone!
> That definitely clears things up.
> -Randy
> On Fri, Jun 25, 2010 at 5:16 PM, Steven D'Aprano 
> wrote:
>>
>> On Sat, 26 Jun 2010 08:46:17 am Randy Kao wrote:
>> > Hi all,
>> >
>> > I'm a newbie to Python (switching from Perl) and had a question about
>> > the best way to run external commands in Python.
>> [...]
>> > through: os.popen, os.popen2, os.popen3, os.system,
>> > commands.getoutput()
>>
>>
>> os.system is the oldest way, and it's pretty much obsolete. Only use it
>> for quick-and-dirty scripts when you're too lazy to do the right thing
>> and don't care who knows it. It doesn't capture either stdin or stdout,
>> only the return value.
>>
>> os.popen, popen2 and popen3 are probably closer to what you're used to
>> in Perl. They basically differ in how many file handles they return:
>>
>> popen returns the external command's stdout as a file handle.
>> popen2 returns (stdin, stdout)
>> popen3 returns (stdin, stdout, stderr)
>>
>> The commands module is meant as an easier to use front end to the popen*
>> functions, for times where popen* are too much and system is too
>> little. If all you want is the output (stdout + stderr) of an external
>> command:
>>
>> import commands
>> output = commands.getoutput('ls -l foo*')
>>
>> will do the trick.
>>
>>
>> --
>> Steven D'Aprano
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

And I was like...me too.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-28 Thread David Hutto
On Mon, Jun 28, 2010 at 8:32 PM, Steven D'Aprano  wrote:
> On Mon, 28 Jun 2010 10:52:03 am Richard D. Moores wrote:
>> On Sun, Jun 27, 2010 at 16:25, Steven D'Aprano 
> wrote:
>> > On Mon, 28 Jun 2010 03:07:47 am Richard D. Moores wrote:
>> >> A "feature" very important to me
>> >> is that with Gmail, my mail is just always THERE, with no need to
>> >> download it
>> >
>> > You see your email without downloading it? You don't understand how
>> > the Internet works, do you?
>>
>> I do, and I also know that you know what I meant.
>
> No, I'm afraid that I don't. You log into Gmail and your browser
> downloads the Gmail page; you click on an email, and your browser
> downloads the contents of the email in order to display it. I'm afraid
> I have no idea what you mean by not downloading your email. Perhaps you
> should try reading a 50MB email over dial-up to drive home the fact
> that you *are* downloading?
>
> The difference is that, with Gmail (or Hotmail, or Yahoo mail), you have
> to download it each time you read the email instead of just once.
>
> Particularly as this is a programming mailing list, I think it is very
> important to remember that fetching information over the Internet *is*
> downloading, and not just gloss over it as some sort of magic. There
> are Python libraries specifically for dealing with all this, and apart
> from the ability to execute Javascript, Python can do pretty much
> everything your browser does.
>
> There are two sorts of people in the world: those who think that (e.g.)
> watching a streaming video in your browser over the Internet is
> fundamentally different from "downloading", and those who know that the
> only difference is that with streaming, the browser deletes the video
> after you've watched it.

But this only matters if a)you're paying for it, not the boss b) that
there are unlimited plans available for a single monthly price, or c)
you have an 'egotistical'(meaning a professional ego/rep to maintain)
perspective on minimizing your code.

 I would think that, as programmers, we should
> be in the second group rather than the first.
>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  tu...@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] OT: need computer advice from wise Tutors

2010-06-29 Thread David Hutto
On Tue, Jun 29, 2010 at 3:48 AM, Alan Gauld  wrote:
>
> "David Hutto"  wrote
>
>> > fundamentally different from "downloading", and those who know > that
>> > the
>> > only difference is that with streaming, the browser deletes the > video
>>
>> But this only matters if a)you're paying for it, not the boss b) that
>> there are unlimited plans available for a single monthly price, or c)
>> you have an 'egotistical'(meaning a professional ego/rep to maintain)
>> perspective on minimizing your code.
>
> Or if the network is shared with other users or other applications
> since heavy downloads slow down access for every network user.
> And if your neighbour is downloading a lot of video you will notice
> the effect on your network speed.

So, the bandwidth supplied(better question for my own ISP) is like a
drop cord, even with alleged T1 connections plugged in, it drop in
accordance with usage that exceeds the max capacity even though they
sell it as it's max capacity?.

 Sometimes I watch the wave of bandwidth and wonder, but a question
seldom asked if service is satisfactory.

>
> Remember that network speeds have become the biggest single
> factor in determining application performance nowadays - it used
> to be memory and disk speed - so we as programmers need to
> be very conscious of the impact of gratuitous downloads and
> consider caching strategies etc. We can't do a lot about other
> people streaming videos other than minimise our network requirements.
> But we should at least be conscious of how network habits affect
> other users.
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  tu...@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] OT: need computer advice from wise Tutors

2010-06-29 Thread David Hutto
On Tue, Jun 29, 2010 at 11:11 AM, Alan Gauld  wrote:
> "David Hutto"  wrote
>
>> > Or if the network is shared with other users or other applications
>>
>> So, the bandwidth supplied(better question for my own ISP) is like a
>> drop cord, even with alleged T1 connections plugged in, it drop in
>> accordance with usage that exceeds the max capacity even though they
>> sell it as it's max capacity?.
>
> It depends on the access mechanism. If its a T1 link then it is a
> dedicated line for your own use and not shared by anyone - although
> the server/router its connected to at the ISP may well be!
>
> If its a typical ADSL line it will be conneced to a DSLAM at the
> centeral office(by the telco) and  that will be shareed. So a typical
> consumer line has a ratio of 50:1 users. A business line might be
> only 10:1 or 20:1. This works on the assumption that most users
> spend more time reading than downooading the content. As we
> move to streaming data sources that assumption becomes invalid
> and the DSLAM bandwidth is effectively shared.
>
> ADSL also loses bandwidth the further you are from the office so what
> is sold as an 8Mb line will rarely give more than 5-6Mb and may be
> as low as 1 or 2. But that is mostly a physical limitation on the
> copper cables used. And finally, the 'A' in ADSL stands for asymmetric
> so the upload speed it usually only a fraction of the download speed,
> often only a few hundred kilobits/sec. Even with ADSL+ (20M+) the
> upload speed is usually less than 1Mb. That means that a 1MB(yte)
> document may only take 1-2 sec to download but take 10s+ to
> upload (why sending mail is usually much slower than receiving)
>
> Alan G.
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

But the process has to be diversified for each customer, because it
all travels at the speed of light. I recall from way back in the day,
that cable boxes sometimes had a weak signal depending on the distance
from the consumer. This signal could be modified from the cable
company, so the box amplified the 'weak', but not further away,
signal.

So this would also be a matter of what was being sent/received being
modified, depending on the priority(given by the ISP provider) of the
current DSL(or whatever connection) consumer? So I'm guessing this
would be determined on the basis of recent usage, as to the priority
of the sending or downloading, correct?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-30 Thread David Hutto
On Wed, Jun 30, 2010 at 3:06 AM, ALAN GAULD  wrote:
>
>
>> > If its a typical ADSL line it will be conneced to a DSLAM at
>> > the centeral office(by the telco) and  that will be shareed.
>>
>> > ADSL also loses bandwidth the further you are from the office
>
>> process has to be diversified for each customer, because it
>> all travels at the speed of light.
>
> It is diversified on the individual line leading to your house
> but it is shared from wherever it gets converted to a digital
> multiplex. That could be at the roadside cabinet or at the
> central office. At that point the data is mixed together
> using a round-robin type algorithm. The more active signals
> that are present the lower the proportion of the total bandwidth
> available to each.
>
> The speed of transmission is not really relevant (it only affects
> transit time not bandwidth) although it is as you say the
> speed of light (but not the speed of light in a vacuum, much
> lower than that) within the bearer. However within the electronics
> the signal travels more slowly - around the speed of sound - but
> fortunately for very small distances.
>
>> sometimes had a weak signal depending on the distance
>> from the consumer. This signal could be modified from the cable
>> company, so the box amplified the 'weak', but not further away,
>> signal.
>
> Its not a matter of signal strength but of signal smearing as it
> travels along the line. The digital data is sent as pulses (a great
> simplification!) but those pulses lose their shape as they travel
> along the line until eventually the electronics cannot distinguish
> one from another. The only way to improve is to send the
> pulses more widely spaced, which reduces the bandwidth,
> or to have repeater boxes which regenerate the pulses at
> regular intervals. On long distance routes, between cities, the
> telco will install repeaters but for domestic use they progressively
> reduce the bandwidth.
>
>> So this would also be a matter of what was being sent/received
>> being modified, depending on the priority (given by the ISP provider)
>> of the current DSL (or whatever connection) consumer?
>
> No, it doesn't matter what priority the comnsumer has it is down
> to the physical characteristics of the line. Telcos typically use
> copper or aluminium conductors in the local lines with paper
> or PTFE insulation and either crimped, twisted or soldered joints.
> All of these affect the transmission characteristics but the biggest
> factor is the length of the line. Its not economical to install
> repeaters in every consumer line so the bandwidth must be
> adjusted to match what the line is capable of. (This is done
> dynamically so you may even find your bandwidth varies slightly
> depending on the weather!) In practice it should be fairly stable
> and the biggest variations will be due to contention at the
> DSLAM.
>
> HTH,
>
> Alan G.
> (Who works for a telco! :-)
>
>

Thanks for taking the time to answer, and sorry for somewhat hijacking
the op's thread.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Reading a file

2010-07-02 Thread David Hutto
In the code below, I'm trying to read from a file, and print out the lines.
I know I've seen the exact function I'm looking for here, but it seems
like the below 'should' work.

The second function(rdfil) works, if just the line number is placed
there, and th first(increment) works for printing a new number in
range for the rdfil to operate while going through the lines in the
file.
Any other options other than using linecache.getline(I'm sure there
are, just haven't jogged the right memory cell loose yet)?

def increment():
for number in range(1, 500):
print number ++1

def rdfil():
outputfile = raw_input('Input file name: ')
for line in outputfile:
if line:
readcont = linecache.getline(outputfile, increment) 
'''increment is
originally supposed to be an int for the line number being read'''
print readcont

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


Re: [Tutor] Reading a file

2010-07-02 Thread David Hutto
On Fri, Jul 2, 2010 at 11:31 AM, Steven D'Aprano  wrote:
> On Fri, 2 Jul 2010 11:16:02 pm David Hutto wrote:
>> In the code below, I'm trying to read from a file, and print out the
>> lines.
>
> f = open("filename.txt")
> for line in f:
>    print line
> f.close()
>
> is all you need, and even the close at the end is optional (but
> recommended).
>
>
>> I know I've seen the exact function I'm looking for here, but
>> it seems like the below 'should' work.
>>
>> The second function(rdfil) works, if just the line number is placed
>> there, and th first(increment) works for printing a new number in
>> range for the rdfil to operate while going through the lines in the
>> file.
>> Any other options other than using linecache.getline(I'm sure there
>> are, just haven't jogged the right memory cell loose yet)?
>>
>> def increment():
>>       for number in range(1, 500):
>>               print number ++1
>
> Why do you have number ++1 instead of just number+1 ?
>
> For that matter, why do you have number+1 instead of changing the range
> to range(2, 501)?

I was 'thinking' that since it worked in the interpreter as printing
the numbers 1-500 , it would cycle through to the linecache.getline's
number of line variable that it calls when it went back through each
time. It might be better explained as to what I thought it was doing.

>
>
>> def rdfil():
>>       outputfile = raw_input('Input file name: ')
>
> This puts a *string* in the variable outputfile. A better name would
> be "outputfilename", because it is a file NAME, not a file.
>
>>       for line in outputfile:
>
> This is terribly misleading, because iterating over a string gives you
> the individual characters of the string, not lines. E.g.:>
> for line in "file.txt":
>    print line
>
> will print:
>
> f
> i
> l
> e
> .
> t
> x
> t
>
>>               if line:
>
> This will always be true, and so is pointless. Even an empty line is not
> truly empty, as it will be a newline character. When the file is empty,
> the for-loop will exit.

This what I thought would happen for the each line, and it would only
loop through until it hit a 'non-assigned' line, which would stop the
call of the for range function, and stop telling the getline to spit
out a new number in range.

Here is where using the above worked and why I added it to the function:

da...@david-laptop:~/Documents/inprogress/projectsmain/Python Projects$ python
Python 2.6.4 (r264:75706, Dec  7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import linecache
>>> readcont = linecache.getline('/home/david/testmkfile.txt', 1)
>>> print readcont
abcdefghijklmnopqrstuvwxyz123456789...@#$%^&*()_+~

>>>

the for line in was added after to the function in an app(which is
where it's being called from) , and I assumed it would go through the
file line by line like that. I could have checked the function better
before placing it to be called by the app.

>
>>                       readcont = linecache.getline(outputfile, increment) 
>> '''increment
>> is originally supposed to be an int for the line number being read'''
>
> This line gives a syntax error. What is it supposed to be? What is the
> purpose of the string? It looks like it is meant to be a comment, but
> why have you written it as a string instead of a # comment?

I started with the #, it was added at the time of the email to explain
why the variable was there and not a numerical line number. At the
last second I added it because I thought if you copied and pasted it,
it would consume more than a one line comment for the person copying
due to the wordwrap.

>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


Thanks, for the memory jog, and snippet though.

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


Re: [Tutor] Help with choices for new database program

2010-07-02 Thread David Hutto
On Fri, Jul 2, 2010 at 8:56 PM, Jeff Johnson  wrote:
> On 07/02/2010 05:35 PM, Chris C. wrote:
>
> Hi Jeff, thank for your reply!  I’m aware of Dabo and was pretty much sold
> on using it until the last couple of days.  I was trying to install it so I
> could start connecting to my tables when I ran into a problem with the
> instructions for installing ReportLab.  I wrote to the mailing list
> Wednesday but haven’t heard from anyone.  Being such a  beginner and knowing
> I’ll be needing help, it kind of has me wary of committing to Dabo when I’m
> having this trouble getting help before I even get started.  I saw your post
> to the Dabo mailing list with the title “Reference to bizjob control” has
> been getting responses.  Can you confirm whether my question went out to the
> list recipients?  Did you receive it?

Stick to the main python libraries(python with sqllite, and for the
standalone exe know it's somewhere, and I've seen it in the past few
days, but didn't pay attention because it wasn't important to what I
was doing at the time) going anywhere else is the beginning of an ADHD
nightmare. It's like being a hypochondriac with an unlimited
healthcare plan, you'll want to see any option except for the obvious
in front of you.

Try not to get distracted by the shiny things unless necessary.

>
>
>
> Like I was saying, I wanted to use Dabo, but I submitted this question to
> this board because I was beginning to lose faith in being able to get help
> from the Dabo mailing list.
>
>
>
> Thanks again,
>
> Chris C.
>
>
>
>
>
> From: Jeff Johnson [mailto:j...@dcsoftware.com]
> Sent: Friday, July 02, 2010 2:09 PM
> To: Chris C.
> Subject: Re: [Tutor] Help with choices for new database program
>
>
>
> On 07/02/2010 11:40 AM, Chris C. wrote: I’m writing this question because I
> want, for my own satisfaction, to rewrite one of my Access dbs (one that
> does our finances) into a stand-alone Python database program using SQLite.
> I know I’ll be learning as I go, but that’ll work, I’m not in a big hurry
> and I’ll work on it in my spare time.  Right now I’m trying to get organized
> and get a game plan, and that’s where I need help.
>
> I have been developing database applications for 20 years using FoxPro and
> VFP.  Now I am developing using Dabo.  Dabo is a framework wrapper for
> wxPython written totally in Python.  I use SQLite for small applications and
> PostgreSQL for larger ones.  Dabo was written by two of the top FoxPro
> developers and is supported by many others all over the world.
>
> http://dabodev.com/
>
> Please check it out.  And go to www.leafe.com and subscribe to the dabo-user
> email list.
>
> --
>
> Jeff
>
>
>
> ---
>
>
>
> Jeff Johnson
>
> j...@dcsoftware.com
>
>
>
> Chris:  The folks on the Dabo list are always available for answers.  Ed and
> Paul (Dabo's developers) are always quick to answer questions and I
> guarantee they respond quicker than most lists.  There are many others that
> develop commercial applications with Dabo that are always monitoring the
> list (just like me only more experienced with Dabo and Python).  If you are
> interested please subscribe to the list:
>
> http://www.leafe.com/mailman/listinfo/dabo-users
>
> I did not see your post on the list so no one else did either.  If you
> developed an app using Access than you are a perfect candidate for Dabo and
> you have at least enough understanding of what is going on to use it.
>
> There are four things that need installing in order to use Dabo.  It may not
> go as smooth as a Windows Installshield application, but you can get plenty
> of help and once it is installed you can follow the great screen casts and
> tutorials.  The users of Dabo are developing applications for users.  Once
> you have your application developed there are ways to package it based on
> your platform.
>
> You need Python, wxPython, Dabo, and Report Lab.  You can install PIL if you
> want to manipulate images.  If you need help, just ask!
>
> Many of the people using Dabo are moving over from Visual FoxPro which is
> very similar to Access, so don't be afraid to ask any question.  If you ask
> a question the question and answer will be saved in the archives for others
> to learn.
>
> Come on in, the water is fine!
>
> --
> Jeff
>
> ---
>
> Jeff Johnson
> j...@san-dc.com
> (623) 582-0323
>
> www.san-dc.com
>
> --
> Jeff
>
> ---
>
> Jeff Johnson
> j...@dcsoftware.com
>
>
>
> ___
> Tutor maillist  -  tu...@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] Help with choices for new database program

2010-07-02 Thread David Hutto
On Fri, Jul 2, 2010 at 9:27 PM, Jeff Johnson  wrote:
> On 07/02/2010 06:14 PM, David Hutto wrote:
>>
>> Stick to the main python libraries(python with sqllite, and for the
>> standalone exe know it's somewhere, and I've seen it in the past few
>> days, but didn't pay attention because it wasn't important to what I
>> was doing at the time) going anywhere else is the beginning of an ADHD
>> nightmare. It's like being a hypochondriac with an unlimited
>> healthcare plan, you'll want to see any option except for the obvious
>> in front of you.
>>
>> Try not to get distracted by the shiny things unless necessary.
>>
>
> I'm not sure how this helps with Chris's application.  I will agree that the
> number of choices is daunting!  The nice thing about Dabo is the group is
> focused on database applications.  Kind of like Django is focused on web
> devopment.

Well, it was mainly that he said he was a beginner and was only using
this for a single banking project, I do believe.

Not that learning a new package would be helpful, I like
experimenting, and failing/succeeding, but if this is all he needs to
accomplish, then not using more than is necessary would be beneficial.
A simple script, with simple sqlite fields to maintain.

>
> I mean this in a joking way:  If you find that Python and open source
> creates too many decisions then you can consider Microsoft .NET and
> Microsoft SQL Server on Windows 7.
>
> I am a recovering Microsoft developer of over 20 years.  ;^)
>
> BTW learning Python is awesome!
>
> --
>
> Jeff
>
> ---
>
> Jeff Johnson
> j...@san-dc.com
> (623) 582-0323
>
> www.san-dc.com
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with choices for new database program

2010-07-02 Thread David Hutto
On Fri, Jul 2, 2010 at 9:31 PM, David Hutto  wrote:
> On Fri, Jul 2, 2010 at 9:27 PM, Jeff Johnson  wrote:
>> On 07/02/2010 06:14 PM, David Hutto wrote:
>>>
>>> Stick to the main python libraries(python with sqllite, and for the
>>> standalone exe know it's somewhere, and I've seen it in the past few
>>> days, but didn't pay attention because it wasn't important to what I
>>> was doing at the time) going anywhere else is the beginning of an ADHD
>>> nightmare. It's like being a hypochondriac with an unlimited
>>> healthcare plan, you'll want to see any option except for the obvious
>>> in front of you.
>>>
>>> Try not to get distracted by the shiny things unless necessary.
>>>
>>
>> I'm not sure how this helps with Chris's application.  I will agree that the
>> number of choices is daunting!  The nice thing about Dabo is the group is
>> focused on database applications.  Kind of like Django is focused on web
>> devopment.
>
> Well, it was mainly that he said he was a beginner and was only using
> this for a single banking project, I do believe.
>
> Not that learning a new package would

wouldn't


 be helpful, I like
> experimenting, and failing/succeeding, but if this is all he needs to
> accomplish, then not using more than is necessary would be beneficial.
> A simple script, with simple sqlite fields to maintain.
>
>>
>> I mean this in a joking way:  If you find that Python and open source
>> creates too many decisions then you can consider Microsoft .NET and
>> Microsoft SQL Server on Windows 7.
>>
>> I am a recovering Microsoft developer of over 20 years.  ;^)
>>
>> BTW learning Python is awesome!
>>
>> --
>>
>> Jeff
>>
>> ---
>>
>> Jeff Johnson
>> j...@san-dc.com
>> (623) 582-0323
>>
>> www.san-dc.com
>>
>>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with choices for new database program

2010-07-02 Thread David Hutto
On Fri, Jul 2, 2010 at 9:44 PM, Jeff Johnson  wrote:
> On 07/02/2010 06:32 PM, David Hutto wrote:
>>
>> On Fri, Jul 2, 2010 at 9:31 PM, David Hutto  wrote:
>>
>>>
>>> Well, it was mainly that he said he was a beginner and was only using
>>> this for a single banking project, I do believe.
>>>
>>> Not that learning a new package would
>>
>> wouldn't
>>
>>
>>  be helpful, I like
>>
>>>
>>> experimenting, and failing/succeeding, but if this is all he needs to
>>> accomplish, then not using more than is necessary would be beneficial.
>>> A simple script, with simple sqlite fields to maintain.
>>>
>>>
>
> David:  Experimenting, failing and succeeding is the life of a programmer.
>  I have been programming for many years in assemply, FORTRAN, COBOL, Basic,
> RPG, FoxPro, C, but I am now totally committed to Python.  It is the best of
> all worlds.  Coming from the Microsoft side, open source and Python creates
> a whole new set of problems.  Do I use Windows?  Do I use Linux?  Do I use
> my Mac Book Pro?  You do have to make some decisions before moving on.  The
> choices are endless.
>
> I have found Dabo and Django to be beneficial for me because they target
> what I want to do.
>
> Your mileage may vary.  ;^)


In the end, there might be so many packages, I might not be able to
handle it all(for my own uses). But, I would think, you would agree
that a simple account balance app, would be no more than tkinter with
a few functions to write and retrieve data from a sqlite db. To quote
Sherlock, 'Sometimes, after eliminating the impossible, what ever is
left, no matter how improbable, must be the solution.', or something
like that.


>
> --
> Jeff
>
> ---
>
> Jeff Johnson
> j...@san-dc.com
> (623) 582-0323
>
> www.san-dc.com
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with choices for new database program

2010-07-02 Thread David Hutto
On Fri, Jul 2, 2010 at 9:55 PM, Jeff Johnson  wrote:
> On 07/02/2010 06:51 PM, David Hutto wrote:
>>
>> In the end, there might be so many packages, I might not be able to
>> handle it all(for my own uses). But, I would think, you would agree
>> that a simple account balance app, would be no more than tkinter with
>> a few functions to write and retrieve data from a sqlite db. To quote
>> Sherlock, 'Sometimes, after eliminating the impossible, what ever is
>> left, no matter how improbable, must be the solution.', or something
>> like that.
>>
>
> David:  I like your quote!  I am a huge Sherlock Holmes fan.  I like Dabo
> because I develop commercial applications.

'I love to develop relatively operational residential programs that
quasi-suit my own purpose', I said sarcastically. 'So hopefully I'll
join the commercial, then industrial one day', I said optimistically,
looking pessimistically up at the sky, while lazily, daydreaming
blurred images of the future.

>
> --
> Jeff
>
> ---
>
> Jeff Johnson
> j...@dcsoftware.com
>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with choices for new database program

2010-07-02 Thread David Hutto
On Fri, Jul 2, 2010 at 10:01 PM, David Hutto  wrote:
> On Fri, Jul 2, 2010 at 9:55 PM, Jeff Johnson  wrote:
>> On 07/02/2010 06:51 PM, David Hutto wrote:
>>>
>>> In the end, there might be so many packages, I might not be able to
>>> handle it all(for my own uses). But, I would think, you would agree
>>> that a simple account balance app, would be no more than tkinter with
>>> a few functions to write and retrieve data from a sqlite db. To quote
>>> Sherlock, 'Sometimes, after eliminating the impossible, what ever is
>>> left, no matter how improbable, must be the solution.', or something
>>> like that.
>>>
>>
>> David:  I like your quote!  I am a huge Sherlock Holmes fan.  I like Dabo
>> because I develop commercial applications.
>
> 'I love to develop relatively operational residential programs that
> quasi-suit my own purpose', I said sarcastically. 'So hopefully I'll
> join the commercial, then industrial one day', I said optimistically,
> looking pessimistically up at the sky, while lazily, daydreaming
> blurred images of the future.
>
>>
>> --
>> Jeff
>>
>> ---
>>
>> Jeff Johnson
>> j...@dcsoftware.com
>>
>>
>>
>

But...maybe actually accessing the bank account url and logging in,
then checking, might be made easier by those you suggested. What would
be the ultimate intent of the developer of the app?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with choices for new database program

2010-07-02 Thread David Hutto
On Fri, Jul 2, 2010 at 10:07 PM, David Hutto  wrote:
> On Fri, Jul 2, 2010 at 10:01 PM, David Hutto  wrote:
>> On Fri, Jul 2, 2010 at 9:55 PM, Jeff Johnson  wrote:
>>> On 07/02/2010 06:51 PM, David Hutto wrote:
>>>>
>>>> In the end, there might be so many packages, I might not be able to
>>>> handle it all(for my own uses). But, I would think, you would agree
>>>> that a simple account balance app, would be no more than tkinter with
>>>> a few functions to write and retrieve data from a sqlite db. To quote
>>>> Sherlock, 'Sometimes, after eliminating the impossible, what ever is
>>>> left, no matter how improbable, must be the solution.', or something
>>>> like that.
>>>>
>>>
>>> David:  I like your quote!  I am a huge Sherlock Holmes fan.  I like Dabo
>>> because I develop commercial applications.
>>
>> 'I love to develop relatively operational residential programs that
>> quasi-suit my own purpose', I said sarcastically. 'So hopefully I'll
>> join the commercial, then industrial one day', I said optimistically,
>> looking pessimistically up at the sky, while lazily, daydreaming
>> blurred images of the future.
>>
>>>
>>> --
>>> Jeff
>>>
>>> ---
>>>
>>> Jeff Johnson
>>> j...@dcsoftware.com
>>>
>>>
>>>
>>
>
> But...maybe actually accessing the bank account url and logging in,
> then checking, might be made easier by those you suggested. What would
> be the ultimate intent of the developer of the app?
>
Or maybe more extensive, in detail documentation?

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


Re: [Tutor] Help with choices for new database program

2010-07-02 Thread David Hutto
On Fri, Jul 2, 2010 at 10:10 PM, David Hutto  wrote:
> On Fri, Jul 2, 2010 at 10:07 PM, David Hutto  wrote:
>> On Fri, Jul 2, 2010 at 10:01 PM, David Hutto  wrote:
>>> On Fri, Jul 2, 2010 at 9:55 PM, Jeff Johnson  wrote:
>>>> On 07/02/2010 06:51 PM, David Hutto wrote:
>>>>>
>>>>> In the end, there might be so many packages, I might not be able to
>>>>> handle it all(for my own uses). But, I would think, you would agree
>>>>> that a simple account balance app, would be no more than tkinter with
>>>>> a few functions to write and retrieve data from a sqlite db. To quote
>>>>> Sherlock, 'Sometimes, after eliminating the impossible, what ever is
>>>>> left, no matter how improbable, must be the solution.', or something
>>>>> like that.
>>>>>
>>>>
>>>> David:  I like your quote!  I am a huge Sherlock Holmes fan.  I like Dabo
>>>> because I develop commercial applications.
>>>
>>> 'I love to develop relatively operational residential programs that
>>> quasi-suit my own purpose', I said sarcastically. 'So hopefully I'll
>>> join the commercial, then industrial one day', I said optimistically,
>>> looking pessimistically up at the sky, while lazily, daydreaming
>>> blurred images of the future.
>>>
>>>>
>>>> --
>>>> Jeff
>>>>
>>>> ---
>>>>
>>>> Jeff Johnson
>>>> j...@dcsoftware.com
>>>>
>>>>
>>>>
>>>
>>
>> But...maybe actually accessing the bank account url and logging in,
>> then checking, might be made easier by those you suggested. What would
>> be the ultimate intent of the developer of the app?
>>
> Or maybe more extensive, in detail documentation?
>
> Sell me and the OP.
>

Actually do, because I have a payment transaction app I've been
thinking about(for personal development, not intentional business
use), that would incorporate something like that for interaction with
several banking accounts from several banks/financial institutions.
So, is there anything in there that would help me and the OP by
actually logging in to the site. And I can, newbie think, about
several ways, but haven't gotten to the specifics. But it does apply,
I think to the OP's question.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python Documentation Clarification

2010-07-12 Thread David Hutto
On Mon, Jul 12, 2010 at 10:49 AM, Huy Ton That  wrote:
> This is going to sound silly, but I realized there are some areas within the
> documentation that do not make absolute sense to me.
> e.g.
> compile(source, filename, mode[, flags[, dont_inherit]])
> I see within this built in function, the first argument can be what they
> define as source, the second argument as the filename and the third as the
> mode.
> But what confuses me is sometimes I see a bracket, above as [, flags[,
> dont_inherit]]. Is this an optional argument like flags=dont_inherit?
> Just not grokking it correctly and I can't seem to track down where the
> documentation formatting is defined within the python.org documentation...
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

From

http://docs.python.org/tutorial/datastructures.html

is this :
'(The square brackets around the i in the method signature denote that
the parameter is optional, not that you should type square brackets at
that position. You will see this notation frequently in the Python
Library Reference.)'
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Request for help learning the right way to deal with lists in lists

2010-07-12 Thread David Hutto
On Mon, Jul 12, 2010 at 9:45 PM, Eric Hamiter  wrote:

> I'm fairly new to programming and Python as well, but I have a suggestion
> that may be worth looking into-- are you familiar with pickling? It sounds
> like something that may fit in well with what you're trying to do.
>
> Good reference article:
>
> http://articles.techrepublic.com.com/5100-10878_11-1052190.html
>
>
> I'm new to python too, but I'd suggest using sqlite ,and entering uploading
the specific pages as text files, and then calling them from the name and
stored file their listed as being in in the db. As it seems now, you're just
listing book names and numbers(or maybe I didn't read more into what you
want to do).


>
> On Mon, Jul 12, 2010 at 5:19 PM, Siren Saren  wrote:
>
>> I'm still fairly new to programming.  Python is my first language and I am
>> teaching myself as best I can.  I'm struggling with a situation that I
>> expect must come up all the time.  I can come up with relatively complicated
>> solutions but I wonder if there's not a more pythonic way of doing it.
>>
>> I've seen a lot of examples in books for dealing with lists of alternating
>> data types, but what about a list that doesn't follow a simple numeric
>> pattern?  For example, say I have a list that's a composite of two elements:
>> books and key pages / albums and favorite tracks / medicines and times
>> taken, whatever.  To make a program that does something to the first set of
>> elements based on the second set of elements, what kind of structure should
>> I set up?
>>
>> Probably easier to choose one of these.  So pretend I have a list like
>> this:
>>
>> (Crime and punishment, page 10, page 40, page 30, Brother's Karamazov,
>> page 22, page 55, page 9000, Father's and Sons, page 100, Anna Karenina,
>> page 1, page 2, page 4, page 7, page 9)
>>
>> Since I can identify the elements and since I know the values are 'in
>> order,' in other words the page numbers between the first and second book
>> all belong to the first book, I can make a mapping.  But I've been surprised
>> at the complexity.  So in this hypothetical, with a regular expression, I
>> can easily convert the pages to integers, and identify the two lists.  But
>> what's the right way to map them to each other, if I am planning to, for
>> example, tear out these key pages and make a wall hanging.  (I would never
>> do this with precious books like these, of course).  Am I right to think
>> that I want to get them into a form that clearly relates them to each other
>> from the outset?  Does a dictionary make sense-- I've read that I should
>> expect to put a lot of my data into dictionaries?
>>
>> My tentative approach has been as follows:
>>
>> a. Make a sublist of the Books.  Here we could just get the non-integers
>> so Books = ('C and P', 'Brothers K' ...)
>> b. Look each up book in the main list to get an index values
>> c.  Now my approach becomes ugly.  In pseudo code-
>>
>> For book in Books:
>> A dictionary should map the book to a list of all the elements in the
>> main list that fall between the book's index value and the next book's index
>> value
>>
>> I keep coming up with embedded loops to express this but I simultaneously
>> feel like I am missing a third layer (somehow maybe it's 'for book,' 'for
>> index,' 'for element'?) and like Occham is going to come by with his razor
>> and laugh at me and say, "oh there's a function that does this called the
>> "one to many mapping function."
>>
>> I think I'm reading the right books and going to the right web pages and
>> such to learn, but in this case, I must have just not comprehended.  Would
>> be grateful for any input.  Have enjoyed reading the archives of this group
>> as I've been trying to get my head around programming.  Thanks again
>>
>> Soren
>>
>>
>
> ___
> 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] Response to responses about list of lists: a meta exercise in mailinglist recursion

2010-07-13 Thread David Hutto
On Tue, Jul 13, 2010 at 8:40 AM, Siren Saren  wrote:

> I'm not sure if there's a way to submit responses 'live' or whether it's
> better to respond to subthreads at once or together, so I'll err on the side
> of discretion and just send one response.  Thanks to each of you who tried
> to help me.  I've responded individually below.
>
>
>  To summarize the discussion so far:
>
>
> I wondered if there was a decent way to sort a list that contained two
> lists, where each could be distinguished based on the list's sequence and
> the elements' data characteristics.  As a subsidiary question, I wondered
> if there was a data structure I should aspire to put the data into once I
> had it sorted.
>
>
> In response to the first question: the consensus seems to be that there is
> no good way to sort a non-alternating one-to-many list like this, so my
> strategy of deriving the index numbers of every item, as awkward as it
> appears, may actually be the best approach.
>
>
>  In response to the second: a pickle, a dictionary, a database, and a
> tuple with a sublist were all proposed.The choice seems somewhat
> arbitrary, but on the bright side, I suppose that also confirms that I have
> a lot of flexibility in what I choose.
>
>
> Specific responses:
>
>
> Steven,
>
> I apologize for using 'reply,' I've never used a mailing list before and
> didn't understand what would happen.  Is there some online forum where I
> could post a message directly rather than mailing it in?  I see that other
> people are somehow responding to my message from the more real-time updates
> I can get on activestate, but I don't know how they are doing it since I
> haven't received the mailing yet that would include my message and its
> responses.
>
> If my list had a million books in it and 10 million page numbers, would the
> approach I've outlined in my initial post be the best for sorting them?  Like
> David and Eric you've given me some good input on a data structure to use.
> If I understand you right, you'd advocate using a tuple of the books,
> bookmarks, where the bookmarks themselves are sublists.
>
>
> David, Yes, I agree it would  be much better to store the data in a
> different manner.  The problem is that I'm not the creator of the data.
>

This, again is a newbie statement but maybe importing re or regular
expressions to parse the known files would be helpful.

The way I'm thinking is that you put your books in a directory. Now, that
directory could contain directories of books with the individual text pages
within those book's directories, or something like a pdf.


Within these documents or directories, you search with an app for those
specific files. Now you can either list within the app those books and pages
and then search the directories, or you could search the directories first
and list the books, then specify the page you want to go to.

My DB idea would work if you placed in an ID, a page number, then a location
to the text file , or stored the text in the sqlite DB globfield .

> Maybe you realize that and are just suggesting the database structure
> rather than a dictionary or a pickle, once I get my sorting accomplished?
> If the book example is confusing how about this.  Say you discovered a
> bunch of data in a secret code document.  You know the sequence of the
> data relates the elements to each other.  You also know there are just two
> elements and that the sequence is a straightforward function of say,
> integers to letters.  So the data you've discovered looks like:
>
>
> A 2 3 B 4 7 5 9 1 C 3 2 1 0 0 4 D 3 3 32 44 ...
>
>
> Once I've sorted the data, I am curious how to best store it (and why), and
> your answer does pertain to that-- use sql--
>

Not just sql, but maybe, and dicts/lists are not my specialty yet, but
utilize it in the process. The main objective of utilizing the DB, in MHO,
is that it forces you to state the information you want to use, so this
refines your code, by defining the fields you must use to state and store
the data. So you have a book, and a page, and a author, and an id to match
these with.

Now you could use an app to search the 'book' directory, and then  'for each
in' print the book containing folder's name., then open() the page and could
go further to bring up the exact line/paragraph of the individual page.

> but I am also curious if there's a less arcane approach than the one I'm
> using to try to do the initial sorting.  Any thoughts, given that I can't
> fix the way the data arrives?  Thanks for the database idea regardless.
>
>
>
This again would be regular expressions, as far as I'm thinking, import re,
help(re) or dir(re), or pydoc re, or something like that. You parse the
book's file or directory, and look for the tags to read out the book's name,
author or page, and then you can just select the book, type in the page
number, or select from a predetermined list of pages that have explanations
as to why you should visit the page, or read the text.


> Eric

Re: [Tutor] Response to responses about list of lists: a meta exercise in mailinglist recursion

2010-07-13 Thread David Hutto
On Tue, Jul 13, 2010 at 1:20 PM, David Hutto  wrote:

>
>
> On Tue, Jul 13, 2010 at 8:40 AM, Siren Saren  wrote:
>
>>  I'm not sure if there's a way to submit responses 'live' or whether it's
>> better to respond to subthreads at once or together, so I'll err on the side
>> of discretion and just send one response.  Thanks to each of you who
>> tried to help me.  I've responded individually below.
>>
>>
>>  To summarize the discussion so far:
>>
>>
>> I wondered if there was a decent way to sort a list that contained two
>> lists, where each could be distinguished based on the list's sequence and
>> the elements' data characteristics.  As a subsidiary question, I wondered
>> if there was a data structure I should aspire to put the data into once I
>> had it sorted.
>>
>>
>> In response to the first question: the consensus seems to be that there is
>> no good way to sort a non-alternating one-to-many list like this, so my
>> strategy of deriving the index numbers of every item, as awkward as it
>> appears, may actually be the best approach.
>>
>>
>>  In response to the second: a pickle, a dictionary, a database, and a
>> tuple with a sublist were all proposed.The choice seems somewhat
>> arbitrary, but on the bright side, I suppose that also confirms that I have
>> a lot of flexibility in what I choose.
>>
>>
>> Specific responses:
>>
>>
>> Steven,
>>
>> I apologize for using 'reply,' I've never used a mailing list before and
>> didn't understand what would happen.  Is there some online forum where I
>> could post a message directly rather than mailing it in?  I see that
>> other people are somehow responding to my message from the more real-time
>> updates I can get on activestate, but I don't know how they are doing it
>> since I haven't received the mailing yet that would include my message and
>> its responses.
>>
>> If my list had a million books in it and 10 million page numbers, would
>> the approach I've outlined in my initial post be the best for sorting them?
>> Like David and Eric you've given me some good input on a data structure to
>> use.  If I understand you right, you'd advocate using a tuple of the
>> books, bookmarks, where the bookmarks themselves are sublists.
>>
>>
>> David, Yes, I agree it would  be much better to store the data in a
>> different manner.  The problem is that I'm not the creator of the data.
>>
>
> This, again is a newbie statement but maybe importing re or regular
> expressions to parse the known files would be helpful.
>
> The way I'm thinking is that you put your books in a directory. Now, that
> directory could contain directories of books with the individual text pages
> within those book's directories, or something like a pdf.
>
>
> Within these documents or directories, you search with an app for those
> specific files. Now you can either list within the app those books and pages
> and then search the directories, or you could search the directories first
> and list the books, then specify the page you want to go to.
>
> My DB idea would work if you placed in an ID, a page number, then a
> location to the text file , or stored the text in the sqlite DB globfield .
>
>>  Maybe you realize that and are just suggesting the database structure
>> rather than a dictionary or a pickle, once I get my sorting accomplished?
>> If the book example is confusing how about this.  Say you discovered a
>> bunch of data in a secret code document.  You know the sequence of the
>> data relates the elements to each other.  You also know there are just
>> two elements and that the sequence is a straightforward function of say,
>> integers to letters.  So the data you've discovered looks like:
>>
>>
>> A 2 3 B 4 7 5 9 1 C 3 2 1 0 0 4 D 3 3 32 44 ...
>>
>>
>> Once I've sorted the data, I am curious how to best store it (and why),
>> and your answer does pertain to that-- use sql--
>>
>
> Not just sql, but maybe, and dicts/lists are not my specialty yet, but
> utilize it in the process. The main objective of utilizing the DB, in MHO,
> is that it forces you to state the information you want to use, so this
> refines your code, by defining the fields you must use to state and store
> the data. So you have a book, and a page, and a author, and an id to match
> these with.
>
> Now you could use an app to search the 'book' directory, and then  'for
> each in' print the b

Re: [Tutor] Python Book recomandation!

2010-07-15 Thread David Hutto
On Thu, Jul 15, 2010 at 5:22 PM, Eric Hamiter  wrote:
> Hi Daniel,
>
> As a fellow complete beginner, I have actually started a web site that
> details just this. I'm learning as I go and have tried to put together
> a curriculum of sorts that will helpfully guide other newbies as well,
> and reinforce what I'm learning for myself.
>
> http://letslearnpython.com/
>
> Pardon my own plug, but you are exactly the audience member I am
> targeting. Everything I recommend with the exception of a paperback
> book is free to access. I'm adding more "lessons" as I go, and
> hopefully as I progress, I can make more specific recommendations.
>
> You are off to a great start by asking this list; I've found the
> people here are very friendly and extremely knowledgeable.
>
> Thanks,
>
> Eric
>
>
> On Thu, Jul 15, 2010 at 4:07 PM, Daniel  wrote:
>> Hello, I recently browsed the BeginnersGuide/NonProgrammers section of the
>> Python website, but I have a question regarding it. With what book I should
>> start learning Python? Or should I take them in the order they are presented
>> there on the website?I have no previous programming experience, thanks.
>>
>>
>>
>> Have a great day!
>>
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

I've done several, including Byte Of  Python, as well as Dive into
python, and this is the best so far:

inventwithpython.com/IYOCGwP_book1.pdf

Although each individually might not make you an immediate expert.
Each helps you gain knowledge by repeating some of what you know, and
then offering a different program in which these fundamentals operate.

 So the more you practice the fundamentals within the books,(and don't
forget the online tutorials available), the more user friendly Python
becomes.

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


Re: [Tutor] [OT] Confusion [was Re: A file containing a string of 1 billion random digits.]

2010-07-19 Thread David Hutto
On Mon, Jul 19, 2010 at 8:57 PM, Steven D'Aprano  wrote:
> On Tue, 20 Jul 2010 01:42:51 am Richard D. Moores wrote:
>
>> The formatting operations described here are obsolete and may go away
>> in future versions of Python. Use the new String Formatting in new
>> code.
>>
>> I hope that use of '*' does disappear. It's the most confusing thing
>> I've recently tried to get my mind around!
>
> If you think that's confusing, you should try reading up on Monads.
>
> http://en.wikipedia.org/wiki/Monad_(functional_programming)
>
>
>> Before that, maybe, was the Trinity..
>
> [Note: the following may be offensive to some Christians, in which case,
> remember that nobody has the right to not be offended, and nobody is
> forcing you to read on.]
>
> The Trinity is simple to understand once you realise one thing --
> despite all the obfuscatory pseudo-justifications for it, it is not
> meant to be understood, it's meant to be believed.

It is meant to be understood, and it is understood, yet man has
attachments to an 'earthly' realm, which leads to a hinderance in the
principles given to guide them...to be all Zen about it.




It is a Mystery,
> something beyond human understanding. Not merely a small-m mystery,
> something which is possible to understand in principle, if we only knew
> enough. As Tertullian said (in a related but slightly different
> context):
>
> "It is certain because it is impossible".
>
> Or, to paraphrase, "I believe it because it is absurd".
>
> Like many religious beliefs (e.g. transubstantiation and dietary
> restrictions), belief in the Trinity is a shibboleth. Belief in the
> Trinity distinguishes Us ("true Christians") from Them (heretics and
> pagans[1]). The more ridiculous and crazy the belief, the more
> effective it is as a shibboleth. Anyone can believe that the son and
> the father are different people, because that's just ordinary
> common-sense[2]. But to believe that the son and the father are one and
> the same while being different *at the same time* makes no sense.

Think of the parent child windows, while one is the master the slave
has limitations, but still can display the 'words' of the parent.

 It
> is, as Tertullian would almost certainly have admitted, absurd and
> ridiculous and totally crazy. Tertullian would have believed it
> *because* it was unbelievable.

Debate 101 can cause men to take strange stances in order to perfect
their arguments.


>
> It really is frightening to realise that, essentially, the Chewbacca
> Defence has held such a grip on human society for so many centuries.

Haven't read it yet, but will get to it eventually.
>
> http://en.wikipedia.org/wiki/Chewbacca_defense
>
>
>
>
> [1] Actually many pagans also believe in trinities. But they believe in
> the *wrong* trinity: the three-as-one nature of Brahma/Vishnu/Shiva,
> Ra/Horus/Osiris, Ceres/Liber/Libera, or (two-in-one) Apollo/Bacchus is
> mere pagan superstition,
Who can really say what is and what isn't, if your stance above is
that [It] is undefinable and a mystery to man.

 while the three-as-one nature of
> Father/Son/Spirit is self-evidently true, at least according to those
> Christian sects which believe in a trinity.
>
> [2] So rare that it ought to count as a superpower.

Anyone can believe that the son and
> the father are different people, because that's just ordinary
> common-sense[2]

How does this relate?

>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  tu...@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] Difficulty Understanding Example Code for Blender Script

2010-07-22 Thread David Hutto
On Thu, Jul 22, 2010 at 2:47 AM, Marc Tompkins  wrote:
> On Wed, Jul 21, 2010 at 9:48 PM, Andrew Martin 
> wrote:
>>
>> This code was part of a Blender script to build a 3d bar graph, so I don't
>> know if understanding Blender is a prereq for understanding this code. The
>> function is for the axis labels.
>>
>> def label(text,position,orientation='z'):
>>     txt=Text3d.New('label')
>>     txt.setText(text)
>>     ob=Scene.GetCurrent().objects.new(txt)
>>     ob.setLocation(*position)
>>     if orientation=='x':
>>         ob.setEuler(-pi/2.0,0,0)
>>     elif orientation=='z':
>>         ob.setEuler(0,0,pi/2.0)
>>     print 'label %s at %s along %s' %(text,position,orientation)
>>
>>  I understand it for the most part except for the orientation part. I
>> assume orientation is for the 3d text object, but how is it determined
>> whether it is x or z?
>
> I don't use Blender myself, so this will be a more generic, high-level
> answer...
>>
>> def label(text,position,orientation='z'):
>
> This definition specifies that label() takes two mandatory parameters - text
> and position - and one optional parameter, orientation.  What makes
> "orientation" optional is the fact that a default value is supplied:
> "orientation='z'".  In other words, "orientation" is equal to "z" unless you
> specify otherwise in your call to label().

Seeing as how blender is 3d graphics, have you tried the 'newbie
fidget with it', and typed in w(quaternion),x, or y to see what
occurs. Also, have you looked into the hierarchy to see if z, which
looks as though it's contained in a string, is an input variable
declared elsewhere as an integer, or represents something else in it's
usage. Z can mean global, or object orientation in blender from what I
see.

>
> Take a look at this section of the Python docs:
> http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions
>
> Hope that helps...
>
>
> ___
> Tutor maillist  -  tu...@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] Running .py files in shell

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 2:39 AM, Kevin Rapley  wrote:
>
>>> I am running Mac OSX v10.6.4 Snow Leopard
>>> I am running Python 2.6.1
>>
>> In general get the MacPython distributions of Python etc, they usually
>> install easier (ie from the GUI) than the "Unix" based versions.
>
> Okay, thanks. I will look into that.
>>>
>>> 1. How do I execute .py files in the command line shell? I have my
>>> files in /Users/Kevin/python-exercises/ and am opening python in
>>> shell from that directory
>>
>> There are numerous ways, especially in MacOS.
>> The simplest way is to put a "shebang" line at the top of your script
>> and then make them executable:
>>
>> $ cat>  myscript.py
>
> What is the significance of this and how do I use it? I guess this is a
> command to add in to Shell, however when I use this I get the following
> error:
>
 cat > tryme1.py
> Traceback (most recent call last):
>  File "", line 1, in 
> NameError: name 'cat' is not defined
>>
>> #! /bin/env python
>
> With my configuration, I am guessing I need to change this snippet to:
>
> #! /opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin python
>>
>> # the above line must be the first line in your file and tells the
>> # shell where to find python
>> # rest of your code follows.
>>
>> Then use chmod +x to make it executable
>>
>> $ chmod +x myscript.py
>
> When I try to run this with one of my files I get the following error:
>
 chmod +x tryme1.py
>  File "", line 1
>    chmod +x tryme1.py
>                  ^
> SyntaxError: invalid syntax
>>
>> Now you can run it:
>>
>> $ myscript.py
>>
>> Alternatively you can just call python explicitly:
>>
>> $ python myscript.py
>
> I get a syntax error doing this too:
>
 python tryme1.py
>  File "", line 1
>    python tryme1.py
>                ^
> SyntaxError: invalid syntax
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

It looks like you're trying to type it into the python prompt, when
you should be trying to type it into the shell command prompt. You can
import tryme1.py in the python shell/interpreter, but you python
tryme.py from the shell
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Order Of Operations Question

2010-07-28 Thread David Hutto
From a practice exercise in Building Skills In Python page 64 I'm
working on How Much Does The Atmosphere Weigh? Part 1:
To check it states that the answer should be app. 10**18kg However,
and I've checked to make sure that the math I've layed out matches up
with the texts, I get 5.07360705863e+20

In the code I have broken the order of operations down to more
parenthetical, and tried outright, but see nothing obvious about how
it's strung together. If anyone has had a similar experience with the
problem given, or see anything blatantly obvious I've done wrong with
the ordering of operations. I tried to include as much of the
problem(formulas are just above variables they're used in) as comments
as possible.

import math
def atmosphereWeight():
pi = math.pi
"""Air Pressure (at sea level) P0. This is the long-term average.
P0 = 1.01325 × 10**5"""
airPressCLevl = 1.01325*(10**5)
gravity = 9.82
"""We can use g to get the kg of mass from the force of air
pressure P0. Apply the acceleration of gravity
(in m/sec2) to the air pressure (in kg · m/sec2). This result is
mass of the atmosphere in kilograms per
square meter (kg/m2).
Mm2 = P0 × g"""
masAtmoInKgPerSqM = airPressCLevl * gravity
"""Given the mass of air per square meter, we need to know how
many square meters of surface to apply
this mass to. Radius of Earth R in meters, m. This is an average
radius; our planet isn’t a perfect sphere.
R = 6.37 × 10"""
avgRadiusEarth = 6.37 * (10**6)
"""The area of a Sphere.
A = 4πr2"""
areaSphere = 4 * pi * (avgRadiusEarth**2)
"""Mass of atmosphere (in Kg) is the weight per square meter,
times the number of square meters
Ma = P0 × g × A"""
masEarthAtmoInKgPerSqM = airPressCLevl * gravity * areaSphere
print(masEarthAtmoInKgPerSqM)

atmosphereWeight()


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


Re: [Tutor] Order Of Operations Question

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 6:11 AM, Evert Rol  wrote:
> Sorry, forgot to reply-to-all:
>
>
> I don't know the book nor the exercise, but see my comments interspersed in 
> the code, and a few general remarks at the bottom
>
>> From a practice exercise in Building Skills In Python page 64 I'm
>> working on How Much Does The Atmosphere Weigh? Part 1:
>> To check it states that the answer should be app. 10**18kg However,
>> and I've checked to make sure that the math I've layed out matches up
>> with the texts, I get 5.07360705863e+20
>>
>> In the code I have broken the order of operations down to more
>> parenthetical, and tried outright, but see nothing obvious about how
>> it's strung together. If anyone has had a similar experience with the
>> problem given, or see anything blatantly obvious I've done wrong with
>> the ordering of operations. I tried to include as much of the
>> problem(formulas are just above variables they're used in) as comments
>> as possible.
>>
>> import math
>> def atmosphereWeight():
>>   pi = math.pi
>>   """Air Pressure (at sea level) P0. This is the long-term average.
>>   P0 = 1.01325 × 10**5"""
>>   airPressCLevl = 1.01325*(10**5)
>>   gravity = 9.82
>>   """We can use g to get the kg of mass from the force of air
>> pressure P0. Apply the acceleration of gravity
>>   (in m/sec2) to the air pressure (in kg · m/sec2). This result is
>> mass of the atmosphere in kilograms per
>>   square meter (kg/m2).
>>   Mm2 = P0 × g"""
>>   masAtmoInKgPerSqM = airPressCLevl * gravity
>
> Simply from looking at the units left and right of the equality sign, you'll 
> need to *divide* by g, not multiply: [kg] = [kg m / s^2] / [m / s^2]
>
>
>>   """Given the mass of air per square meter, we need to know how
>> many square meters of surface to apply
>>   this mass to. Radius of Earth R in meters, m. This is an average
>> radius; our planet isn’t a perfect sphere.
>>   R = 6.37 × 10"""
>>   avgRadiusEarth = 6.37 * (10**6)
>>   """The area of a Sphere.
>>   A = 4πr2"""
>>   areaSphere = 4 * pi * (avgRadiusEarth**2)
>>   """Mass of atmosphere (in Kg) is the weight per square meter,
>> times the number of square meters
>>   Ma = P0 × g × A"""
>>   masEarthAtmoInKgPerSqM = airPressCLevl * gravity * areaSphere
>
> ditto here: divide by gravity, not multiply by it.
>
>
>>   print(masEarthAtmoInKgPerSqM)
>>
>> atmosphereWeight()
>
>
> Few general remarks:
> - the standard way of writing numbers with a power of ten in code is 
> something like 1.01325e5. I guess this is also easier/quicker to execute (not 
> that this code is time-critical, but in general)

I'll probably ending up reading something about it later in the book,
but as a quick question, why does:

>>> 5e18 == 5**18
False
>>> int(5e18) == int(5**18)
False
>>> 1.01325e5 == 1.01325**5
False

> - why do you assign masTmoInKgPerSqM, then later not use it when calculating 
> masEarthAtmoInKgPerSqM?

I turned all of the formulas given into a variables, however in
masEarthAtmoInKgPerSqM it would have been neater to use
masTmoInKgPerSqM * areaSphere, instead of reusing the two variables
again in .masEarthAtmoInKgPerSqM.


> - just use math.pi when calculating areaSphere, instead of "pi = math.pi" and 
> then later using pi. For me, that's just as clear.
> - no need to put parentheses around powers; they are evaluated before the 
> multiplication (unless this is what you meant by "to more parenthetical"

Yes, it was just to break it into smaller, more readable, pieces.

> - try indenting the comments as well; more readable

It looked better when color coded in the editor, but not here in black
and white.

>
> Probably not all of the above are necessary, if you wrote this for debugging 
> your problem, but they're just some thoughts that occurred to me.
>
> Enjoy your calculations.

Will the 'fun' never end?
> ___
> Tutor maillist  -  tu...@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] Order Of Operations Question

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 6:19 AM, Hugo Arts  wrote:
> On Wed, Jul 28, 2010 at 11:41 AM, David Hutto  wrote:
>> From a practice exercise in Building Skills In Python page 64 I'm
>> working on How Much Does The Atmosphere Weigh? Part 1:
>> To check it states that the answer should be app. 10**18kg However,
>> and I've checked to make sure that the math I've layed out matches up
>> with the texts, I get 5.07360705863e+20
>>
>
> Either there is an error in the texts, or you have not checked
> throughly enough. It goes wrong here:
>
>>    """We can use g to get the kg of mass from the force of air
>> pressure P0. Apply the acceleration of gravity
>>    (in m/sec2) to the air pressure (in kg · m/sec2). This result is
>> mass of the atmosphere in kilograms per
>>    square meter (kg/m2).
>>    Mm2 = P0 × g"""
>>    masAtmoInKgPerSqM = airPressCLevl * gravity
>
> The Air pressure is in Pascal, which is kg / (m*s^2), not (kg * m)/s^2
> as you state. That is the Newton. Pascal can also be written as
> Newton/m^2, which is (M*g)/m^2. So to get mass per square meter, you
> should divide by the acceleration g, not multiply.

In the initial email I did forget this part:
Pressure is measured in Newtons, N, kg m/sec2. Air Pressure is is
measured in Newtons of force per square meter, N/m2.

Which might  have been a more informed question. I was trying not to
add in the whole question, and place the pieces in, but apparently
forgot one.
>
> With that modification I get about 5e18, which seems correct.

I get this with yours and Evert's modification from mult to div, but
if you're right, then the 10e18 the book states as a checker is a
typo/error.

Thanks, for your replies, I'll redo the example again, with a little
more sleep this time. Don't really need to know atmospheric pressure
right now, but might endup at wikipedia/google later.
>
> Hugo
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Order Of Operations Question

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 7:35 PM, Hugo Arts  wrote:
> On Thu, Jul 29, 2010 at 1:10 AM, David Hutto  wrote:
>> I get this with yours and Evert's modification from mult to div, but
>> if you're right, then the 10e18 the book states as a checker is a
>> typo/error.
>>
>
> Wait.. in your original e-mail you said the answer as given by the
> book was 10**18,

It is 10**18, in the book, (no e)that was before Eike informed me it
was not the same as 10e18. I stated this after
you used e, and before Eike explained, so I was using 10e18 in the
reply thinking of it as as 10**18.

not 10e18 (which is of course 10 * 10**18). But
> either way, I'd consider 5e18 a correct answer, since it's fairly
> close to 1e18 (relatively anyway, it's still 5 times as big). At least
> there is not an order of magnitude difference anymore.
>
> Hugo
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Order Of Operations Question

2010-07-28 Thread David Hutto
On Wed, Jul 28, 2010 at 8:03 PM, Dave Angel  wrote:
>
>
> David Hutto wrote:
>>
>> 
>> I'll probably ending up reading something about it later in the book,
>> but as a quick question, why does:
>>
>>
>>>>>
>>>>> 5e18 =5**18
>>>>>
>>
>> False
>>
>>>>>
>>>>> int(5e18) =int(5**18)
>>>>>
>>
>> False
>>
>>>>>
>>>>> 1.01325e5 =1.01325**5
>>>>>
>>
>> False
>>
>>
>
> The  999e44  notation is intended to be similar to scientific notation,
> where 44 is the exponent, in base 10.
>
> So redoing your equalities:
>
> 5e18 == 5*(10**18)
> int(5e18) == int(5 * 10**18)
> 1.01325e5 == 1.01325 * 10**5
>
> The extra parens in the first case, and the extra spaces in the others, are
> just for readability.  It'd be just as correct to say:
> 1.01325e5 == 1.01325*10**5
>
> DaveA
>
>
>

Already done!

And 5.3*10**18 or 5.2613095377e+18 is the appropriate answer from a
quick google search that resulted in the rounded 5.3e18. So the book
apparently left out the 5.3*, and just gave 10**18.

Thanks for your help, I think this is solved.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A better way for greatest common divisor

2010-07-29 Thread David Hutto
This is basically to get feedback, on a better way to show the
greatest common divisor in fraction, in order to reduce it fully, than
the one I've come up with. I'm sure there are better ways, so if you
have simpler method, or critique of what I've done, let me know.


'''Greatest Common Divisor Function'''
def gcd(num,den):
while True:
'''Find if numerator is less than denominator'''
if num < den:
'''Range backwards from larger number'''
for y in range.__reversed__(range(1,den+1)):
county = y
'''If den is evenly divisible by county'''
if den%county == 0:
'''And if num is divisible by county'''
if num%county == 0:
'''We have funneled the largest number\
divisible by both, by looping backwards\
from the larger number'''
print(county,'\n')
numdiv = num/county
dendiv = den/county
print('Reduced value is: %d/%d' % (numdiv,dendiv))
break
'''Below is about the same, except turns the fraction\
into it's wholenumber/fraction counterpart'''
if num > den:
for x in range.__reversed__(range(1,num+1)):
countx = x
if num%countx == 0:
if den%countx == 0:
print(countx)
numdiv = num/countx
dendiv = den/countx
print('Reduced value is: %d/%d' % (numdiv,dendiv))

print(int(numdiv/dendiv),'and',int(numdiv%dendiv),'/',int(dendiv))
break
break

'''Greatest Common Divisor Function Instance'''
num=int(float(input('Input numerator: ')))
den=int(float(input('Input denominator: ')))
gcd(num,den)


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


Re: [Tutor] A better way for greatest common divisor

2010-07-29 Thread David Hutto
On Thu, Jul 29, 2010 at 10:36 PM, James Mills
 wrote:
> On Fri, Jul 30, 2010 at 12:22 PM, Richard D. Moores  
> wrote:
>> On Thu, Jul 29, 2010 at 19:10, James Mills  
>> wrote:
>>> On Fri, Jul 30, 2010 at 11:47 AM, David Hutto  wrote:
>>>> This is basically to get feedback, on a better way to show the
>>>> greatest common divisor in fraction, in order to reduce it fully, than
>>>> the one I've come up with. I'm sure there are better ways, so if you
>>>> have simpler method, or critique of what I've done, let me know.
>>>
>>> [snip]
>>>
>>> I have a far simpler solution:
>>>
>>>>>> from tools import gcd
>>>>>> gcd(20, 5)
>>> 5
>>
>> In Python 3.1 that would be
>>>>> from fractions import gcd
>>>>> gcd(20,5)
>> 5
>
> Yes. The code I provided above was code I wrote
> for various Euler problems I had been working on
> a whiel back. It was written for 2.x
>
> cheers
> James
>
> --
> -- James Mills
> --
> -- "Problems are solved by method"
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

Actually, I knew there was a function in one of the modules, this was
for an exercise in Building Skills in python. So it was more from
scratch than use a prebuilt function.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A better way for greatest common divisor

2010-07-29 Thread David Hutto
On Thu, Jul 29, 2010 at 10:16 PM, James Mills
 wrote:
> On Fri, Jul 30, 2010 at 12:10 PM, James Mills
>  wrote:
>> def gcd(a, b):
>>    while b != 0:
>>        (a, b) = (b, a%b)
>>    return a

That was pretty short, and sweet.

>
> Here's another solution that uses a generator called factors to
> generate a list of factors for any given value. The gcd function
> then uses sets and intersection and the max function to find
> the greatest common factor/divisor
>
> http://codepad.org/VJIRyvI8
>
> cheers
> James
>
> --
> -- James Mills
> --
> -- "Problems are solved by method"
> ___
> Tutor maillist  -  tu...@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] A better way for greatest common divisor

2010-07-30 Thread David Hutto
On Fri, Jul 30, 2010 at 2:57 PM, Richard D. Moores  wrote:
> On Thu, Jul 29, 2010 at 18:47, David Hutto  wrote:
>> This is basically to get feedback, on a better way to show the
>> greatest common divisor in fraction, in order to reduce it fully, than
>> the one I've come up with. I'm sure there are better ways, so if you
>> have simpler method, or critique of what I've done, let me know.
>
> I've actually tried to run your script. If it works for you, then I'm
> having a problem getting the indents correct. Could you put it up on
> <http://python.pastebin.com> or somewhere so it could be copied and
> pasted accurately?
>
> Dick Moores
>

This is the url:
http://python.pastebin.com/fP3jjqGj
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A better way for greatest common divisor

2010-07-30 Thread David Hutto
On Fri, Jul 30, 2010 at 10:25 PM, Richard D. Moores  wrote:
> On Fri, Jul 30, 2010 at 17:43, David Hutto  wrote:
>> This is the url:
>> http://python.pastebin.com/fP3jjqGj
>
> This is a slight revision, with my suggested changes highlighted:
> <http://python.pastebin.com/uFznsUYZ>
>
> Dick Moores
>
Before I  see it, here is my revised that shaved a whole 4 lines off
the original. I took out the comments before comparing, so the
pastebin count on the first is off by those comment lines.

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


Re: [Tutor] A better way for greatest common divisor

2010-07-30 Thread David Hutto
On Fri, Jul 30, 2010 at 10:42 PM, David Hutto  wrote:
> On Fri, Jul 30, 2010 at 10:25 PM, Richard D. Moores  
> wrote:
>> On Fri, Jul 30, 2010 at 17:43, David Hutto  wrote:
>>> This is the url:
>>> http://python.pastebin.com/fP3jjqGj
>>
>> This is a slight revision, with my suggested changes highlighted:
>> <http://python.pastebin.com/uFznsUYZ>
>>
>> Dick Moores
>>
> Before I  see it, here is my revised that shaved a whole 4 lines off
> the original. I took out the comments before comparing, so the
> pastebin count on the first is off by those comment lines.
forgot the link:
http://python.pastebin.com/auw36h87
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A better way for greatest common divisor

2010-07-30 Thread David Hutto
On Fri, Jul 30, 2010 at 10:25 PM, Richard D. Moores  wrote:
> On Fri, Jul 30, 2010 at 17:43, David Hutto  wrote:
>> This is the url:
>> http://python.pastebin.com/fP3jjqGj
>
> This is a slight revision, with my suggested changes highlighted:
> <http://python.pastebin.com/uFznsUYZ>
>
> Dick Moores
>

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


Re: [Tutor] A better way for greatest common divisor

2010-07-30 Thread David Hutto
On Fri, Jul 30, 2010 at 10:43 PM, David Hutto  wrote:
> On Fri, Jul 30, 2010 at 10:25 PM, Richard D. Moores  
> wrote:
>> On Fri, Jul 30, 2010 at 17:43, David Hutto  wrote:
>>> This is the url:
>>> http://python.pastebin.com/fP3jjqGj
>>
>> This is a slight revision, with my suggested changes highlighted:
>> <http://python.pastebin.com/uFznsUYZ>
>>
>> Dick Moores
>>
>
> http://python.pastebin.com/auw36h87
>

Maybe this time gmail will post the link, it keeps showing blank when I send::
http://pastebin.com/auw36h87
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A better way for greatest common divisor

2010-07-30 Thread David Hutto
On Fri, Jul 30, 2010 at 10:44 PM, David Hutto  wrote:
> On Fri, Jul 30, 2010 at 10:43 PM, David Hutto  wrote:
>> On Fri, Jul 30, 2010 at 10:25 PM, Richard D. Moores  
>> wrote:
>>> On Fri, Jul 30, 2010 at 17:43, David Hutto  wrote:
>>>> This is the url:
>>>> http://python.pastebin.com/fP3jjqGj
>>>
>>> This is a slight revision, with my suggested changes highlighted:
>>> <http://python.pastebin.com/uFznsUYZ>
>>>
>>> Dick Moores
>>>
>>
>> http://python.pastebin.com/auw36h87
>>
>
> Maybe this time gmail will post the link, it keeps showing blank when I send::
> http://pastebin.com/auw36h87
>


This fixes the floating point 'bug' when numerator is greater than denominator:
http://python.pastebin.com/bJ5UzsBE
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python - RPG Combat System

2010-07-30 Thread David Hutto
On Fri, Jul 30, 2010 at 10:49 PM, Jason MacFiggen  wrote:
> I am have trouble figuring out how to make my program stop at 0 hit
> points if I run it, it always goes into the negative hitpoints...
>
> So my question is how do I make this program end at exactly 0 hit points
> every time instead of going over?
>
> and also, what can I do instead of writing print so many times?
>
> import random
>     my_hp = 50
>     mo_hp = 50
>     my_dmg = random.randrange(1, 20)
>     mo_dmg = random.randrange(1, 20)

You ask for a random number

>     while True:
>     if mo_hp < 0:
>     print "The Lich King has been slain!"
>     elif my_hp < 0:
>     print "You have been slain by the Lich King!"
>     if mo_hp <= 0:
>     break
>     elif my_hp <= 0:
>     break
>     else:
>     print "Menu Selections: "
>     print "1 - Attack"
>     print "2 - Defend"
>     print
>     choice = input ("Enter your selection. ")
>     choice = float(choice)
>     print
>     if choice == 1:
>     mo_hp = mo_hp - my_dmg
>     print "The Lich King is at ", mo_hp, "Hit Points"
>     print "You did ", my_dmg, "damage!"
>     print
>     my_hp = my_hp - mo_dmg
>     print "I was attacked by the lk for ", mo_dmg," damage!"
>     print "My Hit Points are ", my_hp
>     print
>     elif choice == 2:
>     mo_hp = mo_hp - my_dmg / 2
>     print "The Lich King is at", mo_hp, "Hit Points"
>     print "you did ", my_dmg / 2, "damage!"
>     print

Then you your points by that random number, so if the random
subtracted from current hp is negative it will print that negative
when you ask it to print hp - mydmg.

So, you add another if hp <= 0, in addition to the if my mydmg>myhp,
then print 0, instead of hp - myd_mg

>     my_hp = my_hp - mo_dmg
>     print "I was attacked by the lk for ", mo_dmg," damage!"
>     print "My Hit Points are ", my_hp
>     print
>
> ___
> Tutor maillist  -  tu...@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] A better way for greatest common divisor

2010-07-30 Thread David Hutto
On Fri, Jul 30, 2010 at 11:51 PM, Steven D'Aprano  wrote:
> On Sat, 31 Jul 2010 01:03:27 pm David Hutto wrote:
>
>> This fixes the floating point 'bug' when numerator is greater than
>> denominator: http://python.pastebin.com/bJ5UzsBE
>
> I don't mean to be disparaging ... ah hell, who am I fooling? Yes I do.
> What is that mess? *wink*
It works except under [3], and that's fixable. And even, I know it's a
good gradumacated the eighth grade, newbie attempt.*winks* back.
>
> I can see at least four problems with that:
>
> 1. You have a function called "gcd" that doesn't calculate the gcd, but
> does something else as well. That makes it a misleading name.

I still have the habit of wanting to use the functions like I would an
instance of the functions.

>
> 2. The principles of code reuse and encapsulation suggest that each
> function should (as much as possible) do one thing, and do it well. You
> have a function that tries to do two or three things. You should have a
> single function to calculate the gcd, and a second function to use the
> gcd for reducing a fraction as needed, and potentially a third function
> to report the results to the user.

Then maybe I should have done a larger class of functions instead then?


>
> 3. Your function has a serious bug. To see it, call gcd(5, 5) and see
> what it doesn't do.

I'll get to it, but it seems like I had that in the original, not the
revised, maybe not, but did all other test cases for it, other than
that



>
> 4. Code duplication. Your function repeats fairly major chunks of code.
> Copy-and-paste programming is one of the Deadly Sins for programmers.
> The way to get rid of that is by encapsulating code in functions (see
> point 1 above).

I thought about putting certain print statements in a function, as
well as seperating the gcd into a from fractions import *, with a
different parameter for each if the returning if placed it into the
called function, but it seemed a little *overkill*, when it worked
well within the single function, with a few parameters placed in
through an instance with input.

>
>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  tu...@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] A better way for greatest common divisor

2010-07-30 Thread David Hutto
On Sat, Jul 31, 2010 at 12:37 AM, David Hutto  wrote:
> On Fri, Jul 30, 2010 at 11:51 PM, Steven D'Aprano  wrote:
>> On Sat, 31 Jul 2010 01:03:27 pm David Hutto wrote:
>>
>>> This fixes the floating point 'bug' when numerator is greater than
>>> denominator: http://python.pastebin.com/bJ5UzsBE
>>
>> I don't mean to be disparaging ... ah hell, who am I fooling? Yes I do.
>> What is that mess? *wink*
> It works except under [3], and that's fixable. And even, I know it's a
> good gradumacated the eighth grade, newbie attempt.*winks* back.
>>
>> I can see at least four problems with that:
>>
>> 1. You have a function called "gcd" that doesn't calculate the gcd, but
>> does something else as well. That makes it a misleading name.
>
> I still have the habit of wanting to use the functions like I would an
> instance of the functions.
>
>>
>> 2. The principles of code reuse and encapsulation suggest that each
>> function should (as much as possible) do one thing, and do it well. You
>> have a function that tries to do two or three things. You should have a
>> single function to calculate the gcd, and a second function to use the
>> gcd for reducing a fraction as needed, and potentially a third function
>> to report the results to the user.
>
> Then maybe I should have done a larger class of functions instead then?
>
>
>>
>> 3. Your function has a serious bug. To see it, call gcd(5, 5) and see
>> what it doesn't do.
>
> I'll get to it, but it seems like I had that in the original, not the
> revised, maybe not, but did all other test cases for it, other than
> that
>
>
>
>>
>> 4. Code duplication. Your function repeats fairly major chunks of code.
>> Copy-and-paste programming is one of the Deadly Sins for programmers.
>> The way to get rid of that is by encapsulating code in functions (see
>> point 1 above).
>
> I thought about putting certain print statements in a function, as
> well as seperating the gcd into a from fractions import *, with a
> different parameter for each if the returning if placed it into the
> called function, but it seemed a little *overkill*, when it worked
> well within the single function, with a few parameters placed in
> through an instance with input.
>
>>
>>
>>
>> --
>> Steven D'Aprano
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>

But, just to say, it started out as just trying to calculate the GCD
with your current python skills(not import fractions, and
print(gcd(3,9))for a practice exercise, and the rest is just the
input, and stated output.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A better way for greatest common divisor

2010-07-31 Thread David Hutto
On Sat, Jul 31, 2010 at 12:43 AM, David Hutto  wrote:
> On Sat, Jul 31, 2010 at 12:37 AM, David Hutto  wrote:
>> On Fri, Jul 30, 2010 at 11:51 PM, Steven D'Aprano  
>> wrote:
>>> On Sat, 31 Jul 2010 01:03:27 pm David Hutto wrote:
>>>
>>>> This fixes the floating point 'bug' when numerator is greater than
>>>> denominator: http://python.pastebin.com/bJ5UzsBE
>>>
>>> I don't mean to be disparaging ... ah hell, who am I fooling? Yes I do.
>>> What is that mess? *wink*
>> It works except under [3], and that's fixable. And even, I know it's a
>> good gradumacated the eighth grade, newbie attempt.*winks* back.
>>>
>>> I can see at least four problems with that:
>>>
>>> 1. You have a function called "gcd" that doesn't calculate the gcd, but
>>> does something else as well. That makes it a misleading name.
>>
>> I still have the habit of wanting to use the functions like I would an
>> instance of the functions.
>>
>>>
>>> 2. The principles of code reuse and encapsulation suggest that each
>>> function should (as much as possible) do one thing, and do it well. You
>>> have a function that tries to do two or three things. You should have a
>>> single function to calculate the gcd, and a second function to use the
>>> gcd for reducing a fraction as needed, and potentially a third function
>>> to report the results to the user.
>>
>> Then maybe I should have done a larger class of functions instead then?
>>
>>
>>>
>>> 3. Your function has a serious bug. To see it, call gcd(5, 5) and see
>>> what it doesn't do.
>>
>> I'll get to it, but it seems like I had that in the original, not the
>> revised, maybe not, but did all other test cases for it, other than
>> that
>>
>>
>>
>>>
>>> 4. Code duplication. Your function repeats fairly major chunks of code.
>>> Copy-and-paste programming is one of the Deadly Sins for programmers.
>>> The way to get rid of that is by encapsulating code in functions (see
>>> point 1 above).
>>
>> I thought about putting certain print statements in a function, as
>> well as seperating the gcd into a from fractions import *, with a
>> different parameter for each if the returning if placed it into the
>> called function, but it seemed a little *overkill*, when it worked
>> well within the single function, with a few parameters placed in
>> through an instance with input.
>>
>>>
>>>
>>>
>>> --
>>> Steven D'Aprano
>>> ___
>>> Tutor maillist  -  tu...@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>
>
> But, just to say, it started out as just trying to calculate the GCD
> with your current python skills(not import fractions, and
> print(gcd(3,9))for a practice exercise, and the rest is just the
> input, and stated output.
>

however, had it been a math exercise, I would have sucked in boiling
it down, initially.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A better way for greatest common divisor

2010-07-31 Thread David Hutto
On Sat, Jul 31, 2010 at 3:39 AM, David Hutto  wrote:
> On Sat, Jul 31, 2010 at 12:43 AM, David Hutto  wrote:
>> On Sat, Jul 31, 2010 at 12:37 AM, David Hutto  wrote:
>>> On Fri, Jul 30, 2010 at 11:51 PM, Steven D'Aprano  
>>> wrote:
>>>> On Sat, 31 Jul 2010 01:03:27 pm David Hutto wrote:
>>>>
>>>>> This fixes the floating point 'bug' when numerator is greater than
>>>>> denominator: http://python.pastebin.com/bJ5UzsBE
>>>>
>>>> I don't mean to be disparaging ... ah hell, who am I fooling? Yes I do.
>>>> What is that mess? *wink*
>>> It works except under [3], and that's fixable. And even, I know it's a
>>> good gradumacated the eighth grade, newbie attempt.*winks* back.
>>>>
>>>> I can see at least four problems with that:
>>>>
>>>> 1. You have a function called "gcd" that doesn't calculate the gcd, but
>>>> does something else as well. That makes it a misleading name.
>>>
>>> I still have the habit of wanting to use the functions like I would an
>>> instance of the functions.
>>>
>>>>
>>>> 2. The principles of code reuse and encapsulation suggest that each
>>>> function should (as much as possible) do one thing, and do it well. You
>>>> have a function that tries to do two or three things. You should have a
>>>> single function to calculate the gcd, and a second function to use the
>>>> gcd for reducing a fraction as needed, and potentially a third function
>>>> to report the results to the user.
>>>
>>> Then maybe I should have done a larger class of functions instead then?
>>>
>>>
>>>>
>>>> 3. Your function has a serious bug. To see it, call gcd(5, 5) and see
>>>> what it doesn't do.
>>>
>>> I'll get to it, but it seems like I had that in the original, not the
>>> revised, maybe not, but did all other test cases for it, other than
>>> that
>>>
>>>
>>>
>>>>
>>>> 4. Code duplication. Your function repeats fairly major chunks of code.
>>>> Copy-and-paste programming is one of the Deadly Sins for programmers.
>>>> The way to get rid of that is by encapsulating code in functions (see
>>>> point 1 above).
>>>
>>> I thought about putting certain print statements in a function, as
>>> well as seperating the gcd into a from fractions import *, with a
>>> different parameter for each if the returning if placed it into the
>>> called function, but it seemed a little *overkill*, when it worked
>>> well within the single function, with a few parameters placed in
>>> through an instance with input.
>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Steven D'Aprano
>>>> ___
>>>> Tutor maillist  -  tu...@python.org
>>>> To unsubscribe or change subscription options:
>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>
>>>
>>
>> But, just to say, it started out as just trying to calculate the GCD
>> with your current python skills(not import fractions, and
>> print(gcd(3,9))for a practice exercise, and the rest is just the
>> input, and stated output.
>>
>
> however, had it been a math exercise, I would have sucked in boiling
> it down, initially.
>

There is a difference between defining a function as a singular
activity needed to be performed, and a function that serves as a tool,
that asks for input and output, as well as serves several
utilizations, e.g., it not only accepts the numerator/denominator, but
spits out the gcd, the reduced, and the whole numeber reduced if the
numerator is greater. but if they are even, will come with a little if
num == den boolean, when I'm finished .
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python - RPG Combat System

2010-07-31 Thread David Hutto
On Sat, Jul 31, 2010 at 1:51 PM, bob gailer  wrote:
> On 7/30/2010 10:49 PM, Jason MacFiggen wrote:
>>
>> what can I do instead of writing print so many times?
>> import random
>>    my_hp = 50
>>    mo_hp = 50
>>    my_dmg = random.randrange(1, 20)
>>    mo_dmg = random.randrange(1, 20)
>>    while True:
>>        if mo_hp < 0:
>>            print "The Lich King has been slain!"
>>        elif my_hp < 0:
>>            print "You have been slain by the Lich King!"
>>        if mo_hp <= 0:
>>            break
>>        elif my_hp <= 0:
>>            break
>>        else:
>>            print "Menu Selections: "
>>            print "1 - Attack"
>>            print "2 - Defend"
>>            print
>>            choice = input ("Enter your selection. ")
>>            choice = float(choice)
>>            print
>>        if choice == 1:
>>            mo_hp = mo_hp - my_dmg
>>            print "The Lich King is at ", mo_hp, "Hit Points"
>>            print "You did ", my_dmg, "damage!"
>>            print
>>            my_hp = my_hp - mo_dmg
>>            print "I was attacked by the lk for ", mo_dmg," damage!"
>>            print "My Hit Points are ", my_hp
>>            print
>>        elif choice == 2:
>>            mo_hp = mo_hp - my_dmg / 2
>>            print "The Lich King is at", mo_hp, "Hit Points"
>>            print "you did ", my_dmg / 2, "damage!"
>>            print
>>            my_hp = my_hp - mo_dmg
>>            print "I was attacked by the lk for ", mo_dmg," damage!"
>>            print "My Hit Points are ", my_hp
>>            print
>
> Most of the statements in each choice block are identical. Factor them out,
> giving:
>
>        if choice == 1:
>            mo_hp = mo_hp - my_dmg
>            print "you did ", my_dmg /, "damage!"
>        elif choice == 2:
>            mo_hp = mo_hp - my_dmg / 2
>            print "you did ", my_dmg / 2, "damage!"
>        print "The Lich King is at", mo_hp, "Hit Points"
>        my_hp = my_hp - mo_dmg
>        print "You did ", my_dmg, "damage!"
>        print
>        print "I was attacked by the lk for ", mo_dmg," damage!"
>        print "My Hit Points are ", my_hp
>        print
>
> You could (better) move these statements into a function, passing 1 or 2 as
> the divisor for my_dmg and returning the updated values for my_ho

You mean my_dmg I think.

 and my_hp.
>
> def update(factor):
>    print "The Lich King is at", mo_hp, "Hit Points"
>    print "you did ", my_dmg / factor, "damage!"
>    print
>    print "I was attacked by the lk for ", mo_dmg," damage!"
>    print "My Hit Points are ", my_hp
>    print
>    return mo_hp - my_dmg / factor, my_hp - mo_dmg
> ...
>        if choice == 1:
>            mo_hp, my_hp = update(1)
>        elif choice == 2:
>            mo_hp, my_hp = update(2)
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
> ___
> Tutor maillist  -  tu...@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] Writing scripts and apps for Internet consumption

2010-07-31 Thread David Hutto
On Sat, Jul 31, 2010 at 2:27 PM, Eric Hamiter  wrote:
> Not sure if this is the right place for this, since this is a tutor list,
> but I think it is because it involves learning Python and the application of
> knowledge.
>
> I've just started learning it as my initial programming language as of two
> months ago. I like to think I'm making steady progress, and I now understand
> the most rudimentary level of the basics. What I keep reading is how Python
> is most powerful on server side applications, in the cloud, so to speak. The
> portability of Python is also widely evangelized.
>
> Here's my problem with this so far-- I can write a basic script, have it
> take in data, rearrange it, and spit it back out. Following along in a book,
> I can write a basic GUI or game. It's all wine and roses on my Windows
> laptop, where I have everything configured just right, with all of the
> modules in place where they need to be.
>
> Moving this to a server or even another computer so far has been a seemingly
> impossible task. There's a lot of documentation for CGI scripting (which is
> now frowned upon, with every page recommending looking into wsgi), and there
> have been applications devoted to transforming scripts into Windows
> executables (py2exe, etc.) but it seems like this is much more confusing
> than need be, and I can't get them to work regardless. When I try and google
> for solutions, choosing any terms like "web" or "server" point me to massive
> framework solutions like Django or Pylons, which seem extraordinarily
> complex for what I want.
>
> Specific examples: I have a livewires/pygame GUI game I wrote along with
> folowing the book "Python Programming for the Absolute Beginner" and it
> works great on my laptop. I tried installing Python/pygame on a work
> computer and copying my scripts over, but it endlessly fails with errors so
> obtuse I can't troubleshoot. I'm not even sure if I have the correct modules
> installed here. Should they be under "Lib" or "libs" or "includes"?  Trying
> to use py2exe fails because I can't figure out how to include non-scripts in
> the final program, like .pngs or .jpgs. How would I even begin to put this
> on a server? I'm clueless.
>
> Another program I am using on my laptop is a convenience script-- it takes
> in a text list of groceries, and spits out a formatted list based on aisle
> locations so I can get in and out of the grocery store faster. My laptop is
> the only place I can use this. I've tried using multiple CGI examples, and
> it always results in a "File Not Found" error. Not even sure how I can debug
> it. I can have the server do a simple one-line of printing "Hello World" but
> anything more complicated than that makes it implode.
>
> The most frustrating thing is how flippantly experienced programmers say to
> use Django for Python web apps because it's so simple to use. It took me a
> good half-day to just install it, and unless I'm writing a sample code or if
> I want to clone a newspaper service, I have absolutely no idea how I would
> use it efficiently. I want to learn the basics before running off to learn a
> new framework. I'm trying to find good resources so I can continue self
> teaching, but everything I find seems to be tailored to two classes: the
> complete newbie who doesn't know how to print a line, or an advanced
> programmer who is using list comprehension within a recursion with multiple
> modules.
>
> In short, is there a "simple" method for putting python scripts onto a
> server that I do not host myself? I've seen web2py and it looks like it
> would be more my speed, but support is lacking and doesn't seem too
> compatible with my host. I use Dreamhost, and they are very adaptable and
> configurable, but so far I can't find an easy way to accomplish what I want.
>
> Thanks for reading this far if you did! I welcome any suggestions
> whatsoever.
>
> Eric
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

Get a linux hosting account, and a web address, most linux hosting
comes with python, so practice in the 'cloud'.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing scripts and apps for Internet consumption

2010-07-31 Thread David Hutto
On Sat, Jul 31, 2010 at 2:34 PM, David Hutto  wrote:
> On Sat, Jul 31, 2010 at 2:27 PM, Eric Hamiter  wrote:
>> Not sure if this is the right place for this, since this is a tutor list,
>> but I think it is because it involves learning Python and the application of
>> knowledge.
>>
>> I've just started learning it as my initial programming language as of two
>> months ago. I like to think I'm making steady progress, and I now understand
>> the most rudimentary level of the basics. What I keep reading is how Python
>> is most powerful on server side applications, in the cloud, so to speak. The
>> portability of Python is also widely evangelized.
>>
>> Here's my problem with this so far-- I can write a basic script, have it
>> take in data, rearrange it, and spit it back out. Following along in a book,
>> I can write a basic GUI or game. It's all wine and roses on my Windows
>> laptop, where I have everything configured just right, with all of the
>> modules in place where they need to be.
>>
>> Moving this to a server or even another computer so far has been a seemingly
>> impossible task. There's a lot of documentation for CGI scripting (which is
>> now frowned upon, with every page recommending looking into wsgi), and there
>> have been applications devoted to transforming scripts into Windows
>> executables (py2exe, etc.) but it seems like this is much more confusing
>> than need be, and I can't get them to work regardless. When I try and google
>> for solutions, choosing any terms like "web" or "server" point me to massive
>> framework solutions like Django or Pylons, which seem extraordinarily
>> complex for what I want.
>>
>> Specific examples: I have a livewires/pygame GUI game I wrote along with
>> folowing the book "Python Programming for the Absolute Beginner" and it
>> works great on my laptop. I tried installing Python/pygame on a work
>> computer and copying my scripts over, but it endlessly fails with errors so
>> obtuse I can't troubleshoot. I'm not even sure if I have the correct modules
>> installed here. Should they be under "Lib" or "libs" or "includes"?  Trying
>> to use py2exe fails because I can't figure out how to include non-scripts in
>> the final program, like .pngs or .jpgs. How would I even begin to put this
>> on a server? I'm clueless.
>>
>> Another program I am using on my laptop is a convenience script-- it takes
>> in a text list of groceries, and spits out a formatted list based on aisle
>> locations so I can get in and out of the grocery store faster. My laptop is
>> the only place I can use this. I've tried using multiple CGI examples, and
>> it always results in a "File Not Found" error. Not even sure how I can debug
>> it. I can have the server do a simple one-line of printing "Hello World" but
>> anything more complicated than that makes it implode.
>>
>> The most frustrating thing is how flippantly experienced programmers say to
>> use Django for Python web apps because it's so simple to use. It took me a
>> good half-day to just install it, and unless I'm writing a sample code or if
>> I want to clone a newspaper service, I have absolutely no idea how I would
>> use it efficiently. I want to learn the basics before running off to learn a
>> new framework. I'm trying to find good resources so I can continue self
>> teaching, but everything I find seems to be tailored to two classes: the
>> complete newbie who doesn't know how to print a line, or an advanced
>> programmer who is using list comprehension within a recursion with multiple
>> modules.
>>
>> In short, is there a "simple" method for putting python scripts onto a
>> server that I do not host myself? I've seen web2py and it looks like it
>> would be more my speed, but support is lacking and doesn't seem too
>> compatible with my host. I use Dreamhost, and they are very adaptable and
>> configurable, but so far I can't find an easy way to accomplish what I want.
>>
>> Thanks for reading this far if you did! I welcome any suggestions
>> whatsoever.
>>
>> Eric
>>
>>
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> Get a linux hosting account, and a web address, most linux hosting
> comes with python, so practice in the 'cloud'.
>
 Some might argue that this would be a production server, so to speak,
but it's just for target practice, right?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Simple Python Program

2010-07-31 Thread David Hutto
On Sat, Jul 31, 2010 at 2:35 PM, bob gailer  wrote:
> On 7/31/2010 12:00 AM, Jason MacFiggen wrote:
>
> Can anyone tell me how to fix the errors I am getting if possible? I'm quite
> new and so confused...
>
>
> I could give lots of diagnostic advice and detail. There is so much wrong
> with this program.
>
> I suggest you discard it, back up and start with the simplest possible
> statement of the problem which is:
> print a number randomly chosen from (0,1,2)
>
> Then write the simplest possible program to do this one time; no loops or
> functions.
> The entire program could then be written in 2 lines of code. Run it, fix it
> if it does not work. Once you have success -
>
> Add (one at a time) various features:
> - roll dice to select winner
> - player names
> - repetition
>
> Continue to avoid writing functions. They are not necessary for such a
> simple program.

Not to butt in, but... As a newbie didn't you want to feel like a
sophisticated programmer and use functions to hold simple, and use
instances as your 'pride stance'.



>
> The final product will have less than 15 statements.
>
> also how do I display the winner under the displayInfo function?
>
> import random
>
> def main():
>     print
>
>     playerOne, playerTwo = inputNames(playerOne, PlayerTwo)
>
>     while endProgram == 'no':
>
>     endProgram == no
>     playerOne = 'NO NAME'
>     playerTwo = 'NO NAME'
>
>     winnerName = rollDice(p1number, p2number, playerOne, playerTwo,
> winnerName)
>     winnerName = displayInfo
>
>     endProgram = raw_input('Do you want to end program? (Enter yes or
> no): ')
>
> def inputNames(playerOne, PlayerTwo):
>
>     p1name = raw_input("Enter your name.")
>     p2name = raw_input("Enter your name.")
>     return playerOne, playerTwo
>
> def random(winnerName):
>
>     p1number = random.randint(1, 6)
>     p2number = random.randint(1, 6)
>
>     if p1number > p2number:
>     playerOne = winnerName
>     elif p1number < p2number:
>     playerTwo = winnerName
>     else p1number == p2number:
>     playerOne, playerTwo = winnerName
>
> def displayInfo():
>
>     #how do I display winner?
>
> main()
>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
> ___
> Tutor maillist  -  tu...@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] Writing scripts and apps for Internet consumption

2010-07-31 Thread David Hutto
On Sat, Jul 31, 2010 at 2:45 PM, Eric Hamiter  wrote:
>> Get a linux hosting account, and a web address, most linux hosting
>> comes with python, so practice in the 'cloud'.
>
> I have that-- an account with Dreamhost. This hasn't solved my problems yet
> though. Like I said, I can have it write a simple
>
> Hello, World!
>
> ...but if I make it do anything more complex, I get a 404 error. To make my
> question more simple-- how does one learn to create web apps with Python? It
> seems to be that what it is advertised as, but not at all ready to go "out
> of the box" for that type of thing. And that is fine, but I want to learn
> how without having to learn a framework like Django-- yet. Or is this just
> considered a kind of necessity?
>

What do your server logs show the 404 error to be?
Debug it like a script. For me, it's the part about use your own
computer as a host(I'm working on that) that gets me, but a hosting
account is already set up, as opposed to using your own local host
setup, this is provided. So it's just using the html with python just
like with php. I'm not an expert at this, but I do have a little
experience with lamp, so python should just be a replacement of p in
lamp for pythin instead of php
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Writing scripts and apps for Internet consumption

2010-07-31 Thread David Hutto
On Sat, Jul 31, 2010 at 2:56 PM, David Hutto  wrote:
> On Sat, Jul 31, 2010 at 2:45 PM, Eric Hamiter  wrote:
>>> Get a linux hosting account, and a web address, most linux hosting
>>> comes with python, so practice in the 'cloud'.
>>
>> I have that-- an account with Dreamhost. This hasn't solved my problems yet
>> though. Like I said, I can have it write a simple
>>
>> Hello, World!
>>
>> ...but if I make it do anything more complex, I get a 404 error. To make my
>> question more simple-- how does one learn to create web apps with Python? It
>> seems to be that what it is advertised as, but not at all ready to go "out
>> of the box" for that type of thing. And that is fine, but I want to learn
>> how without having to learn a framework like Django-- yet. Or is this just
>> considered a kind of necessity?
>>
>
> What do your server logs show the 404 error to be?
> Debug it like a script. For me, it's the part about use your own
> computer as a host(I'm working on that) that gets me, but a hosting
> account is already set up, as opposed to using your own local host
> setup, this is provided. So it's just using the html with python just
> like with php. I'm not an expert at this, but I do have a little
> experience with lamp, so python should just be a replacement of p in
> lamp for pythin instead of php
>

In other words, make it easy on yourself in the beginning, to avoid
frustration(and therefore a deterence of self toward your initial
language), and then learn the specifics in your downtime.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread David Hutto
On Sun, Aug 1, 2010 at 12:18 PM, Che M  wrote:
>
>
>> Do any of you have any feedback, strategies and best practices
>> related to unit testing within Python. This is a relatively new topic
>> for me. I was thinking of starting with reading the documentation
>> associate with the unittest module.
>
> The idea of unit testing/test driven development has remained
> foreign to me throughout my time trying to learn Python--by choice.
> I want to make desktop GUI applications and I don't use MVC, so
> the idea of writing tests strikes me as far more work--and a major
> delayer of getting to an application that actually does something--
> than simply using the software myself and noting problems.  It
> sounds like TDD is probably the most proper way to go about things,
> but, in the interest of getting something out of Python to warrant the
> time I've put into it, I favor a "good enough" approach for now.

Writers just call this a rough draft. Perfection is in the revisions
that come after a little thought.

>
>
>
>
>
> ___
> Tutor maillist  -  tu...@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] web-based python?

2010-08-01 Thread David Hutto
On Sun, Aug 1, 2010 at 7:38 PM, Eric Hamiter  wrote:
> On Sun, Aug 1, 2010 at 1:56 PM, Che M  wrote:
>>
>> For a long time I have hoped for a "Python web apps for absolute
>> beginners"
>> tutorial that doesn't assume any knowledge.  For a beginner, it is not
>> even
>> clear what a "web frameworks" is let alone which one he/she should start
>> with or if it is even needed.
>>
>> I understand much of this is about web apps generally and is not germane
>> only to Python, but it would be good if a Python tutorial at least pointed
>> toward
>> this information, since for many beginners, the entry portal to anything
>> is through
>> Python.  To just refer someone to Django when they don't know the first
>> thing about
>> web apps is, I think, off-putting.

I think just using the term web app instead of interactive website is
confusing, unless by web app(and this is the way I might, incorrectly,
use the term) you mean a desktop app that works only with an internet
connection, and communication with a nonlocal server.


>>
>> Che
>>
> Che, my sentinments exactly. I'm looking for something similar.
>
> Eric
>
>
> ___
> Tutor maillist  -  tu...@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] Where to start with Unit Testing

2010-08-01 Thread David Hutto
On Sun, Aug 1, 2010 at 9:11 PM, Che M  wrote:
>
>
>> > The idea of unit testing/test driven development has remained
>> > foreign to me throughout my time trying to learn Python--by choice.
>> > I want to make desktop GUI applications and I don't use MVC, so
>> > the idea of writing tests strikes me as far more work--and a major
>> > delayer of getting to an application that actually does something--
>> > than simply using the software myself and noting problems.  It
>> > sounds like TDD is probably the most proper way to go about things,
>> > but, in the interest of getting something out of Python to warrant the
>> > time I've put into it, I favor a "good enough" approach for now.
>>
>> Writers just call this a rough draft. Perfection is in the revisions
>> that come after a little thought.
>
> Well, I don't see what I'm doing as a rough draft, as I am attempting
> to hone it to "perfection" (that is, a working app)--just without unit
> testing.

Every time you try to perfect is a revision of your initial 'written'
algorithm. From concept forward is your revisions. Notice that svn and
cvs are called revisions. How quickly is a different story. To you,
your writing and rewriting, but each rewrite is a revision of the
initial concept. And as far as i can tell, if you want to be the unit
test yourself, it's fine, but unit testing might be inappropriate for
something like this. But basically unit testing would be a script that
inputs the possible combinations of requests to the original script,
which should be tested like chefs do soups-intermittently as you
design it. So the tests are really what you put or type as input given
directly to the script , right?.



>
> A different analogy comes to my mind; I once saw two different sets of
> people analyze data.  One did it "by hand":  visually inspecting thousands
> of signals herself and typing Y or N to accept or reject each signal.  The
> other did it with an automated system that accepted or rejected signals
> based on fuzzy logic.

This depends on your need for control, do you need to manually accept,
or can you just detect the signal, and let the program proceedl. Do
you want the local nuclear plant to have their system throw an error,
without a human response?

In an important interpretation, the automated system
> was far better, and yet the first scientist was done with her analysis and
> accepted for publication before the second team even had the bugs worked
> out of the automated system!

Like you state below, the automated system used, evolved from manually
designed systems, so automation is the easy way, but sometimes not the
best, depending on the circumstance and priority level of the
information being received.

Yes, I think the slow-but-more-proper team
> did the more correct thing, but there is something to be said for "good
> enough", too (it works for evolution, for example).


>
>
>
>
> ___
> Tutor maillist  -  tu...@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] Where to start with Unit Testing

2010-08-01 Thread David Hutto
On Sun, Aug 1, 2010 at 9:31 PM, David Hutto  wrote:
> On Sun, Aug 1, 2010 at 9:11 PM, Che M  wrote:
>>
>>
>>> > The idea of unit testing/test driven development has remained
>>> > foreign to me throughout my time trying to learn Python--by choice.
>>> > I want to make desktop GUI applications and I don't use MVC, so
>>> > the idea of writing tests strikes me as far more work--and a major
>>> > delayer of getting to an application that actually does something--
>>> > than simply using the software myself and noting problems.  It
>>> > sounds like TDD is probably the most proper way to go about things,
>>> > but, in the interest of getting something out of Python to warrant the
>>> > time I've put into it, I favor a "good enough" approach for now.
>>>
>>> Writers just call this a rough draft. Perfection is in the revisions
>>> that come after a little thought.
>>
>> Well, I don't see what I'm doing as a rough draft, as I am attempting
>> to hone it to "perfection" (that is, a working app)--just without unit
>> testing.
>
> Every time you try to perfect is a revision of your initial 'written'
> algorithm. From concept forward is your revisions. Notice that svn and
> cvs are called revisions. How quickly is a different story. To you,
> your writing and rewriting, but each rewrite is a revision of the
> initial concept. And as far as i can tell, if you want to be the unit
> test yourself, it's fine, but unit testing might be inappropriate for
> something like this. But basically unit testing would be a script that
> inputs the possible combinations of requests to the original script,
> which should be tested like chefs do soups-intermittently as you
> design it. So the tests are really what you put or type as input given
> directly to the script , right?.
>
>
>
>>
>> A different analogy comes to my mind; I once saw two different sets of
>> people analyze data.  One did it "by hand":  visually inspecting thousands
>> of signals herself and typing Y or N to accept or reject each signal.  The
>> other did it with an automated system that accepted or rejected signals
>> based on fuzzy logic.
>
> This depends on your need for control, do you need to manually accept,
> or can you just detect the signal, and let the program proceedl. Do
> you want the local nuclear plant to have their system throw an error,
> without a human response?
>
> In an important interpretation, the automated system
>> was far better, and yet the first scientist was done with her analysis and
>> accepted for publication before the second team even had the bugs worked
>> out of the automated system!
>
> Like you state below, the automated system used, evolved from manually
> designed systems, so automation is the easy way, but sometimes not the
> best, depending on the circumstance and priority level of the
> information being received.
>
> Yes, I think the slow-but-more-proper team
>> did the more correct thing, but there is something to be said for "good
>> enough", too (it works for evolution, for example).
>
>
>>
>>
>>
>>
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>

Disclaimer: I have no clue what unit testing is, nor have I had to use it yet.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Where to start with Unit Testing

2010-08-01 Thread David Hutto
On Sun, Aug 1, 2010 at 9:39 PM, David Hutto  wrote:
> On Sun, Aug 1, 2010 at 9:31 PM, David Hutto  wrote:
>> On Sun, Aug 1, 2010 at 9:11 PM, Che M  wrote:
>>>
>>>
>>>> > The idea of unit testing/test driven development has remained
>>>> > foreign to me throughout my time trying to learn Python--by choice.
>>>> > I want to make desktop GUI applications and I don't use MVC, so
>>>> > the idea of writing tests strikes me as far more work--and a major
>>>> > delayer of getting to an application that actually does something--
>>>> > than simply using the software myself and noting problems.  It
>>>> > sounds like TDD is probably the most proper way to go about things,
>>>> > but, in the interest of getting something out of Python to warrant the
>>>> > time I've put into it, I favor a "good enough" approach for now.
>>>>
>>>> Writers just call this a rough draft. Perfection is in the revisions
>>>> that come after a little thought.
>>>
>>> Well, I don't see what I'm doing as a rough draft, as I am attempting
>>> to hone it to "perfection" (that is, a working app)--just without unit
>>> testing.
>>
>> Every time you try to perfect is a revision of your initial 'written'
>> algorithm. From concept forward is your revisions. Notice that svn and
>> cvs are called revisions. How quickly is a different story. To you,
>> your writing and rewriting, but each rewrite is a revision of the
>> initial concept. And as far as i can tell, if you want to be the unit
>> test yourself, it's fine, but unit testing might be inappropriate for
>> something like this. But basically unit testing would be a script that
>> inputs the possible combinations of requests to the original script,
>> which should be tested like chefs do soups-intermittently as you
>> design it. So the tests are really what you put or type as input given
>> directly to the script , right?.
>>
>>
>>
>>>
>>> A different analogy comes to my mind; I once saw two different sets of
>>> people analyze data.  One did it "by hand":  visually inspecting thousands
>>> of signals herself and typing Y or N to accept or reject each signal.  The
>>> other did it with an automated system that accepted or rejected signals
>>> based on fuzzy logic.
>>
>> This depends on your need for control, do you need to manually accept,
>> or can you just detect the signal, and let the program proceedl. Do
>> you want the local nuclear plant to have their system throw an error,
>> without a human response?
>>
>> In an important interpretation, the automated system
>>> was far better, and yet the first scientist was done with her analysis and
>>> accepted for publication before the second team even had the bugs worked
>>> out of the automated system!
>>
>> Like you state below, the automated system used, evolved from manually
>> designed systems, so automation is the easy way, but sometimes not the
>> best, depending on the circumstance and priority level of the
>> information being received.
>>
>> Yes, I think the slow-but-more-proper team
>>> did the more correct thing, but there is something to be said for "good
>>> enough", too (it works for evolution, for example).
>>
>>
>>>
>>>
>>>
>>>
>>> ___
>>> Tutor maillist  -  tu...@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>
>
> Disclaimer: I have no clue what unit testing is, nor have I had to use it yet.
>

But it would be a series of function instances from a module, right?
Not to butt in on the OP.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Menu not working properly

2010-08-02 Thread David Hutto
On Mon, Aug 2, 2010 at 8:00 AM, Evert Rol  wrote:
>> Hello Evert Rol,
>>           Thank you for the menu help, I have completed it with great 
>> success... There is 1 more problem I am currently having, and when I fix it 
>> my program will be completed. If you are interested in helping me with this 
>> last stretch, I will be greatly appreciative.
>>
>>           If you respond with a yes. I will go ahead and send my code over 
>> and list the problem I am currently having.
>
> Jason, it makes more sense to send this to the full tutor list, not just to 
> me:

A ha haha, you hit the wrong 'reply to button'. Stupid newb says what?

there are more people who can and will help you. Unless I've missed a
response to a previous post of yours where people disrecommended your
postings, but that shouldn't happen to quickly.
> Although in general, it's better to try and solve the problem yourself, and 
> ask the tutor list if you're really stuck, either with an error or a concept. 
> And the 'try and solve yourself' step can take one or more days and a lot of 
> Googling, but in the end you learn a lot from it.
> So, depending on your current problem, see if you want to try yourself first, 
> or that you feel you need the input from the list.
> (Code can be included with the mail if short; use something like 
> http://python.pastebin.com/ if lengthly code.)
>
> Good luck,
>
>  Evert
>
>
>
>
>
>>
>>          -Thank You
>>
>> On Mon, Aug 2, 2010 at 3:35 AM, Evert Rol  wrote:
>> > My problem is choice 3. Exit, if you select no or put an invalid answer... 
>> > It will run menu1... but then it runs
>> >     name = raw_input ("Enter your character name. ")
>> >     print "Your character name is:", name
>> >
>> > How can i make it so it prints menu1 like normal... then asks you to enter 
>> > your selection again?
>> > instead of running the above code.
>>
>> Put it in a loop with the necessary break statements. Something like:
>>
>> while True:
>>  print menu1
>>  answer = raw_input()
>>  if ...:
>>    ...
>>    break
>>  elif ...:
>>    ...
>>  elif ...:
>>   answer = raw_input()
>>   if ...:
>>     sys.exit()
>> raw_input('character name')
>>
>> Only the first option will break out of the loop to the 'character name' 
>> question; the other two options will continue to loop, apart from the point 
>> where you exit() the whole program.
>> If you need user input until the correct input has been given, that means 
>> you'll have to wrap things in a loop (generally a while loop that you break 
>> out of when you received correct input).
>> You could factor out the actual code inside the while loop into a function, 
>> which can make the structure clearer.
>>
>>
>> Btw,
>>
>> 
>>
>> >     characterChoice = input ("Enter your choice. ")
>>
>> You have input() here, while further down raw_input(). The latter is 
>> preferred in Python 2.x. I assume this is just a minor mistake.
>>
>>
>>  Evert
>>
>>
>> >     print
>> >
>> >     if characterChoice == 1:
>> >         print """
>> >
>> > *Place Holder*
>> >
>> >         """
>> >
>> >     elif characterChoice == 2:
>> >         print "Currently under construction.\nPlease choose again."
>> >         print menu1
>> >     elif characterChoice == 3:
>> >         endProgram = raw_input ("Do you want to end program? yes or no ")
>> >         if endProgram == "yes":
>> >             sys.exit(0)
>> >         elif endProgram == "no":
>> >             print menu1
>> >         else:
>> >             print "\nInvalid Command:\nSelect from the menu again.\n"
>> >             print menu1
>> >
>> >     print
>> >     name = raw_input ("Enter your character name. ")
>> >     print "Your character name is:", name
>> > ___
>> > Tutor maillist  -  tu...@python.org
>> > To unsubscribe or change subscription options:
>> > http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> ___
> Tutor maillist  -  tu...@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] Menu not working properly

2010-08-02 Thread David Hutto
On Mon, Aug 2, 2010 at 10:41 AM, Luke Paireepinart
 wrote:
>
>
> On Aug 2, 2010, at 8:13 AM, David Hutto  wrote:
>
>> On Mon, Aug 2, 2010 at 8:00 AM, Evert Rol  wrote:
>>>> Hello Evert Rol,
>>>>           Thank you for the menu help, I have completed it with great 
>>>> success... There is 1 more problem I am currently having, and when I fix 
>>>> it my program will be completed. If you are interested in helping me with 
>>>> this last stretch, I will be greatly appreciative.
>>>>
>>>>           If you respond with a yes. I will go ahead and send my code over 
>>>> and list the problem I am currently having.
>>>
>>> Jason, it makes more sense to send this to the full tutor list, not just to 
>>> me:
>>
>> A ha haha, you hit the wrong 'reply to button'. Stupid newb says what?

The first rule of any endeavour is to learn to laugh at yourself. If
you don't have cahunas to call your own self a newb, and laugh at the
mistakes you made, after thought , then what kind of programmers will
you be?

> I hope you're kidding. If you're not, leave the list right away.

It was a joke. Bad but I laughed at it.

You are not being helpful. If you were kidding, make it more clear next time.
>>
>> there are more people who can and will help you. Unless I've missed a
>> response to a previous post of yours where people disrecommended your
>> postings, but that shouldn't happen to quickly.
> Have you heard the saying about throwing rocks at glass houses? 'cause you 
> just screwed up your reply quoting.
>
> -Luke
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to get script to detect whether a file exists?

2010-08-02 Thread David Hutto
On Mon, Aug 2, 2010 at 8:53 PM, Richard D. Moores  wrote:
> On Mon, Aug 2, 2010 at 16:57, Steven D'Aprano  wrote:
>>  # File *probably* doesn't exist. Consider better error checking.
>
> Steve, before I dig into your detailed reply, please tell me what you
> meant by " # File *probably* doesn't exist. Consider better error
> checking.".


He was referring to the uncertainty principle that applies to all man
and life, ain't that right stephan?...*wink*, *wink*, *nudge*,
*nudge*.
>
> Context was
>
> def load(path):
>   """Open file given by path if it exists, and return its contents.
>   If it doesn't exist, save and return the default contents.
>   """
>   try:
>       f = open(path, 'r')
>   except IOError:
>       # File *probably* doesn't exist. Consider better error checking.
>       data = []
>       save(path, data)
>   else:
>       data = pickle.load(f)
>       f.close()
>   return data
>
> Dick
> ___
> Tutor maillist  -  tu...@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] How to get script to detect whether a file exists?

2010-08-02 Thread David Hutto
On Tue, Aug 3, 2010 at 12:05 AM, David Hutto  wrote:
> On Mon, Aug 2, 2010 at 8:53 PM, Richard D. Moores  wrote:
>> On Mon, Aug 2, 2010 at 16:57, Steven D'Aprano  wrote:
>>>  # File *probably* doesn't exist. Consider better error checking.
>>
>> Steve, before I dig into your detailed reply, please tell me what you
>> meant by " # File *probably* doesn't exist. Consider better error
>> checking.".
>
>
> He was referring to the uncertainty principle that applies to all man
> and life, ain't that right stephan?...*wink*, *wink*, *nudge*,
> *nudge*.
>>
>> Context was
>>
>> def load(path):
>>   """Open file given by path if it exists, and return its contents.
>>   If it doesn't exist, save and return the default contents.
>>   """
>>   try:
>>       f = open(path, 'r')
>>   except IOError:
>>       # File *probably* doesn't exist. Consider better error checking.
>>       data = []
>>       save(path, data)
>>   else:
>>       data = pickle.load(f)
>>       f.close()
>>   return data
>>
>> Dick
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>

I know that sometimes, in the darkof night, i say  stephan of oracle
eternance, please impart to me thy wisdom. And stephan answers with
bowels in hand, and relevance upon his tongue he delivers our saving
grace.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding the version # of a module, and py module problem

2010-08-05 Thread David Hutto
On Thu, Aug 5, 2010 at 7:33 PM, Wayne Watson
 wrote:
> It's been awhile since I've used python, and I recall there is a way to find
> the version number from the IDLE command line  prompt. dir, help,
> __version.__?
>
> I made the most minimal change to a program, and it works for me, but not my
> partner. He gets
>
> Traceback (most recent call last):
>   File "C:\Documents and
> Settings\HP_Administrator.DavesDesktop\Desktop\NC-FireballReport20100729.py",
> line 40, in 
>     from scipy import stats as stats # scoreatpercentile
>   File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7, in
> 
>     from stats import *
>   File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191, in
> 
>     import scipy.special as special
>   File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line 22,
> in 
>     from numpy.testing import NumpyTest
> ImportError: cannot import name NumpyTest
>
> Here are the first few lines of code.
>
> import sys, os, glob
> import string
> from numpy import *
> from datetime import datetime, timedelta
> import time
> from scipy import stats as stats # scoreatpercentile
>
> I'm pretty sure he has the same version of Python, 2.5, but perhaps not the
> numpy or scipy modules. I need to find out his version numbers.
>
> --
>Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>
>  (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
>   Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
>
>  "Republicans are always complaining that government is
>   out of control. If they get into power, they will
>   prove it." -- R. J. Rourke
>
>
> Web Page: 
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>

I'm pretty sure their might be an easier way, but since no one has
replied just yet. You can go into your command prompt and type pydoc
-p 1234(noth the python interpreter, and you might have to cd to the
Lib directory with pydoc in it). Then use a browser and go to
localhost:1234, and in the sight packages section click on the numpy,
or scipy, and it shows the version in parentheses beside the name at
top.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding the version # of a module, and py module problem

2010-08-05 Thread David Hutto
On Thu, Aug 5, 2010 at 8:53 PM, David Hutto  wrote:
> On Thu, Aug 5, 2010 at 7:33 PM, Wayne Watson
>  wrote:
>> It's been awhile since I've used python, and I recall there is a way to find
>> the version number from the IDLE command line  prompt. dir, help,
>> __version.__?
>>
>> I made the most minimal change to a program, and it works for me, but not my
>> partner. He gets
>>
>> Traceback (most recent call last):
>>   File "C:\Documents and
>> Settings\HP_Administrator.DavesDesktop\Desktop\NC-FireballReport20100729.py",
>> line 40, in 
>>     from scipy import stats as stats # scoreatpercentile
>>   File "C:\Python25\lib\site-packages\scipy\stats\__init__.py", line 7, in
>> 
>>     from stats import *
>>   File "C:\Python25\lib\site-packages\scipy\stats\stats.py", line 191, in
>> 
>>     import scipy.special as special
>>   File "C:\Python25\lib\site-packages\scipy\special\__init__.py", line 22,
>> in 
>>     from numpy.testing import NumpyTest
>> ImportError: cannot import name NumpyTest
>>
>> Here are the first few lines of code.
>>
>> import sys, os, glob
>> import string
>> from numpy import *
>> from datetime import datetime, timedelta
>> import time
>> from scipy import stats as stats # scoreatpercentile
>>
>> I'm pretty sure he has the same version of Python, 2.5, but perhaps not the
>> numpy or scipy modules. I need to find out his version numbers.
>>
>> --
>>            Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
>>
>>              (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
>>               Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
>>
>>              "Republicans are always complaining that government is
>>               out of control. If they get into power, they will
>>               prove it." -- R. J. Rourke
>>
>>
>>                     Web Page: 
>>
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> I'm pretty sure their might be an easier way, but since no one has
> replied just yet. You can go into your command prompt and type pydoc
> -p 1234(noth the python interpreter, and you might have to cd to the
> Lib directory with pydoc in it). Then use a browser and go to
> localhost:1234, and in the sight packages section click on the numpy,
> or scipy, and it shows the version in parentheses beside the name at
> top.
>

And not sure if this works in 2.5, I only have 2.6, 2.7, and 3.1 to test on.

>>> from setup import *
>>> print __version__
$Revision: 77217 $
>>>

So for you should be:
from numpy import *
print __version__
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] modify csv textfile

2010-08-07 Thread David Hutto
On Sat, Aug 7, 2010 at 7:26 AM, Alan Gauld  wrote:
>
> "TGW"  wrote
>>
>> What I want to output is:
>> 12345|some text|some more text|example|example32423
>> 11223|more text|and more|example|example455667
>>
>> So column 4 is where the change occurs, but only if the beginning
>> of the string in column 4  =~ /^example/i  # and it should be case
>> insensitive
>>
>
>> reader = csv.reader(open(filename, 'rb'), delimiter='|',
>> quoting=csv.QUOTE_NONE)
>> for row in reader:
>>   print row
>>
>> 
>> I can print the file, I just need a little help searching and replacing
>> the column 4 data element.
>
> OK, so I'm not sure which bit is confusing you.
> The reader returns a list of fields per row.
> You want the fourth column which is element 3 in row - ie. row[3]
> You can use startswith() or a regex to test the value
> You can replace the string with whatever you like since lists are mutable
> You can then store/write the modified list to whatever/wherever you like.
>
> Now which bit of that is causing you grief?

Probably the explanation. Mainly because of lack of documentation than
google terms, and appropriate questions
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  tu...@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] modify csv textfile

2010-08-07 Thread David Hutto
On Sat, Aug 7, 2010 at 8:26 AM, David Hutto  wrote:
> On Sat, Aug 7, 2010 at 7:26 AM, Alan Gauld  wrote:
>>
>> "TGW"  wrote
>>>
>>> What I want to output is:
>>> 12345|some text|some more text|example|example32423
>>> 11223|more text|and more|example|example455667
>>>
>>> So column 4 is where the change occurs, but only if the beginning
>>> of the string in column 4  =~ /^example/i  # and it should be case
>>> insensitive
>>>
>>
>>> reader = csv.reader(open(filename, 'rb'), delimiter='|',
>>> quoting=csv.QUOTE_NONE)
>>> for row in reader:
>>>   print row
>>>
>>> 
>>> I can print the file, I just need a little help searching and replacing
>>> the column 4 data element.
>>
>> OK, so I'm not sure which bit is confusing you.
>> The reader returns a list of fields per row.
>> You want the fourth column which is element 3 in row - ie. row[3]
>> You can use startswith() or a regex to test the value
>> You can replace the string with whatever you like since lists are mutable
>> You can then store/write the modified list to whatever/wherever you like.
>>
>> Now which bit of that is causing you grief?
>
> Probably the explanation. Mainly because of lack of documentation than
> google terms,
Not to say that docs are laccking to the proportion of want.

and appropriate questions
>>
>> --
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
>>
>>
>> ___
>> Tutor maillist  -  tu...@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] Distributing Python Code for Commercial Porpoises?

2010-08-08 Thread David Hutto
On Sun, Aug 8, 2010 at 2:41 PM, Eike Welk  wrote:
> Hello Alan!
>
> On Sunday August 8 2010 10:10:20 Alan Gauld wrote:
>> Yes thats a good point. Most books (including mine) focus on how to
>> write code. Very few tell you how to distrubute it! And that's not
>> just
>> in Python, most programming books are the same.
>>
>> Interesting.
>>
>> Alan G.
>
> Yes, I want to endorse that!
>
> Distributing your software is IMHO a worthy subject for any Python website or
> book. Especially because there is this idea, that all important components for
> software development are included in Python.

Four words... Software is python's propaganda.

>
> With Distutils, EasyInstall (*.egg), and Python Package Index there really
> exist an integrated build system with installer, a package manager, and a
> networked software repository.
>
> Additionally with Virtualenv or Buildout one can build encapsulated
> environments for testing or deployment, without fear for conflicting library
> versions.
>
> Someone however needs to find out how these components fit together, and then
> write a nice introduction on the subject.
>
>
> Eike.
>
>
> Links to the mentioned projects for reference:
>
> Distutils:   http://docs.python.org/distutils/
> EasyInstall: http://pypi.python.org/pypi/setuptools
>             http://pypi.python.org/pypi/distribute
> Virtualenv:  http://pypi.python.org/pypi/virtualenv
> Buildout:    http://www.buildout.org/
> Python Package Index: http://pypi.python.org/pypi
> ___
> Tutor maillist  -  tu...@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] Distributing Python Code for Commercial Porpoises?

2010-08-09 Thread David Hutto
On Sun, Aug 8, 2010 at 7:57 PM, Steven D'Aprano  wrote:
> On Mon, 9 Aug 2010 04:44:37 am David Hutto wrote:
>
>> Four words... Software is python's propaganda.
>
> Four more words: please trim unnecessary quoting.

No problem buddy pal.

>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  tu...@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] [SPAM]Re: O'Reilly is offering Learning Python (4th ed.), eBook form for USD 9.99

2010-08-11 Thread David Hutto
I thought the open source mentality of python was it own 'perpetual
bible'. A building of disciples so to speak.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Iterating through a list of replacement regex patterns

2010-09-02 Thread David Hutto
In the below function I'm trying to iterate over the lines in a textfile,
and try to match with a regex pattern that iterates over the lines in
a dictionary(not {}, but turns a text list of alphabetical words into a
list using readlines()).

def regexfiles(filename):
textfile = file(filename, 'r+')
# Open the dictionary file
dictionary = file('/var/www/main/american-english', 'r')
search = 0
readict = dictionary.readlines()
readfile = textfile.readlines()
select = 'abbott'
for item in readict:
search += 1
print search, '\nselect =' , select , 'item = ' , item , 
'readfile =
' , str(readfile) , '\nre.findall =' , re.findall( select,
str(readfile)) , '\nre.search = ' , re.search(select,
str(readfile[:])), '\n'

My last entry that comes up is:

14
select = abbott
item =  abbott
len readfile =  6
readfile =  
['|aaolaachenaaliyahaaronabbasabbasidabbottsaaolaachenaaliyahaaronabbasabbasidabbott"aaolaachenaaliyahaaronabbasabbasidabbott}aaolaachenaaliyahaaronabbasabbasidabbottvaaolaachenaaliyahaaronabbasabbasidabbott']
re.findall = ['abbott', 'abbott', 'abbott', 'abbott', 'abbott']
re.search =  <_sre.SRE_Match object at 0x8838b80>

Which is fine until I begin trying to iterate over the words in my
word 'dictionary' list to use as
replacement patterns with each new word iterated over in the list
getting placed as the regex pattern.

If I try to replace the variable 'select' with anything other than
select = 'abbott'(or whatever random
word being used that is in the file), with something like
str(readict[13]), which is a list of words, and the 13th
word in the list is also abbott, and is turned into a string, yielding
an extra +1 len, I get.

14
select = abbott
item =  abbott
len readfile =  7
readfile =  
['|aaolaachenaaliyahaaronabbasabbasidabbottsaaolaachenaaliyahaaronabbasabbasidabbott']
re.findall = []
re.search =  None

re.findall, and re.search show none, even when the variables show the
same, other than len,
and they've been turned into strings.

So my main question is...drum roll please...how do I iterate through a
list of terms inside of the regex,
without it yielding the second result?

Right now, I can see that it searches the file for the term if it's in
' ', so that
part works, and on other attempts than this one, I can get it to loop
through the words in the dictionary
list and replace the regex pattern as it goes through, then use
readlines() to check the files lines, but
even with this the changing variable makes it show none.

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


Re: [Tutor] Iterating through a list of replacement regex patterns

2010-09-02 Thread David Hutto
I just added +'*' to select in re.search(select+'*', str(readfile[:])),
and it now shows the same in both.

But if you have any input on modifications let me know.

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


Re: [Tutor] Iterating through a list of replacement regex patterns

2010-09-03 Thread David Hutto
On Thu, Sep 2, 2010 at 11:05 PM, David Hutto  wrote:
> I just added +'*' to select in re.search(select+'*', str(readfile[:])),
> and it now shows the same in both.
>
> But if you have any input on modifications let me know.
>
> Thanks,
> David
>

Still a problem. When I use the re.search(select+'*', str(readfile))
the asterisk  for re matches it to any character, so if there are any
letters of the word it matches.

I would like to match the exact word being sent not just any of the
characters, and the only way is with the exact word nothing following it,
but substituting the string parameter with the word even str(word), it
always shows negative for a match, search or findall.

So does this have something to do with the extra len on the str(wordfromlist)
as stated in the first email, and if so how do I remove whats there.

If not, what is the, probably small, thing I'm not doing to the item being
used as the re.search/findall parameter?

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


Re: [Tutor] Iterating through a list of replacement regex patterns

2010-09-03 Thread David Hutto
On Fri, Sep 3, 2010 at 2:51 PM, David Hutto  wrote:
> On Thu, Sep 2, 2010 at 11:05 PM, David Hutto  wrote:
>> I just added +'*' to select in re.search(select+'*', str(readfile[:])),
>> and it now shows the same in both.
>>
>> But if you have any input on modifications let me know.
>>
>> Thanks,
>> David
>>
>
> Still a problem. When I use the re.search(select+'*', str(readfile))
> the asterisk  for re matches it to any character, so if there are any
> letters of the word it matches.
>
> I would like to match the exact word being sent not just any of the
> characters, and the only way is with the exact word nothing following it,
> but substituting the string parameter with the word even str(word), it
> always shows negative for a match, search or findall.
>
> So does this have something to do with the extra len on the str(wordfromlist)
> as stated in the first email, and if so how do I remove whats there.
>
> If not, what is the, probably small, thing I'm not doing to the item being
> used as the re.search/findall parameter?
>
> Thanks,
> David
>

Fixed by rstrip() on item being iterated from dictionary file.

re.findall(str.rstrip(select), str(readfile)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating through a list of replacement regex patterns

2010-09-03 Thread David Hutto
First of all, I'll respond more thoroughly tomorrow, when I can review
what you said more clearly, but for now I'll clarify.

Here is the whole code that I'm using:

http://pastebin.com/Ak8DFjrb

On Fri, Sep 3, 2010 at 9:12 PM, Steven D'Aprano  wrote:
> On Fri, 3 Sep 2010 12:24:00 pm David Hutto wrote:
>> In the below function I'm trying to iterate over the lines in a
>> textfile, and try to match with a regex pattern that iterates over
>> the lines in a dictionary(not {}, but turns a text list of
>> alphabetical words into a list using readlines()).
>>
>> def regexfiles(filename):
> [...]
>
> Your function does too much. It:
>
> 1 manages a file opened for input and output;
> 2 manages a dictionary file;
> 3 handles multiple searches at once (findall and search);
> 4 handles print output;
>
> and you want it to do more:
>
> 5 handle multiple "select" terms.
>
>
> Your function is also poorly defined -- I've read your description
> repeatedly, and studied the code you give, and your three follow up
> posts, and I still don't have the foggiest clue of what it's supposed
> to accomplish!

This is supposed to recreate a thought experiment I've heard about, in which,
if you have an infinite amount of monkeys, with an infinite amount of
typewriters,
they'll eventually spit out Shakespeare.

So, I create a random length file, with random characters, then regex
it for the iteration
of dictionary terms, but the regex is needed further for the
theoretical exploratory purposes
into the thought experiment. If dictionary patterns are matched, then
it needs further regex
for grammatically proper structures, even if they don't make
sense(take mad libs for example),
but are still grammatically correct, randomly produced files.

So the bulldozer is needed.


You do two searches on each iteration, but other than
> print the results, you don't do anything with it.

I had to print the results, in order to understand why using 'apple'
in a variable
yielded something different than when I iterated over the text file.
The end result was that
the list of dictionary words ['a\n'', 'b\n'] had \n, which was the
extra character in the iteration I was referring to,
and thanks to printing it out I was able to further isolate the
problem through len().

So rstrip() removed '\n' from the iterated term in the text file,
yielding just the ['term'], and not ['term\n'].

Print helps you see the info first hand.

>
> What is the *meaning* of the function? "regexfiles" is a meaningless
> name, and your description "I'm trying to iterate over the lines in a
> textfile, and try to match with a regex pattern that iterates over the
> lines in a dictionary" is confusing -- the first part is fine, but what
> do you mean by a regex that iterates over the lines in a dictionary?
>
> What is the purpose of a numeric variable called "search"? It looks like
> a counter to me, not a search, it is incremented each time through the
> loop. The right way to do that is with enumerate(), not a manual loop
> variable.
>
> Why do you call readlines() instead of read()? This makes no sense to
> me. You then convert a list of strings into a single string like this:
>
> readlines() returns ['a\n', 'b\n', 'c\n']
> calling str() returns "['a\n', 'b\n', 'c\n']"
>
> but the result includes a lot of noise that weren't in the original
> file: open and close square brackets, commas, quotation marks.
>
> I think perhaps you want ''.join(readlines()) instead, but even that is
> silly, because you should just call read() and get 'a\nb\nc\n'.
>
> You should split this up into multiple functions. It will make
> comprehension, readability, debugging and testing all much, much
> easier. Code should be self-documenting -- ideally you will never need
> to write a comment, because what the code does should be obvious from
> your choice of function and variable names.
>
> I don't understand why you're using regex here. If I'm guessing
> correctly, the entries in the dictionary are all ordinary (non-regex)
> strings, like:
>
> ape
> cat
> dog
>
> only many, many more words :)
>
> Given that, using the re module is like using a bulldozer to crack a
> peanut, and about as efficient. Instead of re.search(target, text) you
> should just use text.find(target). There's no built-in equivalent to
> re.findall, but it's not hard to write one:
>
> def findall(text, target):
>    results = []
>    start = 0
>    p = text.find(target)
>    while p != -1:
>        r

Re: [Tutor] Iterating through a list of replacement regex patterns

2010-09-03 Thread David Hutto
On Fri, Sep 3, 2010 at 9:57 PM, David Hutto  wrote:
> First of all, I'll respond more thoroughly tomorrow, when I can review
> what you said more clearly, but for now I'll clarify.
>
> Here is the whole code that I'm using:
>
> http://pastebin.com/Ak8DFjrb
>
> On Fri, Sep 3, 2010 at 9:12 PM, Steven D'Aprano  wrote:
>> On Fri, 3 Sep 2010 12:24:00 pm David Hutto wrote:
>>> In the below function I'm trying to iterate over the lines in a
>>> textfile, and try to match with a regex pattern that iterates over
>>> the lines in a dictionary(not {}, but turns a text list of
>>> alphabetical words into a list using readlines()).
>>>
>>> def regexfiles(filename):
>> [...]
>>
>> Your function does too much. It:
>>
>> 1 manages a file opened for input and output;
>> 2 manages a dictionary file;
>> 3 handles multiple searches at once (findall and search);
>> 4 handles print output;
>>
>> and you want it to do more:
>>
>> 5 handle multiple "select" terms.
>>
>>
>> Your function is also poorly defined -- I've read your description
>> repeatedly, and studied the code you give, and your three follow up
>> posts, and I still don't have the foggiest clue of what it's supposed
>> to accomplish!
>
> This is supposed to recreate a thought experiment I've heard about, in which,
> if you have an infinite amount of monkeys, with an infinite amount of
> typewriters,
> they'll eventually spit out Shakespeare.
>
> So, I create a random length file, with random characters, then regex
> it for the iteration
> of dictionary terms, but the regex is needed further for the
> theoretical exploratory purposes
> into the thought experiment. If dictionary patterns are matched, then
> it needs further regex
> for grammatically proper structures, even if they don't make
> sense(take mad libs for example),
> but are still grammatically correct, randomly produced files.
>
> So the bulldozer is needed.

I forgot, the randomly generated files with random len, are regexed,
for words,, then sorted into a range file
for len of the words contained, then regexed for grammatical
structure, and sorted again.

The latters of this have not been set in yet, just up until it finds
the len of real words in the file, then regex of
the grammar is next on my list. So it's more practice with regex, than
use a bulldozer to dig a fire pit.
>
>
> You do two searches on each iteration, but other than
>> print the results, you don't do anything with it.
>
> I had to print the results, in order to understand why using 'apple'
> in a variable
> yielded something different than when I iterated over the text file.
> The end result was that
> the list of dictionary words ['a\n'', 'b\n'] had \n, which was the
> extra character in the iteration I was referring to,
> and thanks to printing it out I was able to further isolate the
> problem through len().
>
> So rstrip() removed '\n' from the iterated term in the text file,
> yielding just the ['term'], and not ['term\n'].
>
> Print helps you see the info first hand.
>
>>
>> What is the *meaning* of the function? "regexfiles" is a meaningless
>> name, and your description "I'm trying to iterate over the lines in a
>> textfile, and try to match with a regex pattern that iterates over the
>> lines in a dictionary" is confusing -- the first part is fine, but what
>> do you mean by a regex that iterates over the lines in a dictionary?
>>
>> What is the purpose of a numeric variable called "search"? It looks like
>> a counter to me, not a search, it is incremented each time through the
>> loop. The right way to do that is with enumerate(), not a manual loop
>> variable.
>>
>> Why do you call readlines() instead of read()? This makes no sense to
>> me. You then convert a list of strings into a single string like this:
>>
>> readlines() returns ['a\n', 'b\n', 'c\n']
>> calling str() returns "['a\n', 'b\n', 'c\n']"
>>
>> but the result includes a lot of noise that weren't in the original
>> file: open and close square brackets, commas, quotation marks.
>>
>> I think perhaps you want ''.join(readlines()) instead, but even that is
>> silly, because you should just call read() and get 'a\nb\nc\n'.
>>
>> You should split this up into multiple functions. It will make
>> comprehension, readability, debugging and testing

Re: [Tutor] Iterating through a list of replacement regex patterns

2010-09-03 Thread David Hutto
snip

I'll go further with this though, just to get the response.
Hypothetically, if I wanted AI(artificial imagination),
then I would want random thoughts that made sense, every once in a
while. So, I hypothesize that the first step
in Artificial Imagination, is random thoughts, and then they have to
make grammatical/formulatic sense, hence the regex.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Iterating through a list of replacement regex patterns

2010-09-05 Thread David Hutto
On Sat, Sep 4, 2010 at 6:16 AM, Steven D'Aprano  wrote:
> On Sat, 4 Sep 2010 11:57:00 am David Hutto wrote:
>> First of all, I'll respond more thoroughly tomorrow, when I can
>> review what you said more clearly, but for now I'll clarify.
>>
>> Here is the whole code that I'm using:
>>
>> http://pastebin.com/Ak8DFjrb
>
> David, in genrandfiles() you say this:
>
>    mkd = 0
>    # This makes the range dir for range of the files for later matched
>    # len of dictionary regex word matches
>    if mkd == 0:
>        makerangedirs()
>
> Firstly, I don't understand the comment. All the words individually make
> sense, but altogether, they look like something generated by one of
> those monkeys with a typewriter... *wink*

The comments are mainly for me, which is why they get wordy, so I know
exactly why I placed it there.

>
> Secondly, given that in the previous line you just set mkd = 0, is there
> any possible circumstance where the test "if mkd == 0" would *not*
> succeed? Why don't you just unconditionally call makerangedirs()?
>
>    mkd = 0
>    makerangedirs()

This only called once to initially create the list of range files. If
it gets called again then it throws an error that the dir
already exists. I haven't checked to see, but I did this because I was
under the impression, that once the while loop is broken it went back
through the function. But once I have it working correctly, I'll
revise it a little more.
>
>
>
>> This is supposed to recreate a thought experiment I've heard about,
>> in which, if you have an infinite amount of monkeys, with an infinite
>> amount of typewriters, they'll eventually spit out Shakespeare.
>
> Ha ha, well, I don't want to discourage you, but the sun will burn out
> and die long before you get more than a couple of words of Shakespeare
> from this technique.

But that would be the point, that infinite monkeys with infinite typewriters,
would be forced to work until the end of time like good little domesticated
beasts of burden.

>
> On the other hand, there are ways to randomly generate non-random text
> *incredibly quickly*. See http://en.wikipedia.org/wiki/Weasel_program
> for more detail.

Will take a look at it later. The characters were just to start at the
initial. I was going to replace that with
randomly selected words from the dictionary instead because of the
above mentioned
time constraints on testing it continuously. Although I'd like to see
it, I might not have until
the sun burns out to test the theory.

Thanks for the help though.
David


>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  tu...@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] Creating custom GUI elements

2010-09-05 Thread David Hutto
I'd suggest you take a look at blender. It has a pretty easy to use
game engine with actuators, sensors and controllers, with a Python
scripts api. It'll take the time out of going 3-d with pygame, and you
can build the custom legos within it as well.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Multiple versions of python and paths problems

2010-09-06 Thread David Hutto
On Mon, Sep 6, 2010 at 1:46 PM, Dominique  wrote:
> Hello,
>
> I usually use python 2.6 and several packages. Everything's fine.
>
> At present, I'm trying to run a package which is only available with python 
> 2.5.
> So, i installed 2.5 and the various dependencies needed to run this package:
> PIL, numpy... which were already installed in my 2.6 site-packages.
>
> Unfortunately, when I try to run it under Idle 2.5, python goes in the 2.6
> site-packages to get these dependencies (PIL,...) and throws me a traceback 
> (due
> to incompatibilities).
>
> I understand it is a paths problem.
>
> So, I added the path of python 2.5 and that of my application to the path and
> Pythonpath in the windows environ variables.
> But the same problems arise.
>
> So, I tried to load the normal 2.5 Idle and unload ('remove') everything 
> related
> to 2.6 from sys.path, but it's strangely not working completely.
>
> Finally, I managed to run the program :
> - by launching D:\python25\python.exe -E -S in a console (which seems to 
> prevent
> python from loading the paths)
> - then appending the application path to sys.path
> but it's really not fun working with this bloody windows console where cut and
> paste is impossible...
>
> So, here is my question:
> How can I force py2.5 to go and find the dependencies only in the 2.5
> site-packages ?
>
> Thanks in advance for your help.
>
> Dominique
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
forgot to hit reply all
>From wht the ole swiss cheese kinda recalls, just cd into the 2.5 main
dir from the windows command propmpt, and then you should be able to
type python /path/to/2.5/idlelib/idle.py, or whatever is on your
system.

If that's not it, then let me know, and I'll switch os's to make sure
what it was.

Also, there is a list specifically for window's python. pywin32.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Multiple versions of python and paths problems

2010-09-07 Thread David Hutto
On Tue, Sep 7, 2010 at 4:03 AM, Dominique  wrote:
> Alan Gauld  btinternet.com> writes:
>
>
>> How do you start IDLE? Is it via a desktop or start menu shortcut?
>> If so what is the startin folder specified as?
> Hello,
> First, thanks to you David, Alan and Dave for your help.
>
> Start with shortcut whose path is : "D:\Python25\python.exe" or
> "D:\Python25\python.exe -E -S".
>
>> What happens when you run it from the command ine with no extra
>> parameters - what error do you get?
> All paths related to python 2.6 and python 2.5 are imported (visible through
> sys.path)in both cases.
> The error is when launching the app which needs PIL, numpy... from 2.5 and not
> 2.6 (the versions imported are those of 2.6, causing the app to crash)
>
> Note that paths are not imported only by launching D:\python25\python.exe -E 
> -S
> in a DOS CONSOLE.
>
>> Do you have both versions of Python in your environment variables?
> Yes
>
>> In which order?
>
> PATH is as follows (one by line):
> %SystemRoot%\system32;
> %SystemRoot%;
> %SystemRoot%\System32\Wbem;
> D:\WINDOWS\system32\WindowsPowerShell\v1.0;
> D:\Program Files\TortoiseSVN\bin;
> D:\Program Files\QuickTime\QTSystem\;
> D:\OpenCV2.1\bin;
> D:\Python26;
> d:\Python26\Scripts;
> D:\Python26\Lib\site-packages;
> D:\Python25;
> D:\Python25\Scripts;
> D:\Python25\Lib\site-packages;
> D:\Python25\Lib\site-packages\pyvision\releases\pyvision_0.8.1\src\;
> D:\Python25\Lib\site-packages\opencv

>
> PYTHONPATH is as follows:
> D:\Python26\Lib\site-packages;
> D:\Python25\Lib\site-packages;
> D:\Python25\Lib\site-packages\pyvision\releases\pyvision_0.8.1\src\
>
> Which order should I use ?



If I'm still understanding the original question, if you right click
on a file, in Windows, and it says edit with idle, then idle is the
last version of python idle you've installed. If you call python from
the command prompt then it should be the first c:/pythonversionnumber
in environment variables that is called. so if you have
c:/python25;c:/python26;c:python3 then you should get 2.5 in command
prompt if you type python.

Paths, from what I know are lists, and the order is what you want to
be shown first to your program.
>
>> Set the Quick Edit option for the terminal it will save you a lot of
>> pain.
> Thanks for the tip !  It's a special cut&paste (you have to right-click on the
> bar to have it work)!!
>
>> There are probably several ways round it, including creating a local
>> startup file.
> OK
>
>> But if the paths are right it should work, and you may need to create
>> a startup
>> DOS file to set them before executing python...
> I tried without success...
> How would you do this ?
>
> Thanks a lot for your help. As usual here!
>
> Dominique
>
>
> ___
> Tutor maillist  -  tu...@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


  1   2   3   4   >