2

in python :

namespace = { 'host': 'facebook.com', 'user': '{somehost}/user/83426347' }
namespace['user'].format(somehost=namespace['host'])

facebook.com/user/83426347

in coffee script I have the same:

namespace=
    host: 'facebook.com'
    user: 'facebook.com/user/42342342'

I am new to CS so how to handle same behaviour to pythons?

2 Answers 2

1

Python

language = "Python"
greet = "I love %s" % language

Coffeescript

language = "Coffescript"
greet = "I love #{language}"
Sign up to request clarification or add additional context in comments.

Comments

1

as seen in older answer

String.prototype.format = ->
  args = arguments
  return this.replace /{(\d+)}/g, (match, number) ->
    return if typeof args[number] isnt 'undefined' then args[number] else match

Then you can do something like:

namespace=
    host: 'facebook.com'
    user: '{0}/user/42342342'
namespace.user = namespace.user.format namespace.host

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.