473,385 Members | 1,856 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,385 software developers and data experts.

A goto-like usage of a function

Here's a function that I want to use to capture
user input. They enter a path and then confirm
that it's the correct path or not or decide to
quit the program if they want. The 'y' (the path
is right, let's continue) and the 'q' (I hate your
stupid program and want to stop it now) both work
fine. However the 'n' (I've entered the path
incorrectly and want to do it again produces this
error:

Traceback (most recent call last):
File "clean_file_names_function_better.py",
line 16, in ?
path_name()
File "clean_file_names_function_better.py",
line 14, in path_name
path_name()
TypeError: 'str' object is not callable

Here's the function... if the user wants to
re-enter the path name... I'm simply calling the
function again... is this wrong???

def path_name():
import sys
path_name = raw_input("\nEnter the absolute
path to the directory that contains the files...
for example, /home/user: ")
print "\nYou entered: ", path_name, "\n"
confirm = raw_input("Is this the correct
path: (press 'y' for YES 'n' for NO or 'q' to
QUIT)\n\n")
if confirm == 'y':
print "\nStarting Program.\n"
return path_name
elif confirm == 'q':
print '\n'
sys.exit()
else:
print "\nTry again.\n"
path_name()

path_name()
Jul 18 '05 #1
2 1276
Bart Nessux wrote:
Here's a function that I want to use to capture user input. They enter a
path and then confirm that it's the correct path or not or decide to
quit the program if they want. The 'y' (the path is right, let's
continue) and the 'q' (I hate your stupid program and want to stop it
now) both work fine. However the 'n' (I've entered the path incorrectly
and want to do it again produces this error:

Traceback (most recent call last):
File "clean_file_names_function_better.py", line 16, in ?
path_name()
File "clean_file_names_function_better.py", line 14, in path_name
path_name()
TypeError: 'str' object is not callable

Here's the function... if the user wants to re-enter the path name...
I'm simply calling the function again... is this wrong???

def path_name():
import sys
path_name = raw_input("\nEnter the absolute path to the directory
that contains the files... for example, /home/user: ")
print "\nYou entered: ", path_name, "\n"
confirm = raw_input("Is this the correct path: (press 'y' for YES
'n' for NO or 'q' to QUIT)\n\n")
if confirm == 'y':
print "\nStarting Program.\n"
return path_name
elif confirm == 'q':
print '\n'
sys.exit()
else:
print "\nTry again.\n"
path_name()

path_name()


Sorry... namespace pollution. Both the function
and a var within it were named "path_name"... I'm
an idiot... I need more coffee.
Jul 18 '05 #2
Bart Nessux wrote:
Here's a function that I want to use to capture user input.... def path_name():
...
else:
print "\nTry again.\n"
path_name()

Besides the "pointless" recursion, this statement should be:
return path_name()

-Scott David Daniels
Scott@Da*****@Acm.Org
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Hayri ERDENER | last post by:
hi, what is the equivalent of C languages' goto statement in python? best regards
45
by: Debashish Chakravarty | last post by:
K&R pg.66 describes two situations when using goto makes sense. Has anyone here come across situations where using goto provided the most elegant solution. --...
7
by: Christopher Benson-Manica | last post by:
Can you goto switch labels? int i=0; /* arbitrary */ switch( i ) { case 0: if( !some_validity_check() ) { goto error; /* could be default as well */ } /* proceed normally */
17
by: SUMIT | last post by:
I wrote a program for removing comment from C source file for which i... 1.first constructed a DFA 2.used goto statement to write a program. now it was very easy to model DFA using goto & i...
17
by: Mike Hofer | last post by:
While I'd toyed with C, C++, and Java over the last 20 years or so, my principal language has been BASIC, QBASIC, then Visual Basic, and finally Visual Basic .NET. But lately, I've been using C#...
77
by: M.B | last post by:
Guys, Need some of your opinion on an oft beaten track We have an option of using "goto" in C language, but most testbooks (even K&R) advice against use of it. My personal experience was that...
34
by: electrician | last post by:
Perl has it, Basic has it, Fortran has it. What is so difficult about creating a goto command for JavaScript. Just set up a label and say go to it.
3
by: electrician | last post by:
Yes, no GOTO. This is a major blunder on part of the creators of these tools. GOTO gives the programmer the absolute control over the program. Yes, no matter what, a GOTO sends the program to...
17
by: SoftEast | last post by:
Hi Buddies, I have read a lot of stuffs regarding not using GOTO statements to opt a good programming style http://david.tribble.com/text/goto.html]. Can anybody give a particular lines of code...
59
by: raashid bhatt | last post by:
why are GOTO's not used they just a simple JMP instructions what's bad about them
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.