470,628 Members | 2,328 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,628 developers. It's quick & easy.

mydate.strftime('%x') and cgi script

Hello,

I'm writing a cgi script which only needs to run in a small LAN. I tried
to show dates in a reasonable format by using

import locale
import datetime

locale.setlocale(locale.LC_ALL, '')
....
dt = datetime.date.today()
print dt.strftime('%x')

This works well in other scripts or at the interactive prompt. It
doesn't work in a cgi script: in the browser the date is shown as
'mm/dd/yyyy' which is _not_ my 'Locale's appropriate date
representation' as the documentation for strftime calls it.

The workaround is simple: explicit description of the right format works
('%d.%m.%Y'). But why doesn't the short form work as well?

Thank you for explanations or links to them,
Koczian

--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
e-mail : Si*************@Bibliothek.Uni-Augsburg.DE
Mar 13 '06 #1
4 1515
In <47************@news.dfncis.de>, Sibylle Koczian wrote:
I'm writing a cgi script which only needs to run in a small LAN. I tried
to show dates in a reasonable format by using

import locale
import datetime

locale.setlocale(locale.LC_ALL, '')
...
dt = datetime.date.today()
print dt.strftime('%x')

This works well in other scripts or at the interactive prompt. It
doesn't work in a cgi script: in the browser the date is shown as
'mm/dd/yyyy' which is _not_ my 'Locale's appropriate date
representation' as the documentation for strftime calls it.


That's the web server's locale appropriate date representation then.

Ciao,
Marc 'BlackJack' Rintsch
Mar 15 '06 #2
Marc 'BlackJack' Rintsch schrieb:
In <47************@news.dfncis.de>, Sibylle Koczian wrote:

I'm writing a cgi script which only needs to run in a small LAN. I tried
to show dates in a reasonable format by using


That's the web server's locale appropriate date representation then.


The web server is on my machine - doesn't it use its regional settings?
I've seen a little more in the meantime:

xx = locale.setlocale(locale.LC_ALL, '')

# print HTML header, title, everything up to and including body tag

print xx

# print rest of page

In the cgi script xx is "C" and not "de_DE.utf-8". Looks as if setlocale
isn't executed.

If I do the same things using Windows instead of Linux, setlocale is
executed in the cgi script, no difference to the interactive interpreter.

Koczian

--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
e-mail : Si*************@Bibliothek.Uni-Augsburg.DE
Mar 20 '06 #3
In <48************@news.dfncis.de>, Sibylle Koczian wrote:
I'm writing a cgi script which only needs to run in a small LAN. I tried
to show dates in a reasonable format by using

That's the web server's locale appropriate date representation then.


The web server is on my machine - doesn't it use its regional settings?


The settings are per user and stored in environment variables. Apache
clears most of them at start.
I've seen a little more in the meantime:

xx = locale.setlocale(locale.LC_ALL, '')

# print HTML header, title, everything up to and including body tag

print xx

# print rest of page

In the cgi script xx is "C" and not "de_DE.utf-8". Looks as if setlocale
isn't executed.


`setlocale()` is executed but if there are no environment variables (LANG,
LC_*) then the default locale `C` is chosen.

Ciao,
Marc 'BlackJack' Rintsch
Mar 22 '06 #4
Marc 'BlackJack' Rintsch schrieb:
In <48************@news.dfncis.de>, Sibylle Koczian wrote:

The web server is on my machine - doesn't it use its regional settings?

The settings are per user and stored in environment variables. Apache
clears most of them at start.

`setlocale()` is executed but if there are no environment variables (LANG,
LC_*) then the default locale `C` is chosen.


And these environment variables aren't there because Apache has cleared
them at start - right?

Thank you,
Koczian

--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
e-mail : Si*************@Bibliothek.Uni-Augsburg.DE
Mar 24 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by John Hunter | last post: by
4 posts views Thread by Andy Leszczynski | last post: by
1 post views Thread by Dennis Benzinger | last post: by
2 posts views Thread by silverburgh.meryl | last post: by
3 posts views Thread by HSeganfredo | last post: by
2 posts views Thread by Giovanni Bajo | last post: by
3 posts views Thread by Andrii V. Mishkovskyi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.