Help Needed !!! Browsing and Selecting More Than One File
Eric Brunel
eric_brunel at despammed.com
Thu Jul 6 10:36:35 EDT 2006
(Please quote at least a significant part of the message you're replying
to, or people will have trouble understanding what you're talking about...)
On Thu, 06 Jul 2006 15:42:28 +0200, Kilicaslan Fatih <fkaslan at yahoo.com>
wrote:
> Dear Diez B. Roggisch,
>
> After clicking a button on the GUI the user can browse
> and than select a ".c" file to assign to the other
> program I have mentioned.
>
> But in this way I can only select one file. I don't
> know how to implement this application for all of the
> "*.c" files in a folder. Do I need to write a for loop
> for this? Or maybe I can create a list after
> sequentially browsing files and than assign this list
> as a parameter to the function I am executing.
What has it to do with running your program with several file names as
arguments? Is it two different ways to select several files in your
application? Or do you want one or the other?
> Here is a part of the code, I am new to Python and
> OOP. Sorry for the ambiguity in my question.
>
> class App:
>
> #Browsing the file, this is triggered
> #through a menu
> def browseFile(self):
> global file
This is unrelated to your question, but why do you use a global variable
in a class? Can't you use an instance attribute, or a class attribute? And
BTW, file is the name of a built-in, so using it to name a variable is a
bad idea.
> file = askopenfilename(filetypes = [("C source
> code", "*.c"), ("All Files", "*.*")])
So is it a third way of selecting multiple files? Anyway, if you want to
be able to select multiple files via askopenfilename, use
askopenfilename(..., multiple=1). The value returned by the function will
then be a sequence of file names.
> #Running the CC program
> #This is triggered by a button push
> def runCC(self, event):
> if type(file)==str:
Unrelated to your question again, but explicitely testing the type of a
variable is usually a bad idea. What can be stored in file? I'd set it to
None in the beginning, then test "if file is not None:" instead of testing
its type.
> dosya = file
> cmd = 'cc ' + dosya
> return os.system(cmd)
> else:
> message = tkMessageBox.showinfo("Window
> Text", "Please Browse a File Firstly")
> print message
This line will always print None (or an empty string maybe), as
tkMessageBox.showinfo doesn't return anything. No print is needed here, as
showinfo already displays the message in a dialog.
You also have a branch of the 'if' explicitely returning something (the
result of the os.system call) and the other one not returning anything,
i.e implicitely returning None. Is there a reason for that? This is -
again - usually a bad idea as it makes your code difficult to understand.
HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
More information about the Python-list
mailing list