I have some old programs from back in the times when python 3.1 came out.
In the program I often used the Callable()
to pass a function and it's parameters like this to my TKinter application:
tvf.mi(datei_bu, text=datei_opt, command=Callable(exec_datei_opts, datei_opt))
Now I wanted to use my programs again but the callable
- Object was gone. In the web I found that this functionality was removed in python 3.2, and none of the alternatives worked for me.
Finally I decided to reinstall python 3.1. However, I have no idea if it is possible to have multiple python 3 versions installed at the same time or how to 'create' a shell command for this version when I want to use this special version.
My questions are:
Callable
- Object that was removed?Callable looks suspiciously like functools.partial
.
Here's partial at work. when i run:
from functools import partial
from operator import mul
def do_stuff(num, command):
return num + command()
for y in range(5):
print(do_stuff(5, partial(mul, y, 2)))
I get:
5
7
9
11
13
You should be able to do:
from functools import partial
tvf.mi(datei_bu, text=datei_opt, command=partial(exec_datei_opts, datei_opt))
It does not seem that Python ever had Callable
built in. You may have confused it with callable
predicate which indeed was removed and then brought back:
New in version 3.2: This function was first removed in Python 3.0 and then brought back in Python 3.2.
All references of Callable
on the web that I could find point to swampy package (a by-product of Think Python book), which has swampy.Gui.Callable
:
class Callable(object):
"""Wrap a function and its arguments in a callable object.
Callables can can be passed as a callback parameter and invoked later.
This code is adapted from the Python Cookbook 9.1, page 302,
with one change: if call is invoked with args and kwds, they
are added to the args and kwds stored in the Callable.
"""
def __init__(self, func, *args, **kwds):
self.func = func
self.args = args
self.kwds = kwds
def __call__(self, *args, **kwds):
d = dict(self.kwds)
d.update(kwds)
return self.func(*self.args+args, **d)
def __str__(self):
return self.func.__name__
You can also look at answers to this question, where OP wanted to reimplement Callable
for the same purpose.
If you still want to try to install the old version of Python 3, you can give the following a try. I assume that Raspbian is Debian-based distro and the same commands apply. Here's the Dockerfile
that verifies that you can do it on Debian Jessie-compatibe system. You can try the RUN
commands from it in your shell:
FROM debian:jessie
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install --no-install-recommends --yes software-properties-common && \
add-apt-repository ppa:deadsnakes/ppa && \
# The PPA is designed for Ubuntu, but the trick makes it work
# because Debian Jessie is compatible with Ubuntu Trusty #
# on package-level
sed -i 's/jessie/trusty/g' \
/etc/apt/sources.list.d/deadsnakes-ppa-jessie.list && \
apt-get update && \
apt-get install --no-install-recommends --yes python3.1
CMD python3.1
From the terminal
, run with:
python3.1 your_program.py
In terminal , give the path where python 3.1 is installed like this:
/<python3.1 folder>/bin/python filename.py
Alternatively you can try to create virtual environment and activate it then you can run the given script here is the helper link: http://docs.python-guide.org/en/latest/dev/virtualenvs/
Using update-alternatives
command. It can help you use python flexibly.
Here's the sample code.
$ sudo update-alternatives --list python3
update-alternatives: error: no alternatives for python
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.4 1
update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python3 (python3) in auto mode
$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 2
update-alternatives: using /usr/bin/python3.5 to provide /usr/bin/python3 (python3) in auto mode
$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.5 2 auto mode
1 /usr/bin/python3.4 1 manual mode
2 /usr/bin/python3.5 2 manual mode
Press enter to keep the current choice[*], or type selection number:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With