02.06.18 03:05, Chris Angelico пише:
The permissions error is reported differently by stat, but then
exists() just says "oh that's an OS error so we're going to say it
doesn't exist". If you truly want the reliable form of os.path.exists,
it would be this:
try:
os.stat(path)
return Tru
01.06.18 16:58, Chris Angelico пише:
Possibly more confusing, though, is this:
os.path.exists(1)
True
os.path.exists(2)
True
os.path.exists(3)
False
I think it's testing that the file descriptors exist, because
os.path.exists is defined in terms of os.stat, which can stat a path
or an FD.
On Fri, Jun 1, 2018 at 6:34 PM, Mike McClain wrote:
> On Fri, Jun 01, 2018 at 08:02:27AM -0700, Mike McClain wrote:
> > On Thu, May 31, 2018 at 07:44:35PM -0700, Mike McClain wrote:
> >
> > > Is there a way in a script to know which version of python is being
> > > run so I can write:
> > >
On 2018-06-01, Steven D'Aprano wrote:
> On Thu, 31 May 2018 17:43:28 +, Grant Edwards wrote:
>
>> Except on the platform in quetion filenames _don't_ contain an embedded
>> \0. What was passed was _not_ a path/filename.
>
> "/wibble/rubbish/nobodyexpectsthespanishinquistion" is not a pathname
On Sat, Jun 2, 2018 at 11:34 AM, Mike McClain wrote:
> On Fri, Jun 01, 2018 at 08:02:27AM -0700, Mike McClain wrote:
>> On Thu, May 31, 2018 at 07:44:35PM -0700, Mike McClain wrote:
>>
>> > Is there a way in a script to know which version of python is being
>> > run so I can write:
>> > If (v
On 2018-06-01, Steven D'Aprano wrote:
> But since "\0" is the correct type (a string), and the fact that it
> happens to be illegal on POSIX is a platform-dependent detail of no more
> importance than the fact that "?" is illegal on Windows, it should be
> treated as any other platform-depende
On Fri, Jun 01, 2018 at 08:02:27AM -0700, Mike McClain wrote:
> On Thu, May 31, 2018 at 07:44:35PM -0700, Mike McClain wrote:
>
> > Is there a way in a script to know which version of python is being
> > run so I can write:
> > If (version == 2.7):
> > do it this way
> > elsif (ver
On Sat, Jun 2, 2018 at 12:14 AM, Steven D'Aprano
wrote:
>
> It isn't even a set of minimum requirements. "<" is legal under POSIX,
> but not Windows.
"<" (i.e. the DOS_STAR wildcard character) is valid in device and
stream names. It's only invalid in filenames, since it's reserved for
wildcard ma
On Sat, Jun 2, 2018 at 10:14 AM, Steven D'Aprano
wrote:
>> But
>> assuming you're right, POSIX is still a set of minimum requirements -
>> not maximums, to my knowledge.
>
> It isn't even a set of minimum requirements. "<" is legal under POSIX,
> but not Windows.
Windows isn't POSIX compliant.
A
On Sat, Jun 2, 2018 at 9:10 AM, Gregory Ewing
wrote:
> Chris Angelico wrote:
>>
>> if you 'break' immediately after a mutation, that isn't
>> continuing to iterate. Even though you're inside the loop, there's no
>> further action taken to process the loop, and no problem.
>
>
> Yes, but you're als
On Sat, 02 Jun 2018 09:56:58 +1000, Chris Angelico wrote:
> On Sat, Jun 2, 2018 at 9:37 AM, Steven D'Aprano
> wrote:
>> On Thu, 31 May 2018 17:43:28 +, Grant Edwards wrote:
>>
>>> Except on the platform in quetion filenames _don't_ contain an
>>> embedded \0. What was passed was _not_ a path
On Sat, Jun 2, 2018 at 9:54 AM, Steven D'Aprano
wrote:
> On Sat, 02 Jun 2018 08:50:38 +1000, Chris Angelico wrote:
>
>> My ideal preference would be for True to mean "we know for certain that
>> this exists" and False "we know for certain that this doesn't exist"
>
> We cannot make that promise, b
On Sat, Jun 2, 2018 at 9:37 AM, Steven D'Aprano
wrote:
> On Thu, 31 May 2018 17:43:28 +, Grant Edwards wrote:
>
>> Except on the platform in quetion filenames _don't_ contain an embedded
>> \0. What was passed was _not_ a path/filename.
>
> "/wibble/rubbish/nobodyexpectsthespanishinquistion"
On Sat, 02 Jun 2018 08:50:38 +1000, Chris Angelico wrote:
> My ideal preference would be for True to mean "we know for certain that
> this exists" and False "we know for certain that this doesn't exist"
We cannot make that promise, because we might not have permission to view
the file. Since we
On Fri, 01 Jun 2018 11:58:42 -0400, Richard Damon wrote:
> I would say that one way to look at it is that os.path.exists
> fundamentally (at the OS level) expects a parameter of the 'type' of
> either a nul terminated string or a file descriptor (aka fixed width
> integer). One issue we have is th
On Fri, Jun 1, 2018 at 3:58 PM, Richard Damon wrote:
>
> The fundamental question is about case 2. Should os.path.exist, having
> been give a value of the right 'Python Type' but not matching the type
> of the operating system parameter identify this as an error (as it
> currently does), or should
Grant Edwards wrote:
Python allows floating point numbers, so it is possible to express
this question in python: os.path.exists(3.14159). Is the fact that
the underlying OS/filesystem can't identify files via a floating point
number relevent? Should it return False or raise ValueError?
I don'
On Thu, 31 May 2018 17:43:28 +, Grant Edwards wrote:
> Except on the platform in quetion filenames _don't_ contain an embedded
> \0. What was passed was _not_ a path/filename.
"/wibble/rubbish/nobodyexpectsthespanishinquistion" is not a pathname on
my system either, and os.path.exists() ret
On Fri, 01 Jun 2018 14:38:56 +, Grant Edwards wrote:
> On 2018-06-01, Paul Moore wrote:
>
>> Python allows strings with embedded \0 characters, so it's possible to
>> express that question in Python - os.path.exists('a\0b'). What can be
>> expressed in terms of the low-level (C-based) opera
Chris Angelico wrote:
if you 'break' immediately after a mutation, that isn't
continuing to iterate. Even though you're inside the loop, there's no
further action taken to process the loop, and no problem.
Yes, but you're also not calling next() again, so no
exception would be triggered.
My po
Marko Rauhamaa wrote:
Interestingly, you get a False even for existing files if you don't have
permissions to access the file.
Obviously in that case, instead of True or False it should
return FileNotFound. :-)
https://thedailywtf.com/articles/What_Is_Truth_0x3f_
--
Greg
--
https://mail.pytho
On Sat, Jun 2, 2018 at 8:10 AM, Steven D'Aprano
wrote:
> But it *isn't* the wrong type. It is the same type:
>
>
> py> type("abc") is type("a\0c")
> True
>
>
> So TypeError is out, since the type is right, only the value is wrong.
I agree with you so far. This parallels the fact that math.asin(5)
On Fri, 01 Jun 2018 09:41:04 -0400, Richard Damon wrote:
> I think this is a key point. os.path.exists needs to pass a null
> terminated string to the system to ask it about the file.
That's an implementation detail utterly irrelevant to Python programmers.
If the OS expects a pointer to a block
On Sat, Jun 2, 2018 at 7:03 AM, Peter J. Holzer wrote:
> On 2018-05-31 14:42:39 -0700, Paul wrote:
>> I have heard that attachments to messages are not allowed on this list,
>> which makes sense. However I notice that messages from Peter do have an
>> attachment, i.e., a signature.asc file.
>
> No
On Sat, Jun 2, 2018 at 7:00 AM, Peter Pearson wrote:
> On Fri, 1 Jun 2018 15:57:58 +0100, Paul Moore wrote:
>> On 1 June 2018 at 15:36, Dan Strohl via Python-list
>> wrote:
>>> So... how does one go about suggesting changes to the built in types?
> [snip]
>>
>> Why does this need to be a string m
On Fri, 1 Jun 2018 15:57:58 +0100, Paul Moore wrote:
> On 1 June 2018 at 15:36, Dan Strohl via Python-list
> wrote:
>> So... how does one go about suggesting changes to the built in types?
[snip]
>
> Why does this need to be a string method? Why can't it be a standalone
> function?
Yes, please, l
On 2018-05-31 14:42:39 -0700, Paul wrote:
> I have heard that attachments to messages are not allowed on this list,
> which makes sense. However I notice that messages from Peter do have an
> attachment, i.e., a signature.asc file.
No this is isn't an attachment. It's a signature. Your MUA probabl
On Sat, Jun 2, 2018 at 2:10 AM, Paul Moore wrote:
> On 1 June 2018 at 16:36, Chris Angelico wrote:
>> On Sat, Jun 2, 2018 at 12:57 AM, Paul Moore wrote:
>
>>> Why does this need to be a string method? Why can't it be a standalone
>>> function? Maybe you should publish an implementation on PyPI,
On 1 June 2018 at 16:36, Chris Angelico wrote:
> On Sat, Jun 2, 2018 at 12:57 AM, Paul Moore wrote:
>> Why does this need to be a string method? Why can't it be a standalone
>> function? Maybe you should publish an implementation on PyPI, collect
>> some data on how popular it is, and then if it
On 6/1/18 9:58 AM, Chris Angelico wrote:
> On Fri, Jun 1, 2018 at 11:41 PM, Richard Damon
> wrote:
>> The confusion is that in python, a string with an embedded null is
>> something pretty much like a string without an embedded null, so the
>> programmer might not think of it as being the wrong t
On Thu, May 31, 2018 at 07:44:35PM -0700, Mike McClain wrote:
> Is there a way in a script to know which version of python is being
> run so I can write:
> If (version == 2.7):
> do it this way
> elsif (version == 3.2):
> do it another way
>
Thanks for the responses,
Mike
On Sat, Jun 2, 2018 at 12:57 AM, Paul Moore wrote:
> On 1 June 2018 at 15:36, Dan Strohl via Python-list
> wrote:
>> So... how does one go about suggesting changes to the built in types? I
>> could take a whack at the code for it, but my C skills are no where near
>> what should probably be ne
>
> It would probably have to go via python-ideas, but if it gets the OK there I
> doubt it would need a PEP.
>
Cool, thanks!
> There are a few key questions I'd expect to see come up.
>
> Why does this need to be a string method? Why can't it be a standalone
> function? Maybe you should publi
On Thu, May 31, 2018 at 11:00:13PM -0400, Terry Reedy wrote:
> On 5/31/2018 10:26 PM, Mike McClain wrote:
> > I'm having understanding the use if the ellipsis.
> >I keep reading that it is used in slices
>
> By numpy for numpy multidimensional arrays, which have their own
> __getitem__, which r
On 1 June 2018 at 15:38, Grant Edwards wrote:
> On 2018-06-01, Paul Moore wrote:
>
>> Python allows strings with embedded \0 characters, so it's possible
>> to express that question in Python - os.path.exists('a\0b'). What
>> can be expressed in terms of the low-level (C-based) operating
>> syst
On 1 June 2018 at 15:36, Dan Strohl via Python-list
wrote:
> So... how does one go about suggesting changes to the built in types? I
> could take a whack at the code for it, but my C skills are no where near what
> should probably be needed for something this close to the core of the
> languag
On 2018-06-01, Paul Moore wrote:
> Python allows strings with embedded \0 characters, so it's possible
> to express that question in Python - os.path.exists('a\0b'). What
> can be expressed in terms of the low-level (C-based) operating
> system API shouldn't be relevant.
Python allows floating
>
> I would prefer to remove the padding, like this:
>
> Test = """
> |Hello, this is a
> | Multiline indented
> |String
> """.outdent(padding='|')
>
> Or write it like this?
>
> Test = """|Hello, this is a
> | Multiline indented
>
Chris Angelico :
> Possibly more confusing, though, is this:
>
os.path.exists(1)
> True
os.path.exists(2)
> True
os.path.exists(3)
> False
>
> I think it's testing that the file descriptors exist, because
> os.path.exists is defined in terms of os.stat, which can stat a path
> or an
On Fri, Jun 1, 2018 at 11:41 PM, Richard Damon wrote:
> The confusion is that in python, a string with an embedded null is
> something pretty much like a string without an embedded null, so the
> programmer might not think of it as being the wrong type. Thus we have
> several options.
>
> 1) we ca
On 5/31/18 1:43 PM, Grant Edwards wrote:
> On 2018-05-31, Paul Moore wrote:
>> On 31 May 2018 at 15:01, Chris Angelico wrote:
>>
>> Honestly, I think the OP's point is correct. os.path.exists should
>> simply return False if the filename has an embedded \0 - at least on
>> Unix.
> Except on the p
Paul Moore :
> On 1 June 2018 at 13:15, Barry Scott wrote:
>> Once you know that all of the string you provided is given to the
>> operating system it can then do whatever checks it sees fit to and
>> return a suitable result.
>
> As the programmer, I don't care. The Python interpreter should take
On Thursday, May 31, 2018 at 10:18:53 PM UTC-4, bob gailer wrote:
> On 5/31/2018 3:49 PM, bruceg113...@gmail.com wrote:
> > How do I list only the methods I define in a class?
> Here's a class with some method, defined in various ways:
>
> >>> class x():
> ... a=3
> ... def f():pass
> ..
On 1 June 2018 at 13:15, Barry Scott wrote:
> I think the reason for the \0 check is that if the string is passed to the
> operating system with the \0 you can get surprising results.
>
> If \0 was not checked for you would be able to get True from:
>
> os.file.exists('/home\0ignore me')
>
On Thursday, 31 May 2018 14:03:01 BST Marko Rauhamaa wrote:
> Chris Angelico :
> > On Thu, May 31, 2018 at 10:03 PM, Marko Rauhamaa wrote:
> >> This surprising exception can even be a security issue:
> >>>>> os.path.exists("\0")
> >>
> >>Traceback (most recent call last):
> >> Fil
Python module with the following file structure:
.
├── mefoo
│ ├── __init__.py
│ ├── bar.py
│ └── command_line
│ ├── __init__.py
│ ├── cli1.py
│ └── cli2.py
└── setup.py
Stripped down `setup.py` is
#!/usr/bin/env python3
i
I'd like to embed console_scripts in a pex file and be able to use them by
specifying them when invoking the pex file.
The details are...
Python module with the following file structure:
.
├── mefoo
│ ├── __init__.py
│ ├── bar.py
│ └── command_line
│ ├── __ini
On Thu, 31 May 2018 16:37:39 +0200, Frank Millman wrote:
[...]
> Agreed, but my gut feel, and the following example, suggest that when
> processing the last key in a dictionary while iterating over it, you
> have not yet stopped iterating.
>
d = {}
d[1] = 'one'
d[2] = 'two'
Before
"Gregory Ewing" wrote in message news:fnccd8ff3s...@mid.individual.net...
Chris Angelico wrote:
> It is an error to mutate the dictionary *and then continue to iterate
> over it*.
But if you're processing the last key, and you add one so
that it's no longer the last key, what should happen?
On Fri, Jun 1, 2018 at 4:56 PM Gregory Ewing
wrote:
> Chris Angelico wrote:
> > It is an error to mutate the dictionary *and then continue to iterate
> over it*.
>
> But if you're processing the last key, and you add one so
> that it's no longer the last key, what should happen?
>
> My feeling is
Here's my take on what an indented multi-line string
syntax should look like.
string foo:
| This is a multi-line indented string declaration.
| Note that it's a statement, not an expression. In
| this example, each line of the final string starts
| with two
On Fri, Jun 1, 2018 at 5:54 PM, Gregory Ewing
wrote:
> Chris Angelico wrote:
>>
>> It is an error to mutate the dictionary *and then continue to iterate over
>> it*.
>
>
> But if you're processing the last key, and you add one so
> that it's no longer the last key, what should happen?
>
> My feeli
Chris Angelico wrote:
It is an error to mutate the dictionary *and then continue to iterate over it*.
But if you're processing the last key, and you add one so
that it's no longer the last key, what should happen?
My feeling is that this should be an error, because it's
not clear whether itera
Can any web programmer tell me why output is not defined?
I know this is python group but my code is so rudimentary that probably any
sufficient good webprogrammer can figure it out, but i am lost."I've tried
comp.lang.javascript"
Problem is I've looked upon this for a week or two, and i just ca
54 matches
Mail list logo