Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/ operator on furl objects #1

Closed
wants to merge 3 commits into from
Closed

/ operator on furl objects #1

wants to merge 3 commits into from

Conversation

amoffat
Copy link

@amoffat amoffat commented Dec 13, 2011

might be too clever for it's own good. boost::filesystem in c++ uses this technique, and i've always liked it. let me know what you think.

@amoffat
Copy link
Author

amoffat commented Dec 13, 2011

example:

>>> url = furl("http://www.google.com")

>>> url/"path"/"another_path"/"one_more_path"
furl('http://www.google.com/path/another_path/one_more_path')

>>> print url
http://www.google.com/path/another_path/one_more_path

@gruns
Copy link
Owner

gruns commented Dec 14, 2011

I think there are better ways to improve conciseness in place of overloaded operators.

One route to ponder is @AlexeyMK's suggestion to process args and kwargs directly. For example, process args like

>>> f = furl('http://www.google.com')
>>> f.path.add('path', 'another_path', 'one_more_path')
>>> f.url
'http://www.google.com/path/another_path/one_more_path'

To me, this is more explicit and straightforward than the overloaded '/' operator.

Here's another example using kwargs for setting fragment query arguments

>>> f = furl('http://www.google.com')
>>> f.fragment.query.add(one=1, two=2)
>>> f.url
'http://www.google.com#two=2&one=1'

So Path and Query objects would each have add(), set(), and remove() methods that process args and kwargs. args and kwargs also play nicely with the unpack operator

>>> argdic = {'one':'1', 'two':'2'}
>>> furl(...).query.set(**argdic)

One downside of adding such args and kwargs functionality to add(), set(), and remove() would be breaking the tenet 'There should be one-- and preferably only one --obvious way to do it.'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants