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

Started by
1 comment, last by MattFrederick 13 years, 3 months ago
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.
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.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

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?

This topic is closed to new replies.

Advertisement