Python 应用程序不执行任何操作

发布于 2024-09-12 04:35:27 字数 1075 浏览 2 评论 0原文

在我更改了一些我不再记得

#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()

编辑的内容后,这段代码根本停止执行任何操作:哈哈,对不起,大家忘了说它应该运行输入

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

謸气贵蔟 2024-09-19 04:35:27

你应该更好地描述你的问题。是否打印输入提示?它输出什么吗?它会退出还是只是坐在那里?我在阅读这段代码时注意到一些可能有帮助的问题。您应该使用 raw_input(),而不是 input()。另外,除非用户输入==“退出”,否则您实际上不会对用户输入执行任何操作。这是不会的,因为您只是使用 input(),而不是 raw_input(),因此该人必须输入“exit”(包括引号),否则循环将永远不会退出。 (假设它不是Python 3代码)

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)

可遇━不可求 2024-09-19 04:35:27

它什么也没做,因为没有代码让它做任何事情。 插入一行。

print("You entered:", userinput)

尝试在循环中的适当位置

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.

情未る 2024-09-19 04:35:27

os.getenv() 必须至少有一个参数。尝试 os.getenv("HOST") 或其他东西。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文