Sublime Forum

Open http / www files at once?

#21

Stop using ST2. ST3 is the future!

2 Likes

#22

Sorry I wasn’t clear in my last post. When I run this generator;

import collections, webbrowser; gen = (("opening '%s'" % link, webbrowser.open(link)) for link in list(collections.OrderedDict.fromkeys(view.substr(sel) for sel in view.sel()).keys()))

I get an AttributeError: ‘module’ object has no attribute ‘OrderedDict’ ?

0 Likes

#23

FichteFoll has already answered that - OrderedDict is a Python 3 thing, Sublime Text 2 uses Python 2, while ST3 uses Python 3. Really, there is no reason to not be using ST3.

2 Likes

#24

Is there not a substitute for Sublime text 2 ?

0 Likes

#25
1 Like

#26

I read that OrderedDict is available in Python 2.7+ considering I have 2.7.3 installed, shouldn’t the command not work ?

0 Likes

#27

it depends which version comes with ST2 - ST uses a built in version of Python for plugins, and it doesn’t matter what version or modules might be installed on the system, ST doesn’t use/see them.

0 Likes

#28

I understand :slightly_smiling:

0 Likes

#29

OrderedDict has been added in python 2.7 and ST2 uses python 2.6.

This is a little bit ugly, but should also work in ST2:

import webbrowser; visited = set([]); gen = (("opening '%s'" % link, webbrowser.open(link)) for link in list(view.substr(sel) for sel in view.sel()) if link not in visited and not visited.add(link))
0 Likes

#30

r-stein - I assume because of the error, the following command must be changed ?

I’m getting an error ‘collections’ is not defined ?

The generator even though it’s as you say ‘ugly’ did work :slightly_smiling:

0 Likes

#31

What do you call the command after the generator is created so I can explain the problem a little better ? :slightly_smiling:

0 Likes