Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12

    running programs without python?


    I searched through some tutorials and the official site but I couldn't found a clear answer on this question. Can I create a .exe file so that others without python can run the program as well or do they need python installed as well?

    Can I write lines to the end of a .txt file, can I move through files? Which function would I need for that? Also I looked through the directory and file changing functions but I couldn't determine which function would be for creating the file, which one would it be?

    Thanks for the help!
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Hey, yes you can create "standalone" python exe's, you do however have to download and install py2exe but well worth it if you plan on working with windows!

    http://starship.python.net/crew/theller/py2exe/

    You may also be interested in Win32All; a set of Python modules which let you interact with the windows API!

    http://starship.python.net/crew/mhammond/

    Yes, Yes, Yes would be the answer to your next Q's! you an do all this and sooooo much more with Python...

    You can use the file()/open() functions, this automatically creates the file when you start writing to it! And you can use the append flag 'a' to write to the end of a file

    Read the Python tutorial, its all in there:

    http://www.python.org/doc/2.3.2/tut/tut.html

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

  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    This Python shell shows the basics, although there are allot more things you can do with files!

    >>> file('sample.txt', 'w').write('doing sum writing..')
    >>> for each in file('sample.txt', 'r'):
    print each


    doing sum writing..
    >>> file('sample.txt', 'a').write('and sumor!')
    >>> for each in file('sample.txt', 'r'):
    print each


    doing sum writing..and sumor!
    >>> sample = file('sample.txt', 'r').read()
    >>> sample
    'doing sum writing..and sumor!'
    >>> sample = file('sample.txt', 'w')
    >>> sample.write('bye bye')
    >>> sample.close()
    >>> print file('sample.txt', 'r').read()
    bye bye
    >>>

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

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12
    Thank you very much

    I once tried to do the python tutorial but since I have a bit of programming knowledge I found it boring, maybe I should have started further in it but then it seems I missed a lot. Today I found the other links to some quick stepins and wrote part of a program I wanted for some time.
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Very welcome leaf! Glad your program is coming along sure you'll pick Python up pretty fast! Whats your program do anyway?

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

  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12
    It's for the game NEverwinter Nights. I'm trying to create custom models. To get these in the game I have to add them to a 2da file, because of new official content I can't add new lines just after the official lines stop. I need to write around 500-600 lines most of the time before I can start putting my content. These lines look like: a number colon and around 10 colons of ****. Now I want it to write these lines automaticaly. I got the loop working only needed the functions to put them in the file at once.

    Maybe I'll later add that it checks at which line to start writing instead of the user input it has now, but first I need this to work right
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12
    I get a strange error with this:

    #intro

    print " ============================================"
    print " Welcome to Darkleaf's 2da padder!"
    print " ============================================"

    #padder
    pad = 1

    while pad == 1:
    try:
    print "**Placeables.2da is the only currently supported type.**\n"
    type = input("Which .2da file do you want to pad?\n-Placeables.2da : \"plc\"\n")

    if (type == "plc"):
    print "Bioware content stops at line 479 as of HotU patch 1.59."
    start = input("Which line do you want to start padding at?\n")

    print "Safe lines start at line 1000 as of HotU patch 1.59."
    end = input("Which line do you want to stop padding at?\n")
    path = input("What is the path of the .2da file? Format: \"<complete path name>\"\n")

    step = 1

    lines = range(start, end, step)

    while start <= end:
    file(path, 'a').write(str(start)+" ****"*11+"\n")
    start = start+1

    if start > end:
    print "Done padding '"+path+"'"
    pad = input("Do you want to pad another file, <1>: yes, <0>: no\n")


    except OverflowError:
    print "Overflow error, please choose a lower number!\n\n"
    continue
    except NameError:
    print "Name error, make sure you're writing in the right format. See readme for further details.\n\n"
    continue
    except SyntaxError:
    print "Syntax error, make sure you're writing in the right format. See readme for further details.\n\n"
    continue
    ## except IOError:
    ## print "See readme for specific error.\n"
    ## continue

    it gives this error every time i try to write to or create a file with the name starting with a 't' , like test. Every other letter is OK but with the t it simply won't work:

    Traceback (most recent call last):
    File "C:\Python23\darkleaf2dapadder.py", line 28, in ?
    file(path, 'a').write(str(start)+" ****"*11+"\n")
    IOError: [Errno 2] No such file or directory: 'C:\text.2da'

    Is this something that's supposed to happen or have I written something that causes the error?

    Thanks! (I commented my custom error msg so you get the python one)
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Ok.. not so strange the reason your getting an error is that '\' is a special char used to escape other special chars. If you escape that it wouls work fine i.e. 'C:\\somefile.txt'

    You could also use a raw string like r'C:\somefile.txt' which will escape all special chars for you!

    Mark.
    Last edited by netytan; December 13th, 2003 at 01:10 PM.
    programming language development: www.netytan.com Hula

  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12
    But do you know what's causing that error?

    is there a way to post the code so that it doesn't get formatted? It looks like a real mess now.
  18. #10
  19. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You can wack [ CODE]...[ /CODE ] tags (without spaces) around it, this will preserve indentation!!!

    yes i know why your getting this error, there simply isnt a path 'C:\test.txt' and i'll show your why.. \t is a tab, so your actually asking Python to write to 'C: est.txt', fun a'

    take a look at this short shell, you should be able to see whats going on.

    >>> print 'C:\test.txt'
    C: est.txt
    >>>

    Optionally you can use forwardslash instead or backslash . so in short, the Error message you got explains everything you need to know to fix it

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

  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    Since he's inputting the strings during the running of the program, he doesn't have to do anything special with slashes ... you can see that it prints out the correct path. It's just that the file doesn't exist, plain and simple.
  22. #12
  23. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Doh, missed the append flag... Oh wait, it works if you escape the path like i said doesn't it

    >>> file('test.txt', 'a').write('some')
    >>> file('C:\test.txt', 'a').write('text')

    Traceback (most recent call last):
    File "<pyshell#3>", line 1, in -toplevel-
    file('C:\test.txt', 'a').write('sdfsd')
    IOError: [Errno 2] No such file or directory: 'C:\test.txt'
    >>> file('C:\\test.txt', 'a').write('text')
    >>>

    Mark.
    Last edited by netytan; December 13th, 2003 at 02:36 PM.
    programming language development: www.netytan.com Hula

  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    What?
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    netherlands
    Posts
    51
    Rep Power
    12
    I see thanks!
  28. #15
  29. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Strike: sorry if that sounded bitchy ... anyway all i was showing was that the file will be created if it doesn't exist if yor using the append flag, so the file net existing isnt an issue! The problem is that 'C: est.txt' just can't be created!

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

Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo