5 Replies - 39860 Views - Last Post: 13 November 2010 - 02:32 AM Rate Topic: -----

#1 vidbahor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 20-October 10

How to generate simple text file with python?

Posted 12 November 2010 - 09:19 AM

Well, I'm going to use text file to save high scores in. There is just one problem.. I can't find any tutorial on how to generate text file and remember its location.

Any ideas?

ty

Using python 3.1 btw =P

This post has been edited by vidbahor: 12 November 2010 - 09:28 AM

Is This A Good Question/Topic? 0
  • +

Replies To: How to generate simple text file with python?

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10482
  • View blog
  • Posts: 38,851
  • Joined: 27-December 08

Re: How to generate simple text file with python?

Posted 12 November 2010 - 09:51 AM

Check out the DIC Python Tutorials Section. Sergio Tapia just submitted an excellent File I/O Tutorial in Python. :)
Was This Post Helpful? 0
  • +
  • -

#3 vidbahor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 20-October 10

Re: How to generate simple text file with python?

Posted 12 November 2010 - 10:00 AM

View Postmacosxnerd101, on 12 November 2010 - 08:51 AM, said:

Check out the DIC Python Tutorials Section. Sergio Tapia just submitted an excellent File I/O Tutorial in Python. :)


Yeah I saw some tutorials on how to use files.. But I just can't find any on how to create one.

I would like to do that:
When I run my game I want it to check if highscores file exists and if not than it should generate it.

hope you get it.. :)
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: How to generate simple text file with python?

Posted 12 November 2010 - 12:10 PM

Here is the Python Documentation. You should get well-acquainted with it. Here is the section on file objects, assuming version 2.7.
Was This Post Helpful? 1
  • +
  • -

#5 Guest_c.user*


Reputation:

Re: How to generate simple text file with python?

Posted 12 November 2010 - 10:59 PM

View Postvidbahor, on 13 November 2010 - 03:00 AM, said:

Yeah I saw some tutorials on how to use files.. But I just can't find any on how to create one.

I would like to do that:
When I run my game I want it to check if highscores file exists and if not than it should generate it.


to create use open("file.txt", "w")
to check use os.path.exists("dir/file.txt")
don't forget to import os
Was This Post Helpful? 1

#6 vidbahor  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 20-October 10

Re: How to generate simple text file with python?

Posted 13 November 2010 - 02:32 AM

ThanksJackOfAllTrades & c.user. I hope that I'll finish today ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1