Обновите Python до 2,6 на Mac

Кажется, как будто Вы просите изящный способ взять Dictionary<TKey,TValue> и превратить, это в SortedDictionary<TValue,TKey> (обратите внимание, что значение эти Dictionary является теперь ключом SortedDictionary). Я не вижу, что любой ответ обращается к этому, таким образом, здесь он идет.

Вы могли создать дополнительный метод, который похож на это:

static class Extensions
{
    public static Dictionary<TValue, TKey> 
         AsInverted<TKey, TValue>(this Dictionary<TKey, TValue> source)
    {
        var inverted = new Dictionary<TValue, TKey>();

        foreach (KeyValuePair<TKey, TValue> key in source)
            inverted.Add(key.Value, key.Key);

        return inverted;
    }
}

И Ваш код приложения был бы похож на это:

using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var dict = new Dictionary<String, Double>();
        dict.Add("four", 4);
        dict.Add("three", 3);
        dict.Add("two", 2);
        dict.Add("five", 5);
        dict.Add("one", 1);

        var sortedDict = new SortedDictionary<Double, String>(dict.AsInverted());
    }
}
14
задан Reinstate Monica 3 January 2010 в 22:02
поделиться

7 ответов

Не обновлять.

  1. Установите ActivePython (который сосуществует с другими).
  2. Откройте терминал
  3. Введите python2.6
8
ответ дан 1 December 2019 в 06:39
поделиться

When an OS is distributed with some specific Python release and uses it for some OS functionality (as is the case with Mac OS X, as well as many Linux distros &c), you should not tamper in any way with the system-supplied Python (as in, "upgrading" it and the like): while Python strives for backwards compatibility within any major release (such as 2.* or 3.*, this can never be 100% guaranted; your OS supplied tested all functionality thoroughly with the specific Python version they distribute; if you manage to alter that version, "on your head be it" -- neither your OS supplier nor the PSF accepts any responsibility for whatever damage that might perhaps do to your system.

Rather, as other answers already suggested, install any other release you wish "besides" the system one -- why tamper with that crucial one, and risk breaking things, when installing others is so easy anyway?! On typical Mac OS X 10.5 machines (haven't upgraded any of my several macs to 10.6 yet), I have the Apple-supplied 2.5, a 2.4 on the side to support some old projects not worth the bother to upgrate, the latest 2.6 for new stuff, 3.1 as well to get the very newest -- they all live together in peace and quiet, I just type the release number explicitly, i.e. using python2.6 at the prompt, when I want a specific release. What release gets used when at the shell prompt you just say python is up to you (I personally prefer that to mean "the system-supplied Python", but it's a matter of taste: by setting paths, or shell aliases, &c, you can make it mean whatever you wish).

20
ответ дан 1 December 2019 в 06:39
поделиться

May I suggest you leave the "Default" be, and install Python in /usr/local/bin.

  1. Download python
  2. Unzip it
  3. ./configure
  4. make
  5. sudo make install

done.

Since /usr/local/bin comes before /usr/bin in the $PATH, you will invoke 2.6 when you type python, but the OS will remain stable...

6
ответ дан 1 December 2019 в 06:39
поделиться

You have a number of options

  • Install with MacPorts or Fink, e.g.:

    sudo port install python2.6
    
  • Install from the disc image from python.org
  • Install from source:

    tar xzvf Python-2.6.3.tgz
    cd Python-2.6.3
    ./configure && make && sudo make install
    
5
ответ дан 1 December 2019 в 06:39
поделиться

I believe there are a few options. The one I like is to install alternative UNIX software on my Macs using MacPorts, http://www.macports.org/ -- this way the new software is installed in a different directory and won't mess up anything depending on the apple-installed version, and macports also has a nice way of keeping their installed software up to date. I believe MacPorts helps take care of dependencies as well.

0
ответ дан 1 December 2019 в 06:39
поделиться

Лучше всего использовать macports (точно так же, как Адам Розенфилд заявил в этой теме).

Вы можете легко переключаться между версиями Python, используя механизм выбора macports:

$ sudo port select --set python pythonXY

Чтобы просмотреть список доступных версий Python, которые вы можете использовать выше, и / или подтвердить, какую из них вы используете:

$ sudo port select --list python

Чтобы установить новую версию Python:

$ sudo port install pythonXY

4
ответ дан 1 December 2019 в 06:39
поделиться

Стандартная установка http://python.org для Mac OSX будет счастливо сосуществовать с «системным питоном». Если вы позволите установщику изменить ваши пути, когда вы запустите python из командной строки в терминале, он найдет версию в

 /Library/Frameworks/Python.framework/Versions/2.6/bin/python

. Однако это не повлияет ни на что, что сама OSX делает с python, который правильно закрепляет путь к версия, которую он устанавливает.

1
ответ дан 1 December 2019 в 06:39
поделиться
Другие вопросы по тегам:

Похожие вопросы: