Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

win32fileDemo.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # This is a "demo" of win32file - it used to be more a test case than a
  2. # demo, so has been moved to the test directory.
  3. import os
  4. # Please contribute your favourite simple little demo.
  5. import win32api
  6. import win32con
  7. import win32file
  8. # A very simple demo - note that this does no more than you can do with
  9. # builtin Python file objects, so for something as simple as this, you
  10. # generally *should* use builtin Python objects. Only use win32file etc
  11. # when you need win32 specific features not available in Python.
  12. def SimpleFileDemo():
  13. testName = os.path.join(win32api.GetTempPath(), "win32file_demo_test_file")
  14. if os.path.exists(testName):
  15. os.unlink(testName)
  16. # Open the file for writing.
  17. handle = win32file.CreateFile(
  18. testName, win32file.GENERIC_WRITE, 0, None, win32con.CREATE_NEW, 0, None
  19. )
  20. test_data = "Hello\0there".encode("ascii")
  21. win32file.WriteFile(handle, test_data)
  22. handle.Close()
  23. # Open it for reading.
  24. handle = win32file.CreateFile(
  25. testName, win32file.GENERIC_READ, 0, None, win32con.OPEN_EXISTING, 0, None
  26. )
  27. rc, data = win32file.ReadFile(handle, 1024)
  28. handle.Close()
  29. if data == test_data:
  30. print("Successfully wrote and read a file")
  31. else:
  32. raise Exception("Got different data back???")
  33. os.unlink(testName)
  34. if __name__ == "__main__":
  35. SimpleFileDemo()