Re: [Tutor] Case Insensitive Globing

2019-05-19 Thread eryk sun
On 5/18/19, Steven D'Aprano  wrote:
>
> That means that, like Windows file systems FAT and NTFS, file names are
> case-insensitive: files "Foo", "foo" and "FOO" are all considered the
> same. But unlike Windows, the file system preserves the case of the file
> as you created it, so if you created it as "foO" that's how it will be
> recorded on the disk rather than normalizied to "foo".

NTFS and FAT32 are case preserving.

> Fun fact: even NTFS supports a case-sensitive mode! But again, hardly
> anyone uses it.

There's nothing inherent in the design of NTFS that prevents
case-sensitive names in a directory. It's strictly a function of the
OS and filesystem driver. On non-Windows platforms, an NTFS driver can
create names that differ only in case. An example is the Linux ntfs-3g
driver, which allows this unless the "windows_names" option is set.

In a Windows system, the NT object namespace is case sensitive, and
overriding a create or open to be case insensitive requires the flag
OBJ_CASE_INSENSITIVE. The Windows API uses this flag by default in the
file and registry APIs. However, beginning with Windows XP, the kernel
takes it a step further. Regardless of the user-mode subsytem, it
forces this flag for object types that are defined as case
insensitive, such as Object Manager "Directory" and "SymbolicLink"
objects (used in the root object namespace, akin to the root
filesystem in Unix), Configuration Manager "Key" objects (registry),
and I/O manager "Device" and "File" objects.

Prior to Windows XP, it was possible to force a CreateFile or
FindFirstFileEx call to be case sensitive, respectively via the flags
FILE_FLAG_POSIX_SEMANTICS and FIND_FIRST_EX_CASE_SENSITIVE.
Internally, this is implemented by *omitting* the OBJ_CASE_INSENSITIVE
flag that the Windows API usually includes for device and file
operations. This didn't change in XP, but, as mentioned above, it's
impotent now since the kernel itself adds the flag for
case-insensitive object types. The only way to change this is to
restart the system after zeroing the "obcaseinsensitive" value in the
"Session Manager\kernel" registry key. That's not tenable in practice,
so we have to just accept that device and file names are case
insensitive.

That said, in Windows 10, the Windows Subsystem for Linux requires a
way to change the filesystem default to case sensitive for individual
directories. If a directory is case sensitive, then create, open, and
control operations in or on it always ignore OBJ_CASE_INSENSITIVE.
This directory attribute can be queried and set with a new file
information class in the NT API named "FileCaseSensitiveInformation",
or on the command line via `fsutil file queryCaseSensitiveInfo `
and `fsutil file setCaseSensitiveInfo  [enable|disable]`.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How arguments to the super() function works?

2019-05-19 Thread eryk sun
On 5/19/19, Arup Rakshit  wrote:
>
> class Dad:
> def can_i_take_your_car(self):
> print("No...")
>
> class Mom(Dad):
> def can_i_take_your_car(self):
> print("Asking your dad...")
>
> class Victor(Mom, Dad):
> def can_i_take_your_car(self):
> print("Asking mom...")
>
> class Pinki(Mom, Dad):
> def can_i_take_your_car(self):
> print("I need it today..")
>
> class Debu(Pinki, Victor):
> def can_i_take_your_car(self):
> super(Victor, self).can_i_take_your_car()
>
> In this piece of code:
>
> print(Debu().can_i_take_your_car())
>
> Why the above call prints "Asking your dad…” but not " print("Asking mom…”)”
> although can_i_take_your_car is defined inside the class Victor ?

Victor comes after Pinki in the MRO:

>>> super(Debu, Debu()).can_i_take_your_car()
I need it today..
>>> super(Pinki, Debu()).can_i_take_your_car()
Asking mom...
>>> super(Victor, Debu()).can_i_take_your_car()
Asking your dad...
>>> super(Mom, Debu()).can_i_take_your_car()
No...

> Last question: Why duplicate PEPs for the same thing
> https://www.python.org/dev/peps/pep-0367/ and
> https://www.python.org/dev/peps/pep-3135/#specification ? Which one to read
> when such duplicate exists?

See https://www.python.org/dev/peps/pep-0367/#numbering-note and
https://www.python.org/dev/peps/pep-3135/#numbering-note.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How arguments to the super() function works?

2019-05-19 Thread Mats Wichmann
On 5/19/19 12:28 AM, Arup Rakshit wrote:
> 
>> On 19-May-2019, at 4:46 AM, Mark Lawrence  wrote:
>>
>> On 18/05/2019 17:21, Arup Rakshit wrote:
>>> I am writing an Flask app following a book, where a piece of python concept 
>>> I am not getting how it works. Code is:
>>> class Role(db.Model):
>>> __tablename__ = 'roles'
>>> id = db.Column(db.Integer, primary_key=True)
>>> name = db.Column(db.String(64), unique=True)
>>> default = db.Column(db.Boolean, default=False, index=True)
>>> permissions = db.Column(db.Integer)
>>> users = db.relationship('User', backref='role', lazy='dynamic')
>>> def __init__(self, **kwargs):
>>> super(Role, self).__init__(**kwargs)
>>> if self.permissions is None:
>>> self.permissions = 0
>>> Here, why super(Role, self).__init__(**kwargs) is used instead of 
>>> super().__init__(**kwargs) ? What that Role and self argument is 
>>> instructing the super() ?
>>> Thanks,
>>> Arup Rakshit
>>> a...@zeit.io
>>
>> Please check this https://www.youtube.com/watch?v=EiOglTERPEo out.  If that 
>> doesn't answer your question please ask again.
>>
> 
> 
> Hello Mark,
> 
> Thanks for sharing the link. Just finished the talk. Little better now about 
> how super uses the MRO.
> 
> class Dad:
> def can_i_take_your_car(self):
> print("No...")
> 
> class Mom(Dad):
> def can_i_take_your_car(self):
> print("Asking your dad...")
> 
> class Victor(Mom, Dad):
> def can_i_take_your_car(self):
> print("Asking mom...")
> 
> class Pinki(Mom, Dad):
> def can_i_take_your_car(self):
> print("I need it today..")
> 
> class Debu(Pinki, Victor):
> def can_i_take_your_car(self):
> super(Victor, self).can_i_take_your_car()
> 
> In this piece of code:
> 
> print(Debu().can_i_take_your_car())
> 
> Why the above call prints "Asking your dad…” but not " print("Asking mom…”)” 
> although can_i_take_your_car is defined inside the class Victor ?

Because that's what you asked for?

in Debu you asked to call the method through the object obtained by
calling super on Victor, and that resolves to Mom per the MRO.  help()
gets that for you, but you can also check it programmatically:

print(Victor.__mro__)

(, , , )


you can also print the method it would resolve to, change class Debu to:

class Debu(Pinki, Victor):
def can_i_take_your_car(self):
print(super(Victor, self).can_i_take_your_car)  # note this is
not a call
super(Victor, self).can_i_take_your_car()

and you can see how it resolves:

>
Asking your dad...


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Query about python recipies for practices

2019-05-19 Thread bijaya dalei
Hii, Good morning. I am a new user of python programming language. I have a
small query on "where to get python recepies for practices".plz
suggest.Thanks.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Two Scripts, Same Commands, One Works, One Doesn't

2019-05-19 Thread Alan Gauld via Tutor
On 19/05/2019 04:58, DL Neil wrote:

> last time I used the term "bomb", I'm guessing that "abend" wouldn't 
> pass muster either...

Gosh, I haven't seen a reference to abend in 20 years.
I'd almost managed to erase the memory... :-)

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Case Insensitive Globing

2019-05-19 Thread Alan Gauld via Tutor
On 19/05/2019 01:37, Steven D'Aprano wrote:

> That's not quite right -- case sensitivity of the OS isn't important, 
> case sensitivity of the *file system* is. And the standard file system 
> on Mac OS, HFS+, defaults to case-preserving but case-insensitive.
> 
> (There is an option to turn case-sensitivity off, but hardly anyone uses 
> it because too many applications break.)

Oops, my mistake. Almost all my MacOS knowledge is based on my ancient
iBook. Having had a look, it appears it's formatted in UFS rather than
HFS+ so I assume I must have done something to force that when I first
installed the system back in 2001...

It certainly appears to be case sensitive but life is too short
for me to do extensive testing right now!

> Fun fact: even NTFS supports a case-sensitive mode! But again, hardly 
> anyone uses it.

Hmm, odd. My NTFS filesystems on Windows all appear to be case
sensitive. For example I have a photo editor that saves its files
with a jpg extension but the files from my camera all end in JPG.
So I always end up with two copies - the original file and the
edited version.

I'm not aware of having done anything to cause that.
More investigation required I think...


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Case Insensitive Globing

2019-05-19 Thread eryk sun
On 5/19/19, Alan Gauld via Tutor  wrote:
>
> Hmm, odd. My NTFS filesystems on Windows all appear to be case
> sensitive. For example I have a photo editor that saves its files
> with a jpg extension but the files from my camera all end in JPG.
> So I always end up with two copies - the original file and the
> edited version.
>
> I'm not aware of having done anything to cause that.
> More investigation required I think...

Maybe you have Explorer configured to hide file extensions, and you
have one file named "filename.JPG" and another named
"filename.jpg.JPG".

On a related note, the new support for case-sensitive directories in
Windows 10 can lead to an issue when running commands. Shells use the
PATHEXT environment variable to supply a list of default extensions
when searching PATH for a command. These are usually upper case, so if
we run "script" and it searches for "script.PY", it won't find
"script.py" in a case-sensitive directory. The same applies to
Python's shutil.which().

Regarding this topic, glob.py and fnmatch.py are unreliable in Windows
for case-sensitive NTFS directories. Sometimes they rely on regular
expressions and os.path.normcase (for ntpath.normcase, this replaces
slash with backslash and converts to lowercase), and sometimes they
rely on stat-based functions such as os.path.lexists, which will be
case sensitive.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor