#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    8
    Rep Power
    0

    create a txt document and write to it.


    does anybody know a function or something that will create a .txt document in the same directory as the .exe file(using py2exe) you run and then add some text to it i can specify myself?
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Look into python's file I/O routines. Specifically open() and the file object.
    Code:
    txtfile = open("hello.txt", "w")
    txtfile.write("Hello World\n")
    txtfile.close()
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    When you compile a Python program with py2exe is will work just like the Python program so all you need to do is to write a program that writes asks the user for input and write it to a file. There is a new article on Devshed that you might be interested in:

    http://www.devshed.com/c/a/Python/File-Management-in-Python/

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo