New to Python, having a problem.

I am using Python version 2.4, (the one that came with Blender 2.4) and I’m using a tutorial I found, I believe it’s called “A non-programmer’s guide to Python”. For one of the first lessons, you do the code:


print "Jack and Jill went up a hill"
print "to fetch a pail of water"
print "Jack fell down and broke his crown"
print "and Jill came tumbling after"

When ever I type the first line into IDLE and press enter, the line is computed, and I never a get a secondary prompt. :x I have tried typing it all out in a text editor, saving it as .py, and running it, but that doesn’t work either. I think I’m probably missing something obvious, as the tutorial is for an older version of Python. If anyone could help, it’d really be appreciated.

I give up!

This code snippet is so trivial it should work in any python version, whether typed into the command prompt or run as a script or run inside a Blender Text window with ALT-P.

The business about using the version of Python that came with Blender 2.40 is a little strange since Blender only comes with an embedded python interpreter. If you have IDLE, I suspect you have a regular Python install. Do you understand how to use IDLE? Hint: Run->Run Module.

Maybe your particular copy of Python is installed over an old Indian burial ground.

Maybe your particular copy of Python is installed over an old Indian burial ground.

That’s hilarious! :smiley:

But no, I was using an installed version, sorry I was wrong. But in IDLE, when you just start it up, what do you do? What I was doing was just starting IDLE, and typing where I got the “Primary Prompt”. Then, as soon as I push Enterkey, it runs it! Are you supposed to select File>New Window, and then type it, then select run module? Sorry I’m not getting this. :expressionless:

how about closing your function

print “Jack and Jill went up a hill”;

Okay, I can’t try it right now, but when I get home I will. So putting a " ; " at the end of a print command gives you the chance to type another line? The help documents talk about >>> and … being different, but I never get the … .

Also I think I don’t really know how to correctly use IDLE.

First off, you don’t need to use ; in python to end a line. You can, but it is not necessary.

When you open IDLE, you get something like:


Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************
    
IDLE 1.1.1      
>>> 

If you type the first line of the code you have and hit enter, it should look like this:

Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************
    
IDLE 1.1.1      
>>> print "Jack and Jill went up a hill"
Jack and Jill went up a hill
>>> 

Do you get this?

If so, this second >>> is where you type the next line. IDLE works a command at a time, so you can do an if statement, or a for loop or just a print statement.
If you copy + paste the whole thing into IDLE, it will only print the first line.

Try doing file > new window in IDLE, and pasting the whole thing there, Then save it as a .py file.

Now, to run this file in IDLE, have your file in focus and hit CTRL-F5. You should see the whole passage printed out.

Does this work?

EDIT-

the chance to type another line? The help documents talk about >>> and … being different, but I never get the … .

You only get the … if you are doing a statement that requires more than one line to function, such as a for loop and are doing so in the python ‘shell’ (not sure of the correct term), IDLE never shows the … instead it puts a tab spacing in. Try typing (dont type the >>>)


>>> for i in range(10):

and hit enter, then “print i” (without the quotes) and hit enter.

then you get:


>>> for i in range(10):
		print i

hit enter again, and it should do this:


>>> for i in range(10):
	print i

	
0
1
2
3
4
5
6
7
8
9
>>> 

Hope this helps.
Ian

The only time you need a ‘;’ is to put multiple statements on the same line.

I just noticed the startup msg for IDLE that warns about IDLE vs personal firewalls. Maybe this is your problem?

I don’t have any fire walls, so no. My PC is not connected to the internet, it’s a virgin.

One of the exercises is to write a program that recites the whole Jack and Jill poem as a paragraph like:


Jack and Jill went up a hill
to fetch a pail of water
Jack fell down and broke his crown,
and Jill came tumbling after.

Is it possible to do this without it being:


print "Jack and Jill went up a hill"
Jack and Jill went up a hill
print "to fetch a pail of water"
to fetch a pail of water

Maybe the tut. is wrong.

Nah, you just need to buy a clue.

There is a difference between running a python interpreter where you get a prompt and running a script.

With the command line interpreter prompt, every time you enter a complete statement, it gets executed. ( this is where that business with the continuation prompt comes in).

Running a python program ( a script ), the whole thing gets executed at once.

In the context of IDLE, if you type in print commands at the prompt, output gets printed after each one. If you create a New Window and enter all your print commands and then Run the module, all your output gets printed at once.

The Python interpreter works in a similar way from a terminal window. Typing ‘python’ brings up a command prompt where you can type commands one by one. If you sava file of commands , you can type ‘python my_file.py’ and run them all at once.

In Blender, if you create a new Text window and add Python or BPy commands, you can execute them all at once by pressing ALT-P.

Nah, you just need to buy a clue.

Do you prefer check or money order?

Sorry I seem like a Python idiot, but I am! I hope that changes soon, and I think you may have helped me a lot.
I just never knew how to actually use Python.

Thank you very much. [/quote]