This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2013年01月15日 21:40 by ericlammerts, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (8) | |||
|---|---|---|---|
| msg180055 - (view) | Author: Eric Lammerts (ericlammerts) | Date: 2013年01月15日 21:40 | |
$ echo lovely spam > "<string>"
$ python -c 'open("nonexistent","r")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
lovely spam
IOError: [Errno 2] No such file or directory: 'nonexistent'
I see this in python 2.7.3 and 3.2.3 from Ubuntu 12.04.
|
|||
| msg180063 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2013年01月15日 22:30 | |
Heh. Nice find. I'm not sure how practical it is to fix, though. We don't have any actual rules about what indicates a 'non-file-stand-in' for the __file__ attribute, just a loose convention that it is an identifier in angle brackets. If we make that a hard rule, though, and someone really has a file named '<string>'.... :) |
|||
| msg180072 - (view) | Author: Ramchandra Apte (Ramchandra Apte) * | Date: 2013年01月16日 03:20 | |
Well, it should't open "<string>" IMHO. |
|||
| msg180074 - (view) | Author: Eric Lammerts (ericlammerts) | Date: 2013年01月16日 05:30 | |
Does it have to be an identifier in angle brackets? An empty string makes more sense to me. |
|||
| msg180083 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2013年01月16日 12:13 | |
Ideally there would be an unambiguous way to know if the object came from a file or some other source (say, __file__ is None and another special attribute gives the clue to the actual source), but that's not the way things work now, and for backward compatibility reasons I doubt that we can change it. I'm sure there are programs that depend on at least '<string>', if not some of the other places where a similar thing is done. |
|||
| msg180084 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2013年01月16日 12:15 | |
Hmm. A backward compatible fix would be to add an attribute that indicates whether or not the __file__ attribute is supposed to be pointing to a real file. |
|||
| msg180086 - (view) | Author: Ramchandra Apte (Ramchandra Apte) * | Date: 2013年01月16日 12:29 | |
+1 On 16 January 2013 17:43, R. David Murray <report@bugs.python.org> wrote: > > R. David Murray added the comment: > > Ideally there would be an unambiguous way to know if the object came from > a file or some other source (say, __file__ is None and another special > attribute gives the clue to the actual source), but that's not the way > things work now, and for backward compatibility reasons I doubt that we can > change it. I'm sure there are programs that depend on at least '<string>', > if not some of the other places where a similar thing is done. > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <http://bugs.python.org/issue16974> > _______________________________________ > |
|||
| msg353957 - (view) | Author: Ashley Whetter (AWhetter) * | Date: 2019年10月04日 17:05 | |
If we were to add a new attribute to indicate whether a file is real or not, there would need to be a way for users to indicate whether a file is real or not to functions such as `compile()` (there's lots more!) that take a filename. Without enforcing this being set and introducing backward incompatible changes, it would need a default value. To be backwards compatible we could default to True and the existing behaviour persists. It's also worth mentioning that there's a few places (there might be more!) where Python already assumes that a file in angle brackets is not a real file: * https://github.com/python/cpython/blob/abd7cd856ba326bd7574135c7d034e98492ab695/Lib/bdb.py#L45 * https://github.com/python/cpython/blob/abd7cd856ba326bd7574135c7d034e98492ab695/Lib/pdb.py#L694 * https://github.com/python/cpython/blob/abd7cd856ba326bd7574135c7d034e98492ab695/Lib/pickle.py#L324 Nothing major though and easily changeable so it's definitely possible but it would be a lot of work to make sure that everything is setting the new attribute properly. Is there a preference on what the name of this attribute should be? Maybe `__is_real_file__`. It's clear but long. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:40 | admin | set | github: 61178 |
| 2021年09月27日 16:00:06 | iritkatriel | set | status: open -> closed superseder: Traceback display code can attempt to open a file named "<stdin>" resolution: duplicate stage: needs patch -> resolved |
| 2019年10月04日 17:05:50 | AWhetter | set | nosy:
+ AWhetter messages: + msg353957 |
| 2018年04月09日 21:00:30 | ned.deily | set | stage: needs patch versions: + Python 3.6, Python 3.7, Python 3.8, - Python 3.2, Python 3.3, Python 3.4 |
| 2018年04月09日 08:10:25 | serhiy.storchaka | link | issue33247 superseder |
| 2014年12月12日 01:16:16 | Arfrever | set | nosy:
+ Arfrever |
| 2013年01月16日 12:29:31 | Ramchandra Apte | set | messages: + msg180086 |
| 2013年01月16日 12:15:20 | r.david.murray | set | messages: + msg180084 |
| 2013年01月16日 12:13:09 | r.david.murray | set | messages: + msg180083 |
| 2013年01月16日 05:30:36 | ericlammerts | set | messages: + msg180074 |
| 2013年01月16日 04:26:13 | eric.araujo | set | nosy:
+ eric.araujo |
| 2013年01月16日 03:20:39 | Ramchandra Apte | set | nosy:
+ Ramchandra Apte messages: + msg180072 |
| 2013年01月15日 22:30:01 | r.david.murray | set | nosy:
+ r.david.murray messages: + msg180063 versions: + Python 3.3, Python 3.4 |
| 2013年01月15日 21:40:06 | ericlammerts | create | |