Re: Understanding the MRO with multiple inheritance

2019-03-30 Thread Arup Rakshit
Thanks Chris and Dieter. I think I got it. It seems it follows the __mro__ of 
the caller class, not the current class __mro_. 

if __name__ == '__main__':
print('MRO of SortedIntList {}'.format(SortedIntList.__mro__))
print('MRO of IntList {}'.format(IntList.__mro__))

# MRO of SortedIntList (, , , , )
# MRO of IntList (, , 
)

I thought obj.add(0) goes to the IntList by following its factory class 
__mro__, and then it follows the __mro__ of the current class(IntList) which is 
SimpleList .

Thanks again.


Thanks,

Arup Rakshit
[email protected]



> On 30-Mar-2019, at 7:02 AM, Chris Angelico  wrote:
> 
> On Fri, Mar 29, 2019 at 11:54 PM Arup Rakshit  wrote:
>> 
>> Now when I call the add method on the SortedIntList class’s instance, I was 
>> expecting super.add() call inside the IntList class add method will dispatch 
>> it to the base class SimpleList. But in reality it doesn’t, it rather 
>> forwards it to the SortedList add method. How MRO guides here can anyone 
>> explain please?
>> 
> 
> When you call super, you're saying "go to the next in the MRO". You
> can examine the MRO by looking at SortedIntList.__mro__ - that should
> show you the exact order that methods will be called.
> 
> ChrisA
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Why do I need to use pip3 but not pip

2019-03-30 Thread Arup Rakshit
Hi,

When I read this https://pip.pypa.io/en/stable/installing/ it says I have the 
pip installed when I installed the python from official doc. But when I run the 
`pip` command from shell, I get error, but pip3 works.

~/python_playground 
   
▶ pip --version

zsh: command not found: pip

~/python_playground 
  ⍉
▶ pip3 --version

pip 18.1 from 
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip
 (python 3.7)

Do I always need to install using pip3 program then?


Thanks,

Arup Rakshit
[email protected]



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


Re: Why do I need to use pip3 but not pip

2019-03-30 Thread Cameron Simpson

On 30Mar2019 13:50, Arup Rakshit  wrote:
When I read this https://pip.pypa.io/en/stable/installing/ it says I 
have the pip installed when I installed the python from official doc. 
But when I run the `pip` command from shell, I get error, but pip3 
works.


~/python_playground
▶ pip --version

zsh: command not found: pip

~/python_playground 
  ⍉
▶ pip3 --version

pip 18.1 from 
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip
 (python 3.7)


Ok, you've installed python 3 on a Mac.

Historically most systems have shipped with python 2 (from the OS 
vendor, which is Apple in your case), and the "python" command invokes 
Python 2.  So python 3 is installed as the "python3" command to avoid 
confusion.  The "pip" command from your python 3 install looks like it 
is also installed as "pip3" to avoid confusion.



Do I always need to install using pip3 program then?


Yes, that is correct for this particular install.

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


Re: Why do I need to use pip3 but not pip

2019-03-30 Thread Nagy László Zsolt

  Hello,

It depends on the operating system. For example on Ubuntu, the default
python version is still 2.7. When you install both python2.7 and python3
on a system, then usually the "pip" will be a symlink to pip version 2
or 3. The default python interpreter can be different on different systems.

The most portable way to run pip with a given version (AFAIK) is to use
"python -m pip" instead of "pip".

E.g.:

python3 -m pip install PACKAGE_NAME

However, there is still a problem when you have multiple python versions
on the same machine. For example, python3.6 and python3.7. On those
systems, python3 will be a symlink to the default one.

For example:

$ which python
/usr/bin/python
$ ls -lah /usr/bin/python

lrwxrwxrwx 1 root root 9 apr   16  2018 /usr/bin/python -> python2.7

$ which python3 
/usr/bin/python3
$ ls -lah /usr/bin/python3

lrwxrwxrwx 1 root root 9 oct   25 13:11 /usr/bin/python3 -> python3.6

Regards,

   Laszlo


2019. 03. 30. 9:20 keltezéssel, Arup Rakshit írta:
> Hi,
>
> When I read this https://pip.pypa.io/en/stable/installing/ it says I
> have the pip installed when I installed the python from official doc.
> But when I run the `pip` command from shell, I get error, but pip3 works.
>
> ~/python_playground ▶ pip --version
>
> zsh: command not found: pip
>
> ~/python_playground ⍉
> ▶ pip3 --version
>
> pip 18.1 from
> /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip
> (python 3.7)
>
> Do I always need to install using pip3 program then?
>
>
> Thanks,
>
> Arup Rakshit
> [email protected]
>
>
>


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


Re: Understanding the MRO with multiple inheritance

2019-03-30 Thread Chris Angelico
On Sat, Mar 30, 2019 at 7:08 PM Arup Rakshit  wrote:
>
> Thanks Chris and Dieter. I think I got it. It seems it follows the __mro__ of 
> the caller class, not the current class __mro_.

That is correct. It is the object that has an MRO, and it's that
object's MRO that matters to super.

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


Re: Why do I need to use pip3 but not pip

2019-03-30 Thread Arup Rakshit
Hello All,

Thanks I got it now.

One related question: Can I use pip3 for example to install packages project 
specific, but not globally? So that when I delete the project, all of them gone 
also from my disk. 

Thanks,

Arup Rakshit
[email protected]



> On 30-Mar-2019, at 2:05 PM, Cameron Simpson  wrote:
> 
> On 30Mar2019 13:50, Arup Rakshit  wrote:
>> When I read this https://pip.pypa.io/en/stable/installing/ it says I have 
>> the pip installed when I installed the python from official doc. But when I 
>> run the `pip` command from shell, I get error, but pip3 works.
>> 
>> ~/python_playground
>> ▶ pip --version
>> 
>> zsh: command not found: pip
>> 
>> ~/python_playground  
>>  
>> ⍉
>> ▶ pip3 --version
>> 
>> pip 18.1 from 
>> /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip
>>  (python 3.7)
> 
> Ok, you've installed python 3 on a Mac.
> 
> Historically most systems have shipped with python 2 (from the OS vendor, 
> which is Apple in your case), and the "python" command invokes Python 2.  So 
> python 3 is installed as the "python3" command to avoid confusion.  The "pip" 
> command from your python 3 install looks like it is also installed as "pip3" 
> to avoid confusion.
> 
>> Do I always need to install using pip3 program then?
> 
> Yes, that is correct for this particular install.
> 
> Cheers,
> Cameron Simpson 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Why do I need to use pip3 but not pip

2019-03-30 Thread Peter Otten
Arup Rakshit wrote:

> Hello All,
> 
> Thanks I got it now.
> 
> One related question: Can I use pip3 for example to install packages
> project specific, but not globally? So that when I delete the project, all
> of them gone also from my disk.

For that you can create a "virtual environment":

$ python3 -m venv foo
$ cd foo
$ . bin/activate

Once you have activated it you can use 'pip' and 'python' to invoke the 
versions attached to the virtual environment:

(foo) $ pip install example
Downloading/unpacking example
  Downloading example-0.1.0.tar.gz
  Running setup.py (path:/home/petto/foo/build/example/setup.py) egg_info 
for package example

Downloading/unpacking six (from example)
  Downloading six-1.12.0-py2.py3-none-any.whl
Installing collected packages: example, six
  Running setup.py install for example

Successfully installed example six
Cleaning up...
(foo) $ python
Python 3.4.3 (default, Nov 12 2018, 22:25:49) 
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import example
>>>

Let's get rid of it now:

(foo) $ deactivate
$ cd ..
$ rm -r foo  # everything should be gone


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


Re: Why do I need to use pip3 but not pip

2019-03-30 Thread Arup Rakshit
Hi Peter,

This is awesome. Now where should I put my source code? I see many folders into 
it.


Thanks,

Arup Rakshit
[email protected]



> On 30-Mar-2019, at 3:26 PM, Peter Otten <[email protected]> wrote:
> 
> Arup Rakshit wrote:
> 
>> Hello All,
>> 
>> Thanks I got it now.
>> 
>> One related question: Can I use pip3 for example to install packages
>> project specific, but not globally? So that when I delete the project, all
>> of them gone also from my disk.
> 
> For that you can create a "virtual environment":
> 
> $ python3 -m venv foo
> $ cd foo
> $ . bin/activate
> 
> Once you have activated it you can use 'pip' and 'python' to invoke the 
> versions attached to the virtual environment:
> 
> (foo) $ pip install example
> Downloading/unpacking example
>  Downloading example-0.1.0.tar.gz
>  Running setup.py (path:/home/petto/foo/build/example/setup.py) egg_info 
> for package example
> 
> Downloading/unpacking six (from example)
>  Downloading six-1.12.0-py2.py3-none-any.whl
> Installing collected packages: example, six
>  Running setup.py install for example
> 
> Successfully installed example six
> Cleaning up...
> (foo) $ python
> Python 3.4.3 (default, Nov 12 2018, 22:25:49) 
> [GCC 4.8.4] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 import example
 
> 
> Let's get rid of it now:
> 
> (foo) $ deactivate
> $ cd ..
> $ rm -r foo  # everything should be gone
> 
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Library for parsing binary structures

2019-03-30 Thread Paul Moore
On Fri, 29 Mar 2019 at 23:21, Cameron Simpson  wrote:
>
> On 27Mar2019 18:41, Paul Moore  wrote:
> >I'm looking for a library that lets me parse binary data structures.
> >The stdlib struct module is fine for simple structures, but when it
> >gets to more complicated cases, you end up doing a lot of the work by
> >hand (which isn't that hard, and is generally perfectly viable, but
> >I'm feeling lazy ;-))
>
> I wrote my own: cs.binary, available on PyPI. The PyPI page has is
> module docs, which I think are ok:
>
>   https://pypi.org/project/cs.binary/

Nice, thanks - that's exactly the sort of pointer I was looking for.
I'll take a look and see how it works for my use case.

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


Re: Python-list Digest, Vol 186, Issue 31

2019-03-30 Thread Alexey Muranov

On ven., Mar 29, 2019 at 4:51 PM, [email protected] wrote:
On Thu, Mar 28, 2019 at 2:30 PM Alexey Muranov 


wrote:


 On jeu., mars 28, 2019 at 8:57 PM, Terry Reedy  
wrote:

 > Throwing the name away is foolish.  Testing functions is another
 > situation in which function names are needed for proper report.

 My idea however was to have it as an exact synonyme of an 
assignment of

 a lambda. Assignment is an assignment, it should not modify the
 attributs of the value that is being assigned.


There could perhaps be a special case for lambda expressions such 
that,

when they are directly assigned to a variable, Python would use the
variable name as the function name. I expect this could be 
accomplished by
a straightforward transformation of the AST, perhaps even by just 
replacing

the assignment with a def statement.


If this will happen, that is, if in Python assigning a lambda-defined 
function to a variable will mutate the function's attributes, or else, 
if is some "random" syntactically-determined cases


f = ...

will stop being the same as evaluating the right-hand side and 
assigning the result to "f" variable, it will be a fairly good extra 
reason for me to go away from Python.


Since this could just as easily be applied to lambda though, I'm 
afraid it

doesn't offer much of a case for the "f(x)" syntactic sugar.


I did not get this. My initial idea was exactly about introducing a 
syntactic sugar for better readability. I've already understood that 
the use cases contradict PEP 8 recommendations.


Alexey.


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


Re: Syntax for one-line "nonymous" functions in "declaration style"

2019-03-30 Thread Alexey Muranov



On ven., Mar 29, 2019 at 4:51 PM, [email protected] wrote:
On Thu, Mar 28, 2019 at 2:30 PM Alexey Muranov 


wrote:


 On jeu., mars 28, 2019 at 8:57 PM, Terry Reedy  
wrote:

 > Throwing the name away is foolish.  Testing functions is another
 > situation in which function names are needed for proper report.

 My idea however was to have it as an exact synonyme of an 
assignment of

 a lambda. Assignment is an assignment, it should not modify the
 attributs of the value that is being assigned.


There could perhaps be a special case for lambda expressions such 
that,

when they are directly assigned to a variable, Python would use the
variable name as the function name. I expect this could be 
accomplished by
a straightforward transformation of the AST, perhaps even by just 
replacing

the assignment with a def statement.


If this will happen, that is, if in Python assigning a lambda-defined 
function to a variable will mutate the function's attributes, or else, 
if is some "random" syntactically-determined cases


   f = ...

will stop being the same as evaluating the right-hand side and 
assigning the result to "f" variable, it will be a fairly good extra 
reason for me to go away from Python.


Since this could just as easily be applied to lambda though, I'm 
afraid it

doesn't offer much of a case for the "f(x)" syntactic sugar.


I did not get this. My initial idea was exactly about introducing a 
syntactic sugar for better readability. I've already understood that 
the use cases contradict PEP 8 recommendations.


Alexey.




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


Re: Why do I need to use pip3 but not pip

2019-03-30 Thread Peter J. Holzer
On 2019-03-30 15:57:55 +0530, Arup Rakshit wrote:
> This is awesome. Now where should I put my source code? I see many folders 
> into it.

You don't. In my opinion virtual environments should be expendable: You
can destroy and recreate them at will. That leaves two possibilies:

1) Use a "central repository" of virtual environments. For example, I
   have a directory ~/venv/ which contains the virtual environments.

   My project directories are elsewhere, so when I'm working on a
   project, I' usually do something like:
% venv project-environment
% cd ~/wrk/project/src
% pip install -r requirements.txt 
   The first (venv is a litte shell function I wrote, see below)
   activates the environment, the second cds to the source code (note
   that the environment and the project don't have to have the same
   name, although they often do), the third installs any required
   packages into the virtual environment (of course I do that only after
   they change, not every time).

2) Put each virtual environment into a subdirectory of the project, like
   this:
.
├── project1
│   ├── src
│   └── venv
└── project2
├── src
└── venv

   Then I would do something like:
% cd project1
% venv
% cd src
% pip install -r requirements.txt

I started with the second method and switched to the first. I like the
flexibility: I can reuse the same environment for multiple projects or
test the same project in multiple environments. I can also easily see
which environments I have and delete them if I don't need them any more
(I can always recreate them with pip install -r requirements.txt)

The requirements.txt file contains the packages your project needs.
Every project should have one. Some people like to generate it
automatically with "pip freeze", but I prefer to write it myself and put
only first-level requirements (not requirements of those requirements)
into it. I also only put version numbers into it if I know that I need a
specific version (or range of versions). Normally getting the newest
version is fine.

Finally, here is my venv function:

venv() {
for d in venv/"$1" ve/"$1" ~/venv/"$1" "$1"
do
if [ -f "$d"/bin/activate ]
then
. "$d"/bin/activate
break
fi
done
}


hp

-- 
   _  | Peter J. Holzer| we build much bigger, better disasters now
|_|_) || because we have much more sophisticated
| |   | [email protected] | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson 


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


Re: Syntax for one-line "nonymous" functions in "declaration style"

2019-03-30 Thread Ian Kelly
On Sat, Mar 30, 2019, 5:32 AM Alexey Muranov 
wrote:

>
> On ven., Mar 29, 2019 at 4:51 PM, [email protected] wrote:
> >
> > There could perhaps be a special case for lambda expressions such
> >  that,
> > when they are directly assigned to a variable, Python would use the
> > variable name as the function name. I expect this could be
> >  accomplished by
> > a straightforward transformation of the AST, perhaps even by just
> >  replacing
> > the assignment with a def statement.
>
> If this will happen, that is, if in Python assigning a lambda-defined
> function to a variable will mutate the function's attributes, or else,
> if is some "random" syntactically-determined cases
>
> f = ...
>
> will stop being the same as evaluating the right-hand side and
> assigning the result to "f" variable, it will be a fairly good extra
> reason for me to go away from Python.
>

Is there a particular reason you don't like this? It's not too different
from the syntactic magic Python already employs to support the 0-argument
form of super().
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Library for parsing binary structures

2019-03-30 Thread Cameron Simpson

On 30Mar2019 10:29, Paul Moore  wrote:

On Fri, 29 Mar 2019 at 23:21, Cameron Simpson  wrote:


On 27Mar2019 18:41, Paul Moore  wrote:
>I'm looking for a library that lets me parse binary data structures.
>The stdlib struct module is fine for simple structures, but when it
>gets to more complicated cases, you end up doing a lot of the work by
>hand (which isn't that hard, and is generally perfectly viable, but
>I'm feeling lazy ;-))

I wrote my own: cs.binary, available on PyPI. The PyPI page has is
module docs, which I think are ok:

  https://pypi.org/project/cs.binary/


Nice, thanks - that's exactly the sort of pointer I was looking for.
I'll take a look and see how it works for my use case.


I'd be happy to consider adapting some stuff for your use cases; as you 
may imagine it is written to my use cases.


Also, I should point you at the cs.binary.structtuple factory, which 
makes a class for those structures trivially defined with a struct 
format string. As it uses struct for the parse step and transcribe 
steps, so it should be performant. Here's an example from the 
cs.iso14496 module:


 PDInfo = structtuple('PDInfo', '>LL', 'rate initial_delay')

which makes a PDInfo class for 2 big endian unsigned longs with .rate 
and .initial_delay attributes.


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


Re: Getting file extensions [linux fs]

2019-03-30 Thread Paulo da Silva
Às 22:18 de 28/03/19, Cameron Simpson escreveu:
> On 28Mar2019 01:12, Paulo da Silva  wrote:
>> Às 23:09 de 27/03/19, Cameron Simpson escreveu:
...

> 
> Oh, just tangential to this.
> 
> If you were doing this ad hoc, yes calling the filefrag executable is
> very expensive. But if you are always doing a large batch of filenames
> invoking:
> 
>  filefrag lots of filenames here ...>
> and reading from its output can be very effective, because the expense
> of the executable is amortized over all the files - the per file cost is
> much reduced. And it saves you working out how to use the ioctls from
> Python :-)
That's not the case.
I need to do it on some files basis which I don't know in advance.
Using IOCTL, I don't need to parse or unpack the output. Only compare
the output arrays. Besides I need to store many of the outputs. Doing
that from filefrag text output would be unpractical. I needed, at least,
to compress the data. Although may be I might have to compress the ioctl
arrays ... Let's see how big in average is the storage needed.

I have to go with ioctl. I have to open the files anyway, so there is no
overhead for that when calling the ioctl.

Anyway, thank you for the suggestion.

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