Hi I need some help with this code, at the moment I am just trying to get the commandline function to work. It should when I type a command like help or exit react to it, however I have to type the command 3 times for it to work which is strange. I would like a fix for the code rather than an alternate method for what I would like for it to do but I would be happy to hear your solution. Many thanks.

# Speed/Time/Distance
# Velocity/Lambda/Frequency
# d = speed*time
# v = frequency*wavelength

class Formulator(object):
    def __init__(self):
        speed = 0
        time = 0
        distance = 0
        velocity = 0
        wavelength = 0
        frequency = 0
        unit = "undefined"
    def speeddistancetime(self):
        pass
    def speedlambdafrequency(self):
        pass

def commandline():
    command = input("Command: ")
    command.lower()
    return command

def Help():
    print("Formulae: Waves|Dimensional - cant think of a better name :s ")
    print("At least 2 variables are needed to calculate the missing value of the last variable.")
    print("To choose a formula you will need to type the name of it into the command line.")
    print("The missing variable will need to be entered afterwards.")
    print("You then need to enter the values of the other 2 variables.")
    print("Type exit to exit the program.")

#Start up    
fo = Formulator()
stop = False
print("For information about commands, type help.")

#Management
while stop == False:
    commandline()
    print(commandline())
    if stop == False:
        if commandline()== "exit":
            print("yep")
            stop = True
    if stop == False:
        if commandline()== "help":
            Help()

Recommended Answers

All 6 Replies

# Speed/Time/Distance
# Velocity/Lambda/Frequency
# d = speed*time
# v = frequency*wavelength
try:
    input = raw_input
except:
    pass

class Formulator(object):
    def __init__(self):
        speed = 0
        time = 0
        distance = 0
        velocity = 0
        wavelength = 0
        frequency = 0
        unit = "undefined"
    def speeddistancetime(self):
        pass
    def speedlambdafrequency(self):
        pass

def commandline():
    command = input("Command: ")
    return command.lower()

def help_():
    print("Formulae: Waves|Dimensional - cant think of a better name :s ")
    print("At least 2 variables are needed to calculate the missing value of the last variable.")
    print("To choose a formula you will need to type the name of it into the command line.")
    print("The missing variable will need to be entered afterwards.")
    print("You then need to enter the values of the other 2 variables.")
    print("Type exit to exit the program.")

#Start up    
fo = Formulator()

print("For information about commands, type help.")

#Management
while True:
    cl = commandline()
    if cl== "exit":
        break
    elif cl == "help":
        help_()

print("yep")        

Your __init__ does nothing so it can also be removed

I've made the help function into a class. The commandline has been made into a module. Typing help_.info will result in an error, stating that 1 argument has been given and that it requires none which is bull****... lol. Thanks :)

# Speed/Time/Distance
# Velocity/Lambda/Frequency
# d = speed*time
# v = frequency*wavelength
import mcommandline

class Formulator(object):
    def __init__(self):
        speed = 0
        time = 0
        distance = 0
        velocity = 0
        wavelength = 0
        frequency = 0
        unit = "undefined"
    def speeddistancetime(self):
        input("")
    def velocitylambdafrequency(self):
        pass
class Help():
    def dir(self):
        print("""
        :Help directories:
        -syntax
        -program information
        -formulae

        Type help then the section that
        you would like to see.
        """)
    def info():
        print("""
        Author: Jerome Smith
        """)
    def syntax():
        pass
    def formulae():
        pass

#Start up
print("For information about commands, type help.")
form = Formulator()
help_ = Help()
#Management
while True:
    command = mcommandline.getcommand()
    if command == "exit":
        break
    if command == "help":
        help_.dir()
        helpdir = input("Directory: ")
        if helpdir == "program information":
            help_.info()            
    if command == "Dimensional":
        pass

Actually, the error message is exactly correct - you invoked a class method (info(), which as written does not take a self argument) with the name of an instance, which in Python is the same as passing it an argument (namely,help_ itself). Just to make it clearer what is happening, you need to know that these two forms are equivalent:

help_.info()

and

Help.info(help_)

You should either invoke it with the name of the class, and no arguments, instead

Help.info()

or else add a self argument to the method parameters.

As an aside, I would like to point out that there is a standard module metadata variable named __author__ which you usually would use for this purpose:

__author__ = 'Jerome Smith'

This automagically gets included in the docstring for the module, if you use the standard help() built-in function. For more flavor, see PEP-258 for details on docstrings and the help() function, and this thread on StackOverflow about the Pydoc metadata variables.

That clears it up, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.