Jump to content
  • Advertisement
Sign in to follow this  
Gallivan

Receiving invalid literal() error

This topic is 4009 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 tried to make this program work for a few days now, and it has progressed which I am ecstatic about. :D But I seem to have run into a stumbling block that my mIRC visits and Google pit stops can't identify. launch.py http://rafb.net/p/CkNTGz59.html mapgen.py http://rafb.net/p/wTzi4r73.html timestamp.py http://rafb.net/p/dYwLxx86.html In short: 1. mapgen.py generates a sequence of random integers and coordinates (Successful) 2. timestamp.py records the integers and coordinates and terrains to two files (Successful) 3. launch.py reads the integer file per character and creates a PyGame map using .BMP files (Failure) I know that my code is failing somewhere in launch.py between lines 29 and 40, and I know that the loop may be somewhat wrong. What I cannot understand is why:
                        f = open('pythonnumberfile.txt', 'r')
                        setReader = f.read(int(counterNumber))
                        background.blit(watcherList[int(setReader)], (x,y))
                        counterNumber = counterNumber + 1
                        f.close()
fails to process? Any idea what I am doing wrong, is it syntax or is it the loop itself?

Share this post


Link to post
Share on other sites
Advertisement
"invalid literal" means that one of those int(string) conversions is failing because the string does not represent a valid integer. Since counterNumber is already an int that one isn't it so it must be the int(setReader) at line 37. I'd have to see pythonnumberfile.txt to give you anything more specific than that.

Share this post


Link to post
Share on other sites
I don't think File.read does what you think it does.

Don't repeatedly open the same file inside of a loop like that. You only need to open the file once. File.read(x) reads the next x bytes from the file. You only need to open the file once. What you're doing will only work if you have 10 or less types of terrain, but I think you know that already.

If you're only using python, you might want to look into python's pickle module. It provides a way to save and load python objects to and from files. There's also a module for writing and parsing comma separated values, and if you wanted to get fancier you could even use xml.

Share this post


Link to post
Share on other sites
Although I think the problem has already been found above, you should never be at a loss to see exactly which line of a Python program is causing the error; it produces quite precise tracebacks to tell you where the exception is raised. I wonder what you're doing to be in this situation.

What is in pythonnumberfile.txt? One number? Several numbers?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!