file IO

Started by
1 comment, last by Antheus 16 years, 2 months ago
Ive recently learned about reading, writing, pickling, and shelving information to files in python. Im curious as to when this is needed? Should I store all different parts of my program in files and then load them? I dont see where this method can be practically used in my programming. For instance , for practice im creating the basis of a future RPG i want to create. Im simply creating some hero classes, monster classes, inventories, weapons, etc. Im hoping to eventually implement this stuff graphically when I learn pygame. Should this stuff be stored in files? I just wanna be cleared up on this stuff.
Advertisement
Pickling/shelving and related concepts are useful for when you want to write code to let your game be saved and loaded. For example, you'd pickle your hero instance(s), inventory items and other game state objects when saving and unpickle them when loading.
Pickling just allows you to automatically (re)store your data objects to disk. This saves you most of head-aches of writing every member manually. You basically just say: write(my_object), and it'll get completely written automatically.

File IO is just reading and writing bytes to/from files.

For an RPG, you could store data, scripts, models, textures, .... in files, rather than hard-code them into your application, which is mostly impractical and unfeasible.

Having assets stored in separate files allows you to modify them without rebuilding the application, possibly even modify the graphics while the game is running. Either way, it's a time saver.

This topic is closed to new replies.

Advertisement