Sign in to follow this  
biggjoee5790

file IO

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this