Re: [Tutor] running an imported function

2012-04-27 Thread Steven D'Aprano

Cranky Frankie wrote:


Is there a way I can import clr.py and then run clr()?


The same way you import any other module and then call a function in that 
module. Don't be fooled by the function having the same name as the module.


import clr  # import the module
clr.clr()  # and call the fully-qualified name of the function


Or if you prefer:

from clr import clr  # import only the function
clr()


By the way, this may be a simpler way of clearing the screen:

def clr():
print("\n"*50)


This is probably better, although it's not guaranteed to work for all terminal 
types:


def clr():
print("\033[2J")


--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] running an imported function

2012-04-27 Thread Cranky Frankie
This is in 3.2.2.

I wanted a function to clear the screen in IDLE. I have this in a
clr.py file in a directory in my path:

# Function to clear the IDLE screen by printing blank lines
def clr():
'''Function to clear the IDLE screen
   by printing 50 lines.'''
for i in range(1, 50):
print()


I can import it in IDLE no problem, but when I do this:

>>> clr()

I get

Traceback (most recent call last):
  File "", line 1, in 
clr()
TypeError: 'module' object is not callable



Is there a way I can import clr.py and then run clr()?


-- 
Frank L. "Cranky Frankie" Palmeri
Risible Riding Raconteur & Writer
“The problem with quotes on the Internet is that
it is often difficult to verify their authenticity.”
- Abraham Lincoln
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor