Apriori Algorithm

2021-03-07 Thread sarang shah
I have this dataset in a text file I need to make an apriori algorithm based on 
it. Please help.

25 52 164 240 274 328 368 448 538 561 630 687 730 775 825 834 
39 120 124 205 401 581 704 814 825 834 
35 249 674 712 733 759 854 950 
39 422 449 704 825 857 895 937 954 964 
15 229 262 283 294 352 381 708 738 766 853 883 966 978 
26 104 143 320 569 620 798 
7 185 214 350 529 658 682 782 809 849 883 947 970 979 
227 390 
71 192 208 272 279 280 300 333 496 529 530 597 618 674 675 720 855 914 932 
183 193 217 256 276 277 374 474 483 496 512 529 626 653 706 878 939 
161 175 177 424 490 571 597 623 766 795 853 910 960 
125 130 327 698 699 839 
392 461 569 801 862 
27 78 104 177 733 775 781 845 900 921 938 
101 147 229 350 411 461 572 579 657 675 778 803 842 903 
71 208 217 266 279 290 458 478 523 614 766 853 888 944 969 
43 70 176 204 227 334 369 480 513 703 708 835 874 895 
25 52 278 730 
151 432 504 830 890 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Apriori Algorithm

2021-03-07 Thread dn via Python-list
On 07/03/2021 20.56, sarang shah wrote:
> I have this dataset in a text file I need to make an apriori algorithm based 
> on it. Please help.
> 
> 25 52 164 240 274 328 368 448 538 561 630 687 730 775 825 834 
> 39 120 124 205 401 581 704 814 825 834 
> 35 249 674 712 733 759 854 950 
> 39 422 449 704 825 857 895 937 954 964 
> 15 229 262 283 294 352 381 708 738 766 853 883 966 978 
> 26 104 143 320 569 620 798 
> 7 185 214 350 529 658 682 782 809 849 883 947 970 979 
> 227 390 
> 71 192 208 272 279 280 300 333 496 529 530 597 618 674 675 720 855 914 932 
> 183 193 217 256 276 277 374 474 483 496 512 529 626 653 706 878 939 
> 161 175 177 424 490 571 597 623 766 795 853 910 960 
> 125 130 327 698 699 839 
> 392 461 569 801 862 
> 27 78 104 177 733 775 781 845 900 921 938 
> 101 147 229 350 411 461 572 579 657 675 778 803 842 903 
> 71 208 217 266 279 290 458 478 523 614 766 853 888 944 969 
> 43 70 176 204 227 334 369 480 513 703 708 835 874 895 
> 25 52 278 730 
> 151 432 504 830 890 


Great!
For what purpose - is this a 'homework assignment'?
What code do you have so far?

-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


A 35mm film camera represented in Python object

2021-03-07 Thread D.M. Procida
Hi everyone, I've created  -
a representation of a Canonet G-III QL17 in Python.

There's also documentation: .

It's a pure Python model of the physical sub-systems of a camera and
their interactions. So far it's at a fairly high level - I haven't yet
got down to the level of individual springs and levers yet.

I spend quite a bit of my time repairing old cameras. To me they feel
like computer programs encoded into physical objects, and figuring out
how a mechanism works feels like working out how code works (but more
fun).

The Canonet G-III QL17 is one of my favourites. One of my reasons for
writing this code is to appreciate the intricate mechanical logic
embodied in the machine.

You can do things like advance the film, release the shutter, meter the
scene with the built-in light meter (if the camera has a battery of
course) and even spoil your film if you make the mistake of opening the
back in daylight.

>>> from camera import Camera
>>> c = Camera()

>>> c.state()
== Camera state =

-- Controls -
Selected speed:1/120

-- Mechanical ---
Back closed:   True
Lens cap on:   False
Film advance mechanism:False
Frame counter: 0
Shutter cocked:False
Shutter timer: 1/128 seconds
Iris aperture: ƒ/16
Camera exposure settings:  15.0 EV

-- Metering -
Light meter reading:4096 cd/m^2
Exposure target:15.0 EV
Mode:   Shutter priority
Battery:1.44 V
Film speed: 100 ISO

-- Film -
Speed:  100 ISO
Rewound into cartridge: False
Exposed frames: 0 (of 24)
Ruined: False

-- Environment --
Scene luminosity:   4096 cd/m^2

>>> c.film_advance_mechanism.advance()
Cocking shutter
Cocked

>>> c.shutter.trip()
Shutter opens
Shutter closes
Shutter opened for 1/128 seconds
Shutter uncocked

You can't do impossible things:

>>> c.shutter_speed = 1/33
Traceback (most recent call last):
  File "", line 1, in 
  File "/Users/daniele/Repositories/camera/camera.py", line 29, in 
shutter_speed
raise self.NonExistentShutterSpeed(f"Possible shutter speeds are
  {possible_settings}")
camera.NonExistentShutterSpeed: Possible shutter speeds are 1/4, 
  1/8, 1/15, 1/30, 1/60, 1/120, 1/240, 1/500

But you can also do things that you shouldn't do, like opening the back
of the camera in daylight with a partially-exposed roll of film inside -
which will spoil the film::

>>> c.back.open()
Opening back
Resetting frame counter to 0
'Film is ruined'

I hope this interesting to someone.

Daniele
-- 
https://mail.python.org/mailman/listinfo/python-list


How to implement logging for an imported module?

2021-03-07 Thread Robert Latest via Python-list
Hello,

I'm trying to add logging to a module that gets imported by another module. But
I only get it to work right if the imported module knows the name of the
importing module. The example given in the "Logging Cookbook" also rely on this
fact.

https://docs.python.org/3/howto/logging-cookbook.html#logging-cookbook

I couldn't find any information on how to implement logging in a library that
doesn't know the name of the application that uses it. How is that done?

Here's some example code consisting of the main module foo.py and imported
modules bar.py and baz.py


### foo.py
import logging

import bar, baz

formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')

ch = logging.StreamHandler()
ch.setFormatter(formatter)

logger = logging.getLogger('foo')
logger.addHandler(ch)
logger.setLevel(logging.DEBUG)

logger.debug('debug from <%s>', __name__)
logger.info('info from <%s>', __name__)
logger.warning('warning from <%s>', __name__)
logger.error('error from <%s>', __name__)

bar.func()
baz.func()

### bar.py
'''This "generic" approach doesn't honor loglevel or formats
when imported by another module'''
import logging

l = logging.getLogger(__name__)
def func():
l.debug('debug from <%s>', __name__)
l.info('info from <%s>', __name__)
l.warning('warning from <%s>', __name__)
l.error('error from <%s>', __name__)

### baz.py
'''This only works if the importing module is named 'foo', which
precludes its use as a library module'''
import logging

l = logging.getLogger('foo.baz')
def func():
l.debug('debug from <%s>', __name__)
l.info('info from <%s>', __name__)
l.warning('warning from <%s>', __name__)
l.error('error from <%s>', __name__)

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


python curses constant names for mouse wheel movements?

2021-03-07 Thread pjfarley3
I have a python curses project trying to detect mouse wheel movements, and I
understand that mouse wheel events by convention are reported as BUTTON4 and
BUTTON5 events.

I am running on a Win10 system with python 3.8.7 and windows-curses 2.2.0,
which I am given to understand uses the gohlke PDCurses wheels for the
underlying curses implementation.

I can display the values of all of the BUTTON1 to BUTTON4 event constants
but python 3.8.7 barfs if I try to use any BUTTON5 event names.  It also
does not recognize the BUTTONn_RESERVED_EVENT names for buttons 1-4.

print(   "B1={:08x},{:08x},{:08x},{:08x},{:08x}\n".format(
curses.BUTTON1_RELEASED, curses.BUTTON1_PRESSED,
curses.BUTTON1_CLICKED, 
curses.BUTTON1_DOUBLE_CLICKED,
curses.BUTTON1_TRIPLE_CLICKED) + \
"B2={:08x},{:08x},{:08x},{:08x},{:08x}\n".format(
curses.BUTTON2_RELEASED, curses.BUTTON2_PRESSED,
curses.BUTTON2_CLICKED, 
curses.BUTTON2_DOUBLE_CLICKED,
curses.BUTTON2_TRIPLE_CLICKED) + \
"B3={:08x},{:08x},{:08x},{:08x},{:08x}\n".format(
curses.BUTTON3_RELEASED, curses.BUTTON3_PRESSED,
curses.BUTTON3_CLICKED, 
curses.BUTTON3_DOUBLE_CLICKED,
curses.BUTTON3_TRIPLE_CLICKED) + \
"B4={:08x},{:08x},{:08x},{:08x},{:08x}\n".format(
curses.BUTTON4_RELEASED, curses.BUTTON4_PRESSED,
curses.BUTTON4_CLICKED, 
curses.BUTTON4_DOUBLE_CLICKED,
curses.BUTTON4_TRIPLE_CLICKED) + \
"S/C/A={:08x},{:08x},{:08x}".format(
curses.BUTTON_SHIFT, curses.BUTTON_CTRL,
curses.BUTTON_ALT))

yields this output:

B1=0001,0002,0004,0008,0010
B2=0020,0040,0080,0100,0200
B3=0400,0800,1000,2000,4000
B4=8000,0001,0002,0004,0008
S/C/A=0400,0800,1000

Any attempt to use a BUTTON5 constant name or BUTTONn_RESERVED_EVENT
constant name fails:

Python 3.8.7 (tags/v3.8.7:6503f05, Dec 21 2020, 17:59:51) [MSC v.1928 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
>>> print("B5={:08x}".format(curses.BUTTON5_RELEASED))
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: module 'curses' has no attribute 'BUTTON5_RELEASED'
>>> print("B5={:08x}".format(curses.BUTTON1_RESERVED_EVENT))
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: module 'curses' has no attribute 'BUTTON1_RESERVED_EVENT'

When I actually capture mouse wheel events, the wheel-up event is reported
as 0x0001 or BUTTON4_PRESSED, but the wheel-down event is reported as 0x
0020, which has no constant name associated with it for which I can find
any documentation.

This is a logging trace if curses.get_wch() and curses.getkey() results and
the curses.getmouse() results when KEY_MOUSE is returned.  I have manually
annotated the getmouse display lines indicating what mouse action I actually
performed.

DEBUG:root:wch='539' = 0x021b at (0,0)
DEBUG:root:3ch='KEY_MOUSE at (0,0)'
DEBUG:root:3ch KEY_MOUSE detected at (0,0)
DEBUG:root:Mouse data id=0, x=60, y=31, z=0, bs=0004
Button 1 click
DEBUG:root:wch='539' = 0x021b at (0,0)
DEBUG:root:3ch='KEY_MOUSE at (0,0)'
DEBUG:root:3ch KEY_MOUSE detected at (0,0)
DEBUG:root:Mouse data id=0, x=-1, y=-1, z=0, bs=0001
wheel up once
DEBUG:root:wch='539' = 0x021b at (0,0)
DEBUG:root:3ch='KEY_MOUSE at (0,0)'
DEBUG:root:3ch KEY_MOUSE detected at (0,0)
DEBUG:root:Mouse data id=0, x=-1, y=-1, z=0, bs=0020
wheel down once
DEBUG:root:wch='539' = 0x021b at (0,0)
DEBUG:root:3ch='KEY_MOUSE at (0,0)'
DEBUG:root:3ch KEY_MOUSE detected at (0,0)
DEBUG:root:Mouse data id=0, x=-1, y=-1, z=0, bs=0001
wheel up once
DEBUG:root:wch='539' = 0x021b at (0,0)
DEBUG:root:3ch='KEY_MOUSE at (0,0)'
DEBUG:root:3ch KEY_MOUSE detected at (0,0)
DEBUG:root:Mouse data id=0, x=-1, y=-1, z=0, bs=0020
wheel down once

Where can I find any documentation of the correct curses constant name(s) to
use for detecting a "wheel down" action?  Or do I just have to manually
define my own BUTTON5 constant name for the wheel-down event?

TIA for any help or RTFM you can provide.

Peter


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


google text-to-speech python

2021-03-07 Thread tommy yama
Hi,

Anyone familiar with how to change speech pace with python script?

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Apriori Algorithm

2021-03-07 Thread Avi Gross via Python-list
I apologize for my earlier snide remark as I was not then aware there was an
algorithm called apriori based on the Latin term and wondered if someone was
pulling someone's leg, in advance.

Someone has posted a pointer to Python code that is supposed to do that. If
that is suitable, then the serious task is to read what they say and use it.
I note the data you show below is ambiguous and not in the format that code
asks for.

Are you saying each line I see of what looks like integers is a grouping you
want to contrast to other such lines in the algorithm? I doubt it can be
used as is but needs to become some kind of data structure such as a list of
tuples or whatever the algorithm wants.

-Original Message-
From: Python-list  On
Behalf Of dn via Python-list
Sent: Sunday, March 7, 2021 3:09 AM
To: python-list@python.org
Subject: Re: Apriori Algorithm

On 07/03/2021 20.56, sarang shah wrote:
> I have this dataset in a text file I need to make an apriori algorithm
based on it. Please help.
> 
> 25 52 164 240 274 328 368 448 538 561 630 687 730 775 825 834 
> 39 120 124 205 401 581 704 814 825 834 
> 35 249 674 712 733 759 854 950 
> 39 422 449 704 825 857 895 937 954 964 
> 15 229 262 283 294 352 381 708 738 766 853 883 966 978 
> 26 104 143 320 569 620 798 
> 7 185 214 350 529 658 682 782 809 849 883 947 970 979 
> 227 390 
> 71 192 208 272 279 280 300 333 496 529 530 597 618 674 675 720 855 914 932

> 183 193 217 256 276 277 374 474 483 496 512 529 626 653 706 878 939 
> 161 175 177 424 490 571 597 623 766 795 853 910 960 
> 125 130 327 698 699 839 
> 392 461 569 801 862 
> 27 78 104 177 733 775 781 845 900 921 938 
> 101 147 229 350 411 461 572 579 657 675 778 803 842 903 
> 71 208 217 266 279 290 458 478 523 614 766 853 888 944 969 
> 43 70 176 204 227 334 369 480 513 703 708 835 874 895 
> 25 52 278 730 
> 151 432 504 830 890 


Great!
For what purpose - is this a 'homework assignment'?
What code do you have so far?

-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list

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


Re: How to implement logging for an imported module?

2021-03-07 Thread Dieter Maurer
Robert Latest wrote at 2021-3-7 10:21 GMT:
>I'm trying to add logging to a module that gets imported by another module. But
>I only get it to work right if the imported module knows the name of the
>importing module. The example given in the "Logging Cookbook" also rely on this
>fact.

I have used so called "monkey patching" to achieve something like this
(in fact "function call tracing").
"monkey patching" means code modification at runtime.

Suppose your application implements a logging decorator `log`.
Then on import, you can replace methods (easiest) or functions
with decorated variants either directly in the imported module/class
or for use by the importer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Choosable dependency

2021-03-07 Thread Grant Edwards
On 2021-03-06, Manfred Lotz  wrote:
> Let us say I have a package which reads a TOML file. 
>
> I want to give the user of my package the choice to decide if he wants
> to use the toml, tomlkit or rtoml package. 

Why would the user choose one over the other?  Does the user get
different functions/features depending on which one they choose?

If you're just using a common subset to provide a fixed set of
features regardless, then just use whatever is installed.

--
Grant


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


Please don't feed the trolls

2021-03-07 Thread Terry Reedy
Trolling, among other things, is fishing with a moving line, especially 
with a revolving lure, as from a moving boat.  A troll, among other 
things, is that method or the lure used.


On the internet, 'troll' is used metaphorically.  A troll is a flashy 
post designed to catch peoples emotions and hook them into responding. 
Trolling is posting such posts.  People do this either out of compulsion 
or for entertainment.


Quite separately, a troll in Scandinavian folklore is an unpleasant 
mythical creature living in a cave, or perhaps under or around a bridge. 
Bridge trolls are reputed to disrupt communication by travel.


Fishermen would not call a person trolling for fish a troll.  It would 
be an insult.  On the internet, we do call people trolling trolls, again 
methphorically, because they disrupt communication.


The proper response to trolls is to not feed them by responding as they 
wish.  When people respond, they continue trolling, and a moderator has 
to ban them.


People reading python-list posts on google groups or comp.lang.python 
should not help them evade their bans by quoting them.


On 3/6/2021 2:11 PM, Bonita Montero, responding to a banned troll for at 
least a third time:



Someone who says that he is capable of writing a compiler that
translates every language has megalomania. No one can do this.


We certainly need not believe so until it is done.

But we do not know whether X is an actual megalomaniac acting like a 
troll or an actual troll acting like a megalomaniac.  The same can apply 
to any other character type that can lead to trolling or be assumed as a 
pose by a troll.


In Spanish, bonito/a means a pretty male/female.  By coincidence, it is 
also a tuna-like fish caught by trolling.  (Decades ago, my father 
caught one on a boat one a Mexican river/lagoon.)  Please unhook 
yourself and swim away.



--
Terry Jan Reedy

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


Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-07 Thread Peter J. Holzer
On 2021-03-06 23:41:10 +0100, Mirko via Python-list wrote:
> I even wonder why they have tried. Writing a universal
> compiler/interpreter sounds logically impossible to me, Here's a
> simple Python expression:
> 
> >>> 3+3*5
> 18
> 
> And here's the same expression in (GNU) Smalltalk:
> 
> st> 3+3*5
> 30
> 
> 
> How would such a universal compiler know which evaluation strategy
> to follow, if not by writing a parser end evaluator for every
> supported language?

That depends on what you mean by "writing". If we stick to your example,
you would need to specify in some way that in Python * has higher
precedence than +, while in Smalltalk it doesn't. You could write some
code in Python or Smalltalk or C or Assembler or even for a Turing
machine to do that. Or you can write the grammar in some formal language
(e.g. BNF) and let the compiler interpret that (or generate native code
from it and run that). The latter is what a "universal compiler" would
do and parser generators have been around for a long time (they were
nothing new when I studied CS in the 1980's). While there is still
progress here (I've come across a few interesting papers over the last
year or so), I'd say that part of the problem is solved.

The second part is converting a parse tree into code. I am quite sure
that it is possible to devise a formal language to specify the semantics
of any programming language and then to use this to generate the code.
However, I strongly suspect that such a language would be comparable in
expressiveness and ease of use to other programming languages - or in
other worlds it would be just another programming language. Certainly
better suited to compiler construction (otherwise why would you use
it?), but probably not massively so (unlike writing a Yacc grammar is a
lot easier/quicker than writing a top-down parser), So there wouldn't be
a huge incentive to use it unless you plan to write compilers for lots
of languages. On the other hand there are downsides: Such a generic
system might be slow and/or memory-hungry, it might not run on every
platform, it might have a steep learning curve, and it's probably not so
well-suited for non-compiler programs.

> And if it's hard for this simple problem, how about more complex
> cases.

For this simple problem it's easy :-)

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: How to implement logging for an imported module?

2021-03-07 Thread Joseph L. Casale
> I couldn't find any information on how to implement logging in a library that
> doesn't know the name of the application that uses it. How is that done?

Hello,
That's not how it works, it is the opposite. You need to know the name of its 
logger,
and since you imported it, you do.

Logging is hierarchical, organized by dot separated names. However, all loggers
share the same root (top level) logger (a logger without any name, or in other 
words,
no hierarchical specificity). Loggers are singletons, all loggers share the 
same root
and each time you get a logger, if any code has previously asked for that 
logger by
name and therefore created it, you'll get that instance.

When you create a logger, it starts at level WARNING, which means only warnings
or higher are considered.

When you create a handler, it starts at level NOTSET, which means only level 0
and above are considered. Since NOTSET is 0, everything is considered by 
default.

Loggers pass messages that they are considering to all their handlers, which 
then
each filter again by the handlers own distinct level.

Don't add handlers in library code (except a null handler).

Do set a level on your library logger that you deem appropriate (INFO is likely
not appropriate).

Then, in your consuming code, if you instantiate a named logger, you won't see
messages that fall below the threshold of the library, and root defaults.

Create (get) a root logger (you don't have to use it) and set the level, and 
attach a
handler to it. Then get the logger your library uses and set the level to what 
you want.

Proceed with creating your own named logger and using that in your code, however
when the library emits a log message, it will traverse up, unfiltered and be 
passed to
a handler.

Think of the process like a tree data structure,  with the single root at the 
top, and
each immediate child being a named logger without additional specificity (no 
dot),
and each child of those taking the named plus one dot, followed by another name.

That helps when understanding the design behavior of propagation, and rather 
than
restate what is already well done, see 
https://docs.python.org/3/library/logging.html#logging.Logger.propagate. 

It does make a lot of sense, and it facilitates a concise and powerful ability 
to configure
an application where some messages can be ignored, written to different files, 
combined
into one, or some even emailed.

Last word of advice, don't fight it by hacking up or patching (somehow?), it 
will
simply not work right for any other case even slightly different than the one 
you
somehow beat into submission.

I hope that helps,
Joseph Casale

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


RE: neonumeric - C++ arbitrary precision arithmetic library

2021-03-07 Thread Avi Gross via Python-list
The precedence example used below made a strange assumption that the
imaginary program would not be told up-front what computer language it was
being asked to convert from. That is not the scenario being discussed as we
have described. In any particular language, there usually is a well-known
precedence order such as "*" coming before "+" unless you use something like
parentheses to make your intent clear and over-ride it.

But it makes me think of a related question. Assume you are writing code in
a language like Python and the language has been analyzed and all kinds of
info stored that describes it and that includes things like precedence rules
for operators. Suppose it works fine and YOU want to break it. Could you?

If your language supports constructs like creating what looks like new infix
operators as an example, or overloading existing ones, could you write
expressions this mystical product would interpret differently than the
original compiler or interpreter?

As an example, what does this simple statement mean:

A + B

I mean A can be an integer or floating point number or character string but
can also be a complex number or a data.frame  or just about any arbitrary
object. So can B. And in many cases, the operation is not at all Abelian and
B+A is something else. In many cases, the logic is to look at the right-hand
or left-hand variable and see if it has a method defined to be called such
as __ADD__ or __RADD__  or maybe  inherited such a method from another class
perhaps using some specific method with complicated multiple inheritance
scenarios. Or the language may choose to convert either A or B or both to
some other format and perform some kind of addition and maybe convert the
result to something. Lots of work is in the Python interpreter to deal with
this and some of it has to be flexible enough to deal with times when a
class or object is changed as the program runs. Might it be possible to
create edge cases that break a static set of description files? If not, how
much more complex must the imaginary program get to handle these challenges
and what might that do to the purported gains in efficiency claimed?

I am currently studying a language called Kotlin. They, like some other
languages, allow the creation of new infix operators and once I have defined
"myplus" I can write code like:

A myplus B

What if it would also allow me to specify dynamically what the priority of
"myplus" is? Clearly it cannot be a reserved keyword in some table loaded in
the language in advance. R lets me do something similar like create
"%myplus%" as an operator and even weirder things like rebinding "+" to mean
something else that no longer has a particular priority that was
pre-ordained.

So if we had a contest on finding ways to break a sort of general purpose
customizable any-language mangler, I wonder if it might be easy to mangle it
at first. To get around that, you might have to not handle languages you
declare as misbehaving, or make a more complex system that handles all known
cases. But even then, can we design a new language for the express purpose
of exposing some hidden flaw and make them deal with that?

New languages keep popping up, some with no prior intent on breaking
anything, but I think a universal translator may not be imminent.

-Original Message-
From: Python-list  On
Behalf Of Peter J. Holzer
Sent: Sunday, March 7, 2021 2:43 PM
To: python-list@python.org
Subject: Re: neonumeric - C++ arbitrary precision arithmetic library

On 2021-03-06 23:41:10 +0100, Mirko via Python-list wrote:
> I even wonder why they have tried. Writing a universal 
> compiler/interpreter sounds logically impossible to me, Here's a 
> simple Python expression:
> 
> >>> 3+3*5
> 18
> 
> And here's the same expression in (GNU) Smalltalk:
> 
> st> 3+3*5
> 30
> 
> 
> How would such a universal compiler know which evaluation strategy to 
> follow, if not by writing a parser end evaluator for every supported 
> language?

That depends on what you mean by "writing". If we stick to your example, you
would need to specify in some way that in Python * has higher precedence
than +, while in Smalltalk it doesn't. You could write some code in Python
or Smalltalk or C or Assembler or even for a Turing machine to do that. Or
you can write the grammar in some formal language (e.g. BNF) and let the
compiler interpret that (or generate native code from it and run that). The
latter is what a "universal compiler" would do and parser generators have
been around for a long time (they were nothing new when I studied CS in the
1980's). While there is still progress here (I've come across a few
interesting papers over the last year or so), I'd say that part of the
problem is solved.

The second part is converting a parse tree into code. I am quite sure that
it is possible to devise a formal language to specify the semantics of any
programming language and then to use this to generate the code.
However, I strongly suspect that such 

Re: Apriori Algorithm

2021-03-07 Thread sarang shah
On Sunday, March 7, 2021 at 11:55:21 AM UTC-6, Avi Gross wrote:
> I apologize for my earlier snide remark as I was not then aware there was an 
> algorithm called apriori based on the Latin term and wondered if someone was 
> pulling someone's leg, in advance. 
> 
> Someone has posted a pointer to Python code that is supposed to do that. If 
> that is suitable, then the serious task is to read what they say and use it. 
> I note the data you show below is ambiguous and not in the format that code 
> asks for. 
> 
> Are you saying each line I see of what looks like integers is a grouping you 
> want to contrast to other such lines in the algorithm? I doubt it can be 
> used as is but needs to become some kind of data structure such as a list of 
> tuples or whatever the algorithm wants.
> -Original Message- 
> From: Python-list  On
> Behalf Of dn via Python-list 
> Sent: Sunday, March 7, 2021 3:09 AM 
> To: pytho...@python.org 
> Subject: Re: Apriori Algorithm 
> 
> On 07/03/2021 20.56, sarang shah wrote:
> > I have this dataset in a text file I need to make an apriori algorithm 
> based on it. Please help. 
> > 
> > 25 52 164 240 274 328 368 448 538 561 630 687 730 775 825 834 
> > 39 120 124 205 401 581 704 814 825 834 
> > 35 249 674 712 733 759 854 950 
> > 39 422 449 704 825 857 895 937 954 964 
> > 15 229 262 283 294 352 381 708 738 766 853 883 966 978 
> > 26 104 143 320 569 620 798 
> > 7 185 214 350 529 658 682 782 809 849 883 947 970 979 
> > 227 390 
> > 71 192 208 272 279 280 300 333 496 529 530 597 618 674 675 720 855 914 932 
> 
> > 183 193 217 256 276 277 374 474 483 496 512 529 626 653 706 878 939 
> > 161 175 177 424 490 571 597 623 766 795 853 910 960 
> > 125 130 327 698 699 839 
> > 392 461 569 801 862 
> > 27 78 104 177 733 775 781 845 900 921 938 
> > 101 147 229 350 411 461 572 579 657 675 778 803 842 903 
> > 71 208 217 266 279 290 458 478 523 614 766 853 888 944 969 
> > 43 70 176 204 227 334 369 480 513 703 708 835 874 895 
> > 25 52 278 730 
> > 151 432 504 830 890
> Great! 
> For what purpose - is this a 'homework assignment'? 
> What code do you have so far? 
> 
> -- 
> Regards, 
> =dn
> -- 
> https://mail.python.org/mailman/listinfo/python-list




Yes. Each line is a group set. 

a.Pleaseimplement analgorithm of your choice (Apriori, or FP-Tree) tofind 
frequent itemsets. You can importstandardlibraries/modules, but thealgorithm 
should be written by yourself. Min-support should be a user input parameter. 
Two sample of transaction datasets, Dataset1and Dataset2, are providedto test 
if your program works correctly.You can usePython, Java or C++.

 b.  Extend your program to output all the maximal frequent itemsets and closed 
frequent itemsets. 
c.  Extend your program to output all the association rules. Min-Confidence 
should be a user input parameter. For all the association rules, output 
measures include support, confidence, lift, all-confidence and cosine.


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


Re: Choosable dependency

2021-03-07 Thread Manfred Lotz
On Sat, 6 Mar 2021 15:40:41 - (UTC)
Grant Edwards  wrote:

> On 2021-03-06, Manfred Lotz  wrote:
> > Let us say I have a package which reads a TOML file. 
> >
> > I want to give the user of my package the choice to decide if he
> > wants to use the toml, tomlkit or rtoml package.   
> 
> Why would the user choose one over the other?  Does the user get
> different functions/features depending on which one they choose?
> 

I am a user of my package and I like to use rtoml which however is not
available on another OS (due to Rust no being available there) where I
also want to use my package. Here I can use toml which is always
possible to install. Therefore, toml is the default so that the ordinary
user doesn't need to care.


-- 
Manfred

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


RE: Apriori Algorithm

2021-03-07 Thread Avi Gross via Python-list
Speaking for myself, that is a very significant piece of homework to do and
unless you do quite a bit and get stuck and ask for help in some aspect,
this is not the place to ask if anyone wishes to do all the work.

The assignment seems to want you to write your own code to implement the
algorithm. So unless the outlines of the algorithm were taught in class or a
textbook, you need to find the algorithm by searching the internet and you
may find places with more or less of a good description:

https://en.wikipedia.org/wiki/Apriori_algorithm

Once you find one you need to choose a language you are able to program in
from the list of choices and see what libraries of allowed components are
likely to be helpful so you do not have to start from nothing but the
basics. If you decide on JAVA or C++, this is not the forum to ask.

As I noted earlier, your data will need to be read in by any program and
made into whatever format your algorithm uses. What this is will be up to
you but note you have a collection of collections where you are told of two
very specific datasets that must be handled by the algorithm. So your
algorithm might be asked to just handle interest, or perhaps also character
strings and arbitrary items. You need to know what is expected so you design
your code to handle it. Given the nature of the data you show, it should not
use anything that holds a fixed number of items as the number of items per
line varies and presumably it should handle any number of such lines.

It looks like for a basic version they suggest a particular parameter be
included and they want an extended version that does more and another that
does even more.

Looks like a serious amount of work and way too detailed to expect anything
but this kind of answer. Many people get paid hundreds of dollars per hour
to do things like this and if you learn how, you could be one.

Presumably your class has taught you most of what is needed to understand
the assignment and how to find out more. I, like most others here, have not
been in the class or had any reason to think about this problem before. Any
voluntary role here is generally to help with questions about fairly
specific python code as compared to big projects.

Good luck!

-Original Message-
From: Python-list  On
Behalf Of sarang shah
Sent: Sunday, March 7, 2021 5:23 PM
To: python-list@python.org
Subject: Re: Apriori Algorithm

On Sunday, March 7, 2021 at 11:55:21 AM UTC-6, Avi Gross wrote:
> I apologize for my earlier snide remark as I was not then aware there 
> was an algorithm called apriori based on the Latin term and wondered 
> if someone was pulling someone's leg, in advance.
> 
> Someone has posted a pointer to Python code that is supposed to do 
> that. If that is suitable, then the serious task is to read what they say
and use it.
> I note the data you show below is ambiguous and not in the format that 
> code asks for.
> 
> Are you saying each line I see of what looks like integers is a 
> grouping you want to contrast to other such lines in the algorithm? I 
> doubt it can be used as is but needs to become some kind of data 
> structure such as a list of tuples or whatever the algorithm wants.
> -Original Message-
> From: Python-list  
> On Behalf Of dn via Python-list
> Sent: Sunday, March 7, 2021 3:09 AM
> To: pytho...@python.org
> Subject: Re: Apriori Algorithm
> 
> On 07/03/2021 20.56, sarang shah wrote:
> > I have this dataset in a text file I need to make an apriori 
> > algorithm
> based on it. Please help. 
> > 
> > 25 52 164 240 274 328 368 448 538 561 630 687 730 775 825 834
> > 39 120 124 205 401 581 704 814 825 834
> > 35 249 674 712 733 759 854 950
> > 39 422 449 704 825 857 895 937 954 964
> > 15 229 262 283 294 352 381 708 738 766 853 883 966 978
> > 26 104 143 320 569 620 798
> > 7 185 214 350 529 658 682 782 809 849 883 947 970 979
> > 227 390
> > 71 192 208 272 279 280 300 333 496 529 530 597 618 674 675 720 855 
> > 914 932
> 
> > 183 193 217 256 276 277 374 474 483 496 512 529 626 653 706 878 939
> > 161 175 177 424 490 571 597 623 766 795 853 910 960
> > 125 130 327 698 699 839
> > 392 461 569 801 862
> > 27 78 104 177 733 775 781 845 900 921 938
> > 101 147 229 350 411 461 572 579 657 675 778 803 842 903
> > 71 208 217 266 279 290 458 478 523 614 766 853 888 944 969
> > 43 70 176 204 227 334 369 480 513 703 708 835 874 895
> > 25 52 278 730
> > 151 432 504 830 890
> Great! 
> For what purpose - is this a 'homework assignment'? 
> What code do you have so far? 
> 
> --
> Regards,
> =dn
> --
> https://mail.python.org/mailman/listinfo/python-list




Yes. Each line is a group set. 

a.Pleaseimplement analgorithm of your choice (Apriori, or FP-Tree) tofind
frequent itemsets. You can importstandardlibraries/modules, but thealgorithm
should be written by yourself. Min-support should be a user input parameter.
Two sample of transaction datasets, Dataset1and Dataset2, are providedto
test if your program works correctly.You can usePyt

Re: editor recommendations?

2021-03-07 Thread Russell
Dan Stromberg  wrote:
> On Tue, Mar 2, 2021 at 8:11 PM Dan Stromberg  wrote:
> 
>>
>> On Tue, Mar 2, 2021 at 8:00 PM Russell  wrote:
>>
>>> Ethan Furman  wrote:
>>> > I'm currently using vim, and the primary reason I've stuck with it for
>>> so long is because I can get truly black screens with it.  By which I mean
>>> that I have a colorful window title bar, a light-grey menu bar, and then a
>>> light-grey frame around the text-editing window (aka the only window), and
>>> a nice, black-background editing area.
>>>
>>> I use vim. It's actually extremely powerful, especially for text/code
>>> editing. I'd recommend reading one of the many books on using vim
>>> effectively. Also, plugins can really add a lot...
>>>
>>
>> On the subject of learning vim: There's an excellent vi cheat sheet
>> available on the internet.  I've put a copy of it at
>> https://stromberg.dnsalias.org/~strombrg/vi.ref.6
>>
>> vi is of course the predecessor of vim. But that cheat sheet is still
>> great for learning much of vim.
>>
> 
> I just ran across:  http://lib.ru/MAN/viref.txt
> ...which is pretty much the same thing, but converted to nice HTML.

To that end, vim also has extensive documentation built in. Just type
:help to get started. There's a pretty good tutorial accessible from the
main help screen. 

And I'll stop talking about vim in the Python group now, I promise. :)

-- 
rust
0x68caecc97f6a90122e51c0692c88d9cb6b58a3dc
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python curses constant names for mouse wheel movements?

2021-03-07 Thread Alan Gauld via Python-list
On 07/03/2021 07:16, pjfarl...@earthlink.net wrote:

> Where can I find any documentation of the correct curses constant name(s) to
> use for detecting a "wheel down" action?  Or do I just have to manually
> define my own BUTTON5 constant name for the wheel-down event?

I suspect you need to look in the ncurses documentation or
even the C code. And that is no guarantee that the Python
curses module will expose any values you do find other
than as numeric codes.

I would have expected the mouse wheel down/click to appear as
a BUTTON2 event to be honest. I didn't even realize there was
a BUTTON4 event defined let alone BUTTON5.

Incidentally, when you talk about wheel up/down are you
talking about wheel rotation events rather than actual
button down/up events? In that case 4 and 5 might make sense.

If you find the answer please post back, I'm very interested
since I'm in the middle of writing a book on the Python curses
module and was unaware of this behaviour. A whole new area
to explore I'm also interested in any documentation you
have already found on it - where did you get this understanding?

-- 
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


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


Re: Choosable dependency

2021-03-07 Thread Dan Stromberg
I sometimes do things like:

try:
import rtoml as toml
except ImportError:
import toml

...but I don't like it very much, because it tends to confuse static
analyzers like pyflakes and pylint.  Maybe mypy will deal with it better?
Not sure yet.

On Sat, Mar 6, 2021 at 3:05 AM Manfred Lotz  wrote:

> Let us say I have a package which reads a TOML file.
>
> I want to give the user of my package the choice to decide if he wants
> to use the toml, tomlkit or rtoml package.
>
> So, in case the user chose to use rtoml then there should be an import
> only for rtoml, aso.
>
> How could I achieve this?
>
> --
> Thanks,
> Manfred
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Choosable dependency

2021-03-07 Thread Grant Edwards
On 2021-03-07, Manfred Lotz  wrote:
> On Sat, 6 Mar 2021 15:40:41 - (UTC)
> Grant Edwards  wrote:
>
>> On 2021-03-06, Manfred Lotz  wrote:
>> > Let us say I have a package which reads a TOML file. 
>> >
>> > I want to give the user of my package the choice to decide if he
>> > wants to use the toml, tomlkit or rtoml package.   
>> 
>> Why would the user choose one over the other?  Does the user get
>> different functions/features depending on which one they choose?
>
> I am a user of my package and I like to use rtoml which however is not
> available on another OS (due to Rust no being available there) where I
> also want to use my package. Here I can use toml which is always
> possible to install. Therefore, toml is the default so that the ordinary
> user doesn't need to care.

I still don't understand why the user needs to choose. Why not just use 
whichever one is installed?

Import whichever one you prefer, and if that fails, import one of the
others, if that fails, import the third one.

--
Grant



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


Re: How to implement logging for an imported module?

2021-03-07 Thread Pankaj Jangid
"Joseph L. Casale"  writes:

>> I couldn't find any information on how to implement logging in a
>> library that doesn't know the name of the application that uses
>> it. How is that done?

> Create (get) a root logger (you don't have to use it) and set the
> level, and attach a handler to it. Then get the logger your library
> uses and set the level to what you want.

So does that mean if we change the following code to get a logger
without any name then it will work? Without any further change.

>> logger = logging.getLogger('foo')
>> logger.addHandler(ch)
>> logger.setLevel(logging.DEBUG)

-- 
Regards,
Pankaj Jangid


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


Re: editor recommendations?

2021-03-07 Thread Cameron Simpson
On 03Mar2021 10:00, Lele Gaifax  wrote:
>Cameron Simpson  writes:
>> My fingers know vim. Some others' fingers know emacs.
>
>Emacs has also an Evil[1] mode, that mimics some vi/vim features.

Whenever I've tries emulate-vi modes they tend to lack some coner case 
known to my fingers.

[... Doom Emacs recommendation - I have no opinion ...]

>-- Emacs outshines all other editing software in approximately the same
>way that the noonday sun does the stars. It is not just bigger and
>brighter; it simply makes everything else vanish.  — Neal Stephenson

A novice of the temple once approached the Chief Priest with a question.

  "Master, does Emacs have the Buddha nature?" the novice asked.

  The Chief Priest had been in the temple for many years and could be relied
  upon to know these things.  He thought for several minutes before replying.

  "I don't see why not.  It's got bloody well everything else."

  With that, the Chief Priest went to lunch.  The novice suddenly achieved
enlightenment, several years later.

Commentary:

His Master is kind,
Answering his FAQ quickly,
With thought and sarcasm.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-07 Thread Christian Gollwitzer

Am 07.03.21 um 20:42 schrieb Peter J. Holzer:

The second part is converting a parse tree into code. I am quite sure
that it is possible to devise a formal language to specify the semantics
of any programming language and then to use this to generate the code.
However, I strongly suspect that such a language would be comparable in
expressiveness and ease of use to other programming languages - or in
other worlds it would be just another programming language. 


As far as I understand the idea, Leigh (aka Mr Flibble) thinks that he 
can create a "library" of code translators that translate the individual 
pieces of the parse tree into some intermediate code, and by specifying 
these codelets within the grammar the semantics of a language can be 
fully described.


My argument against this whole thing is that the library would be 
enormous. He seems to think that big chunks can be reused for different 
languages, but I don't believe this. A simple example:


int a = -3
unsigned int b = 5;

in C: a < b is false. This is insane but follows from the type casting 
rules in C.


in Python or any other language with sane integers, -3 < 5 will always 
be true. For large enough values you must convert them to big integers. 
CPython simply uses big integers for everything, but that obviously 
slows down the whole thing. If you want to compile that to fast machine 
code, you need to do the computation in fixed integers and check for 
overflow *after every single step*.


And there are myriads of differences. Introducing JavaScript again will 
bring myriads of differences and so on. The closest thing to such a 
project I can think of is LLVM. It still requires you to write the 
actual code generator, but features many intrinsics and libriaries that 
could be reused and therefore it is easy to add a new language. The 
approximate value of LLVM is estimated here:


  https://chriscummins.cc/2019/llvm-cost/

It's over 5000 man years of work. There is no way a single developer, 
regardless how brilliant he may be, can recreate this in his lifetime. 
Maybe focussed to a single language or two, but not "universal" in any 
sense.



Christian
--
https://mail.python.org/mailman/listinfo/python-list