Jump to content
  • Advertisement
Sign in to follow this  
MattFrederick

[pygame] handling dat files to load things into pygame.

This topic is 2806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a dat file that contains the following.

background: bg1.bmp
music: song1.wav

how would i use this to load the value into pygame to use them, I am not sure what to do here.

Share this post


Link to post
Share on other sites
Advertisement
Typically you would open the file, read a line from the file, parse the line you read (in this case you might want to use the split member function of string types) and then, based on what you read on the left, decide what to do with what you read on the right of the line. the string member function "partition" will likely be very helpful.

Share this post


Link to post
Share on other sites
Well now I have a small script to load the data in and read the lines of the data file. I don't really understand about the splitting and also it puts a space between the two text entries.
[source]

f = open("test.dat", "r")
for line in f.readlines():
print line
f.close()
[/source]

Edit: I got it loading the items into a list like this
x = []
f = open("test.dat", "r")
for line in f.readlines():
x.append(line)
f.close()
print x[1]
print x[0]

So I should just be able to do in my program background = x[0] right?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!