0

This is my code:

import win32api
import wmi

def username_func():
    uname = win32api.GetUserName()
    print "Username is:" ,uname, "\r "

def disk_func():
    c = wmi.WMI()
    for disk in c.Win32_LogicalDisk (DriveType=3):
            print disk.Caption, "%0.1f%% vrij \r" % (100.0 * long (disk.FreeSpace) / long     (disk.Size)),long (disk.FreeSpace) / long (1073741824),"gb van",long (disk.Size) / long     (1073741824),"gb"
            print

def main():
    username_func()
    disk_func()

main()

raw_input("Press Enter to continue...")

when i run this is pyscripter it gives me this output:

Username is: ****** 

C: 66.7% vrij 
79 gb van 119 gb

D: 21.9% vrij 
130 gb van 596 gb

when i double click the python.py i get a different output:

sername is: *****
79 gb van 119 gb

130 gb van 596 gb

why is this? am i forgetting something?

2 Answers 2

3

In addition to formatting your code correctly, you should change your \r to \n

Sign up to request clarification or add additional context in comments.

Comments

0

Try to put your code in a main() function and then write:

if __name__ == '__main__':
    main()

I remember I read in python api that it's important on Windows. But I don't remember why. If I find the link I'll post it later.

It's just a convention really, and no more or less important on Windows than any other platform. The reason why it is good is that it means you can run your code as a script but you can also import it as a module and re-use functions such as username_func and disk_func in other bits of code.

Your Answer

Draft saved
Draft discarded

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.