You are not logged in.

#1 2004-08-13 11:59:22

zeppelin
Member
From: Athens, Greece
Registered: 2004-03-05
Posts: 807
Website

python's webbrowser module won't work with AL?

Hi guys/girls.
I have latest python AL pkg.
what is more I do:
$ echo "I love GNOME" > /tmp/foo.txt
$ python
Python 2.3.4 (#2, May 27 2004, 17:42:19)
[GCC 3.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> webbrowser.open('/tmp/foo.txt')
it will wait for 2 secs BUT NOTHING WILL HAPPEN
>>> webbrowser.open_new('/tmp/foo.txt')
it will wait for 2 secs BUT NOTHING WILL HAPPEN
>>>


is this an error I do in Python. If not, is it AL specific?
I think python interpreter cannot find which browser to use? when is this deteermined [maybe on compiled time?]

I have latest FireFox and Mozilla
Anyways does it work on your ArchLinux box?

thanks

ps. this of course works:
os.spawnlp(os.P_WAIT, 'gnome-open', 'gnome-open', '/tmp/foo.txt')

Offline

#2 2004-08-13 13:04:25

Win
Member
Registered: 2004-03-04
Posts: 155

Re: python's webbrowser module won't work with AL?

Hi zepellin.

The parameter for webbrowser.open is a URL, not a file name.

From the on-line Python Library documentation:

open(url[, new=0][, autoraise=1])
    Display url using the default browser. If new is true, a new browser window is opened if possible. If autoraise is true, the window is raised if possible (note that under many window managers this will occur regardless of the setting of this variable).

So, you should use:

webbrowser.open('file:/tmp/foo.txt').

Regards,

Win

Offline

#3 2004-08-13 15:54:59

zeppelin
Member
From: Athens, Greece
Registered: 2004-03-05
Posts: 807
Website

Re: python's webbrowser module won't work with AL?

>>> webbrowser.open('file:/tmp/foo.txt') # your style
>>> webbrowser.open('file:///tmp/foo.txt') # mozilla style
nothing happens #both styles smile

Offline

#4 2004-08-13 16:42:13

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: python's webbrowser module won't work with AL?

it works for me with html files, starting up in links! big_smile


arch + gentoo + initng + python = enlisy

Offline

#5 2004-08-13 18:24:26

Win
Member
Registered: 2004-03-04
Posts: 155

Re: python's webbrowser module won't work with AL?

Hi zepellin and xerxes2.

The standard URL format for regular and HTML files works for me. The default browser in my case is Mozilla.

The Python webbrowser documentation indicates that you can set different browsers (more generally, applications) as the target for loading the URL:

http://docs.python.org/lib/module-webbrowser.html

Since webbrowser uses the default browser, check that you have a value for the shell varaiable, BROWSER:

echo $BROWSER

If this is not set or set to an inappropriate value, you can reset this using the values provided in the Python documentation mentioned above, for example, one of the following

export BROWSER='kfm'
export BROWSER='mozilla'
export BROWSER='netscape'
...

This value should be put into a configuration file such as .bashrc.

You can check that you have a default browser by using the webbrowser.get() method with no parameter. This will return the default web browser.

Regards,

Win

Offline

#6 2004-08-13 21:22:46

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: python's webbrowser module won't work with AL?

thanks for the tip win, works perfectly.
I've got a lot of python code around that needs these small adjustments.


arch + gentoo + initng + python = enlisy

Offline

#7 2004-08-13 22:17:27

zeppelin
Member
From: Athens, Greece
Registered: 2004-03-05
Posts: 807
Website

Re: python's webbrowser module won't work with AL?

Win wins smile

but tell me sth mr Win.
How $BROWSER  did not get exported automatically?
should that come with python pkg ?
I didn't have it [i have NoUpgrade = etc/profile] btw
and just out of interest:
what are the chances that other distros also don't export this Variable?

Offline

#8 2004-08-13 23:52:05

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: python's webbrowser module won't work with AL?

zeppelin wrote:

How $BROWSER  did not get exported automatically?
should that come with python pkg ?

Wouldn't it be user dependent, as in which browser do *you* prefer? As a packager, I can't guess if you want to use lynx or firefox, so what do I export?

There certainly could be a suitable default (lynx, perhaps) in the source code.

Dusty

Offline

#9 2004-08-14 19:28:16

Win
Member
Registered: 2004-03-04
Posts: 155

Re: python's webbrowser module won't work with AL?

Hi zepellin.

As Dusty suggests, a packager should not set your default browser since it is a user preference. There is perhaps one specifc exception: a package might set a default browser (preferably from one of the known existing possibilities on your system) if one's not already been set by the user. This behavior is often annoying since it's usually performed in silence (the package installation process should alert the user to the change) and behavior unexpected by the user may ensue. Users may not understand the implications of setting or unsetting variables for other applications or processes.

Just add a line to .bashrc or .profile, as is your wont, such as:

export BROWSER='mozilla'

Regards,

Win

Offline

#10 2004-08-14 20:40:53

zeppelin
Member
From: Athens, Greece
Registered: 2004-03-05
Posts: 807
Website

Re: python's webbrowser module won't work with AL?

Dusty and Win. Ok I agree. I always find it ugly that default browser is Mozilla (suite) in some Distros.
I like Mozilla [super fan]. But I mostly use Firefox, eventhough I have mozilla installed (some apps (al pkgs) seem to need that one and not firefox [hm..])

Anyways.
I think though that an echo "make sure you export $BROWSER to the executable of your browser of choice in .bash_profile or in /etc/profile [if you want to make it global]"
wouldn't hurt anyone though.

now I know that AL is an advanced distro. But that doesn't mean it should say to the user: "hey don't lose 10 minutes in ArchLinux forms to see why python webbrowser doesn't work out of the box"
{now I'm not complaining here but others may in the future}

that's all
Thank you very much

xuf007024.gif

Offline

Board footer

Powered by FluxBB