Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > fr.comp.lang.python > #4089

Re: API, dict et interrogations...

From Dominique <zzz@aol.com>
Newsgroups fr.comp.lang.python
Subject Re: API, dict et interrogations...
Date 2023-08-12 17:22 +0200
Organization A noiseless patient Spider
Message-ID <ub8837$1c5ej$2@dont-email.me> (permalink)
References <ub7ej9$18ncg$1@dont-email.me> <64d799dc$0$6430$426a74cc@news.free.fr>

Show all headers | View raw


Le 12/08/2023 à 16:40, yves a écrit :
> Le Sat, 12 Aug 2023 10:07:04 +0200, Dominique a écrit:
> 
>> date=str(datetime.date.today()).split('-')
>> date[0],date[1],date[2]=date[2],date[1],date[0]
> 
> On peut écrire ça comme ça, aussi :
> 
> import datetime
> 
> date=datetime.date.today().strftime("%d-%m-%Y")
> print(date)


Et la sortie est plus propre :

import requests
import datetime


result=requests.get("http://api.open-notify.org/astros.json").json()

date=datetime.date.today().strftime("%d-%m-%Y")


print()
print('Équipages dans l\'espace ce ', date)
print()
print('Nom',27*' ','vaisseau')
print()

for i in range(len (result['people'])):
     print(result['people'][i]['name'], 
(30-len(result['people'][i]['name']))*' ',result['people'][i]['craft'])


Ce qui donne :
Nom                             vaisseau

Sergey Prokopyev                ISS
Dmitry Petelin                  ISS
Frank Rubio                     ISS
Stephen Bowen                   ISS
Warren Hoburg                   ISS
Sultan Alneyadi                 ISS
Andrey Fedyaev                  ISS
Jing Haiping                    Tiangong
Gui Haichow                     Tiangong
Zhu Yangzhu                     Tiangong


-- 
Dominique
Esto quod es

Back to fr.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

API, dict et interrogations... Dominique <zzz@aol.com> - 2023-08-12 10:07 +0200
  Re: API, dict et interrogations... yves <yves@free.invalid> - 2023-08-12 08:36 +0000
    Re: API, dict et interrogations... Dominique <zzz@aol.com> - 2023-08-12 12:02 +0200
  Re: API, dict et interrogations... yves <yves@free.invalid> - 2023-08-12 14:40 +0000
    Re: API, dict et interrogations... Dominique <zzz@aol.com> - 2023-08-12 17:14 +0200
    Re: API, dict et interrogations... Dominique <zzz@aol.com> - 2023-08-12 17:22 +0200
      Re: API, dict et interrogations... yves <yves@free.invalid> - 2023-08-12 16:43 +0000
        Re: API, dict et interrogations... Dominique <zzz@aol.com> - 2023-08-13 09:00 +0200
        Re: API, dict et interrogations... yves <yves@free.invalid> - 2023-08-14 14:12 +0000
          Re: API, dict et interrogations... Dominique <zzz@aol.com> - 2023-08-14 16:48 +0200

csiph-web