Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Get filename using filefialog.askfilename

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


cheirasacan at gmail

May 7, 2013, 1:27 PM

Post #1 of 7 (105 views)
Permalink
Get filename using filefialog.askfilename

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

--
http://mail.python.org/mailman/listinfo/python-list


gordon at panix

May 7, 2013, 1:37 PM

Post #2 of 7 (102 views)
Permalink
Re: Get filename using filefialog.askfilename [In reply to]

In <ab1feb45-0397-4411-bab1-898c95f57b05 [at] googlegroups> cheirasacan [at] gmail 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 [at] panix B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

--
http://mail.python.org/mailman/listinfo/python-list


tjreedy at udel

May 7, 2013, 2:53 PM

Post #3 of 7 (100 views)
Permalink
Re: Get filename using filefialog.askfilename [In reply to]

On 5/7/2013 4:27 PM, cheirasacan [at] gmail 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


--
http://mail.python.org/mailman/listinfo/python-list


cheirasacan at gmail

May 8, 2013, 1:14 PM

Post #4 of 7 (90 views)
Permalink
Re: Get filename using filefialog.askfilename [In reply to]

El martes, 7 de mayo de 2013 23:53:32 UTC+2, Terry Jan Reedy escribió:
> On 5/7/2013 4:27 PM, cheirasacan [at] gmail 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.
--
http://mail.python.org/mailman/listinfo/python-list


davea at davea

May 8, 2013, 3:52 PM

Post #5 of 7 (90 views)
Permalink
Re: Get filename using filefialog.askfilename [In reply to]

On 05/08/2013 04:14 PM, cheirasacan [at] gmail 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 [at] gmail 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
--
http://mail.python.org/mailman/listinfo/python-list


cheirasacan at gmail

Aug 10, 2013, 3:37 AM

Post #6 of 7 (16 views)
Permalink
Re: Get filename using filefialog.askfilename [In reply to]

.... Sarcastic.... what the kcuf ¿?¿?¿?

My english is SO bad?

Do you know me?

I can not understand this paranoia.... i only was giving thanks.





--
http://mail.python.org/mailman/listinfo/python-list


joshua at landau

Aug 10, 2013, 4:33 AM

Post #7 of 7 (15 views)
Permalink
Re: Get filename using filefialog.askfilename [In reply to]

On 10 August 2013 11:37, <cheirasacan [at] gmail> wrote:
> .... Sarcastic.... what the kcuf ¿?¿?¿?
>
> My english is SO bad?
>
> Do you know me?
>
> I can not understand this paranoia.... i only was giving thanks.

Sarcasm and a lack thereof is very hard to see over the Internet. It's
probably just a misunderstanding :).
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.