|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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. |
|
#3
|
||||
|
||||
|
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. |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
Very welcome leaf! Glad your program is coming along
sure you'll pick Python up pretty fast! Whats your program do anyway?Mark. |
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
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) |
|
#8
|
||||
|
||||
|
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 12:10 PM. |
|
#9
|
|||
|
|||
|
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. |
|
#10
|
||||
|
||||
|
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. |
|
#11
|
|||
|
|||
|
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.
|
|
#12
|
||||
|
||||
|
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 01:36 PM. |
|
#13
|
|||
|
|||
|
What?
|
|
#14
|
|||
|
|||
|
I see
thanks! |