Re: Odd truth result with in and ==

2018-11-23 Thread Thomas Jollans
On 2018-11-22 09:58, Chris Angelico wrote:
> On Thu, Nov 22, 2018 at 7:51 PM Thomas Jollans  wrote:
>>
>> On 21/11/2018 20:18, Python wrote:
>>> $ python3
>>> Python 3.5.2 (default, Nov 23 2017, 16:37:01)
>>> [GCC 5.4.0 20160609] on linux
>>> Type "help", "copyright", "credits" or "license" for more information.
>> 1 in [1,2,3] == True
>>> False
>> 1 in ([1,2,3] == True)
>>> Traceback (most recent call last):
>>>   File "", line 1, in 
>>> TypeError: argument of type 'bool' is not iterable
>> (1 in [1,2,3]) == True
>>> True
>>>
>>
>> See: https://github.com/cosmologicon/pywat ;-)
>>
> 
> I find it fascinating that quite a few of the Wats given on the
> landing page are specifically poking fun at IEEE floating point
> (completely documented and intended behaviour that exists across many
> languages), yet the "Wat Quiz", also in that repository, specifically
> excludes floats. TRWTF is inconsistently poking fun at a language's
> consistencies.

Clearly the author was struggling to find "wat"s of the sort you get in
Ruby or JavaScript.

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


Install

2018-11-23 Thread Salomon Chavarin



Sent from Mail for Windows 10



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
-- 
https://mail.python.org/mailman/listinfo/python-list


Improvement Request

2018-11-23 Thread Sayan Kundu
*** Please make "Table of Contents" an independent scrolling panel*
For a long documentation, users have to scroll up all the way to navigate a
different sub-topic.
-- 
https://mail.python.org/mailman/listinfo/python-list


Unable to find newly installed Python 3.7.1

2018-11-23 Thread Edward Popko
Snake people:


I'm a Java person and thought to try Python for Windows.
I installed Python 3.7.1 (64-bit) hoping for an IDE, documentation and even
a sample or two.
The python-3.7.1-amd64.exe unpacks and installs fine.
Only problem is I cannot find it. There was no install option to add an
shortcut to the
desktop, there is no C:\ folder, no folder added to Program Files or Program
Files (x86).


I have Windows 10, 64 bit professional

 

Where did it go? Where is the IDE?

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


can you please help me in opening the python programming.

2018-11-23 Thread hello!



Sent from Mail for Windows 10

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


Intitalize values for a class

2018-11-23 Thread Ganesh Pal
Hello team,

I am a python 2.7 user on Linux. I will need feedback on the below program
as I'm  new to oops .

#!/usr/bin/python


class System(object):

  '''Doc - Inside Class '''

  def __init__(self, params=None):

   if params is None:

  self.params = {'id': '1',

  'name': 's-1'}

  print self.params

   if type(params) is dict and params.get('id') == '0':

 raise ValueError('ERROR: id 0 is reserved !! ')

   #print self.params

   else:

self.params = params

print self.params

# Test all conditions

#case 0 - Default should create {'id': '1','name': 's-1'}
#s0 = System()

#Case 1 (id has value '0')
#test1_params = {'id': '0', 'name': 's-0'}
#s1 = System(params=test1_params)


#Case 2 (id has some other values)
#test2_params = {'id': '10', 'name': 's-10'}
#s2 = System(params=test2_params)


Question:

I have to initialize the values the below class such that

 1.  Intitalize  default values if nothing is supplied by the username  i.e
self.params = {'id': '1', 'name': 's-1'}

2. I need to raise an Exception if the value for the key params[id] is '0'.

3. It should work if  params[I'd] has values other than (1) and (2)

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


Re: can you please help me in opening the python programming.

2018-11-23 Thread Bob Gailer
We would be glad to help. I can't tell from your question what kind of help
you need so please give us more information.

Have you tried to install python?

If so has the installation succeeded?

What do you mean by "open the programming"?

What have you tried?

What do you expect to see?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Install

2018-11-23 Thread Bob Gailer
OK.

On Nov 23, 2018 8:08 AM, "Salomon Chavarin"  wrote:

>
>
> Sent from Mail for Windows 10
>
>
>
> ---
> This email has been checked for viruses by Avast antivirus software.
> https://www.avast.com/antivirus
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: initialize the values of the class

2018-11-23 Thread Ganesh Pal
Sorry for reposting,  typo in the subject line  !

On Fri, Nov 23, 2018, 19:11 Ganesh Pal  Hello team,
>
> I am a python 2.7 user on Linux. I will need feedback on the below program
> as I'm  new to oops .
>
> #!/usr/bin/python
>
>
> class System(object):
>
>   '''Doc - Inside Class '''
>
>   def __init__(self, params=None):
>
>if params is None:
>
>   self.params = {'id': '1',
>
>   'name': 's-1'}
>
>   print self.params
>
>if type(params) is dict and params.get('id') == '0':
>
>  raise ValueError('ERROR: id 0 is reserved !! ')
>
>#print self.params
>
>else:
>
> self.params = params
>
> print self.params
>
> # Test all conditions
>
> #case 0 - Default should create {'id': '1','name': 's-1'}
> #s0 = System()
>
> #Case 1 (id has value '0')
> #test1_params = {'id': '0', 'name': 's-0'}
> #s1 = System(params=test1_params)
>
>
> #Case 2 (id has some other values)
> #test2_params = {'id': '10', 'name': 's-10'}
> #s2 = System(params=test2_params)
>
>
> Question:
>
> I have to initialize the values the below class such that
>
>  1.  Intitalize  default values if nothing is supplied by the username
> i.e self.params = {'id': '1', 'name': 's-1'}
>
> 2. I need to raise an Exception if the value for the key params[id] is '0'.
>
> 3. It should work if  params[I'd] has values other than (1) and (2)
>
> Regards,
> Ganesh
>
>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Intitalize values for a class

2018-11-23 Thread Bob Gailer
On Nov 23, 2018 8:42 AM, "Ganesh Pal"  wrote:
>
> Hello team,
>
> I am a python 2.7 user on Linux. I will need feedback on the below program
> as I'm  new to oops .

What kind of feedback do you want?
>
> #!/usr/bin/python
>
>
> class System(object):
>
>   '''Doc - Inside Class '''
>
>   def __init__(self, params=None):
>
>if params is None:
>
>   self.params = {'id': '1',
>
>   'name': 's-1'}
>
>   print self.params
>
>if type(params) is dict and params.get('id') == '0':
>
>  raise ValueError('ERROR: id 0 is reserved !! ')
>
>#print self.params
>
>else:
>
> self.params = params
>
> print self.params
>
> # Test all conditions
>
> #case 0 - Default should create {'id': '1','name': 's-1'}
> #s0 = System()
>
> #Case 1 (id has value '0')
> #test1_params = {'id': '0', 'name': 's-0'}
> #s1 = System(params=test1_params)
>
>
> #Case 2 (id has some other values)
> #test2_params = {'id': '10', 'name': 's-10'}
> #s2 = System(params=test2_params)
>
>
> Question:
>
> I have to initialize the values the below class such that
>
>  1.  Intitalize  default values if nothing is supplied by the username
i.e
> self.params = {'id': '1', 'name': 's-1'}
>
> 2. I need to raise an Exception if the value for the key params[id] is
'0'.
>
> 3. It should work if  params[I'd] has values other than (1) and (2)
>
> Regards,
> Ganesh
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Intitalize values for a class

2018-11-23 Thread Bob Gailer
On Nov 23, 2018 8:42 AM, "Ganesh Pal"  wrote:
>
> Hello team,
>
> I am a python 2.7 user on Linux. I will need feedback on the below program
> as I'm  new to oops .

My feedback is:

Firstly there's a blank line between every line of program text which makes
it hard to read.

Also some statements are spread out over more than one line which also
makes it hard to read.

Secondly this sounds like a homework assignment. Is that true? If so be
aware that we will be glad to help if you tell us where you are stuck but
we won't write the code for you.

Please learn how to write effective questions. You can Google that and find
several good resources.

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


Re: Unable to find newly installed Python 3.7.1

2018-11-23 Thread Peter via Python-list

On 23/11/2018 10:51 PM, Edward Popko wrote:

Snake people:


I'm a Java person and thought to try Python for Windows.
I installed Python 3.7.1 (64-bit) hoping for an IDE, documentation and even
a sample or two.
The python-3.7.1-amd64.exe unpacks and installs fine.
Only problem is I cannot find it. There was no install option to add an
shortcut to the
desktop, there is no C:\ folder, no folder added to Program Files or Program
Files (x86).

I have Windows 10, 64 bit professional

Where did it go? Where is the IDE?


You can find out where the executable is with:

   >>> import sys
   >>> sys.executable
   'C:\\Program Files (x86)\\Python37-32\\python.exe'


(Your location may well be different)
Peter
--
https://mail.python.org/mailman/listinfo/python-list


Re: Odd truth result with in and ==

2018-11-23 Thread John Pote

On 21/11/2018 19:18, Python wrote:

$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

1 in [1,2,3] == True

False

1 in ([1,2,3] == True)

Traceback (most recent call last):
   File "", line 1, in 
TypeError: argument of type 'bool' is not iterable

(1 in [1,2,3]) == True

True

How is the first not equivalent to either one of the second or third?
My expectation is it should produce the same result as the second.  It
*seems* like Python is ignoring the '1 in' part and just giving the
result for '[1,2,3] == True'...  Is this just a bug?

I've followed this thread with interest, as I do with threads like this, 
and learnt a useful detail about Python.


But the following I found unexpected. (Python 3.6 on a Windows 7 64 bit box)

>>> if []: print("Truthy")
...
>>> if [1,2,3]: print("Truthy")
...
Truthy
>>>

from which I concluded [] is Falsey and [1,2,3] is Truthy and the above 
if statements work as expected.


but,

>>> [1,2,3] == True
False
>>>

is unexpected as to my mind as [1,2,3] is 'Truthy' and True has ultimate 
'Truthiness'.


Any ideas? Is there an implicit 'casting' taking place and if so is this 
documented somewhere?


I interpret the above comparison as

>>> bool([1,2,3]) == bool(True)
True
>>>

Thanks everyone.



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


Re: Odd truth result with in and ==

2018-11-23 Thread Chris Angelico
On Sat, Nov 24, 2018 at 11:28 AM John Pote  wrote:
> But the following I found unexpected. (Python 3.6 on a Windows 7 64 bit box)
>
>  >>> if []: print("Truthy")
> ...
>  >>> if [1,2,3]: print("Truthy")
> ...
> Truthy
>  >>>
>
> from which I concluded [] is Falsey and [1,2,3] is Truthy and the above
> if statements work as expected.

This is correct. Empty collections are falsey, non-empty collections are truthy.

> but,
>
>  >>> [1,2,3] == True
> False
>  >>>
>
> is unexpected as to my mind as [1,2,3] is 'Truthy' and True has ultimate
> 'Truthiness'.

This is also correct, because now you're asking if this is EQUAL TO
the specific value "True".

It is true to say that Python is a programming language.
It is true to say that a python is a snake.
It is NOT true to say that these statements are equivalent.

> Any ideas? Is there an implicit 'casting' taking place and if so is this
> documented somewhere?
>
> I interpret the above comparison as
>
>  >>> bool([1,2,3]) == bool(True)
> True
>  >>>

If you want to check if two values have the same truthiness, then this
would be how you do it. (Or you could say "not [1,2,3] == not True",
but that's a bit less clear.) An equality check is not the same. You
would not expect 4 to be equal to 5, but both of them are truthy
values (since they're both nonzero).

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


subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=PIPE) itself hangs/deadlocks (Linux)

2018-11-23 Thread Henrik Bengtsson
I ran into an interesting problem where calling
`subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=PIPE)` hangs and
never returns.

$ python
Python 2.7.9 (default, Apr 23 2015, 22:07:47)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import subprocess
>>> p = subprocess.Popen(['/sbin/ldconfig', '-p'], stdout=subprocess.PIPE)
^CTraceback (most recent call last):
  File "", line 1, in 
  File "/opt/Python/Python-2.7.9/lib/python2.7/subprocess.py", line
710, in __init__
errread, errwrite)
  File "/opt/Python/Python-2.7.9/lib/python2.7/subprocess.py", line
1316, in _execute_child
data = _eintr_retry_call(os.read, errpipe_read, 1048576)
  File "/opt/Python/Python-2.7.9/lib/python2.7/subprocess.py", line
476, in _eintr_retry_call
return func(*args)
KeyboardInterrupt
>>>

Note how I have to send a user interrupt to break out of `subprocess.Popen()`.


TROUBLESHOOTING:

First, it's interesting to note that the following works:

>>> import subprocess
>>> p = subprocess.Popen(['/sbin/ldconfig -p'], stdout=subprocess.PIPE, 
>>> shell=True)
>>> out,err = p.communicate()
>>> len(out)
102460
>>>

which I believe is the same as:

>>> import subprocess
>>> p = subprocess.Popen(['sh', '-c', '/sbin/ldconfig -p'], 
>>> stdout=subprocess.PIPE)
>>> out,err = p.communicate()
>>> len(out)
102460
>>>

which also works.



Second, calling:

>>> import subprocess
>>> p = subprocess.Popen(['/sbin/ldconfig', '-p'])
1562 libs found in cache `/etc/ld.so.cache'
libzmq.so.1 (libc6,x86-64) => /usr/lib64/libzmq.so.1
libz.so.1 (libc6,x86-64) => /lib64/libz.so.1
[ ... all 102,460 bytes of ldconfig -p output ...]
ld-linux-x86-64.so.2 (libc6,x86-64) => /lib64/ld-linux-x86-64.so.2
>>>

also works, so the PIPE is my main suspect.


Finally, if I do:

>>> import subprocess
>>> p = subprocess.Popen(['/sbin/ldconfig', '-p'], stdout=subprocess.PIPE)

   [ manually pkill -INT ldconfig' ]

>>> out,err = p.communicate()
>>> len(out)
65536
>>>

then I notice that it reads exactly 65,536=2^16 bytes (out of 102,460
bytes).  I suspect this is related to the default buffer-size limit of
pipes set by the Linux kernel.  Using `strace` on the latter Python
process, reveals:

[...]
open("/opt/Python/Python-2.7.9/lib/python2.7/lib-dynload/cStringIO.so",
O_RDONLY) = 6
read(6, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0@\32\0\0\0\0\0\0"...,
832) = 832
fstat(6, {st_mode=S_IFREG|0755, st_size=49556, ...}) = 0
mmap(NULL, 2115000, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 6,
0) = 0x2ad3ca6e7000
mprotect(0x2ad3ca6eb000, 2093056, PROT_NONE) = 0
mmap(0x2ad3ca8ea000, 8192, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 6, 0x3000) = 0x2ad3ca8ea000
close(6)= 0
close(5)= 0
close(4)= 0
getrlimit(RLIMIT_NOFILE, {rlim_cur=64*1024, rlim_max=64*1024}) = 0
close(3)= 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x2ad3ca8ec000
write(1, "1\n", 21
)  = 2
pipe([3, 4])= 0
fcntl(3, F_GETFD)   = 0
fcntl(3, F_SETFD, FD_CLOEXEC)   = 0
fcntl(4, F_GETFD)   = 0
fcntl(4, F_SETFD, FD_CLOEXEC)   = 0
pipe([5, 6])= 0
fcntl(5, F_GETFD)   = 0
fcntl(5, F_SETFD, FD_CLOEXEC)   = 0
fcntl(6, F_GETFD)   = 0
fcntl(6, F_SETFD, FD_CLOEXEC)   = 0
clone(child_stack=0,
flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD,
child_tidptr=0x2ad3c972adf0) = 239074
close(6)= 0
mmap(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0) = 0x2ad3ca8ed000
read(5,

and `strace` on the stalled `ldconfig` process reveals:

  $ strace -p $(pgrep ldconfig)
Process 239074 attached - interrupt to quit
write(1, "ibgconfmm-2.6.so.1 (libc6,x86-64"..., 4096
 RH  6.6 0:-  1:-* 2:--

That latter `write()` contains the bytes after position 65,536, i.e.
bytes 65,537 and beyond (not shown, but verified after careful
inspection).


MY CONCLUSION:

To me, this looks like a deadlock in Popen() itself - is that correct?


SESSION INFORMATION:

All of the above is with Python 2.7.9 (installed from EPEL), but I can
also reproduce it with Python 2.7.15 installed from source.

What is also useful to know, is that I'm observing this on a legacy
RHEL 6 system *with a customized kernel* part of the Scyld ClusterWare
(https://www.penguincomputing.com/products/software/scyld-clusterware/)
that *cannot* be updated:

$ uname -a
Linux n6 2.6.32-504.12.2.el6.664g.x86_64 #1 SMP Wed Mar 11
14:20:51 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux


I appreciate any suggestions to further troubleshoot this and ideally
resolve it.  The reason for this being an impor

Re: Intitalize values for a class

2018-11-23 Thread Ganesh Pal
On Fri, Nov 23, 2018, 19:30 Bob Gailer  What kind of feedback do you want?
>
Wanted to know if there is any problem in the code and if you can review it
:-)

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


Re: subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=PIPE) itself hangs/deadlocks (Linux)

2018-11-23 Thread INADA Naoki
Thank you for a very informative report.

> PS. This is my first post to this list - please let me know if I
> should send to another forum instead.

Would you send this report to the issue tracker?
https://bugs.python.org/

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


Re: Odd truth result with in and ==

2018-11-23 Thread Alan Bawden
Chris Angelico  writes:

> Or you could say "not [1,2,3] == not True",
> but that's a bit less clear

It's less clear in more ways than one:

   3.6> not [1,2,3] == not True
 File "", line 1
   not [1,2,3] == not True
^
   SyntaxError: invalid syntax
   3.6> not [1,2,3] == (not True)
   True
   3.6> not [] == (not True)
   True
   3.6> (not []) == (not True)
   False

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


Re: subprocess.Popen(['/sbin/ldconfig', '-p'], stdin=PIPE) itself hangs/deadlocks (Linux)

2018-11-23 Thread Henrik Bengtsson
Ok, thanks. I've just created https://bugs.python.org/issue35305. /Henrik
On Fri, Nov 23, 2018 at 6:47 PM INADA Naoki  wrote:
>
> Thank you for a very informative report.
>
> > PS. This is my first post to this list - please let me know if I
> > should send to another forum instead.
>
> Would you send this report to the issue tracker?
> https://bugs.python.org/
>
> --
> INADA Naoki  
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Odd truth result with in and ==

2018-11-23 Thread Frank Millman
"John Pote"  wrote in message 
news:e0a8e1bc-6e03-e42b-d6e8-d690e2d5a...@jptechnical.co.uk...


I interpret the above comparison as

 >>> bool([1,2,3]) == bool(True)
True
 >>>



A tiny addition to what has already been said.

As True is by definition a boolean, you can write this as


bool([1, 2, 3]) == True

True




I have on vary rare occasions had to convert 'truthiness' to an actual 
boolean, and this is how I do it.


Frank Millman






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


help me in a program in python to implement Railway Reservation System using file handling technique.

2018-11-23 Thread jasminamrutia007
hello all,
 please hepl me in the above program. python to implement Railway Reservation 
System using file handling technique.

System should perform below operations.
a. Reserve a ticket for a passenger.
b. List information all reservations done for today’s trains.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: help me in a program in python to implement Railway Reservation System using file handling technique.

2018-11-23 Thread Chris Angelico
On Sat, Nov 24, 2018 at 5:36 PM  wrote:
>
> hello all,
>  please hepl me in the above program. python to implement Railway Reservation 
> System using file handling technique.
>
> System should perform below operations.
> a. Reserve a ticket for a passenger.
> b. List information all reservations done for today’s trains.

We won't do your homework for you. Have a shot at writing it yourself
first, and then if you need help, bring specific questions to the
list.

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