Click to See Complete Forum and Search --> : Python question, if I may
joelmon
12-04-2001, 12:39 AM
Hey, I was just wondering, while I futz with python on my pc if there is a command to insert a file and if python offers features to create an app with buttons to open other files with this app
just curious, I am trying to learn more about python as I get started to see what it's capable of, that's all
thanks
(I promise I will search google/python.org lol)
TheLinuxDuck
12-04-2001, 10:28 AM
Originally posted by joelmon:
<STRONG>to insert a file</STRONG>
What do you mean by this? Insert a file where?
[gb] and if python offers features to create an app with buttons to open other files with this app[/QB]
Do you mean like a GUI text editor, or what? Python has widgets to go GUI stuff, for example, Tk.. I've never used any of them, though.
George Kilroy
12-04-2001, 08:45 PM
Originally posted by joelmon:
<STRONG>...insert a file...?</STRONG>
File IO? (http://www.honors.montana.edu/~jjc/easytut/easytut/node17.html)
Aragorn
12-05-2001, 02:09 AM
Umm like everyone else I am not quite sure what you mean by insert a file, so I am going to assume you mean to access one and handle input/output of file. So a quick rundown of the BUILT IN function. I make that uppercase as there is a library that comes with python that allows you to access files in a different way, but I won't go into that here.
#To open a file, your except can be for #specific exceptions need be, but I just
#use a catch all except
try:
file = open("readme.txt", 'r')
except:
print "Error"
#then to read and write
try:
storage = file.read()
except:
print "Error reading file"
try:
file.write("I am writing to readme.txt")
except:
print "Error writing to file"
Alrighty if that isn't what you wanted I just wasted my time! ;) There is also the command to read from file line by line which is readline() so it would be file.readline()
Now the GUI...there are a few, TK being the most popular, my preference is wxPython which can be found at http://www.wxpython.org.
Aragorn