$5 Campaign - Packt Publishing

2015-12-23 Thread gavin . packt
Hey,

Packt Publishing is inviting the tech world to explore its extensive library of 
eBooks and video courses for one amazing price. For the rest of December and 
into the New Year, every single eBook and video course Packt has ever created 
will be available on the publisher's website for just $5!

Check it out: http://bit.ly/1O8QkNG

Offer lasts till 8th Jan, 2016.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why doesn't os.remove work on directories?

2015-12-23 Thread eryk sun
On Tue, Dec 22, 2015 at 10:29 PM, Random832  wrote:
>
> This is surprising to anyone accustomed to the POSIX C remove
> function, which can remove either files or directories.  Is there
> any known rationale for this decision?

Guido added os.remove as a synonym for os.unlink in version 1.4 (1996)
[1]. This is also mentioned in the NEWS for 1.4b1 [2].

Note that C99 only specifies the behavior for files, as opposed to the
extended unlink/rmdir that POSIX mandates [3].

7.19.4.1 The remove function
Synopsis
1
#include 
int remove(const char *filename);
Description
2
The remove function causes the file whose name is the string
pointed to by filename to be no longer accessible by that
name. A subsequent attempt to open that file using that name
will fail, unless it is created anew. If the file is open,
the behavior of the remove function is implementation-
defined.
Returns
3
The remove function returns zero if the operation succeeds,
nonzero if it fails.

For Windows, the CRTs remove() function doesn't implement the extended
POSIX behavior. It only calls DeleteFile, not RemoveDirectory. (In
contrast the native NtDeleteFile [4] works for both files and
directories, and relative to an open handle like unlinkat.)

[1]: https://hg.python.org/cpython/rev/9fa2228bb096
[2]: https://hg.python.org/cpython/file/v1.4/Misc/NEWS#l565
[3]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/remove.html
[4]: https://msdn.microsoft.com/en-us/library/ff566435
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: $5 Campaign - Packt Publishing

2015-12-23 Thread Paul Rubin
gavin.pa...@gmail.com writes:
> Packt Publishing is inviting the tech world to explore its extensive...

This looks like affiliate spam (shortened link omitted).  Direct link:

  https://www.packtpub.com

They do have some good stuff there.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: convert to python code

2015-12-23 Thread Steven D'Aprano
On Wed, 23 Dec 2015 03:14 pm, Rodrick Brown wrote:

> Tried a few things but can't seem to get it right any help ?
> 
> let times = (...matrices) =>
> 
>   matrices.reduce(
> 
> ([a,b,c], [d,e,f]) => [a*d + b*e, a*e + b*f, b*e + c*f]
> 
>   );


Are you expecting us to guess what language this is written in, decipher
what it does, and write Python code to do the same thing?

How about if you tell us the language and explain what it does?


-- 
Steven

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


object() can't have attributes

2015-12-23 Thread Neal Becker
I'm a bit surprised that an object() can't have attributes:

In [30]: o = object()

In [31]: o.x = 2
---
AttributeErrorTraceback (most recent call last)
 in ()
> 1 o.x = 2

AttributeError: 'object' object has no attribute 'x'

Sometimes I want to collect attributes on an object.  Usually I would make 
an empty class for this.  But it seems unnecessarily verbose to do this.  So 
I thought, why not just use an Object?  But no, an instance of Object 
apparantly can't have an attribute.  Is this intentional?

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


Unable to use python 3.5

2015-12-23 Thread Ankit Deshmukh
Hi there,



I am maters student in India, I have installed python 3.5 in my windows 10
64bit machine. Everything works fine except package installing. When in use
“pip install numpy” is shows unable to find *‘vcvarsall.bat’* I don’t know
how to fix it. I tried several things nothing works.



Please help me.

Thank You.



Ankit Deshmukh

-- 
*Ankit Deshmukh*
IIT Hyderabad
P: 9581540937 || E:ankit 7a...@gmail.com 
--

*Simplicity is the ultimate sophisticationLeonardo da Vinci*
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to use python 3.5

2015-12-23 Thread Chris Angelico
On Wed, Dec 23, 2015 at 5:38 PM, Ankit Deshmukh  wrote:
> I am maters student in India, I have installed python 3.5 in my windows 10
> 64bit machine. Everything works fine except package installing. When in use
> “pip install numpy” is shows unable to find *‘vcvarsall.bat’* I don’t know
> how to fix it. I tried several things nothing works.

Try grabbing a binary from here:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

Otherwise, pip tries to compile numpy from source, which you probably
aren't set up to do.

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


Re: object() can't have attributes

2015-12-23 Thread Chris Angelico
On Wed, Dec 23, 2015 at 11:46 PM, Neal Becker  wrote:
> Sometimes I want to collect attributes on an object.  Usually I would make
> an empty class for this.  But it seems unnecessarily verbose to do this.  So
> I thought, why not just use an Object?  But no, an instance of Object
> apparantly can't have an attribute.  Is this intentional?

Yes; there are other uses of object() that benefit from being
extremely compact. You can use types.SimpleNamespace for this job, or
you can create the empty class as you're describing. (Chances are you
can give the class a meaningful name anyway.)

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


Re: Unable to use python 3.5

2015-12-23 Thread Chris Warrick
On 23 December 2015 at 07:38, Ankit Deshmukh  wrote:
> Hi there,
>
>
>
> I am maters student in India,

We don’t care (expect that you made a typo there).

> I have installed python 3.5 in my windows 10
> 64bit machine. Everything works fine except package installing. When in use
> “pip install numpy” is shows unable to find *‘vcvarsall.bat’* I don’t know
> how to fix it. I tried several things nothing works.

You clearly haven’t tried enough, as this question is answered by a
simple Google search. You need to:

(a) install Visual Studio 2015 and configure it; or
(b) find a binary package, eg. here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/

A student who wants to work in programming should be able to find
answers to their questions online. And know better than putting a
phone number in their e-mail signature for the whole world to see.

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to use python 3.5

2015-12-23 Thread Glenn Hutchings
On Wednesday, 23 December 2015 12:46:43 UTC, Ankit Deshmukh  wrote:
> I am maters student in India, I have installed python 3.5 in my windows 10
> 64bit machine. Everything works fine except package installing. When in use
> "pip install numpy" is shows unable to find *'vcvarsall.bat'* I don't know
> how to fix it. I tried several things nothing works.

You might find the following useful (I had the same problem):

http://stackoverflow.com/questions/2817869/error-unable-to-find-vcvarsall-bat
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unable to open IDLE for Python3.50rc1 on windows10 64bit AMD

2015-12-23 Thread Nicky Mac
slight progress:
i reinstalled ticking precompile options in the "Advanced features".
Now I get this:
icrosoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\Nick>python -m idlelib
C:\Python\Python35\python.exe: Error while finding spec for
'idlelib.__main__' (: bad magic number in 'idlelib':
b'\x03\xf3\r\n'); 'idlelib' is a package and cannot be directly executed

any help hugely appreciated!
season's greetings
Nick

On 22 December 2015 at 20:27, Nicky Mac  wrote:

> I have run the install (and repair) which explicitly includes Tcl/Tk and l
> have this problem:
>
> Microsoft Windows [Version 10.0.10586] (c) 2015 Microsoft Corporation. All
> rights reserved.
>
> >C:\Python\Python35\python.exe -m idlelib
> ** IDLE can't import Tkinter.
> Your Python may not be configured for Tk. **
>
> Please suggest how this can be fixed
> any support greatly appreciated
>
> Nick  McElwaine
>



-- 
Nick "Mac" McElwaine
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Unable to use python 3.5

2015-12-23 Thread Mark Lawrence

On 23/12/2015 06:38, Ankit Deshmukh wrote:

Hi there,

I am maters student in India, I have installed python 3.5 in my windows 10
64bit machine. Everything works fine except package installing. When in use
“pip install numpy” is shows unable to find *‘vcvarsall.bat’* I don’t know
how to fix it. I tried several things nothing works.

Please help me.

Thank You.

Ankit Deshmukh



Welcome to this list and, regretably, one of the worst aspects of Python.

You can download numpy-1.9.3+mkl-cp35-none-win_amd64.whl from 
http://www.lfd.uci.edu/~gohlke/pythonlibs/ and use pip to install the 
.whl file.


Another option is to get a version of Python with a preloaded scientific 
stack, see here http://www.scipy.org/install.html for several choices.


Then you can always install Visual Studio 2015 Community Edition.  That 
will take hours, should get rid of the infamous "unable to find 
*‘vcvarsall.bat’*" message but still isn't guaranteed to work, so 
strangely I don't recommend it.


--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

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


Re: Unable to use python 3.5

2015-12-23 Thread Steven D'Aprano
On Thu, 24 Dec 2015 12:00 am, Chris Warrick wrote:

> And know better than putting a
> phone number in their e-mail signature for the whole world to see.

You mean, like putting their phone number in the phone book, e-card or
website for the whole world to see?


-- 
Steven

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


Re: Unable to use python 3.5

2015-12-23 Thread Aaron Christensen
Wow, you can find cyber bullies just about anywhere...

On Wed, Dec 23, 2015 at 8:00 AM, Chris Warrick  wrote:

> On 23 December 2015 at 07:38, Ankit Deshmukh  wrote:
> > Hi there,
> >
> >
> >
> > I am maters student in India,
>
> We don’t care (expect that you made a typo there).
>
> > I have installed python 3.5 in my windows 10
> > 64bit machine. Everything works fine except package installing. When in
> use
> > “pip install numpy” is shows unable to find *‘vcvarsall.bat’* I don’t
> know
> > how to fix it. I tried several things nothing works.
>
> You clearly haven’t tried enough, as this question is answered by a
> simple Google search. You need to:
>
> (a) install Visual Studio 2015 and configure it; or
> (b) find a binary package, eg. here:
> http://www.lfd.uci.edu/~gohlke/pythonlibs/
>
> A student who wants to work in programming should be able to find
> answers to their questions online. And know better than putting a
> phone number in their e-mail signature for the whole world to see.
>
> --
> Chris Warrick 
> PGP: 5EAAEA16
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unable to open IDLE for Python3.50rc1 on windows10 64bit AMD

2015-12-23 Thread eryk sun
On Wed, Dec 23, 2015 at 7:16 AM, Nicky Mac  wrote:
> C:\Python\Python35\python.exe: Error while finding spec for
> 'idlelib.__main__' (: bad magic number in 'idlelib':
> b'\x03\xf3\r\n'); 'idlelib' is a package and cannot be directly executed

0xf303 (62211) is for Python 2.7. Make sure you don't have the
environment variables PYTHONHOME or PYTHONPATH defined.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: object() can't have attributes

2015-12-23 Thread Irmen de Jong
On 23-12-2015 13:58, Chris Angelico wrote:
> On Wed, Dec 23, 2015 at 11:46 PM, Neal Becker  wrote:
>> Sometimes I want to collect attributes on an object.  Usually I would make
>> an empty class for this.  But it seems unnecessarily verbose to do this.  So
>> I thought, why not just use an Object?  But no, an instance of Object
>> apparantly can't have an attribute.  Is this intentional?
> 
> Yes; there are other uses of object() that benefit from being
> extremely compact. You can use types.SimpleNamespace for this job, or
> you can create the empty class as you're describing. (Chances are you
> can give the class a meaningful name anyway.)
> 
> ChrisA
> 

Hey, nice, didn't know about SimpleNamespace. I was about to suggest
collections.namedtuple but that one is probably more than Neal asked for.

Alternatively, you can still put attributes on a function, so this works as 
well (but I
think it's rather ugly):

thing = lambda: None
thing.attr = 42
vars(thing)   #  {'attr': 42}


-irmen

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


Re: object() can't have attributes

2015-12-23 Thread Chris Angelico
On Thu, Dec 24, 2015 at 2:49 AM, Irmen de Jong  wrote:
> Hey, nice, didn't know about SimpleNamespace. I was about to suggest
> collections.namedtuple but that one is probably more than Neal asked for.
>
> Alternatively, you can still put attributes on a function, so this works as 
> well (but I
> think it's rather ugly):
>
> thing = lambda: None
> thing.attr = 42
> vars(thing)   #  {'attr': 42}

If you can't use SimpleNamespace (eg you need to support pre-3.3), the
easiest way is an empty class:

class SimpleNamespace(object): pass

This will work in all versions of Python back to... I dunno,
2.something, maybe 1.x. Or, of course, you could lift the pure-Python
definition of SimpleNamespace from the docs and use that :)

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


Re: object() can't have attributes

2015-12-23 Thread Chris Angelico
On Wed, Dec 23, 2015 at 11:46 PM, Neal Becker  wrote:
> I'm a bit surprised that an object() can't have attributes:
>
> In [30]: o = object()
>
> In [31]: o.x = 2
> ---
> AttributeErrorTraceback (most recent call last)
>  in ()
> > 1 o.x = 2
>
> AttributeError: 'object' object has no attribute 'x'

BTW, the reason for this is that the base 'object' type doesn't have a
__dict__. When you create a subclass, you get a __dict__ by default;
but you can override this.

$ python3
Python 3.6.0a0 (default:6e114c4023f5, Dec 20 2015, 19:15:28)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> object().__dict__
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'object' object has no attribute '__dict__'
>>> import sys
>>> class NS(object): pass
...
>>> class empty(object): __slots__ = ()
...
>>> sys.getsizeof(object())
16
>>> sys.getsizeof(NS())
56
>>> sys.getsizeof(empty())
16

The cost of supporting arbitrary attributes is significant. It's
common enough in custom classes that you have to explicitly ask for
the cut-down version, but when all you need is a sentinel, that's a
slab of memory and functionality that you just don't need, so it's not
there.

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


Re: object() can't have attributes

2015-12-23 Thread Zachary Ware
On Dec 23, 2015 7:00 AM, "Chris Angelico"  wrote:
> On Wed, Dec 23, 2015 at 11:46 PM, Neal Becker  wrote:
> > Sometimes I want to collect attributes on an object.  Usually I would make
> > an empty class for this.  But it seems unnecessarily verbose to do this.  So
> > I thought, why not just use an Object?  But no, an instance of Object
> > apparantly can't have an attribute.  Is this intentional?
>
> Yes; there are other uses of object() that benefit from being
> extremely compact. You can use types.SimpleNamespace for this job, or
> you can create the empty class as you're describing. (Chances are you
> can give the class a meaningful name anyway.)

Its more that if you give object() an instance dict, all objects
inheriting from object (i.e., all of them) must have an instance dict,
which would make __slots__ and its benefits impossible.

Another cross-version option:

   >>> bag = type("AttrBag", (), {})()
   >>> bag.spam = 2
   >>> bag.spam
   2

You can even sneak in keyword arguments like SimpleNamespace supports
by passing them in the namespace dict (the third argument):

   >>> bag = type("AttrBag", (), dict(spam=3))()
   >>> bag.spam
   3

Of course, using this you lose easy access to the 'AttrBag' class, but
in most cases you shouldn't need it.  If you do, just make it a
regular class as has been suggested, or save off a reference to the
class before instantiating.

No comments on how ugly this is, though :)

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


Re: Unable to use python 3.5

2015-12-23 Thread Lele Gaifax
Chris Warrick  writes:

>> I am maters student in India,
>
> We don’t care (expect that you made a typo there).

Oh, really? Surprisingly, he's not alone :-)

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Re: Unable to use python 3.5

2015-12-23 Thread Ben Finney
Chris Warrick  writes:

> On 23 December 2015 at 07:38, Ankit Deshmukh  wrote:
> > I am maters student in India,
>
> We don’t care (expect that you made a typo there).
>
> > […] When in use “pip install numpy” is shows unable to find
> > *‘vcvarsall.bat’* I don’t know how to fix it. I tried several things
> > nothing works.
>
> You clearly haven’t tried enough, as this question is answered by a
> simple Google search. […]
>
> A student who wants to work in programming should be able to find
> answers to their questions online. And know better than putting a
> phone number in their e-mail signature for the whole world to see.

Chris, I found your response to be needlessly condescending and hostile
to a newcomer. The original request was well-formed, and did not warrant
such a slap-down.

Please work to keep our community welcoming, and assume good faith in
newcomers.

-- 
 \ “Do unto others twenty-five percent better than you expect them |
  `\  to do unto you. (The twenty-five percent is [to correct] for |
_o__)error.)” —Linus Pauling's Golden Rule |
Ben Finney

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


Re: unable to open IDLE for Python3.50rc1 on windows10 64bit AMD

2015-12-23 Thread eryk sun
On Wed, Dec 23, 2015 at 8:38 AM, Nicky Mac  wrote:
>
> I removed the old python2.7 entries in system Path, the PYTHON variables you
> mentioned are not present.
> All I have is Python35 in the PATH.

Maybe there's still a stale directory on sys.path for another reason.
Print sys.path from the command prompt:

python -c "import sys; print(*sys.path, sep='\n')"

P.S. Please reply to the list also this time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unable to open IDLE for Python3.50rc1 on windows10 64bit AMD

2015-12-23 Thread Nicky Mac
dear Python team
thanks for your amazing support!
no sign of old Py2.7 anywhere :-

C:\Users\Nick>python -c "import sys; print(*sys.path, sep='\n')"

C:\Python\Python35\python35.zip
C:\Python\Python35\DLLs
C:\Python\Python35\lib
C:\Python\Python35
C:\Python\Python35\lib\site-packages


On 23 December 2015 at 19:30, eryk sun  wrote:

> On Wed, Dec 23, 2015 at 8:38 AM, Nicky Mac  wrote:
> >
> > I removed the old python2.7 entries in system Path, the PYTHON variables
> you
> > mentioned are not present.
> > All I have is Python35 in the PATH.
>
> Maybe there's still a stale directory on sys.path for another reason.
> Print sys.path from the command prompt:
>
> python -c "import sys; print(*sys.path, sep='\n')"
>
> P.S. Please reply to the list also this time.
>



-- 
Nick "Mac" McElwaine
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: unable to open IDLE for Python3.50rc1 on windows10 64bit AMD

2015-12-23 Thread eryk sun
On Wed, Dec 23, 2015 at 1:51 PM, Nicky Mac  wrote:
>
> no sign of old Py2.7 anywhere :-
>
> C:\Users\Nick>python -c "import sys; print(*sys.path, sep='\n')"
>
> C:\Python\Python35\python35.zip
> C:\Python\Python35\DLLs
> C:\Python\Python35\lib
> C:\Python\Python35
> C:\Python\Python35\lib\site-packages

The first blank entry is for the current directory. Do you maybe have
an old "idlelib" directory in your profile?

Print what it's attempting to load:

python -c "import importlib; print(importlib.find_loader('idlelib').path)"
-- 
https://mail.python.org/mailman/listinfo/python-list


What interface is a ‘Popen.stdout’ presenting?

2015-12-23 Thread Ben Finney
Howdy all,

When I want to wrap a binary stream to provide a text stream, such as
the ‘Popen.stdout’ attribute from a subprocess, I can use
‘io.TextIOWrapper’.

That works on Python 3::

$ python3
Python 3.4.4rc1 (default, Dec  7 2015, 11:09:54)
[GCC 5.3.1 20151205] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> import io
>>> gnupg_subprocess = subprocess.Popen(["/usr/bin/gpg", "--version"], 
stdout=subprocess.PIPE)
>>> gnupg_stdout = io.TextIOWrapper(gnupg_subprocess.stdout)
>>> type(gnupg_stdout)


but not Python 2::

$ python2
Python 2.7.11 (default, Dec  9 2015, 00:29:25)
[GCC 5.3.1 20151205] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> import io
>>> gnupg_subprocess = subprocess.Popen(["/usr/bin/gpg", "--version"], 
stdout=subprocess.PIPE)
>>> gnupg_stdout = io.TextIOWrapper(gnupg_subprocess.stdout)
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'file' object has no attribute 'readable'

I'm trying to write code that, as far as practicable, works unchanged on
Python 2 and Python 3.

How do I wrap an arbitrary byte stream – already opened, such as a
‘Popen.stdout’ attribute – in a text wrapper with a particular encoding?

-- 
 \“With Lisp or Forth, a master programmer has unlimited power |
  `\ and expressiveness. With Python, even a regular guy can reach |
_o__)   for the stars.” —Raymond Hettinger |
Ben Finney

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


Re: What interface is a ‘Popen.stdout’ presenting?

2015-12-23 Thread Ben Finney
I left the Subject field with the wrong question. The immediate answer
is “it presents the ‘file’ interface”. The consequent questions remain:

Ben Finney  writes:

> $ python2
[…]
> >>> gnupg_stdout = io.TextIOWrapper(gnupg_subprocess.stdout)
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'file' object has no attribute 'readable'
>
> I'm trying to write code that, as far as practicable, works unchanged
> on Python 2 and Python 3.
>
> How do I wrap an arbitrary byte stream – already opened, such as a
> ‘Popen.stdout’ attribute – in a text wrapper with a particular
> encoding?

It appears the Python 2 ‘file’ type doesn't implement a “buffer” as
expected by ‘io.TextIOWrapper’.

So how do I get from a Python 2 ‘file’ object, to whatever
‘io.TextIOWrapper’ wants?

-- 
 \ “Nature is trying very hard to make us succeed, but nature does |
  `\   not depend on us. We are not the only experiment.” —Richard |
_o__)   Buckminster Fuller, 1978-04-30 |
Ben Finney

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


need some basic help

2015-12-23 Thread Qurrat ul Ainy
Hello,

Can someone please explain this code below. I am new at Python .
Thanks 


def receive_messages(self, msgs, time):
  for msg in msgs:
 msg.set_recv_time(time)
  self.msgs_received.extend(msgs)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: citizens and countries - was Re: v3.5.1 - msi download

2015-12-23 Thread Gregory Ewing

Michael Torrie wrote:

A country in which citizens only expect things from the country and
never think about their ability to change and benefit the country is a
week country indeed.

  

Yep, definitely won't last more than 7 days. :-)

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


Re: need some basic help

2015-12-23 Thread Benjamin Kulas
On Wednesday, December 23, 2015 at 7:53:43 PM UTC-6, Qurrat ul Ainy wrote:
> Hello,
> 
> Can someone please explain this code below. I am new at Python .
> Thanks 
> 
> 
> def receive_messages(self, msgs, time):
>   for msg in msgs:
>  msg.set_recv_time(time)
>   self.msgs_received.extend(msgs)

What exactly are you confused about? This looks like it is part of a class; can 
you post the entire class definition? Also, what is the purpose of the program 
that contains this snippet?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What interface is a ‘Popen.stdout’ presenting?

2015-12-23 Thread eryk sun
On Wed, Dec 23, 2015 at 7:36 PM, Ben Finney  wrote:
> So how do I get from a Python 2 ‘file’ object, to whatever
> ‘io.TextIOWrapper’ wants?

I would dup the file descriptor and close the original file. Then open
the file descriptor using io.open:

>>> p = subprocess.Popen(['uname'], stdout=subprocess.PIPE)
>>> fd = os.dup(p.stdout.fileno())
>>> fd
4
>>> p.stdout.close()
>>> fout = io.open(fd, 'r')
>>> fout
<_io.TextIOWrapper name=4 encoding='UTF-8'>
>>> fout.read()
u'Linux\n'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What interface is a ‘Popen.stdout’ presenting?

2015-12-23 Thread Ben Finney
eryk sun  writes:

> On Wed, Dec 23, 2015 at 7:36 PM, Ben Finney  
> wrote:
> > So how do I get from a Python 2 ‘file’ object, to whatever
> > ‘io.TextIOWrapper’ wants?
>
> I would dup the file descriptor and close the original file. Then open
> the file descriptor using io.open

Thanks. Okay, now I reveal (I apologise for not making this clear
initially) that I need the *same* code to work with pseudo files created
by the unit test suite: files with no underlying file handle.

That is, I need the same code to accept:

* A Python 2 ‘file’ instance as emitted by many stdlib functions.
* A Python 3 ‘io.*’ file object as emitted by many stdlib functions.
* A pseudo-file (e.g. ‘io.BytesIO’) test double.

With any of those, I need the code to wrap a stream already open in
“binary” mode, and give me a wrapper (e.g. ‘io.TextIOWrapper’) to read
and/or write text on that stream.

-- 
 \ “It is hard to believe that a man is telling the truth when you |
  `\  know that you would lie if you were in his place.” —Henry L. |
_o__)  Mencken |
Ben Finney

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


Re: OT: citizens and countries - was Re: v3.5.1 - msi download

2015-12-23 Thread jfong
Michael Torrie at 2015/12/23  UTC+8 12:22:23PM wrote:
> In the American way of thinking, the country *is* the people.  So it was
> neither a lie nor a bad thing that Kennedy proclaimed.  Maybe this is
> not true for other countries, but I think most Americans would feel it
> is true for their country.  And indeed the sentiment that Kennedy
> expressed resonates deeply with many/most Americans. A country is only
> made great by citizens willing to do many things for the good of the
> country and their fellow citizens.

I don't think any country can be "great" if it can't even take care of its own 
people well. American can not be great because of there are millions of 
citizens has no enough food, health cares and living on the street, at the same 
time this country spend billions of dollars on bombing other country's people.

This situation is painful to human mind and it was supposed to be solved by the 
country leaders. But politicians are incapable of doing anything except been 
good on spreading glorious words and sentences. As an anaesthetic to divert 
people from this incapability, these words also make some Americans happy to 
ignore the facts and continuously to believe that American is still a great 
country.
-- 
https://mail.python.org/mailman/listinfo/python-list