question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

implement a ".join(*args)" method

See original GitHub issue

It would be nice to have a DOMElement.join() method that mimics the str.join() method in python.

Ideally, this method would accept a list of things and returns the passed list with the chosen TemPy tag instances between the list elements just like the str.join method:

Br.join(["pizza", "pasta", "lasagna"])
>>> ["pizza", Br(), "pasta", Br(), "lasagna"]

Hr.join(["pizza", "pasta", "lasagna"])
>>> ["pizza", Hr(), "pasta", Hr(), "lasagna"]

Br.join(["pizza"])
>>> ["pizza"]

I’d make it a classmethod, so both Br.join(["pizza", "pasta", "lasagna"]) and Br().join(["pizza", "pasta", "lasagna"]) sytntaxes are allowed. In the latter syntax copies of Br() have to be created.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Hrabalcommented, Oct 4, 2019

Hi @Navneet78 thanks for taking this. I assigned you this issue. If you have any question just ask on this issue.

0reactions
Hrabalcommented, Oct 8, 2019

Hi,

I think by using ‘cls()’ first you are creating a new object of class and returning it.

Yes, this is ok to happen, we don’t want the same instance in between the elements of the input, but several new instances of the same class.

For instantiating an object we need parameters of init method

it’s ok to just init the class with no parameters ( cls() ).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implementing a join function that is being passed 3 arguments
You know the function has three arguments, so just use: ... number of strings to join as long as the separator is the...
Read more >
Java Join Strings: String.join Method - Dot Net Perls
In Java, the join method receives a variable number of arguments. It accepts first a delimiter string—characters that are inserted between all joined ......
Read more >
Python String join() Method - GeeksforGeeks
join () is an inbuilt string function in Python used to join elements of the sequence separated by a string separator. This function...
Read more >
Join in Python: Definition, Usage, Syntax, and Parameters
Join in Python is an in-built method used to join an iterable's elements, separated by a string separator, which is specified by you....
Read more >
Allow str.join to take *args in addition to iterable (like min/max)
I want to use str.join to directly construct multi-line strings, i.e.: "\n".join( "line1", "line2", ) but because only an iterable is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found