Re: Program to find Primes of the form prime(n+2) * prime(n+1) - prime(n) +- 1.

2018-10-04 Thread Alister via Python-list
On Wed, 03 Oct 2018 09:43:07 -0700, Musatov wrote:

> On Wednesday, October 3, 2018 at 11:12:43 AM UTC-5, Michael Torrie
> wrote:
>> On 10/03/2018 09:26 AM, Musatov wrote:
>> > I don't even know where to begin! (I'm reading the Dummies book)
>> 
>> If you have no experience in computer programming, it's going to be a
>> steep learning curve.
>> 
>> But your first step is to learn Python and how to write programs in it.
>> That book and others will help with that.  You'll have to write lots of
>> simple programs unrelated to primes along the way that help you
>> understand programming concepts.
>> 
>> If you already have experience in other languages, the task will be
>> easier.
>> 
>> Computer programming is quite natural to some (small children seem to
>> get it much easier than us adults), but I've seen others struggle to
>> grasp the abstract concepts for years.
>> 
>> Once you've grasped basic Python programming, you can return top the
>> original problem at hand.  Start by identifying the process or
>> algorithm that would find these primes. In other words, how would you
>> do it on pen and paper?  Computer programs are not magic.  They are
>> only expressions of human thinking. Often some very smart
>> mathematicians have come up with powerful algorithms (a step-by-step
>> process) to do these things,
>> and your job as a programmer is to turn this mathematical process into
>> a computer program using things like loops and Boolean logic. How would
>> you find these primes using your pen, paper, and calculator?
> 
> Literally, how I found them was taking a list of primes and checking if
> the calculations with the lesser primes resulted in numbers also further
> along on the list.
> 
> Another way I guess would be to do the calculations then check if the
> number is prime.

That is exactly how you do it with in a program.

create a loop & check to see if the target number can be divided by each 
possible divisor in turn
.
for large numbers this will take a large number of tests (hey that is why 
you have the computer do them, it is faster than you & does not get 
bored ;-) ) there are numerous tricks for speeding up this process once 
you have the basic working.

start by testing small numbers & then use your real data once you have 
something that works

as a starter a simple loop in python could be as follows

for x in xrange(10):
print x

once you have an outline of a program post it back here if things dont 
work as expected



-- 
A narcissist is someone better looking than you are.
-- Gore Vidal
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to find Primes of the form prime(n+2) * prime(n+1) - prime(n) +- 1.

2018-10-04 Thread Tony van der Hoff
On 04/10/18 09:31, Alister via Python-list wrote:
> On Wed, 03 Oct 2018 09:43:07 -0700, Musatov wrote:
> 
>> On Wednesday, October 3, 2018 at 11:12:43 AM UTC-5, Michael Torrie
>> wrote:
>>> On 10/03/2018 09:26 AM, Musatov wrote:
 I don't even know where to begin! (I'm reading the Dummies book)
>>>
>>> If you have no experience in computer programming, it's going to be a
>>> steep learning curve.
>>>
>>> But your first step is to learn Python and how to write programs in it.
>>> That book and others will help with that.  You'll have to write lots of
>>> simple programs unrelated to primes along the way that help you
>>> understand programming concepts.
>>>
>>> If you already have experience in other languages, the task will be
>>> easier.
>>>
>>> Computer programming is quite natural to some (small children seem to
>>> get it much easier than us adults), but I've seen others struggle to
>>> grasp the abstract concepts for years.
>>>
>>> Once you've grasped basic Python programming, you can return top the
>>> original problem at hand.  Start by identifying the process or
>>> algorithm that would find these primes. In other words, how would you
>>> do it on pen and paper?  Computer programs are not magic.  They are
>>> only expressions of human thinking. Often some very smart
>>> mathematicians have come up with powerful algorithms (a step-by-step
>>> process) to do these things,
>>> and your job as a programmer is to turn this mathematical process into
>>> a computer program using things like loops and Boolean logic. How would
>>> you find these primes using your pen, paper, and calculator?
>>
>> Literally, how I found them was taking a list of primes and checking if
>> the calculations with the lesser primes resulted in numbers also further
>> along on the list.
>>
>> Another way I guess would be to do the calculations then check if the
>> number is prime.
> 
> That is exactly how you do it with in a program.
> 
> create a loop & check to see if the target number can be divided by each 
> possible divisor in turn
> .
> for large numbers this will take a large number of tests (hey that is why 
> you have the computer do them, it is faster than you & does not get 
> bored ;-) ) there are numerous tricks for speeding up this process once 
> you have the basic working.
> 
> start by testing small numbers & then use your real data once you have 
> something that works
> 
> as a starter a simple loop in python could be as follows
> 
> for x in xrange(10):
>   print x
> 
> once you have an outline of a program post it back here if things dont 
> work as expected
> 

Two lines, two errors! To save the noob a lot of head-scratching, that
should be:
for x in range(10):

If you're running python 3, as you should do for any new project:
print( x )



-- 
Tony van der Hoff| mailto:t...@vanderhoff.org
Buckinghamshire, England |
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Program to find Primes of the form prime(n+2) * prime(n+1) - prime(n) +- 1.

2018-10-04 Thread Alister via Python-list
On Thu, 04 Oct 2018 09:44:01 +0100, Tony van der Hoff wrote:

> On 04/10/18 09:31, Alister via Python-list wrote:
>> On Wed, 03 Oct 2018 09:43:07 -0700, Musatov wrote:
>> 
>>> On Wednesday, October 3, 2018 at 11:12:43 AM UTC-5, Michael Torrie
>>> wrote:
 On 10/03/2018 09:26 AM, Musatov wrote:
> I don't even know where to begin! (I'm reading the Dummies book)

 If you have no experience in computer programming, it's going to be a
 steep learning curve.

 But your first step is to learn Python and how to write programs in
 it.
 That book and others will help with that.  You'll have to write lots
 of simple programs unrelated to primes along the way that help you
 understand programming concepts.

 If you already have experience in other languages, the task will be
 easier.

 Computer programming is quite natural to some (small children seem to
 get it much easier than us adults), but I've seen others struggle to
 grasp the abstract concepts for years.

 Once you've grasped basic Python programming, you can return top the
 original problem at hand.  Start by identifying the process or
 algorithm that would find these primes. In other words, how would you
 do it on pen and paper?  Computer programs are not magic.  They are
 only expressions of human thinking. Often some very smart
 mathematicians have come up with powerful algorithms (a step-by-step
 process) to do these things,
 and your job as a programmer is to turn this mathematical process
 into a computer program using things like loops and Boolean logic.
 How would you find these primes using your pen, paper, and
 calculator?
>>>
>>> Literally, how I found them was taking a list of primes and checking
>>> if the calculations with the lesser primes resulted in numbers also
>>> further along on the list.
>>>
>>> Another way I guess would be to do the calculations then check if the
>>> number is prime.
>> 
>> That is exactly how you do it with in a program.
>> 
>> create a loop & check to see if the target number can be divided by
>> each possible divisor in turn .
>> for large numbers this will take a large number of tests (hey that is
>> why you have the computer do them, it is faster than you & does not get
>> bored ;-) ) there are numerous tricks for speeding up this process once
>> you have the basic working.
>> 
>> start by testing small numbers & then use your real data once you have
>> something that works
>> 
>> as a starter a simple loop in python could be as follows
>> 
>> for x in xrange(10):
>>  print x
>> 
>> once you have an outline of a program post it back here if things dont
>> work as expected
>> 
>> 
> Two lines, two errors! To save the noob a lot of head-scratching, that
> should be:
> for x in range(10):
> 
> If you're running python 3, as you should do for any new project:
>   print( x )

perfectly legit python 2.7
I probably should have considered writing python 3 compatible code but 
range operates differently on the 2 versions & would be a poor choice for 
python 2 when numbers get larger

ass for the head scratching a noob (& anyone else for that mater) far 
more from correcting code than they do from simply copy & pasting working 
code.




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


Re: Program to find Primes of the form prime(n+2) * prime(n+1) - prime(n) +- 1.

2018-10-04 Thread Chris Angelico
On Fri, Oct 5, 2018 at 12:47 AM Alister via Python-list
 wrote:
>
> On Thu, 04 Oct 2018 09:44:01 +0100, Tony van der Hoff wrote:
>
> > On 04/10/18 09:31, Alister via Python-list wrote:
> >> On Wed, 03 Oct 2018 09:43:07 -0700, Musatov wrote:
> >>
> >>> On Wednesday, October 3, 2018 at 11:12:43 AM UTC-5, Michael Torrie
> >>> wrote:
>  On 10/03/2018 09:26 AM, Musatov wrote:
> > I don't even know where to begin! (I'm reading the Dummies book)
> 
>  If you have no experience in computer programming, it's going to be a
>  steep learning curve.
> 
>  But your first step is to learn Python and how to write programs in
>  it.
>  That book and others will help with that.  You'll have to write lots
>  of simple programs unrelated to primes along the way that help you
>  understand programming concepts.
> 
>  If you already have experience in other languages, the task will be
>  easier.
> 
>  Computer programming is quite natural to some (small children seem to
>  get it much easier than us adults), but I've seen others struggle to
>  grasp the abstract concepts for years.
> 
>  Once you've grasped basic Python programming, you can return top the
>  original problem at hand.  Start by identifying the process or
>  algorithm that would find these primes. In other words, how would you
>  do it on pen and paper?  Computer programs are not magic.  They are
>  only expressions of human thinking. Often some very smart
>  mathematicians have come up with powerful algorithms (a step-by-step
>  process) to do these things,
>  and your job as a programmer is to turn this mathematical process
>  into a computer program using things like loops and Boolean logic.
>  How would you find these primes using your pen, paper, and
>  calculator?
> >>>
> >>> Literally, how I found them was taking a list of primes and checking
> >>> if the calculations with the lesser primes resulted in numbers also
> >>> further along on the list.
> >>>
> >>> Another way I guess would be to do the calculations then check if the
> >>> number is prime.
> >>
> >> That is exactly how you do it with in a program.
> >>
> >> create a loop & check to see if the target number can be divided by
> >> each possible divisor in turn .
> >> for large numbers this will take a large number of tests (hey that is
> >> why you have the computer do them, it is faster than you & does not get
> >> bored ;-) ) there are numerous tricks for speeding up this process once
> >> you have the basic working.
> >>
> >> start by testing small numbers & then use your real data once you have
> >> something that works
> >>
> >> as a starter a simple loop in python could be as follows
> >>
> >> for x in xrange(10):
> >>  print x
> >>
> >> once you have an outline of a program post it back here if things dont
> >> work as expected
> >>
> >>
> > Two lines, two errors! To save the noob a lot of head-scratching, that
> > should be:
> > for x in range(10):
> >
> > If you're running python 3, as you should do for any new project:
> >   print( x )
>
> perfectly legit python 2.7
> I probably should have considered writing python 3 compatible code but
> range operates differently on the 2 versions & would be a poor choice for
> python 2 when numbers get larger

For a loop with a print in it, I'd definitely just use range(). It'll
work on all versions, and long before you run into problems with the
RAM usage on Py2, you've spammed your terminal so much that you're
waiting for it :)

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


Re: Help please installing Python on Windows 10

2018-10-04 Thread Sibylle Koczian

Am 03.10.2018 um 09:34 schrieb Timothy Cowell via Python-list:

Could I please ask for help installing Python on Windows 10 - I've tried twice 
(Version 3.7 for windows) selecting the install now option. After first attempt 
I uninstalled and tried again.

Each time it has put 4 items in the programs list from the windows start 
button, all under heading Python 3.7, but the first time they said 64 bit and 
the second time only 32 bit - I guess I must have clicked on different versions.

32 bit on a 64 bit PC and Windows version should work, 64 bit on 32 bit 
Windows probably not. So, if you kept your second attempt, that should 
be enough to start with.


Both times there was IDLE, Python 3.7, Manuals, and Module Docs. The last two 
of these worked when clicked on, but the first two just put up a small window 
of which first was white, and second was black, but I couldn't make them do 
anything.


IDLE and the Python shell both start with windows showing text like this:

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 
bit (AMD64)] on win32

Type "copyright", "credits" or "license()" for more information.
>>>

Did you get something like this? In that case nothing was wrong, Python 
just waited for your commands. The manual contains a tutorial which 
starts using the interactive interpreter - try it out. If you don't get 
the results the tutorial predicts, come back here or subscribe to the 
tutor list:

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

If your "small windows" don't contain such a header, that really would 
look wrong. In that case: are they completely empty? Or what else? If 
they contain any text at all, can you copy and paste it into your 
answer? Please don't try to send a screenshot, the list won't accept it.


HTH
Sibylle





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


Calling an instance method defined without any 'self' parameter

2018-10-04 Thread Ibrahim Dalal
class A:
def foo():
print 'Hello, world!'

a = A()print A.foo   # print a.foo   #
>print
type(A.foo) # 
a.foo()   # TypeError: foo() takes no arguments (1 given)
A.foo()   # TypeError: unbound method foo() must be called
with A instance as first argument (got nothing instead)


Clearly, foo is an instance method. I know one should use @staticmethod for
declaring a method static. The question here is, given the above code, is
there any way to call foo?

Python 2.7


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


problem

2018-10-04 Thread Rémy Dpx
Hello,
I’ve got a problem with my Python.
Indeed my Idle act like if my ctrl button were always pushed ( when i press Q, 
it selects everything ; when i press W, it goes back in the last form)
I tried to uninstall and download back and also to change the version, but my 
problem is still there.
I hope u will give me a solution.
Thanks.
Rémy


---
L'absence de virus dans ce courrier électronique a été vérifiée par le logiciel 
antivirus Avast.
https://www.avast.com/antivirus
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Calling an instance method defined without any 'self' parameter

2018-10-04 Thread Thomas Jollans
On 2018-10-04 10:25, Ibrahim Dalal wrote:
> class A:
> def foo():
> print 'Hello, world!'
> 
> a = A()print A.foo   # print a.foo   #
> >print
> type(A.foo) # 
> a.foo()   # TypeError: foo() takes no arguments (1 given)
> A.foo()   # TypeError: unbound method foo() must be called
> with A instance as first argument (got nothing instead)
> 
> 
> Clearly, foo is an instance method. I know one should use @staticmethod for
> declaring a method static. The question here is, given the above code, is
> there any way to call foo?

Yes: use Python 3!

Python 3.7.0 (default, Jun 28 2018, 13:15:42)
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> class A:
... def foo():
... print('yo!')
...
>>> A.foo

>>> A.foo()
yo!
>>>


> 
> Python 2.7
> 

There is a way in Python 2 as well, and I'm sure someone else will
demonstrate. I won't. It's easy enough to discover if you know that it
should exist. I'll just tell you that Python 3 is much nicer:

Python 3 is much nicer.

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


Re: Calling an instance method defined without any 'self' parameter

2018-10-04 Thread Terry Reedy

On 10/4/2018 4:25 AM, Ibrahim Dalal wrote:

class A:
 def foo():
 print 'Hello, world!'

a = A()print A.foo   # print a.foo   #
>print
type(A.foo) # 
a.foo()   # TypeError: foo() takes no arguments (1 given)
A.foo()   # TypeError: unbound method foo() must be called
with A instance as first argument (got nothing instead)


Clearly, foo is an instance method.


It is either a buggy instance method, missing the required first 
parameter, *or* a buggy static method, missing the decorator, making it 
appear to the interpreter as an instance method even though it it not.


 I know one should use @staticmethod for

declaring a method static. The question here is, given the above code, is
there any way to call foo?


Fix the bug, whichever deficiency you regard as the bug.

--
Terry Jan Reedy

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


Re: problem

2018-10-04 Thread Terry Reedy

On 10/4/2018 6:05 AM, Rémy Dpx wrote:

Hello,
I’ve got a problem with my Python.


What OS?, What Python version?


Indeed my Idle act like if my ctrl button were always pushed ( when i press Q, 
it selects everything ;


On all built-in keysets, Control-Q is bound to 'close-all-windows', 
which is 'quit'.



when i press W, it goes back in the last form)


Control-W does not have this meaning in any built-in IDLE keyset.
Are you really using IDLE?


I tried to uninstall and download back and also to change the version, but my 
problem is still there.


Perhaps your keyboard or OS keyboard handler has a problem.

--
Terry Jan Reedy


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


Re: Calling an instance method defined without any 'self' parameter

2018-10-04 Thread Bob van der Poel
On Thu, Oct 4, 2018 at 1:25 AM Ibrahim Dalal 
wrote:

> class A:
> def foo():
> print 'Hello, world!'
>
> a = A()print A.foo   # print a.foo   #
> >print
> type(A.foo) # 
> a.foo()   # TypeError: foo() takes no arguments (1 given)
> A.foo()   # TypeError: unbound method foo() must be called
> with A instance as first argument (got nothing instead)
>
>
> Clearly, foo is an instance method. I know one should use @staticmethod for
> declaring a method static. The question here is, given the above code, is
> there any way to call foo?
>
> Python 2.7
>
>
> Thanks,
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Use the magic of staticmethod :)

class A:
   @staticmethod
   def foo():
... do foo stuff


Hope this helps.

-- 

 Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: b...@mellowood.ca
WWW:   http://www.mellowood.ca
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Calling an instance method defined without any 'self' parameter

2018-10-04 Thread Ibrahim Dalal
On Thu, Oct 4, 2018 at 10:20 PM Thomas Jollans  wrote:

> On 2018-10-04 10:25, Ibrahim Dalal wrote:
> > class A:
> > def foo():
> > print 'Hello, world!'
> >
> > a = A()print A.foo   # print a.foo   #
> > >print
> > type(A.foo) # 
> > a.foo()   # TypeError: foo() takes no arguments (1 given)
> > A.foo()   # TypeError: unbound method foo() must be called
> > with A instance as first argument (got nothing instead)
> >
>
> There is a way in Python 2 as well, and I'm sure someone else will
> demonstrate. I won't. It's easy enough to discover if you know that it
> should exist. I'll just tell you that Python 3 is much nicer:
>

Thought a little about it. A.__dict__['foo']() works! Thanks.


>
> Python 3 is much nicer.
>
> Cheers,
> Thomas
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


pip hangs after successful operation

2018-10-04 Thread Ryan Johnson
Hello, I am seeking some quick help, and probably am reporting bugs along the 
way. I apologize that this is a long email. Please let me know what I should do 
in the future.

On Windows, pip hangs and does not install packages in the proper location (or 
perhaps, at all), even if pip claims it installed successfully. Upon hanging, I 
can use Ctrl+C to terminate individual processes that have succeeded, and the 
results show up in “pip list”, but this bug affects any packages that call pip 
within their install script, which makes this a critical bug, since the package 
install scripts will never complete.

Filed bug report here: https://github.com/pypa/pip/issues/5850

My environment:
➢ Python 3.7.0 x64
➢ pip 18.0
➢ Windows 10 Pro x64

Steps taken to resolve, so far:
➢ Repaired Installation.
➢ Removed and Reinstalled Installation.
➢ Rebooted computer as last resort.

This appears to be a bug similar to https://github.com/pypa/pip/issues/4588 

However, unlike in that bug report, pip hangs after all of these commands:
• pip list
• pip install
• pip install --upgrade pip

However, when called using “py -m pip”, these commands do not hang, and, upon 
inspection of the package list, via “pip list” and “py -m pip list” methods, 
there is a discrepancy. This is the culprit, but I don’t know how to fix the 
problem. Output:

• PS C:\Users\Ryan> py -V
Python 3.7.0

• PS C:\Users\Ryan> pip list
Package Version
--- ---
Click   7.0
mysqlclient 1.3.13
pip 18.0
pip-tools   3.0.0
setuptools  40.4.3
six 1.11.0

• PS C:\Users\Ryan> py -m pip list
Package    Version
-- ---
pip    18.0
setuptools 40.4.3

Notice the package lists are different. The outputs above are from the exact 
same pip executable:

• PS C:\Users\Ryan> pip -V
pip 18.0 from 
c:\users\ryan\appdata\local\programs\python\python37\lib\site-packages\pip 
(python 3.7)

• PS C:\Users\Ryan> py -m pip -V
pip 18.0 from 
C:\Users\Ryan\AppData\Local\Programs\Python\Python37\lib\site-packages\pip 
(python 3.7)

I have another machine running Python 3.7.0 x64 that does not experience this 
issue.

Both machines have the same set-up:
➢ Python 3.7.0 from x64 installer (local user install, not All Users install, 
with PATH option checked. pip runs directly in terminal.)
➢ Python 3.6.6 from Visual Studio 2017 installer (pip does not run unless 
called from py -m pip or py -3.6 m pip)
➢ Anaconda from installer (not used yet)
➢ MySQL Connector Python 8.0.12 from MySQL Installer (only installs for Python 
3.6.6, not compatible with Python 3.7.0)
➢ Cygwin
➢ MinGW/MSYS

I have exhausted all online help documentation, and none of the bug reports 
contain answers that explain why one computer fails while the other does not.

Further testing reveals more bugs:

This bug does not affect the older Python 3.6.6 pip on either machine:

• py -3.6 -m pip -V
pip 10.0.1 from < blah path to Python36_64 package dir >

• py -3.6 -m pip install matplotlib
MySQL-connector-python 8.0.12 requires protobuf>=3.0.0, which is not installed.

The installation [also] fails, but at least it doesn’t hang.
However it is not possible to install protobuf, as this also fails:

• py -3.6 -m pip install protobuf
Could not install packages due to an EnvironmentError: [Errno 13] Permission 
denied: C:\\ ….. \\six.py

And it cannot upgrade:

• py -3.6 -m pip install --upgrade pip
Could not install packages due to an EnvironmentError: [WinError 5] Access is 
denied: ‘c:\\program...\\...\\pip-10.0.1.dist-info\\entry_points.txt’
Consider using the `--user` option or check the permissions.

Used the suggestion, which looked more like a warning:

• Py -3.6 -m pip install --upgrade pip --user
Successfully installed

Permission denied is a bad excuse to fail, when a command line argument can 
change this. I do not like adding command line switches to something that 
should work without them (since I specifically call this user-specific resource 
in the command statement), because there is no telling what the application 
will do from a black-box engineering viewpoint. This error message / hint 
should be more elaborate, explaining what the switch does, as it is 
counterintuitive for anyone familiar with Linux to believe for one second that 
“--user” is supposed get around a “permission denied” problem by elevating 
permissions, after years of telling users they need to use “sudo” to run 
something as root. This is an advantage for the ignorant coder. If ignorance is 
an advantage, then that just means the error message is not explanative enough. 
Requiring users to glean the meaning of “—user” from the “—help” option wastes 
time and mental resources by adding another layer of complexity to the 
installation process. It is not obvious that there is a “–help” option for “pip 
install” (hence the waste of time).

Other bug encountered recently:

Also, there is a bug that I reported approximately a week ago with the 
mysqlclient package installer, in which an install sc