Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old December 12th, 2003, 09:27 AM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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!

Reply With Quote
  #2  
Old December 12th, 2003, 09:39 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #3  
Old December 12th, 2003, 09:52 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #4  
Old December 12th, 2003, 10:14 AM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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.

Reply With Quote
  #5  
Old December 12th, 2003, 10:19 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Very welcome leaf! Glad your program is coming along sure you'll pick Python up pretty fast! Whats your program do anyway?

Mark.

Reply With Quote
  #6  
Old December 12th, 2003, 12:21 PM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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

Reply With Quote
  #7  
Old December 13th, 2003, 10:08 AM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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)

Reply With Quote
  #8  
Old December 13th, 2003, 12:06 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #9  
Old December 13th, 2003, 12:10 PM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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.

Reply With Quote
  #10  
Old December 13th, 2003, 12:29 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #11  
Old December 13th, 2003, 01:21 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
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.

Reply With Quote
  #12  
Old December 13th, 2003, 01:34 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #13  
Old December 13th, 2003, 03:49 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
What?

Reply With Quote
  #14  
Old December 13th, 2003, 04:19 PM
darkleaf darkleaf is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: netherlands
Posts: 51 darkleaf User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I see thanks!

Reply With Quote