Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > de.comp.lang.python > #5652
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | ruppert@hs-worms.de |
| Newsgroups | de.comp.lang.python |
| Subject | Re: [Python-de] f-string Formatanweisung |
| Date | Mon, 13 Jul 2020 11:13:52 -0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 47 |
| Message-ID | <rehfle$5os$1@dont-email.me> (permalink) |
| References | <rcq1j2$5b5$1@dont-email.me> <3e3c30fe-d11e-6061-2ed4-0a7015359882@behnel.de> <mailman.253.1592831688.24731.python-de@python.org> <Formatierung-20200712232843@ram.dialup.fu-berlin.de> |
| Reply-To | ruppert@hs-worms.de |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-15 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Mon, 13 Jul 2020 11:13:52 -0000 (UTC) |
| Injection-Info | reader02.eternal-september.org; posting-host="6bc33fb679a990ee61f0279ff128a01d"; logging-data="5916"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+V7YrQUX3Zsb84O3npGN5g" |
| User-Agent | tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/4.19.0-6-amd64 (x86_64)) |
| Cancel-Lock | sha1:3xYBJGNx877L+RiZMe7k/1XmHBs= |
| Xref | csiph.com de.comp.lang.python:5652 |
Show key headers only | View raw
Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> Stefan Behnel <python-de@behnel.de> writes:
>>möglich, f-strings zu generieren. (Ok, du könntest eval() verwenden, aber
>>das ist recht langsam und auch fehleranfällig ??? tu's lieber nicht.)
>
> ...
>
> import sys
>
> argv = sys.argv
> argv =[ "my/program.py" ]
> argv =[ "my/program.py", "3" ]
>
> def check_usage():
> if len( argv )< 2 :
> a = argv[ 0 ].split( '/' )
> a = a[ -1 ]
> print( 'usage:', a, 'digits of GrayCode' )
> print( ' eg.', a, '12' )
> sys.exit( 1 )
>
> check_usage()
>
> def gray_code_from_binary_code( bin ):
> return bin^( bin >> 1 )
>
> def format_digits( digits ):
> return digits if digits >= 4 else 4
>
> specified_digits = int( argv[ 1 ])
> decimal_digits = format_digits( int( specified_digits / 3.321928 + 1 ))
> gray_digits = format_digits( specified_digits )
> binary_digits = gray_digits
> table_header = f'{"#val":{decimal_digits}s} {"gray":{gray_digits}s} {"bin":{binary_digits}s}'
> for binary_code in range( 2**specified_digits ):
> if binary_code % 24 == 0: print( table_header )
> gray_code = gray_code_from_binary_code( binary_code )
> print( f"{binary_code:0{decimal_digits}d}, {gray_code:0{gray_digits}b}, {binary_code:0{binary_digits}b}" )
>
>
Vielen Dank für das Posting, ich hab' viel daraus gelernt.
Und in mein grayCode.py habe ich die f'-strings bereits
übernommen und es funktioniert. :-)
nochmals vielen Dank
Martin Ruppert
Back to de.comp.lang.python | Previous | Next — Previous in thread | Find similar
f-string Formatanweisung ruppert@hs-worms.de - 2020-06-22 10:36 +0000
Re: [Python-de] f-string Formatanweisung Mike Müller <mmueller@python-academy.de> - 2020-06-22 14:27 +0200
Re: [Python-de] f-string Formatanweisung Mike Müller <mmueller@python-academy.de> - 2020-06-22 14:31 +0200
Re: [Python-de] f-string Formatanweisung ruppert@hs-worms.de - 2020-06-22 13:22 +0000
Re: [Python-de] f-string Formatanweisung Stefan Behnel <python-de@behnel.de> - 2020-06-22 14:55 +0200
Re: f-string Formatanweisung "Andreas B." <ab@sysing.de> - 2020-06-22 15:03 +0200
Re: f-string Formatanweisung ruppert@hs-worms.de - 2020-06-22 13:28 +0000
Re: [Python-de] f-string Formatanweisung Stefan Behnel <python-de@behnel.de> - 2020-06-22 15:14 +0200
Re: [Python-de] f-string Formatanweisung ruppert@hs-worms.de - 2020-06-22 14:03 +0000
Re: [Python-de] f-string Formatanweisung ruppert@hs-worms.de - 2020-07-13 11:13 +0000
csiph-web