Re: how to specify trusted hosts in windows config file

2020-04-05 Thread Peter J. Holzer
On 2020-03-31 08:35:35 +1100, Chris Angelico wrote:
> On Tue, Mar 31, 2020 at 8:21 AM  wrote:
> > For pypi.org alone, my dns lookup differs from yours:  151.101.128.223.
> 
> Ahh, I think I see what's happening. Something's interfering with your
> DNS - that's a Fastly IP address.

The four addresses you got were also Fastly addresses:

| pypi.org. 86278 IN A 151.101.192.223
| pypi.org. 86278 IN A 151.101.64.223
| pypi.org. 86278 IN A 151.101.128.223
| pypi.org. 86278 IN A 151.101.0.223

And in fact the address dcwhatthe gets (151.101.128.223) is one of those
four.

So it doesn't look like something is interfering with DNS. 

But maybe something intercepts the SSL connection? Since he wrote that
he's at the office, I'm guessing its some kind of malware protection,
probably at the corporate firewall.

A simple way to check this is to open the URL (here https://pypi.org) in
the browser and check the certificate. For me it says (in Firefox, other
browsers may format the information slightly different):

Certificate issued to:

Python Software Foundation
Wolfeboro
New Hampshire, US

Verified by: DigiCert, Inc.

dcwhatthe will probably see something different there.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | [email protected] |-- 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 specify trusted hosts in windows config file

2020-04-05 Thread Chris Angelico
On Sun, Apr 5, 2020 at 8:22 PM Peter J. Holzer  wrote:
>
> On 2020-03-31 08:35:35 +1100, Chris Angelico wrote:
> > On Tue, Mar 31, 2020 at 8:21 AM  wrote:
> > > For pypi.org alone, my dns lookup differs from yours:  151.101.128.223.
> >
> > Ahh, I think I see what's happening. Something's interfering with your
> > DNS - that's a Fastly IP address.
>
> The four addresses you got were also Fastly addresses:
>
> | pypi.org. 86278 IN A 151.101.192.223
> | pypi.org. 86278 IN A 151.101.64.223
> | pypi.org. 86278 IN A 151.101.128.223
> | pypi.org. 86278 IN A 151.101.0.223
>
> And in fact the address dcwhatthe gets (151.101.128.223) is one of those
> four.
>
> So it doesn't look like something is interfering with DNS.

Oh, good point, I missed that. Though the fact that it gives different
results _at all_ was the surprising part to me.

> But maybe something intercepts the SSL connection? Since he wrote that
> he's at the office, I'm guessing its some kind of malware protection,
> probably at the corporate firewall.

Yeah, that's exactly what I'm worried about. In fact, this is
*exactly* what SSL is supposed to protect against.

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


python script to give a list of prime no.

2020-04-05 Thread Sathvik Babu Veligatla
hi,
I am new to python, and i am trying to output the prime numbers beginning from 
3 and i cannot get the required output.
It stops after giving the output "7" and that's it.

CODE:
a = 3
l = []
while True:
for i in range(2,a):
if a%i == 0:
l.append(1)
else:
l.append(0)

if l.count(1) == 0:
print(a)
a = a + 2
elif l.count(1) >> 0:
a = a + 2



Any help is appreciated,
Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script to give a list of prime no.

2020-04-05 Thread Orges Leka
You can try the following:
It is based on trial division and very slow, compared to the state of the
art:

import math
def is_prime(n):
if int(math.sqrt(n))**2 == n:
return(False)
for i in range(2,int(math.ceil(math.sqrt(n:
if n%i==0:
return(False)
return(True)

then:

primes = [x for x in range(1,1000) if is_prime(x)]

print(primes)

Kind regards,
Orges

Am So., 5. Apr. 2020 um 14:27 Uhr schrieb Sathvik Babu Veligatla <
[email protected]>:

> hi,
> I am new to python, and i am trying to output the prime numbers beginning
> from 3 and i cannot get the required output.
> It stops after giving the output "7" and that's it.
>
> CODE:
> a = 3
> l = []
> while True:
> for i in range(2,a):
> if a%i == 0:
> l.append(1)
> else:
> l.append(0)
>
> if l.count(1) == 0:
> print(a)
> a = a + 2
> elif l.count(1) >> 0:
> a = a + 2
>
>
>
> Any help is appreciated,
> Thank you.
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 
Mit freundlichen Grüßen
Herr Dipl. Math. Orges Leka

Mobil: 015751078391
Email: [email protected]
Holzheimerstraße 25
65549 Limburg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script to give a list of prime no.

2020-04-05 Thread Chris Angelico
On Sun, Apr 5, 2020 at 10:26 PM Sathvik Babu Veligatla
 wrote:
>
> hi,
> I am new to python, and i am trying to output the prime numbers beginning 
> from 3 and i cannot get the required output.
> It stops after giving the output "7" and that's it.
>
> CODE:
> a = 3
> l = []
> while True:
> for i in range(2,a):
> if a%i == 0:
> l.append(1)
> else:
> l.append(0)
>
> if l.count(1) == 0:
> print(a)
> a = a + 2
> elif l.count(1) >> 0:
> a = a + 2
>
>

Firstly, good job on several points: you posted your code, you said
what the purpose is, and you said how the output differs from that.
Unfortunately not everyone does that :)

Secondly, though: What does "some_number >> 0" mean? Play around with
that in the interactive interpreter and see what results you get.

You may want to consider using a simple 'else'. When you have exactly
two possibilities, you don't need to say "else, if". For instance,
suppose you say "If today is a weekday, go to work; otherwise, play
games", you don't need to word it as "otherwise, if today is a
weekend, play games" - you just say "otherwise". You can simplify this
code the same way.

Something worth remembering is that all code can be buggy, so writing
less code usually means you have less bugs. Try to write your program
with less code rather than more. :)

All the best!

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


Re: python script to give a list of prime no.

2020-04-05 Thread Chris Angelico
On Sun, Apr 5, 2020 at 10:35 PM Orges Leka  wrote:
>
> You can try the following:
> It is based on trial division and very slow, compared to the state of the
> art:
>

I think it's more helpful to assist the OP in learning coding, rather
than provide a completely different function to do a similar purpose
:) I strongly suspect that the OP is doing this prime number finder as
part of learning Python, not as a means of actually finding prime
numbers.

BTW, you may want to be careful of mixing floats and ints. It's
generally safest to stick to just integers - fewer things to have to
think about.

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


Re: Adding tkinter modules to notebook tabs

2020-04-05 Thread Rich Shepard

On Sat, 4 Apr 2020, Terry Reedy wrote:


IDLE's currently-working Settings dialog uses a  ttl.Notebook with 5 tabs.
To see it, run IDLE and on the top menu, select Options => Configure IDLE.
Each tab displays a ttk.Frame with multiple widgets. Where there is a
choice, ttk widgets are used. They make the most different on macOS and
least difference on Windows (because the tk widgets look pretty good
there).

The code is in idlelib/configdialog.py.  ConfigDialog creates a window and 
notebook and adds the tab frames.  As Christian indicated, the notebook 
itself takes very little code.  Each of the tab frames is a separate Frame 
subclass in the same file, but they could be in separate files.


Thanks, Terry.

Regards,

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


Re: python script to give a list of prime no.

2020-04-05 Thread Sathvik Babu Veligatla
On Sunday, April 5, 2020 at 6:04:20 PM UTC+5:30, Orges Leka wrote:
> You can try the following:
> It is based on trial division and very slow, compared to the state of the
> art:
> 
> import math
> def is_prime(n):
> if int(math.sqrt(n))**2 == n:
> return(False)
> for i in range(2,int(math.ceil(math.sqrt(n:
> if n%i==0:
> return(False)
> return(True)
> 
> then:
> 
> primes = [x for x in range(1,1000) if is_prime(x)]
> 
> print(primes)
> 
> Kind regards,
> Orges
> 
> Am So., 5. Apr. 2020 um 14:27 Uhr schrieb Sathvik Babu Veligatla <
> [email protected]>:
> 
> > hi,
> > I am new to python, and i am trying to output the prime numbers beginning
> > from 3 and i cannot get the required output.
> > It stops after giving the output "7" and that's it.
> >
> > CODE:
> > a = 3
> > l = []
> > while True:
> > for i in range(2,a):
> > if a%i == 0:
> > l.append(1)
> > else:
> > l.append(0)
> >
> > if l.count(1) == 0:
> > print(a)
> > a = a + 2
> > elif l.count(1) >> 0:
> > a = a + 2
> >
> >
> >
> > Any help is appreciated,
> > Thank you.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> 
> 
> -- 
> Mit freundlichen Grüßen
> Herr Dipl. Math. Orges Leka
> 
> Mobil: 015751078391
> Email: [email protected]
> Holzheimerstraße 25
> 65549 Limburg

umm, first of all, thank you for the quick response.
But, I am basically trying to get the output using the simplest means 
possible(beginner's trial :-)). So can you try to run it tell me, why it isn't 
working?
thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script to give a list of prime no.

2020-04-05 Thread Sathvik Babu Veligatla
On Sunday, April 5, 2020 at 6:09:04 PM UTC+5:30, Chris Angelico wrote:
> On Sun, Apr 5, 2020 at 10:26 PM Sathvik Babu Veligatla
>  wrote:
> >
> > hi,
> > I am new to python, and i am trying to output the prime numbers beginning 
> > from 3 and i cannot get the required output.
> > It stops after giving the output "7" and that's it.
> >
> > CODE:
> > a = 3
> > l = []
> > while True:
> > for i in range(2,a):
> > if a%i == 0:
> > l.append(1)
> > else:
> > l.append(0)
> >
> > if l.count(1) == 0:
> > print(a)
> > a = a + 2
> > elif l.count(1) >> 0:
> > a = a + 2
> >
> >
> 
> Firstly, good job on several points: you posted your code, you said
> what the purpose is, and you said how the output differs from that.
> Unfortunately not everyone does that :)
> 
> Secondly, though: What does "some_number >> 0" mean? Play around with
> that in the interactive interpreter and see what results you get.
> 
> You may want to consider using a simple 'else'. When you have exactly
> two possibilities, you don't need to say "else, if". For instance,
> suppose you say "If today is a weekday, go to work; otherwise, play
> games", you don't need to word it as "otherwise, if today is a
> weekend, play games" - you just say "otherwise". You can simplify this
> code the same way.
> 
> Something worth remembering is that all code can be buggy, so writing
> less code usually means you have less bugs. Try to write your program
> with less code rather than more. :)
> 
> All the best!
> 
> ChrisA

yeah bro, tried as said. But still no luck... :-(
i cannot understand the issue in the code.
-- 
https://mail.python.org/mailman/listinfo/python-list


Windows python 3.8 module finder problem.

2020-04-05 Thread Barry Scott
I have code that uses the modulefinder:

mf = modulefinder.ModuleFinder()
mf.run_script( self.main_program )

with python 3.7 all works without problems. But python 3.8 tracebacks (TB), 
here is the end of the TB:

  File "C:\Python38.Win64\lib\modulefinder.py", line 326, in import_module
m = self.load_module(fqname, fp, pathname, stuff)
  File "C:\Python38.Win64\lib\modulefinder.py", line 344, in load_module
co = compile(fp.read()+'\n', pathname, 'exec')
  File "C:\Python38.Win64\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 308: 
character maps to 

I added this debug print in both the 3.7 and 3.8 code of modulefinder.py:

def load_module(self, fqname, fp, pathname, file_info):
print('QQQ load_module(%r, %r, %r, %r)' % (fqname, fp, pathname, 
file_info))

The file that causes the TB is functools.py as there is text that is non-ASCII 
at offset 308.

The debug shows this for functools.py:

QQQ load_module('functools', <_io.TextIOWrapper 
name='C:\\Python37.win64\\lib\\functools.py' mode='r' encoding='utf-8'>, 
'C:\\Python37.win64\\lib\\functools.py', ('.py', 'r', 1))

QQQ load_module('functools', <_io.TextIOWrapper 
name='C:\\Python38.Win64\\lib\\functools.py' mode='r' encoding='cp1252'>, 
'C:\\Python38.Win64\\lib\\functools.py', ('.py', 'r', 1))

In 3.7 the fp is opened with encoding UTF-8, but on 3.8 its cp1252.

The code in modulefinder does not seem to handle encoding when opening .py 
files.
Adding an explicit coding comment to functools.py did not work.
So the default encoding will be used; which is 
locale.getpreferredencoding(False) according
to the docs for open().

How did modulefinder end up wth utf-8 encoding being used? It does seem to look 
at
chcp setting.

On both 3.7 and 3.8 I see that locale.getpreferredencoding(False) returns 
'cp1252'.
I have not figured out how the 3.7 code manages to use utf-8 that is required 
to get things
working.

I can workaround this by setting PYTHONUTF8=1, but I want to change the 
behavour from within python.

I have failed to find a way to change what is returned by 
locale.getpreferredencoding(False) from
within python. Is the only way to set the PYTHONUTF8?

Barry

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


Re: python script to give a list of prime no.

2020-04-05 Thread Barry Scott



> On 5 Apr 2020, at 14:08, Sathvik Babu Veligatla  
> wrote:
> 
> On Sunday, April 5, 2020 at 6:09:04 PM UTC+5:30, Chris Angelico wrote:
>> On Sun, Apr 5, 2020 at 10:26 PM Sathvik Babu Veligatla
>>  wrote:
>>> 
>>> hi,
>>> I am new to python, and i am trying to output the prime numbers beginning 
>>> from 3 and i cannot get the required output.
>>> It stops after giving the output "7" and that's it.
>>> 
>>> CODE:
>>> a = 3
>>> l = []
>>> while True:
>>>for i in range(2,a):
>>>if a%i == 0:
>>>l.append(1)
>>>else:
>>>l.append(0)
>>> 
>>>if l.count(1) == 0:
>>>print(a)
>>>a = a + 2
>>>elif l.count(1) >> 0:
>>>a = a + 2
>>> 
>>> 
>> 
>> Firstly, good job on several points: you posted your code, you said
>> what the purpose is, and you said how the output differs from that.
>> Unfortunately not everyone does that :)
>> 
>> Secondly, though: What does "some_number >> 0" mean? Play around with
>> that in the interactive interpreter and see what results you get.
>> 
>> You may want to consider using a simple 'else'. When you have exactly
>> two possibilities, you don't need to say "else, if". For instance,
>> suppose you say "If today is a weekday, go to work; otherwise, play
>> games", you don't need to word it as "otherwise, if today is a
>> weekend, play games" - you just say "otherwise". You can simplify this
>> code the same way.
>> 
>> Something worth remembering is that all code can be buggy, so writing
>> less code usually means you have less bugs. Try to write your program
>> with less code rather than more. :)
>> 
>> All the best!
>> 
>> ChrisA
> 
> yeah bro, tried as said. But still no luck... :-(
> i cannot understand the issue in the code.

You need to figure out what the code is doing.

One way to do this is to add some more print statements to
show the values of your variables as the code runs.

What is the value of i for example in the for loop?
What does the list l look like?
Also try printing the values that you use the if statments.
print( l.count(1) == 0) etc.

Barry


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


Re: python script to give a list of prime no.

2020-04-05 Thread Peter J. Holzer
On 2020-04-05 05:22:45 -0700, Sathvik Babu Veligatla wrote:
> I am new to python, and i am trying to output the prime numbers
> beginning from 3 and i cannot get the required output. It stops after
> giving the output "7" and that's it.

A technique I learned when I started programming (back in the days when
computers were made from bones and rocks), is to "play computer":

Grab a piece of paper and a pencil. Make a column for each variable (a,
l, and i in your case). Then walk through the code line by line, think
about what each line does, and every time a new value is assigned to a
variable, note the new value on your paper.

Do the values of the variables change the way you expect them to? If
not, why not?

hp

PS: You can also single-step through the program in a debugger, but I
think doing this by hand on a piece of paper is very useful, especially
for a beginner, since it forces you to think what happens (The downside
is of course that you may make mistakes - but then you can learn from
them).

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


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


Fwd: python script to give a list of prime no.

2020-04-05 Thread inhahe
On Sun, Apr 5, 2020 at 8:26 AM Sathvik Babu Veligatla <
[email protected]> wrote:

> hi,
> I am new to python, and i am trying to output the prime numbers beginning
> from 3 and i cannot get the required output.
> It stops after giving the output "7" and that's it.
>
> CODE:
> a = 3
> l = []
> while True:
> for i in range(2,a):
> if a%i == 0:
> l.append(1)
> else:
> l.append(0)
>
> if l.count(1) == 0:
> print(a)
> a = a + 2
> elif l.count(1) >> 0:
> a = a + 2
>
>
>
> Any help is appreciated,
> Thank you.
> --
> https://mail.python.org/mailman/listinfo/python-list



"l = []" needs to go inside the "while True" loop. as it is, it keeps
adding 1's and 0's to the list with each new "a" value, and then counts the
1's and 0's, without ever resetting the list back to empty, so once it gets
to 9 the list has a 1 in it and l.count(1) will never be false again. 3, 5
and 7 are prime so a 1 doesn't get added yet with those values, which is
why 7 is the highest it gets to. so with "l = []" inside the while loop,
"l" would be reset to empty with each new "a" value.

btw, this is a very inefficient way to compute prime numbers. for example,
why add the 0's to the list? you never count the number of 0's so it's
unnecessary. another example.. why use a list at all? all that matters is
that it find *one* result where a%i==0, it doesn't matter how many results
it found after that, so all you need is a boolean. and you might as well
stop testing a%i for *all* i values up to i, because once it finds the
first result that's 0, you know it's prime so you can just go to the next
number. and you don't need i to go all the way to a, because a%i will
always be > 0 for any i over a/2. and since you're not testing evens, it's
actually any i over a/3. in actuality, though, computing any a%i where i >
the square root of a is redundant because for each factor of a above the
square root of a, you've already tested its cofactor, say a is 100. the
square root of 100 is 10. if you're testing 100%20, that's unnecessary
because 100/20 is 5 and you've already tested 100%5.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Adding tkinter modules to notebook tabs [RESOLVED]

2020-04-05 Thread Rich Shepard

On Sat, 4 Apr 2020, Christian Gollwitzer wrote:


Add that thing instead of the frame.

blabla=BioDataForm() # whatever args it needs, maybe parent=nb

nb.add(blabla, text="Biodata")


Christian,

This clarifies my uncertainty and answers my question. Thanks.

PS: I suggest to change all Tk widgets to ttk widgets for optical reasons, 
but that's a side note.


I thought I had all as ttk; I'll check and correct as necessary.

Best regards,

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


Re: python script to give a list of prime no.

2020-04-05 Thread Sathvik Babu Veligatla
On Sunday, April 5, 2020 at 8:03:19 PM UTC+5:30, inhahe wrote:
> On Sun, Apr 5, 2020 at 8:26 AM Sathvik Babu Veligatla <
> [email protected]> wrote:
> 
> > hi,
> > I am new to python, and i am trying to output the prime numbers beginning
> > from 3 and i cannot get the required output.
> > It stops after giving the output "7" and that's it.
> >
> > CODE:
> > a = 3
> > l = []
> > while True:
> > for i in range(2,a):
> > if a%i == 0:
> > l.append(1)
> > else:
> > l.append(0)
> >
> > if l.count(1) == 0:
> > print(a)
> > a = a + 2
> > elif l.count(1) >> 0:
> > a = a + 2
> >
> >
> >
> > Any help is appreciated,
> > Thank you.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> "l = []" needs to go inside the "while True" loop. as it is, it keeps
> adding 1's and 0's to the list with each new "a" value, and then counts the
> 1's and 0's, without ever resetting the list back to empty, so once it gets
> to 9 the list has a 1 in it and l.count(1) will never be false again. 3, 5
> and 7 are prime so a 1 doesn't get added yet with those values, which is
> why 7 is the highest it gets to. so with "l = []" inside the while loop,
> "l" would be reset to empty with each new "a" value.
> 
> btw, this is a very inefficient way to compute prime numbers. for example,
> why add the 0's to the list? you never count the number of 0's so it's
> unnecessary. another example.. why use a list at all? all that matters is
> that it find *one* result where a%i==0, it doesn't matter how many results
> it found after that, so all you need is a boolean. and you might as well
> stop testing a%i for *all* i values up to i, because once it finds the
> first result that's 0, you know it's prime so you can just go to the next
> number. and you don't need i to go all the way to a, because a%i will
> always be > 0 for any i over a/2. and since you're not testing evens, it's
> actually any i over a/3. in actuality, though, computing any a%i where i >
> the square root of a is redundant because for each factor of a above the
> square root of a, you've already tested its cofactor, say a is 100. the
> square root of 100 is 10. if you're testing 100%20, that's unnecessary
> because 100/20 is 5 and you've already tested 100%5.

yeah, I get that.
Initially, i put the else columns empty and had a somewhat different code. I 
thought maybe that's messing up with the code and added the 'l.append(0)' line 
and some other things.
Thank you for the feedback :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script to give a list of prime no.

2020-04-05 Thread Sathvik Babu Veligatla
On Sunday, April 5, 2020 at 8:03:19 PM UTC+5:30, inhahe wrote:
> On Sun, Apr 5, 2020 at 8:26 AM Sathvik Babu Veligatla <
> [email protected]> wrote:
> 
> > hi,
> > I am new to python, and i am trying to output the prime numbers beginning
> > from 3 and i cannot get the required output.
> > It stops after giving the output "7" and that's it.
> >
> > CODE:
> > a = 3
> > l = []
> > while True:
> > for i in range(2,a):
> > if a%i == 0:
> > l.append(1)
> > else:
> > l.append(0)
> >
> > if l.count(1) == 0:
> > print(a)
> > a = a + 2
> > elif l.count(1) >> 0:
> > a = a + 2
> >
> >
> >
> > Any help is appreciated,
> > Thank you.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> "l = []" needs to go inside the "while True" loop. as it is, it keeps
> adding 1's and 0's to the list with each new "a" value, and then counts the
> 1's and 0's, without ever resetting the list back to empty, so once it gets
> to 9 the list has a 1 in it and l.count(1) will never be false again. 3, 5
> and 7 are prime so a 1 doesn't get added yet with those values, which is
> why 7 is the highest it gets to. so with "l = []" inside the while loop,
> "l" would be reset to empty with each new "a" value.
> 
> btw, this is a very inefficient way to compute prime numbers. for example,
> why add the 0's to the list? you never count the number of 0's so it's
> unnecessary. another example.. why use a list at all? all that matters is
> that it find *one* result where a%i==0, it doesn't matter how many results
> it found after that, so all you need is a boolean. and you might as well
> stop testing a%i for *all* i values up to i, because once it finds the
> first result that's 0, you know it's prime so you can just go to the next
> number. and you don't need i to go all the way to a, because a%i will
> always be > 0 for any i over a/2. and since you're not testing evens, it's
> actually any i over a/3. in actuality, though, computing any a%i where i >
> the square root of a is redundant because for each factor of a above the
> square root of a, you've already tested its cofactor, say a is 100. the
> square root of 100 is 10. if you're testing 100%20, that's unnecessary
> because 100/20 is 5 and you've already tested 100%5.

thank you buddy,
it worked...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script to give a list of prime no.

2020-04-05 Thread Pieter van Oostrum
Sathvik Babu Veligatla  writes:

> hi,
> I am new to python, and i am trying to output the prime numbers beginning 
> from 3 and i cannot get the required output.
> It stops after giving the output "7" and that's it.
>
> CODE:
> a = 3
> l = []
> while True:
> for i in range(2,a):
> if a%i == 0:
> l.append(1)
> else:
> l.append(0)
>
> if l.count(1) == 0:
> print(a)
> a = a + 2
> elif l.count(1) >> 0:
> a = a + 2
> 
>
>
> Any help is appreciated,
> Thank you.

As others have already noticed, the l.count(1) >> 0: is faulty. You probably 
meant
l.count(1) > 0:, but else would be simpler.

But then, once there is a 1 in l that never disappears, so after that it will 
never print any more numbers. You should put the l = [] AFTER the while True, 
so that you start with a new empty list every cycle.

And then, putting 0 an 1's in a list and then counting how many 1's there are 
is quite inefficient. Just counting from the beginning would be more efficient. 
Like:

a = 3
while True:
count = 0
for i in range(2,a):
if a%i == 0:
count += 1
if count == 0:
print(a)
a = a + 2
else:
a = a + 2

Which can be simplified to:

a = 3
while True:
count = 0
for i in range(2,a):
if a%i == 0:
count += 1
if count == 0:
print(a)
a = a + 2

And you effectively use the counter as a boolean, so replace is by a boolean.

a = 3
while True:
is_prime = True
for i in range(2,a):
if a%i == 0:
is_prime = False
# once we found a divisor, it is no use to continue
break
if is_prime:
print(a)
a = a + 2

Further optimizations are possible, for example use range(2,a/2) or even range 
(2, sqrt(a)).
-- 
Pieter van Oostrum
www: http://pieter.vanoostrum.org/
PGP key: [8DAE142BE17999C4]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python script to give a list of prime no.

2020-04-05 Thread Dan Sommers
On Sun, 05 Apr 2020 19:46:00 +0200
Pieter van Oostrum  wrote:

> Sathvik Babu Veligatla  writes:
> 
> > hi,
> > I am new to python, and i am trying to output the prime numbers
> > beginning from 3 and i cannot get the required output.  It stops
> > after giving the output "7" and that's it.
> > CODE:
> > a = 3
> > l = []
> > while True:
> > for i in range(2,a):
> > if a%i == 0:
> > l.append(1)
> > else:
> > l.append(0)
> >
> > if l.count(1) == 0:
> > print(a)
> > a = a + 2
> > elif l.count(1) >> 0:
> > a = a + 2

[intervening optimizations omitted to conserve electrons]

> And you effectively use the counter as a boolean, so replace is by a boolean.
> 
> a = 3
> while True:
> is_prime = True
> for i in range(2,a):
> if a%i == 0:
> is_prime = False
> # once we found a divisor, it is no use to continue
> break
> if is_prime:
> print(a)
> a = a + 2
> 
> Further optimizations are possible, for example use range(2,a/2) or
> even range (2, sqrt(a)).

Now if only there were a way to get rid of that extraneous flag and
build some sort of "if the loop ran to completion" construct

a = 3
while True:
for i in range(2,a):
if a%i == 0:
# once we found a divisor, it is no use to continue
break
else:   # magic here!
print(a)
a = a + 2

The Time Machine Strikes Again,
Dan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to specify trusted hosts in windows config file

2020-04-05 Thread dcwhatthe
On Sunday, April 5, 2020 at 2:15:21 PM UTC-4, Peter J. Holzer wrote:
> --yrj/dFKFPuw6o+aM
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> Content-Transfer-Encoding: quoted-printable
> 
> On 2020-03-31 08:35:35 +1100, Chris Angelico wrote:
> > On Tue, Mar 31, 2020 at 8:21 AM dc wrote:
> > > For pypi.org alone, my dns lookup differs from yours:  151.101.128.223.
> >=20
> > Ahh, I think I see what's happening. Something's interfering with your
> > DNS - that's a Fastly IP address.
> 
> The four addresses you got were also Fastly addresses:
> 
> | pypi.org. 86278 IN A 151.101.192.223 | pypi.org. 86278 IN A 151.101.64.223 
> | 
> pypi.org. 86278 IN A 151.101.128.223 | pypi.org. 86278 IN A 151.101.0.223
> 
> And in fact the address dcwhatthe gets (151.101.128.223) is one of those four.
> 
> So it doesn't look like something is interfering with DNS.=20
> 
> But maybe something intercepts the SSL connection? Since he wrote that he's 
> at 
> the office, I'm guessing its some kind of malware protection, probably at the 
> corporate firewall.
> 
> A simple way to check this is to open the URL (here https://pypi.org) in the 
> browser and check the certificate. For me it says (in Firefox, other browsers 
> may format the information slightly different):
> 
> Certificate issued to:
> 
> Python Software Foundation
> Wolfeboro
> New Hampshire, US
> 
> Verified by: DigiCert, Inc.
> 
> dcwhatthe will probably see something different there.
> 
> hp
> 
> --=20
>_  | Peter J. Holzer| Story must make more sense than reality.
> |_|_) ||
> | |   | hjp |-- Charles Stross, "Creative writing
> __/   | http://www.hjp.at/ |   challenge!"
> 
> --yrj/dFKFPuw6o+aM
> Content-Type: application/pgp-signature; name="signature.asc"
> 
> -BEGIN PGP SIGNATURE-
> 
> iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl6Jry4ACgkQ8g5IURL+
> KF0TnRAAp3r4DxFh24jsXmuLlUykG9Yd4wOloVyGKyajRJjYqQ0AgkTgZrTz6A5N
> 0YVvUnINlY65kkJXA703fb+f7mS7Ij6V3/UvxHGxitLatDauHvlkENTD1GzJzf7l
> Lg05G3krkEpb41S+GLFYO3MVFbeBPV9jUKoHJs96UHxi5tHiTe3IA14xmgooeS32
> 3/JI+wAFV5pR5ICM8sTcRu+9wrNNEtbdg8sNfodIh5d9j3kY7s4SV0srPI3hBRUE
> F949/YAPCA8rH5RcCkM3JQuJeI24hOCBvMXXknjY3pcC4ocAPAXHznTAgNtn8dKd
> Z3uzFkql/7Sd1FK5qIKIvsBUS3TlOvVfbAm8rxZZPitbMEa/GWhDEQq3J5GGrPDx
> 7Sty4TegLa292TJZcEJqDcFEAMjVETGeYRTEkqXdHfbVT8KYy4Lwyka1fLjpFiCC
> mvZdeV2KppO3Kae0ow0mgAOXrLO719ZrgxLrzENA/K4Foq+iOZxozSyGiqjjVzO8
> W7icMQt7sPDCfDfAXxkeEr58yehRdKD6K8gpmQ2inEwk7jAVtauPIUuwlfZzIllm
> 5B6LRAtF7FbZsL1KRzYKtZi2TCPTND/2jW8nUQGaTCEW6W/fa0VLkHhr3sZFmmYA
> I0I3XHyh/At5RCv9XgTtcpchgXvEJlD2D27X08TQNb1k2U7DL6w=
> =crJH
> -END PGP SIGNATURE-
> 
> --yrj/dFKFPuw6o+aM--

Thanks, Peter.  For the time being, I'm dealing with this by doing the 
development on my personal laptop, including the generation of the executable.  
We're all working from home and logging in during the pandemic, anyway.

When this is done and I have the time, I'll try & trace this down, while trying 
to avoid office politics.



Regards,

DC

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


Is there a difference between python

2020-04-05 Thread Malcolm Greene
Is there a difference between the following 2 ways to launch a console-less 
script under Windows?

python 

Re: Is there a difference between python

2020-04-05 Thread Mike Dewhirst

On 6/04/2020 8:35 am, Malcolm Greene wrote:

Is there a difference between the following 2 ways to launch a console-less 
script under Windows?

python 

Re: Is there a difference between python

2020-04-05 Thread David L Neil via Python-list

On 6/04/20 10:35 AM, Malcolm Greene wrote:

Is there a difference between the following 2 ways to launch a console-less 
script under Windows?

python 

Re: Exceptions versus Windows ERRORLEVEL

2020-04-05 Thread Eryk Sun
On 4/3/20, Stephen Tucker  wrote:
>
> Does an exception raised by a Python 3.x program on a Windows machine set
> ERRORLEVEL?

ERRORLEVEL is an internal state of the CMD shell. It has nothing to do
with Python. If Python exits due to an unhandled exception, the
process exit code will be 1. If CMD waits on the process, it will set
the ERRORLEVEL based on the exit code. But CMD doesn't always wait. By
default its START command doesn't wait. Also, at the interactive
command prompt it doesn't wait for non-console applications such as
"pythonw.exe"; it only waits for console applications such as
"python.exe".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a difference between python

2020-04-05 Thread Eryk Sun
On 4/5/20, Malcolm Greene  wrote:
> Is there a difference between the following 2 ways to launch a console-less
> script under Windows?
>
> python