[Tutor] Case Insensitive Globing

2019-05-18 Thread Richard Damon
I am working on a program to process some files created by an old
windows program that created it files with varying case with a python
program.

Using glob.glob on Windows seems to ignore the case, and find all the
matching files.

The same directory, running the same program under Mac OS X, which also
is a case insensitive file system, is only files that match the case of
the glob, and is missing many of the files that were found under windows.

Is there an easy was to make glob match files as a case insensitive manner?

Or a simple way to do this with something else.

I am trying to do something like:

  for file in glob.glob(pattern): processfile(file)

-- 
Richard Damon

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


Re: [Tutor] [SPAM?] Re: Case Insensitive Globing

2019-05-18 Thread Richard Damon
On 5/18/19 6:52 AM, Alan Gauld via Tutor wrote:
> On 18/05/2019 03:14, Richard Damon wrote:
>
>> The same directory, running the same program under Mac OS X, which also
>> is a case insensitive file system, 
> That is your mistake. Darwin, the core of the MacOS X system
> is a version of BSD Unix and like all Unix OS is very much
> case sensitive.
>
> Some of the GUI tools in MacOS X may work as if they were case
> insensitive (presumably for backwards compatibility to MacOS 9)
> but the underlying OS is case sensitive and all the Terminal
> type tools and commands, including Python, follow suit.
Ok, I guess I have gotten used to the GUI tools and their behavior, that
would explain why glob works the way it does.
>> Is there an easy was to make glob match files as a case insensitive manner?
> Depends on what you mean by easy :-)
> You could include both upper and lower case letters in the search:
>
> glob.glob("[aA][mM][iI][xX][eE][dD][nN][aA][mM][eE]")
>
> And you could write a helper function to generate the search strings.
>
> But personally I'd probably just use listdir and compare with
> my search string expressed as a regex.
>
> for fname in os.listdir('.'):
> if re.match("aregex", fname)
>...
>
> Another option might be to use fnmatch against the uppercase
> version of the name
>
> for fname in os.listdir('.'):
>if fnmatch(pattern, fname.upper())
>  ...
>
> HTH

I was hoping for something simpler, but I guess an explicit directory
search isn't that bad.

Thanks.

-- 
Richard Damon

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


[Tutor] Setting Command Line Arguments in IDLE

2019-05-26 Thread Richard Damon
I am working on a python script that will be provided arguments when run
from the system command line. Is there any place in IDLE to provide
equivalent arguments for testing while developing in IDLE?

Is there any way to define the working directory for the program, or
will it always be the directory the script is in (it will be typically
run using the PATH, so not the same directory as the script)?

If not, is there an easy way to detect that I am running in IDLE so I
can fake the command line arguments when testing?

-- 
Richard Damon

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


Re: [Tutor] Make a linked list subscriptable?

2019-07-12 Thread Richard Damon
On 7/11/19 10:55 AM, Mats Wichmann wrote:
> On 7/10/19 6:30 PM, Sarah Hembree wrote:
>> How might I best make a linked list subscriptable? Below is skeleton code
>> for a linked list (my
>> actual is much more). I've done __iter__ and __next__ but I would like to
>> be able to do start:stop:stride I just can't figure out how. Suggestions or
>> just hints please?
> As a learning exercise this can be interesting, but as to practical
> applications, one would like to ask "why"?  If index into the list is
> important, then choose a regular list; the "interesting" part of a
> linked list, which is "next node" is then available as index + 1.
>
To expand on the question, the primary use of something like a linked
list is that you want cheap insertions/deletions (of O(1)) and in
exchange for that indexing becomes O(n), verse an array based list which
has O(1) indexing but O(N) insertions/deletions (since you need to
compact the array). Both can be iterated in O(1).

You can add an index operator that takes O(N) time to a linked list.
obj[n] will call obj.__getitem__ (and you will also want to implement
__setitem__, __delitem__), and check if the argument is a slice to
handle slices.

-- 
Richard Damon

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


Re: [Tutor] Output reason

2019-07-12 Thread Richard Damon
If I remember how that works right, there is a single empty list that is 
created and used for all the calls that use the default argument, and then your 
function modifies that empty list so it is no longer empty, and that modified 
list is used on future calls. (Not good to use a mutable as a default 
parameter).

A better solution would be to make the default something like None, and test if 
at the beginning of the function li is None, and if so set it to an empty list, 
and that empty list will be in function scope so it goes away and a new one is 
created on a new call.

> On Jul 12, 2019, at 10:24 AM, Gursimran Maken  
> wrote:
> 
> Hi,
> 
> Can someone please explain me the reason for below output.
> 
> Program:
> def fun(n,li = []):
>a = list(range(5))
>li.append(a)
>print(li)
> 
> fun(4)
> fun(5,[7,8,9])
> fun(4,[7,8,9])
> fun(5) # reason for output (why am I getting to values in this output.)
> 
> Output:
> [[0, 1, 2, 3, 4]]
> [7, 8, 9, [0, 1, 2, 3, 4]]
> [7, 8, 9, [0, 1, 2, 3, 4]]
> [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]
> 
> Thank you,
> Gursimran
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

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


Re: [Tutor] Name for this type of class?

2019-08-03 Thread Richard Damon
On 8/3/19 1:40 PM, Alex Kleider wrote:
> On 2019-08-03 10:16, Mats Wichmann wrote:
>
>> .  It also comes up here:
>>
>>>> file_count
>>>> line_count
>>>> byte_count
>>>> row_count
>>>> batch_count
>>>> job_count
>>>> error_count
>>>> warning_count
>>
>> why not "files", "lines", "bytes"... the plural form already tells you
>> it's a counter.
>
> To me "files", "lines", "bytes" implies collections of files, lines
> bytes. (i.e. arrays or tuples...)
> "___count" implies an integer.
> If the latter, I'd use "n_files", "n_lines" ... (possibly without the
> underscores if you find typing them a bother.)
> Comments? 

I agree, plural nouns imply collections, and collections should
generally be plural nouns.

file_count is fine to me, or it could be numfiles or nfiles (possibly
adding the underscore)

-- 
Richard Damon

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