views:

74

answers:

4

This code stopped doing anything at all after I changed something that I no longer remember

#Dash Shell
import os
import datetime

class LocalComputer:
    pass

def InitInformation():
    Home = LocalComputer()
    #Acquires user information
    if (os.name == "nt"):
        Home.ComputerName = os.getenv("COMPUTERNAME")
        Home.Username = os.getenv("USERNAME")
        Home.Homedir = os.getenv("HOMEPATH")
    else:
        Home.ComputerName = os.getenv()
        Home.Username = os.getenv("USER")
        Home.Homedir = os.getenv("HOME")
    return Home

def MainShellLoop():
    print ("--- Dash Shell ---")
    Home = InitInformation()
    userinput = None
    currentdir = Home.Homedir
    while (userinput != "exit"):
        rightnow = datetime.datetime.now()
        try:
            userinput = input(str(Home.ComputerName) + "\\" + str(Home.Username) + ":" + str(rightnow.month) + "/" + str(rightnow.day) + "/" + str(rightnow.year) + "@" + str(currentdir))
        except:
            print("Invalid Command specified, please try again")

MainShellLoop()

edit: Lol sorry guys forgot to say its supposed to run the input

+2  A: 

You should better describe your problem. Does it print the input prompt? Does it output anything? Does it exit or just sit there? I noticed a few issues while reading over this code that might help. You should be using raw_input(), not input(). Also, you don't actually do anything with userinput unless it == 'exit'. Which is won't, because you are just using input(), not raw_input(), so the person would have to enter 'exit' (including quotes) or else the loop will never exit. (Assuming it's not Python 3 Code)

Stealth-
If the code is Python 3 (which it may well be, since `print` is used as a function), then `input()` is correct.
Greg Hewgill
You have a good point. Thanks for mentioning that.
Stealth-
Its python 3.1.2
Indebi
+1  A: 

os.getenv() must have at least one param. Try os.getenv("HOST") or something.

petraszd
It worked without anything in it before, and its being coded on Windows 7 so that part isn't run yet
Indebi
A: 

I'm closing this question and opening a new one, while rephrasing this one

Sorry about this.

Indebi
First of all, this should be a comment, and also, please don't ask the same question again. If you want to rephrase your question, that's great, but edit this one instead of creating a new one.
David Zaslavsky
+2  A: 

It's doing nothing because there's no code to make it do anything. Try inserting a line like

print("You entered:", userinput)

at an appropriate place in your loop.

John Machin