Jump to content

Python help please!?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
rpb1323

rpb1323

    Newbie

  • Members
  • Pip
  • 4 posts
I have a huge project coming up for python, and I basically have to crunch a bunch of numbers and then output them into an organized text file. The text file will contain several columns, such as time, latitude/longitude, and elevation (its for a plane), and the problem is I don't know how to come up with a python program that does this, or even one that outputs a text file...

Help?!

#2
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 890 posts
  • Location:::1
class File:
    def __init__(self, name):
        self.file = file(name, "w")

    def write(self, time, position, elevation):
        self.file.write("%02d:%02d:%02d : %s, %d\n" % (time.hour, time.minute, time.second, str(position), elevation))

    def close(self):
        self.file.close()
Then simply make a File object and use write method:
myFile = File("data.txt")

myFile.write(datetime.datetime.now(), (63.233627,-44.296875), 12500)
myFile.close() # don't forget to close the file when you're done!
In example above, write method would write time (hour, min and sec) with lat/long = 63.233627,-44.296875 and elevation of 12.5 km.

Note: this was written off the top of my head, so there may be errors.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users