473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Are rank noobs tolerated, here?


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
11 1512
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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael L. | last post by:
hi everyone, It is relatively easy to translate RANK() from teradata to DB2, but I get to a glitch when I realize what Qualify RANK does. I know that there are a lot of experienced DB2...
32
by: sandy | last post by:
I have a hobby website at: http://www.montana-riverboats.com which also resolves as: http://montana-riverboats.com ...without the www. One address has a Google page rank of three. The other...
10
by: Can | last post by:
I am creating an on-line survey. I want the user to have a list of choices of say 10 items that are radio buttons. They need to rank their preference. They click on preference 1, that option is...
3
by: Elden Carnahan | last post by:
I am trying to derive rank values in a query, just as one would with the Rank function in Excel. Can't see how to do this elementary task. Can anyone advise?
2
by: dam_fool_2003 | last post by:
Just now I asked a question about signed char and unsigned char. I had the replay very fast by jens.torring and Tim prince. I post via google so now goes my thanking replay. (I must be more precise...
3
by: j0mbolar | last post by:
what's the rules of rank and how they affect types of expressions?
13
by: Steve Edwards | last post by:
Hi, Given a map: typedef map<long, string, greater<long> > mapOfFreq; Is there a quicker way to find the rank (i.e. index) of the elememt that has the long value of x? At the moment I'm...
1
by: volunteer | last post by:
<?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="filename.xsl"?> <markers date="20060523"> 04:21:50 PM <marker sn="1" rank="6" name="john" /> <marker sn="2" rank="5"...
2
by: orenlevy1 | last post by:
Hi Everyone. I have a problem that I could not figure out what to do with it. I have a couple of tables and views. All have the same unique ID. When a user try to do a search on our web site...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.