By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,080 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,080 IT Pros & Developers. It's quick & easy.

Are rank noobs tolerated, here?

P: n/a

I'm trying to learn how to program. I'm using:

How to Think Like a Computer Scientist

Learning with Python
2nd Edition

Am I likely to receive any help, here, or is there another irc, forum, etc,
that might better serve a complete amateur such as myself. Thnx.

nb
Jun 27 '08 #1
Share this Question
Share on Google+
11 Replies


P: n/a
notbob <no****@nothome.comwrites:
Am I likely to receive any help, here, or is there another irc, forum, etc,
that might better serve a complete amateur such as myself. Thnx.
You're very likely to receive help here. Or at the very least, people will
point you at the best place to get it. Fire away!

Glenn
Jun 27 '08 #2

P: n/a
CM
On May 4, 7:45 pm, notbob <not...@nothome.comwrote:
I'm trying to learn how to program. I'm using:

How to Think Like a Computer Scientist

Learning with Python
2nd Edition

Am I likely to receive any help, here, or is there another irc, forum, etc,
that might better serve a complete amateur such as myself. Thnx.

nb
Another good place to be aware of is the Python Tutor List, some great
people helping out there. You can search the archive and/or subscribe
to
the list here:
http://www.nabble.com/Python---tutor-f2981.html

I've found learning from scratch is aided if you know what sorts of
things
you hope to do with programming and then work from within that, using
issues
germane to that area as building blocks.
Jun 27 '08 #3

P: n/a
On May 4, 6:45 pm, notbob <not...@nothome.comwrote:
I'm trying to learn how to program. I'm using:

How to Think Like a Computer Scientist

Learning with Python
2nd Edition

Am I likely to receive any help, here, or is there another irc, forum, etc,
that might better serve a complete amateur such as myself. Thnx.
Everybody is very nice on IRC, in forums, and here. We don't bite that
hard!
>
nb
Jun 27 '08 #4

P: n/a
notbob <no****@nothome.comwrites:
Am I likely to receive any help, here, or is there another irc,
forum, etc, that might better serve a complete amateur such as
myself. Thnx.
This forum is particularly welcoming to newbies, I've found. Go ahead
and start a new thread for any Python question.

One caveat: When you do compose a message asking a question, please
make the Subject field of your message meaningful by itself and don't
put anything like "Newbie question" in there. If it's a newbie
question, we'll figure that out for ourselves, and it shouldn't affect
whether or not it gets answered.

(You haven't done anything like that, but I'm noting it in advance and
because I hope *other* newbies will also see this and take note.)

--
\ "I'd take the awe of understanding over the awe of ignorance |
`\ any day." -- Douglas Adams |
_o__) |
Ben Finney
Jun 27 '08 #5

P: n/a
On 2008-05-04, notbob <no****@nothome.comwrote:
I'm trying to learn how to program. I'm using:

How to Think Like a Computer Scientist

Learning with Python
2nd Edition
http://openbookproject.net//thinkCSpy/index.xhtml

OK then, using the above, I get everything up till chap 3 and functions and
then it all falls apart. I try using his code and nothing. I'm running
vers 2.5.1 on slackware 12. Here's what I don't get:

----------

"Here is an example of a user-defined function that has a parameter:
def print_twice(bruce):
print bruce, bruce

This function takes a single argument and assigns it to the parameter named
bruce. The value of the parameter (at this point we have no idea what it
will be) is printed twice, followed by a newline. The name bruce was chosen
to suggest that the name you give a parameter is up to you, but in general,
you want to choose something more illustrative than bruce.

****ME****
is this just an example of how the def should be written and it doesn't
really do anthing... yet? I read another newb explanation here:
http://www.codepedia.com/1/Beginners...thon_Functions
....and it doesn't work, either. I define myfirstfunction in the pyth editor
and give the command print myfirstfuntion and I get back this:
<function myfirstfunction at 0xb7b9c994>
.....when I add the ._doc_, it get this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute '_doc_'
.....so, there is a no go there, too.
****ME****
The interactive Python shell provides us with a convenient way to test
our functions. We can use the import statement to bring the functions
we have defined in a script into the interpreter session. To see how this
works, assume the print_twice function is defined in a script
named chap03.py. We can now test it interactively by
importing it into our Python shell session:

****ME****
ok, I try and follow the above, but where is he getting the script? So, I
make a script called chap03.py and put it in ~/pyth/chap03/.
****ME****
>>from chap03 import *
print_twice('Spam')
Spam Spam
>>print_twice(5)
5 5
>>print_twice(3.14159)
3.14159 3.14159

****ME****
I then try an do the import thing above, but the pyth ed accepts none of it.
not from:
from ~/pyth/chap03/ import *
from chap03 import * #taken from ~/pyth/
.....nor from any other configuration I can imagine, so that "from" command
makes no sense.
****ME****
In a function call, the value of the argument is assigned to the
corresponding parameter in the function definition. In effect, it is if
bruce = 'Spam' is executed when print_twice('Spam')
is called, bruce = 5 in print_twice(5), and
bruce = 3.14159 in print_twice(3.14159)."

****ME****
OK, I'm totally lost. Neither the above or the other link works or make any
sense at all. Is the above print_twice(5), etc, supposed to work like the
original print_twice(bruce) function (which still doesn't!), just with a
different parameter? Call me stupid, but I'd sure like to get past this.
How am I supposed to get the original def to work? I've yet to figure out
how to get plain ol':
bruce bruce
Yes, I've indented 4 spaces where I should.
****ME****

----------

I feel dumber'n a bag 0' hammers and in need of clarification.

Thank you
nb
Jun 27 '08 #6

P: n/a
On May 5, 1:43*pm, notbob <not...@nothome.comwrote:
On 2008-05-04, notbob <not...@nothome.comwrote:
I'm trying to learn how to program. *I'm using:
How to Think Like a Computer Scientist
Learning with Python
2nd Edition

http://openbookproject.net//thinkCSpy/index.xhtml

OK then, using the above, I get everything up till chap 3 and functions and
then it all falls apart. *I try using his code and nothing. *I'm running
vers 2.5.1 on slackware 12. *Here's what I don't get:

----------

"Here is an example of a user-defined function that has a parameter:

def print_twice(bruce):
* * print bruce, bruce

This function takes a single argument and assigns it to the parameter named
bruce. *The value of the parameter (at this point we have no idea what it
will be) is printed twice, followed by a newline. *The name bruce was chosen
to suggest that the name you give a parameter is up to you, but in general,
you want to choose something more illustrative than bruce.

****ME****
is this just an example of how the def should be written and it doesn't
really do anthing... yet? *
Well, it prints whatever bruce is.
I read another newb explanation here:http://www.codepedia.com/1/Beginners...thon_Functions
...and it doesn't work, either. *I define myfirstfunction in the pyth editor
and give the command print myfirstfuntion and I get back this:
<function myfirstfunction at 0xb7b9c994>
Looks like you didn't call it right. Even though myfirstfunction
doesn't
take any parameters, you still have to use parentheses. You must
invoke
it by myfirstfunction(). Without the parenthese, you're just printing
the
location of the function. This allows functions to call functions, so
that
you can take a list and apply myfirstfunction to every item in the
list
even though myfirstfunction was designed to process only a single
item.
....when I add the ._doc_, it get this:
Traceback (most recent call last):
* File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute '_doc_'
....so, there is a no go there, too.
Should be TWO underscores, '.__doc__', not '._doc_'.
Such doc strings can be very useful.

For example:
>>import collatz_functions
help(collatz_functions.collatz)
Help on function collatz in module collatz_functions:

collatz(a, p)
3x+1 sequencer, no loop detection

collatz(a,p)
a: starting value
p: print options (binary)
bit 0 print even numbers (turns off power division)
bit 1 print odd numbers
bit 2 print debug (if any)
returns: CollatzSequenceParameters [R1count, R2count]

Notice collatz() takes two arguments, but I left off the
parentheses and arguments when using the help() function.
That's an example of using the function location.
****ME****

The interactive Python shell provides us with a convenient way to test
our functions. *We can use the import statement to bring the functions
we have defined in a script into the interpreter session. *To see how this
works, assume the print_twice function is defined in a script
named chap03.py. *We can now test it interactively by
importing it into our Python shell session:

****ME****
ok, I try and follow the above, but where is he getting the script? *So,I
make a script called chap03.py and put it in ~/pyth/chap03/. *
Actually, I'm not sure where you should put it. I put mine in
the Lib directory.
****ME****
>from chap03 import *
print_twice('Spam')
Spam Spam
>print_twice(5)
5 5
>print_twice(3.14159)

3.14159 3.14159

****ME****
I then try an do the import thing above, but the pyth ed accepts none of it.
not from:
from ~/pyth/chap03/ import * * * *
from chap03 import * * * * * * *#taken from ~/pyth/
....nor from any other configuration I can imagine, so that "from" command
makes no sense. *
You use "from" to specify what parts of the module to
import, not specify where the module is located. For instance, I
could have said above

from collatz_functions import collatz

and just that function would have been loaded and I could call
it directly, collatz(x,y) instead of collatz_functions.collatz(x,y).
****ME****

In a function call, the value of the argument is assigned to the
corresponding parameter in the function definition. *In effect, it is if
bruce = 'Spam' is executed when print_twice('Spam')
is called, bruce = 5 in print_twice(5), and
bruce = 3.14159 in print_twice(3.14159)."

****ME****
OK, I'm totally lost. *Neither the above or the other link works or makeany
sense at all. *Is the above print_twice(5), etc, supposed to work like the
original print_twice(bruce) function (which still doesn't!), just with a
different parameter? *
Yes, once you define print_twice(bruce), you have to call it with
something.

print_twice(5) prints 5 5
print_twice('fred') prints fred fred
print_twice(bruce) is an error if you haven't defined a variable
named bruce
Call me stupid, but I'd sure like to get past this.
How am I supposed to get the original def to work? *I've yet to figure out
how to get plain ol':
bruce bruce
Yes, I've indented 4 spaces where I should.
You have to use parentheses and enclose some legal entity when you
call it.
*
****ME****

----------

I feel dumber'n a bag 0' hammers and in need of clarification.

Thank you
nb
Jun 27 '08 #7

P: n/a
On May 6, 4:43 am, notbob <not...@nothome.comwrote:
"Here is an example of a user-defined function that has a parameter:

def print_twice(bruce):
print bruce, bruce
****ME****
ok, I try and follow the above, but where is he getting the script? So, I
make a script called chap03.py and put it in ~/pyth/chap03/.
Did you copy the function definition into chap03.py? Because the error
sounds a lot like you're trying to import something from an empty
file.

I think you may have missed the following line that occurs in the
paragraph just before the import example: "To see how this works,
assume the print_twice function is defined in a script
named chap03.py."

If you copy the code provided for 'print_twice' into your 'chap03.py'
file, the example should work.

Hope this helps.

- alex23
Jun 27 '08 #8

P: n/a
notbob wrote:
I'm running
vers 2.5.1 on slackware 12.
Nice to see another Slackware user around here!

"Here is an example of a user-defined function that has a parameter:
def print_twice(bruce):
print bruce, bruce
<snip>
is this just an example of how the def should be written and it doesn't
really do anthing... yet?
That's correct. A function doesn't generally *do* anything until it is
called. Here, it is only defined. The only thing this function does when
called is to print the value of bruce twice.
I define myfirstfunction in the pyth
editor and give the command print myfirstfuntion and I get back this:
<function myfirstfunction at 0xb7b9c994>
Functions are objects too, and this is a printed representation of that
function object. It still hasn't been "called" at this point.

....when I add the ._doc_, it get this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute '_doc_'
....so, there is a no go there, too.
The functions docstring is stored in the attribute named "__doc__". Like
other python "special" attributes, it starts and ends with TWO underscores.

ok, I try and follow the above, but where is he getting the script? So, I
make a script called chap03.py and put it in ~/pyth/chap03/.
You are correct to create this script yourself from scratch.

I then try an do the import thing above, but the pyth ed accepts none of
it. not from:
from ~/pyth/chap03/ import *
from chap03 import * #taken from ~/pyth/
....nor from any other configuration I can imagine, so that "from" command
makes no sense.
Modules are imported from your PYTHONPATH, which is a search path similar to
bash's PATH: It is a list of directories that are searched for *module*
names when you attempt an import. You can examine your python path by
doing:
>>import sys
sys.path
Your module files, i.e., chap03.py, should be in one of the directories on
that path.

"from" modifies a *module* name, not a path component. So "from module
import one_function, another_function". This allows you to use one_function
without referencing it through the imported module name. In other words,
these two are equivalent:
>>import chap03
chap03.print_twice()
and:
>>from chap03 import print_twice
print_twice()
In the above examples, "chap03" is the *module* file, chap03.py.
Hope that helps clarifies things a bit,
Jeffrey
Jun 27 '08 #9

P: n/a
On 2008-05-06, Jeffrey Froman <je*****@fro.manwrote:
Nice to see another Slackware user around here!
Likewise. ;)

That's correct. A function doesn't generally *do* anything until it is
called. Here, it is only defined. The only thing this function does when
called is to print the value of bruce twice.
I suspected as much. It was a bit confusing, but I get it now.

Functions are objects too, and this is a printed representation of that
function object. It still hasn't been "called" at this point.
Good to know. Thnx.

other python "special" attributes, it starts and ends with TWO underscores.
....as Alex also pointed out. I didn't notice that. Thnx.

You are correct to create this script yourself from scratch.
Do python scripts require the:

#!/usr/bin/env python

.....line at the beginning of every script or just the .py file extension? I
see examples both ways, with and without.

Your module files, i.e., chap03.py, should be in one of the directories on
that path.
Gotchya.
"from" modifies a *module* name, not a path component. So "from module
import one_function, another_function". This allows you to use one_function
without referencing it through the imported module name. In other words,
these two are equivalent:
>>>import chap03
chap03.print_twice()

and:
>>>from chap03 import print_twice
print_twice()

In the above examples, "chap03" is the *module* file, chap03.py.
mmmmm..... that's still a bit much to wrap my feeble brain around, but I get
your drift. I'm still working on the basic function concept as python uses
it. But, I found two more websites that explain it better and I think I
pretty much get it, now. Thank you, and the others, for your help. It's
very much appreciated.

nb

Slackware: simplicity through transparency

Jun 27 '08 #10

P: n/a
notbob wrote:
Do python scripts require the:

#!/usr/bin/env python
An appropriate shebang is required if you intend to use the module itself as
a script, from the command line, like:

$ ./my_module.py argument argument ...

It is not required merely to import the module into a python program or
interpreter. Even without the shebang, the module can be run indirectly
with:

$ python ./my_module.py argument argument ...

or, if the module is somewhere on your sys.path:

$ python -m my_module argument argument ...
Jeffrey
Jun 27 '08 #11

P: n/a
On 2008-05-06, hdante <hd****@gmail.comwrote:
When you have a problem with your code, always post here the complete
code and a complete execution. For example:
I'll keep this example. Thnx.

/----------\ glued
| bruce | ------42
\----------/

When you use a stamp, it returns what it's glued on:
>bruce = 42 # glue a stamp
print bruce # use the stamp
42
'bruce' is a string (notice the quotes). In this case bruce is glued
to 'bruce':

/----------\ glued
| bruce | ------'bruce'
\----------/
The light is dawning.....
Stupid. Not really. :-) I'd rather say that the problem is the book.
Well, me too, of course. ;)
The book is just another introduction to programming. There's no
special attempt to make the reader learn to think like a computer
scientist.
Apparently, and I understand. It's hard for someone who is very
knowledgable on a subject to remain in "explain it like they're 5 yrs old"
mode. It's tedious and time consuming.
>How am I supposed to get the original def to work? I've yet to figure out
file myfile.py:
-------------------------------
def print_twice(bruce):
print bruce, bruce

print_twice('bruce')
print_twice(2)
-------------------------------

execution:
-------------------------------
$ python myfile.py
bruce bruce
2 2
BINGO! (and it worked (after I got the indents right))
Finally, you don't understand something, ask again.
Thank you. I really do appreciate your taking the time to break it down
so completely. I found another python book (A Byte of Python) that keeps it
simple enough for me. I'm not really a programmer, but I decided to do
something to challenge this old geezer brain and figured this would keep it
awake.

I'd also like to thank all you other folks who responded. I got some good
info and tips from all of you.

nb
Jun 27 '08 #12

This discussion thread is closed

Replies have been disabled for this discussion.