Re: [Tutor] function animals at 0x662f0 what does it mean?

2006-11-13 Thread Richard Gelling
 


Registered Linux User : 256848
Failure isn't an option -- it comes bundled with Microsoft Windows

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Kristinn Didriksson
Sent: 13 November 2006 16:51
To: tutor@python.org
Subject: [Tutor] function animals at 0x662f0 what does it mean?

Hello,
This is my first program calling functions :) It worked nicely except for
the message above. Can anyone explain what the message means.
Thanks,
Kristinn

Program
-
# a program that prints the lyrics for Old Mcdonal had a farm for 5
different animals.
# this will have two functions: oldMac and animals # two functions will be
passed: animal and sound

def animals(animal, sound):
# print out the lyrics calling the subroutine for aminals
print Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!
print And on the farm he had a , animal + , Ee-igh, Ee-igh, Oh!
print With a, sound + ,, sound, here and a , sound + ,,
sound +  there.
print Here a, sound + , there a, sound + , everyehere a, sound

+ ,, sound + .
print Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!
print
return animals



def oldMac():
print animals(cow, moo)
print animals(pig, oink)
print animals(horse, neigh)
print animals(dog, woof)
print animals(cat, meow)

oldMac()


--
Output
-
Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!
And on the farm he had a  cow, Ee-igh, Ee-igh, Oh!
With a moo, moo here and a moo, moo there.
Here a moo, there a moo, everyehere a moo, moo.
Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!

function animals at 0x66030
Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!
And on the farm he had a  pig, Ee-igh, Ee-igh, Oh!
With a oink, oink here and a oink, oink there.
Here a oink, there a oink, everyehere a oink, oink.
Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!

function animals at 0x66030
Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!
And on the farm he had a  horse, Ee-igh, Ee-igh, Oh!
With a neigh, neigh here and a neigh, neigh there.
Here a neigh, there a neigh, everyehere a neigh, neigh.
Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!

function animals at 0x66030
Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!
And on the farm he had a  dog, Ee-igh, Ee-igh, Oh!
With a woof, woof here and a woof, woof there.
Here a woof, there a woof, everyehere a woof, woof.
Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!

function animals at 0x66030
Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!
And on the farm he had a  cat, Ee-igh, Ee-igh, Oh!
With a meow, meow here and a meow, meow there.
Here a meow, there a meow, everyehere a meow, meow.
Old MacDonald had a farm, Ee-igh, Ee-igh, Oh!

function animals at 0x66030

---
I don't think you need the 'return animals' in the animals function. It is
just displaying where the aniaml function is in memory. 

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


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


[Tutor] any help with this piece of code

2005-05-12 Thread Richard gelling
import os

fileList = []
subDirectories = []
directories = []
directoryPath = raw_input( Type in the path you want to start at:  )

for directory,subDirectory, files in os.walk( directoryPath ):
directories.append( directory )
subDirectories.append( subDirectory )
fileList.append( files )

for Files in fileList:
print Files

# It works fine up until here

fileToSearchFor = raw_input( Type in the file name you want to search 
for: )

if fileToSearchFor in fileList:
print %s was found % fileToSearchFor
else:
print %s was not found % fileToSearchFor

Could someone explain to me why this pice of code doesn't work, in that 
it works fine up until where I have commented , but when I come to 
search the list for a file name, even though I know the filename is in 
that particular directory, and is present in the list returned by 
'fileList.append( files )' it always reports that the file is not found. 
Incidentally if you try this code out, when prompted for the path to 
start at, don't select a large directory as it takes sometime to run. It 
may not be very useful I am just curious as to why the file name cannot 
be found in the list, what am I missing?

Richard Gelling


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


Re: [Tutor] sys.argv[1: ] help

2005-02-28 Thread Richard gelling
Hi,
Thanks a lot to everyone that replied. I was missing the %* in the 
following line, in the File associations I just had upto the %1. 
Adding %* cured my problem.

Python.File=C:\Python24\python.exe %1 %*
Sorry for the typos in some of my examples, every keyboard I've tried appears 
to have the same fault on it!
Anyway thanks a lot again,
Richard G.




Smith, Jeff wrote:
Richard,
I have no problems running your example.  It would be helpful in the
future ot let us know which version and variant of Python you are
running.  I am using the canonical (as oppose to ActiveState) Python
2.4.
From the command prompt, type
assoc .py
and you should see
.py=Python.File
Then type
ftype Python.File
which should return
Python.File=C:\Python24\python.exe %1 %*
If the last one isn't correct (with approriate path and assoc type
associations) then you can correct it with
ftype ASSOCTYPE=PATHSTUFF
As an added bonus, you can also create a system environment variable
called PATHEXT and set it to .py and you won't even have to type the .py
to execute the script.  I added all the following to my PATHEXT:
.py;.pyw;.pys;.pyo;.pyc
While you're at it, you should also check the assoc/ftype for .pyw as
.pyw=Python.NoConFile
Python.NoConFile=C:\Python24\pythonw.exe %1 %*
Good luck,
Jeff
-Original Message-
From: Richard gelling [mailto:[EMAIL PROTECTED] 
Sent: Sunday, February 27, 2005 1:41 PM
To: tutor@python.org
Subject: Re: [Tutor] sys.argv[1: ] help


Hi,
It is actually associated with just 'python', changed it to associate 
with 'pythonw' and I got nothing on the same example not even the [], so

I am assuming that 'python' is the correct one?






Liam Clarke wrote:
 

Yeah, right click on a .py and check if it's associated with pythonw or
   

 

python.exe
GL,
Liam Clarke
On Sun, 27 Feb 2005 18:28:18 +, Richard gelling 
[EMAIL PROTECTED] wrote:

   

Hi,
Yes, I use both Wndows XP and Linux( at work ) . I left that in by 
mistake I am actually just typing in

arg1,py a b c
at the windows XP command prompt
Sorry for the confusion.
Liam Clarke wrote:
  

 

Are you using XP still? I've never seen this before -


   

./arg1.py a  b c
  

 

But anyhoo, I tried out just
'c:\python23\foo.py'
as opposed to
'c:\python23\python foo.py' and
while foo.py will run, it doesn't echo to the console, as on my 
machine running a .py file runs it through pythonw.exe - I'd check it
   

 

out for your machine, it's probably the same. You'd need to change 
the association to python.exe, but that would mean that you always 
got a DOS box for every Python script you ran, which is annoying with
   

 

GUIs.
Erm, if you don't want to type in python each time, either change the
   

 

association or create a batch file called x or a or something that 
runs Python  and stick it in a directory that's in your PATH system 
variable. Only problem with that is passing command line 
variables

...might just be better to type python
Good Luck,
Liam Clarke
On Sun, 27 Feb 2005 17:55:54 +, Richard gelling 
[EMAIL PROTECTED] wrote:



   

Hi,
No What I get if I was to type in
./arg1.py a  b c
All I get is
[]
If i type at the command prompt
python arg1.py a b c
I get ['a','b','c']  as expected
All the other programs and examples I have typed in work fine just 
by typing in the file name, I don't have to preced the file name 
with python, only this example. I hope this makes it clearer

Richard G.
Nick Lunt wrote:

  

 

Richard,
if you try to print sys.argv[1:] when sys.argv only contain 
sys.argv[0] then you are bound to get an empty list returned, [] .

Im not sure I understand the problem you think you've got but 
here's what happens with sys.argv for me, and it's correct.

[argl.py]
$ cat argl.py
#!/usr/bin/python
import sys
print sys.argv[1:]
./argl.py
[]
./argl.py a b c
['a', 'b', 'c']
Is that what your getting ?





   

Sorry for the late response, I tried all of the the suggestions, 
including correcting my typo of print sys[1:] and tried print 
sys,argv[1:], this does now work as long as I run 'python test.py 
fred joe' it returns all the arguments. If I try just test.py all 
I get is '[]' . Is there something wrong with my environmental 
variables in Windows XP, I would like to be able to just use the 
file name rather than having to type python each time. Any help 
would be gratefully received.

Richard G. ___
 

 

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


Re: [Tutor] sys.argv[1: ] help

2005-02-27 Thread Richard gelling
Danny Yoo wrote:
 

I am reading ' Learning Python second edition' by Mark Lutz and David
Ascher, and I trying the code examples as I go along. However I am
having a problem with the following, which I don't seem to be able to
resolve :-
 

 

# test.py
import sys
print sys[ 1: ]
This I believe is supposed to print the 1st argument passed to the
program. However if I try
test.py fred
All I get at the command line is
[]
 


Hi Jay,
Are you sure that is what your program contained?  I'm surprised that this
didn't error out!  The program:
##
import sys
print sys[1:]
##
should raise a TypeError because 'sys' is a module, and not a list of
elements, and modules don't support slicing.  Just out of curiosity, can
you confirm that you aren't getting an error message?

(I know I'm being a bit silly about asking about what looks like a simple
email typo, but computer programming bugs are all-too-often about typos.
*grin*
When you write about a program, try using cut-and-paste to ensure that the
program that you're running is the same as the program you're showing us.)
Best of wishes to you!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
 

Hi,
Sorry for the late response, I tried all of the the suggestions, 
including correcting my typo of print sys[1:] and tried print 
sys,argv[1:], this does now work as long as I run 'python test.py fred 
joe' it returns all the arguments. If I try just test.py all I get is 
'[]' . Is there something wrong with my environmental variables in 
Windows XP, I would like to be able to just use the file name rather 
than having to type python each time. Any help would be gratefully received.

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


Re: [Tutor] sys.argv[1: ] help

2005-02-27 Thread Richard gelling
Hi,
It is actually associated with just 'python', changed it to associate 
with 'pythonw' and I got nothing on the same example not even the [], so 
I am assuming that 'python' is the correct one?







Liam Clarke wrote:
Yeah, right click on a .py and check if it's associated with pythonw
or python.exe
GL,
Liam Clarke 

On Sun, 27 Feb 2005 18:28:18 +, Richard gelling
[EMAIL PROTECTED] wrote:
 

Hi,
Yes, I use both Wndows XP and Linux( at work ) . I left that in by
mistake I am actually just typing in
arg1,py a b c
at the windows XP command prompt
Sorry for the confusion.
Liam Clarke wrote:
   

Are you using XP still? I've never seen this before -
 

./arg1.py a  b c
   

But anyhoo, I tried out just
'c:\python23\foo.py'
as opposed to
'c:\python23\python foo.py' and
while foo.py will run, it doesn't echo to the console, as on my
machine running a .py file runs it through pythonw.exe - I'd check it
out for your machine, it's probably the same. You'd need to change the
association to python.exe, but that would mean that you always got a
DOS box for every Python script you ran, which is annoying with GUIs.
Erm, if you don't want to type in python each time, either change the
association or create a batch file called x or a or something that
runs Python  and stick it in a directory that's in your PATH system
variable. Only problem with that is passing command line variables
...might just be better to type python
Good Luck,
Liam Clarke
On Sun, 27 Feb 2005 17:55:54 +, Richard gelling
[EMAIL PROTECTED] wrote:
 

Hi,
No What I get if I was to type in
./arg1.py a  b c
All I get is
[]
If i type at the command prompt
python arg1.py a b c
I get ['a','b','c']  as expected
All the other programs and examples I have typed in work fine just by
typing in the file name, I don't have to preced the file name with
python, only this example. I hope this makes it clearer
Richard G.
Nick Lunt wrote:

   

Richard,
if you try to print sys.argv[1:] when sys.argv only contain sys.argv[0]
then you are bound to get an empty list returned, [] .
Im not sure I understand the problem you think you've got but here's
what happens with sys.argv for me, and it's correct.
[argl.py]
$ cat argl.py
#!/usr/bin/python
import sys
print sys.argv[1:]
./argl.py
[]
./argl.py a b c
['a', 'b', 'c']
Is that what your getting ?



 

Sorry for the late response, I tried all of the the suggestions,
including correcting my typo of print sys[1:] and tried print
sys,argv[1:], this does now work as long as I run 'python test.py fred
joe' it returns all the arguments. If I try just test.py all I get is
'[]' . Is there something wrong with my environmental variables in
Windows XP, I would like to be able to just use the file name rather
than having to type python each time. Any help would be gratefully received.
Richard G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

   

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


 

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

   


 

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


 

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


Re: [Tutor] sys.argv[1: ] help

2005-02-27 Thread Richard gelling
Hi,
It is actually associated with just 'python', changed it to associate
with 'pythonw' and I got nothing on the same example not even the [], so
I am assuming that 'python' is the correct one?






Liam Clarke wrote:
Yeah, right click on a .py and check if it's associated with pythonw
or python.exe
GL,
Liam Clarke 

On Sun, 27 Feb 2005 18:28:18 +, Richard gelling
[EMAIL PROTECTED] wrote:
 

Hi,
Yes, I use both Wndows XP and Linux( at work ) . I left that in by
mistake I am actually just typing in
arg1,py a b c
at the windows XP command prompt
Sorry for the confusion.
Liam Clarke wrote:
   

Are you using XP still? I've never seen this before -
 

./arg1.py a  b c
   

But anyhoo, I tried out just
'c:\python23\foo.py'
as opposed to
'c:\python23\python foo.py' and
while foo.py will run, it doesn't echo to the console, as on my
machine running a .py file runs it through pythonw.exe - I'd check it
out for your machine, it's probably the same. You'd need to change the
association to python.exe, but that would mean that you always got a
DOS box for every Python script you ran, which is annoying with GUIs.
Erm, if you don't want to type in python each time, either change the
association or create a batch file called x or a or something that
runs Python  and stick it in a directory that's in your PATH system
variable. Only problem with that is passing command line variables
...might just be better to type python
Good Luck,
Liam Clarke
On Sun, 27 Feb 2005 17:55:54 +, Richard gelling
[EMAIL PROTECTED] wrote:
 

Hi,
No What I get if I was to type in
./arg1.py a  b c
All I get is
[]
If i type at the command prompt
python arg1.py a b c
I get ['a','b','c']  as expected
All the other programs and examples I have typed in work fine just by
typing in the file name, I don't have to preced the file name with
python, only this example. I hope this makes it clearer
Richard G.
Nick Lunt wrote:

   

Richard,
if you try to print sys.argv[1:] when sys.argv only contain sys.argv[0]
then you are bound to get an empty list returned, [] .
Im not sure I understand the problem you think you've got but here's
what happens with sys.argv for me, and it's correct.
[argl.py]
$ cat argl.py
#!/usr/bin/python
import sys
print sys.argv[1:]
./argl.py
[]
./argl.py a b c
['a', 'b', 'c']
Is that what your getting ?



 

Sorry for the late response, I tried all of the the suggestions,
including correcting my typo of print sys[1:] and tried print
sys,argv[1:], this does now work as long as I run 'python test.py fred
joe' it returns all the arguments. If I try just test.py all I get is
'[]' . Is there something wrong with my environmental variables in
Windows XP, I would like to be able to just use the file name rather
than having to type python each time. Any help would be gratefully received.
Richard G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

   

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


 

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

   


 

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


 


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