Discussion:
problem with zfill
Adam Szpakowski
2003-06-07 21:31:26 UTC
Permalink
Hi,

I've strange problem with using zfill in python scripts in Zope.

My script is simple:
--------------
import string
outa = str1.zfill(6)
return outa
--------------

str1 is a parameter given by interface.

Running the script gives me:

Error Type: AttributeError
Error Value: 'str' object has no attribute 'zfill'

I understand the meaning of the error but why it's happening?

Others functions like:
outa = str1.upper()
works great.

Zope is in version 2.6.1 and Python in 2.2.1.

Regards,
--
Adam Szpakowski
Silesian University of Technology - Institute of Physics
Department of Optoelectronic
e-mail: worf-+dH9fp+***@public.gmane.org

_______________________________________________
Zope maillist - Zope-***@public.gmane.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
David Hassalevris
2003-06-07 22:28:59 UTC
Permalink
Adam,
try
import string
return string.zfill(outa,6)
David
----- Original Message -----
From: "Adam Szpakowski" <worf-+dH9fp+***@public.gmane.org>
To: <zope-***@public.gmane.org>
Sent: Saturday, June 07, 2003 2:31 PM
Subject: [Zope] problem with zfill
Post by Adam Szpakowski
Hi,
I've strange problem with using zfill in python scripts in Zope.
--------------
import string
outa = str1.zfill(6)
return outa
--------------
str1 is a parameter given by interface.
Error Type: AttributeError
Error Value: 'str' object has no attribute 'zfill'
I understand the meaning of the error but why it's happening?
outa = str1.upper()
works great.
Zope is in version 2.6.1 and Python in 2.2.1.
Regards,
--
Adam Szpakowski
Silesian University of Technology - Institute of Physics
Department of Optoelectronic
_______________________________________________
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
_______________________________________________
Zope maillist - Zope-***@public.gmane.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
Adam Szpakowski
2003-06-08 06:29:31 UTC
Permalink
Post by Adam Szpakowski
try
import string
return string.zfill(outa,6)
It's no use. Same error. Beside in my example "outa" was intended to be an
output string adn "str1" an input one. So if zfill() is the method for string
type (same as upper()) the form: "11".zfill(5) should give "00011". But it
still gives an error.

Reagards,
--
Adam Szpakowski
Silesian University of Technology - Institute of Physics
Department of Optoelectronic
e-mail: worf-+dH9fp+***@public.gmane.org

_______________________________________________
Zope maillist - Zope-***@public.gmane.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
Jamie Heilman
2003-06-08 08:32:57 UTC
Permalink
"11".zfill(5) should give "00011". But it still gives an error.
The zfill method wasn't added to str types until python 2.2.2b1.
http://python.org/2.2.2/NEWS.txt
--
Jamie Heilman http://audible.transient.net/~jamie/
"Most people wouldn't know music if it came up and bit them on the ass."
-Frank Zappa

_______________________________________________
Zope maillist - Zope-***@public.gmane.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
Adam Szpakowski
2003-06-08 09:04:34 UTC
Permalink
Post by Jamie Heilman
The zfill method wasn't added to str types until python 2.2.2b1.
http://python.org/2.2.2/NEWS.txt
Thanks... that seems to be a solution to my problem.

Regards,
--
Adam Szpakowski
Silesian University of Technology - Institute of Physics
Department of Optoelectronic
e-mail: worf-+dH9fp+***@public.gmane.org

_______________________________________________
Zope maillist - Zope-***@public.gmane.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
Dennis Allison
2003-06-08 15:50:49 UTC
Permalink
zfill does not appear to be string method for the new syle (Python 2.X)
strings. It is in the string module and so is accessed by

import string
string.zfill(string, width)

In this case, zfill('11',5) produces '00011'.

This works for me in a Python Script with Zope 2.5.1 and Python 2.1.3.
Post by Adam Szpakowski
Post by Adam Szpakowski
try
import string
return string.zfill(outa,6)
It's no use. Same error. Beside in my example "outa" was intended to be an
output string adn "str1" an input one. So if zfill() is the method for string
type (same as upper()) the form: "11".zfill(5) should give "00011". But it
still gives an error.
Reagards,
--
Adam Szpakowski
Silesian University of Technology - Institute of Physics
Department of Optoelectronic
_______________________________________________
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
_______________________________________________
Zope maillist - Zope-***@public.gmane.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

Loading...