PDA

View Full Version : [SOLVED] how to return a line in python interp



SonnHalter
December 28th, 2008, 05:58 AM
i want to move down a line. but it just runs the code when i hit enter. helP?

nvteighen
December 28th, 2008, 12:56 PM
i want to move down a line. but it just runs the code when i hit enter. helP?

Well, the idea of an interpreter is that you get an immediate result of the command you entered... In the days of QBASIC, the interpreter was called the "Immediate" window for that reason...

You have two possiblities: either create a function and execute it or create a .py file with the code you want.

iQuizzle
December 28th, 2008, 04:28 PM
use teh backslash!

print 'use teh \
backslash!'

SonnHalter
December 28th, 2008, 04:59 PM
Well, the idea of an interpreter is that you get an immediate result of the command you entered... In the days of QBASIC, the interpreter was called the "Immediate" window for that reason...

You have two possiblities: either create a function and execute it or create a .py file with the code you want.

w8, so what would i use if i wanted to write a multi-line code?

nvteighen
December 28th, 2008, 08:04 PM
In the interpreter:


ugi@UGI:~$ python
Python 2.5.2 (r252:60911, Nov 14 2008, 19:46:32)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def multiline(arg):
... myvar = arg * 2
...
... if myvar == 10:
... print "AAA!"
... else:
... print "BBB!"
...
>>> multiline(15)
BBB!
>>> multiline(5)
AAA!
>>>


def introduces functions in Python. But anyway, the interpreter is meant for playing with the language or testing small pieces of code, never for development. For that, you write files and then run them using python <filename> at the terminal.

SonnHalter
December 28th, 2008, 08:09 PM
so to write a python file would i just write in the text editor and then save as py?

nvteighen
December 28th, 2008, 10:27 PM
so to write a python file would i just write in the text editor and then save as py?
Exactly :)