Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27402
| Date | 2012-08-19 13:31 -0400 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? |
| References | <db49919e-9c9f-4e1f-8dfe-2765c6717dbe@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3510.1345397520.4697.python-list@python.org> (permalink) |
On 08/19/2012 12:25 PM, crispy wrote:
> <SNIP>
> So I have guessed, that characters processed by .rjust() function, are placed in output, relative to previous ones - NOT to first, most to left placed, character.
rjust() does not print to the console, it just produces a string. So if
you want to know how it works, you need to either read about it, or
experiment with it.
Try help("".rjust) to see a simple description of it. (If you're
not familiar with the interactive interpreter's help() function, you owe
it to yourself to learn it).
Playing with it:
print "abcd".rjust(8, "-") produces ----abcd
for i in range(5): print "a".rjust(i, "-")
produces:
a
a
-a
--a
---a
In each case, the number of characters produced is no larger than i. No
consideration is made to other strings outside of the literal passed
into the method.
> Why it works like that?
In your code, you have the rjust() method inside a loop, inside a join,
inside a print. it makes a nice, impressive single line, but clearly
you don't completely understand what the pieces are, nor how they work
together. Since the join is combining (concatenating) strings that are
each being produced by rjust(), it's the join() that's making this look
"relative" to you.
> What builtn-in function can format output, to make every character be placed as i need - relative to the first character, placed most to left side of screen.
If you want to randomly place characters on the screen, you either want
a curses-like package, or a gui. i suspect that's not at all what you want.
if you want to randomly change characters in a pre-existing string,
which will then be printed to the console, then I could suggest an
approach (untested)
res = [" "] * length
for column in similarity:
res[column] = "|"
res = "".join(res)
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? crispy <ryniek90@gmail.com> - 2012-08-19 09:25 -0700
Re: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? crispy <ryniek90@gmail.com> - 2012-08-19 09:35 -0700
Re: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? Dave Angel <d@davea.name> - 2012-08-19 13:31 -0400
Re: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? crispy <ryniek90@gmail.com> - 2012-08-19 12:25 -0700
Re: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? crispy <ryniek90@gmail.com> - 2012-08-19 12:25 -0700
Re: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? Peter Otten <__peter__@web.de> - 2012-08-20 14:45 +0200
Re: How does .rjust() work and why it places characters relative to previous one, not to first character - placed most to left - or to left side of screen? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-19 14:56 -0400
csiph-web