Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44902 > unrolled thread

Get filename using filefialog.askfilename

Started bycheirasacan@gmail.com
First post2013-05-07 13:27 -0700
Last post2013-05-08 18:52 -0400
Articles 5 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Get filename using filefialog.askfilename cheirasacan@gmail.com - 2013-05-07 13:27 -0700
    Re: Get filename using filefialog.askfilename John Gordon <gordon@panix.com> - 2013-05-07 20:37 +0000
    Re: Get filename using filefialog.askfilename Terry Jan Reedy <tjreedy@udel.edu> - 2013-05-07 17:53 -0400
      Re: Get filename using filefialog.askfilename cheirasacan@gmail.com - 2013-05-08 13:14 -0700
        Re: Get filename using filefialog.askfilename Dave Angel <davea@davea.name> - 2013-05-08 18:52 -0400

#44902 — Get filename using filefialog.askfilename

Fromcheirasacan@gmail.com
Date2013-05-07 13:27 -0700
SubjectGet filename using filefialog.askfilename
Message-ID<ab1feb45-0397-4411-bab1-898c95f57b05@googlegroups.com>
Well. It's driving me crazy. So simple....

I use:

file = filedialog.askopenfile ( mode....... )

to open a file with an open dialog box, OK. Made it.

How i get the name of the opened file?

i do :

print(file)

the output is: <......name="file.doc"...mode=......encoding..........  >

How can i get the second member of 'file'?

I had prove with print(file[1]) and print(file(1)) but does not work.

And i am unable to find a detailed reference to this object in the i.net

http://fossies.org/dox/Python-3.3.1/filedialog_8py_source.html#l00393 is
where i could reach!



Thanks

[toc] | [next] | [standalone]


#44903

FromJohn Gordon <gordon@panix.com>
Date2013-05-07 20:37 +0000
Message-ID<kmbom6$itp$1@reader1.panix.com>
In reply to#44902
In <ab1feb45-0397-4411-bab1-898c95f57b05@googlegroups.com> cheirasacan@gmail.com writes:

> print(file)

> the output is: <......name="file.doc"...mode=......encoding..........  >

> How can i get the second member of 'file'?

If you're using the interpreter, you can type this command:

    >>> help(file)

And it will display documentation for using objects of that type.
You can also use this command:

    >>> dir(file)

And it will display all the members and methods that the object provides.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

[toc] | [prev] | [next] | [standalone]


#44906

FromTerry Jan Reedy <tjreedy@udel.edu>
Date2013-05-07 17:53 -0400
Message-ID<mailman.1419.1367963622.3114.python-list@python.org>
In reply to#44902
On 5/7/2013 4:27 PM, cheirasacan@gmail.com wrote:

> file = filedialog.askopenfile ( mode....... )

askopenfile is a convenience function that creates an Open dialog 
object, shows it, gets the name returned by the dialog, opens the file 
with that name, and returns an appropriate normal file object

> to open a file with an open dialog box, OK. Made it.
>
> How i get the name of the opened file?

file.name, (at least in 3.3), which in your example below is "file.doc"

> print(file)
>
> the output is: <......name="file.doc"...mode=......encoding..........  >

This is the standard string representation of a file object. It is 
created from the various attributes of the file instance, including 
file.name.

> How can i get the second member of 'file'?

Strings do not have fields. The second 'member', would be the second 
character, file[1], which is not what you want.

> And i am unable to find a detailed reference to this object in the i.net

Use the Fine Manual. The entry for builtin open() function, which you 
should read to understand the 'open' part of askopenfile, directs you to 
the Glossary entry 'file object' which says "There are actually three 
categories of file objects: raw binary files, buffered binary files and 
text files. Their interfaces are defined in the io module. The canonical 
way to create a file object is by using the open() function." The kind 
of file object you get is determined by the mode ('b' present or not), 
buffer arg, and maybe something else. You can look in the io chapter or 
use dir() and help() as John G. suggested.

Python programmers should really learn to use dir(), help(), and the 
manuls, including the index and module index.

--
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#44963

Fromcheirasacan@gmail.com
Date2013-05-08 13:14 -0700
Message-ID<f41664f6-9f02-473c-bcd9-5f88980aab63@googlegroups.com>
In reply to#44906
El martes, 7 de mayo de 2013 23:53:32 UTC+2, Terry Jan Reedy  escribió:
> On 5/7/2013 4:27 PM, cheirasacan@gmail.com wrote:
> 
> 
> 
> > file = filedialog.askopenfile ( mode....... )
> 
> 
> 
> askopenfile is a convenience function that creates an Open dialog 
> 
> object, shows it, gets the name returned by the dialog, opens the file 
> 
> with that name, and returns an appropriate normal file object
> 
> 
> 
> > to open a file with an open dialog box, OK. Made it.
> 
> >
> 
> > How i get the name of the opened file?
> 
> 
> 
> file.name, (at least in 3.3), which in your example below is "file.doc"
> 
> 
> 
> > print(file)
> 
> >
> 
> > the output is: <......name="file.doc"...mode=......encoding..........  >
> 
> 
> 
> This is the standard string representation of a file object. It is 
> 
> created from the various attributes of the file instance, including 
> 
> file.name.
> 
> 
> 
> > How can i get the second member of 'file'?
> 
> 
> 
> Strings do not have fields. The second 'member', would be the second 
> 
> character, file[1], which is not what you want.
> 
> 
> 
> > And i am unable to find a detailed reference to this object in the i.net
> 
> 
> 
> Use the Fine Manual. The entry for builtin open() function, which you 
> 
> should read to understand the 'open' part of askopenfile, directs you to 
> 
> the Glossary entry 'file object' which says "There are actually three 
> 
> categories of file objects: raw binary files, buffered binary files and 
> 
> text files. Their interfaces are defined in the io module. The canonical 
> 
> way to create a file object is by using the open() function." The kind 
> 
> of file object you get is determined by the mode ('b' present or not), 
> 
> buffer arg, and maybe something else. You can look in the io chapter or 
> 
> use dir() and help() as John G. suggested.
> 
> 
> 
> Python programmers should really learn to use dir(), help(), and the 
> 
> manuls, including the index and module index.
> 
> 
> 
> --
> 
> Terry Jan Reedy

Yeah. This is an answer. A lot of thanks.

[toc] | [prev] | [next] | [standalone]


#44972

FromDave Angel <davea@davea.name>
Date2013-05-08 18:52 -0400
Message-ID<mailman.1464.1368053587.3114.python-list@python.org>
In reply to#44963
On 05/08/2013 04:14 PM, cheirasacan@gmail.com wrote:
> El martes, 7 de mayo de 2013 23:53:32 UTC+2, Terry Jan Reedy  escribió:
>> On 5/7/2013 4:27 PM, cheirasacan@gmail.com wrote:
>>
>>
>>     <SNIP - a double-spaced google-groups copy of lots of useful advice>
>>>
>
> Yeah. This is an answer. A lot of thanks.
>

For a moment there, I thought you were being sarcastic, and ungrateful 
at that.  But I figured that it must have been my imagination.

Usually, it's better to teach a man to fish, rather than just handing 
him one.  But some would rather just have an answer, but not the 
understanding of how to acquire it.

So, some unsolicited advice.  And mixed in, maybe the actual answer to 
your original question.

1) Lose googlegroups, or figure a way to avoid its bad habits.  Your 
responses here are doublespaced, which makes it hard to read, especially 
when you include so much that has nothing to do with your response. 
Also, triple posting leads to a number of problems, not the least of 
which is the number of other responders who killfile anything from 
googlegroups.  See http://wiki.python.org/moin/GoogleGroupsPython.

2) Include enough of your code that people can actually figure out what 
you're up to.  You're asking a question about a method of an object 
filedialog, but you never show how it's created.

3) Include enough of your error messages or diagnostic prints that we 
can see what's going on.

 > output is: <......name="file.doc"...mode=......encoding..........  >

You elided the only important part of that line, the type of the object 
you're asking about.  Most of us would know that a file object has an 
attribute of name.  But instead I spent quite a while trying to find 
what GUI library you were using that might be handing back something 
representing a file.

4) include the environment you're running in.  In your first thread, you 
included a line:
    Using Windows 7, Python 3.3, sfml 1.3.0 library, ...

Very helpful.  But no such hints here.

5) try not to override builtin names with your own local variables.  In 
this case, you defined a local variable called file, which overwrites, 
presumably by coincidence, its own type name.


Thanks for pointing out the "annotated source code" on fossies.org.  I 
wasn't aware of that location.





-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web