[Zope] string formatting

2010-08-13 Thread Ebbe Kvist
Hi all,

I want to process a variable, signum2, which is picked up from a MySQL
database. The content of the variable is
"B006".
The aim is to process this variable so the result will be 
"B007" and it will then be saved as part of a new record in the
database.
The core process is to increment the integer part of the variable "006"
with 1.

I have successfully done this incrementation but I have not been able to
create a new 
correct content for the new varable new_xyz.




How can I from here create the correct content of the new variable? I
need to bring the "B" part
with me and then the incremented integer part formatted with two
preceeding zeroes. Does anyone know?

Best regards,

Ebbe Kvist
Stockholm 



___Hitta
 kärleken med hjälp av vårt matchningstest - http://spray.matchaffinity.se/?mtcmk=614114";>Klicka här!___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] string formatting

2010-08-13 Thread Andreas Jung
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Firstly, why DTML?

Secondly, write a browser view or your app logic into a Python Script
and use a ZPT for calling the script and rendering the result. Such code
as seen below makes us shiver.

Andreas

Ebbe Kvist wrote:
> Hi all,
> 
> I want to process a variable, signum2, which is picked up from a MySQL
> database. The content of the variable is
> "B006".
> The aim is to process this variable so the result will be
> "B007" and it will then be saved as part of a new record in the database.
> The core process is to increment the integer part of the variable "006"
> with 1.
> 
> I have successfully done this incrementation but I have not been able to
> create a new
> correct content for the new varable new_xyz.
> 
> 
> 
> 
> How can I from here create the correct content of the new variable? I
> need to bring the "B" part
> with me and then the incremented integer part formatted with two
> preceeding zeroes. Does anyone know?
> 
> Best regards,
> 
> Ebbe Kvist
> Stockholm
> 
> ___
> Hitta kärleken med hjälp av vårt matchningstest - Klicka här!
> 
> 
> 
> 
> 
> ___
> Zope maillist  -  Zope@zope.org
> https://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  https://mail.zope.org/mailman/listinfo/zope-announce
>  https://mail.zope.org/mailman/listinfo/zope-dev )


- -- 
ZOPYX Limited   | zopyx group
Charlottenstr. 37/1 | The full-service network for Zope & Plone
D-72070 Tübingen| Produce & Publish
www.zopyx.com   | www.produce-and-publish.com
- 
E-Publishing, Python, Zope & Plone development, Consulting


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxlcNYACgkQCJIWIbr9KYzwqwCfeFrBsPilwyn1AcKhpE0e6hL8
M1gAn1AWaZf00EVOnAQYIGNfiy5vZLKw
=NAMv
-END PGP SIGNATURE-
<>___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] string formatting

2010-08-13 Thread Jonathan (dev101)
Something like:

 





won’t work because you will turn B006 into B7

 

If you want to retain the leading zeros you will need to pad them. 

 

As Andreas said, this would be better done using a python script (which you
can call from dtml you don’t have to use zpt).

 

 

 

Jonathan

 

From: zope-boun...@zope.org [mailto:zope-boun...@zope.org] On Behalf Of Ebbe
Kvist
Sent: August-13-10 12:17 PM
To: zope@zope.org
Subject: [Zope] string formatting

 

Hi all,

I want to process a variable, signum2, which is picked up from a MySQL
database. The content of the variable is
"B006".
The aim is to process this variable so the result will be 
"B007" and it will then be saved as part of a new record in the database.
The core process is to increment the integer part of the variable "006" with
1.

I have successfully done this incrementation but I have not been able to
create a new 
correct content for the new varable new_xyz.




How can I from here create the correct content of the new variable? I need
to bring the "B" part
with me and then the incremented integer part formatted with two preceeding
zeroes. Does anyone know?

Best regards,

Ebbe Kvist
Stockholm 

___
Hitta kärleken med hjälp av vårt matchningstest - Klicka här!
<http://spray.matchaffinity.se/?mtcmk=614114> 

___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] string formatting

2010-08-13 Thread Jeff Peterson
def inc(s):
id, count = (s[:1], int(s[1:4]))
count += 1
return '%s%03d' % (id, count)

--
Jeffrey D Peterson
Webmaster
Crary Industries, Inc.

From: zope-boun...@zope.org [mailto:zope-boun...@zope.org] On Behalf Of Ebbe 
Kvist
Sent: Friday, August 13, 2010 11:17 AM
To: zope@zope.org
Subject: [Zope] string formatting

Hi all,

I want to process a variable, signum2, which is picked up from a MySQL 
database. The content of the variable is
"B006".
The aim is to process this variable so the result will be
"B007" and it will then be saved as part of a new record in the database.
The core process is to increment the integer part of the variable "006" with 1.

I have successfully done this incrementation but I have not been able to create 
a new
correct content for the new varable new_xyz.




How can I from here create the correct content of the new variable? I need to 
bring the "B" part
with me and then the incremented integer part formatted with two preceeding 
zeroes. Does anyone know?

Best regards,

Ebbe Kvist
Stockholm

___
Hitta kärleken med hjälp av vårt matchningstest - Klicka 
här!<http://spray.matchaffinity.se/?mtcmk=614114>
___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] string formatting

2010-08-13 Thread Jeff Peterson
To be more flexible it should probably look more like this:

def inc(s):
import string
id, count = (s[:1], s[1:])
count = string.zfill(str(int(count) + 1), len(count))
return '%s%s' % (id, count)

That way even 'B0006' would get incremented properly.

--
Jeffrey D Peterson
Webmaster
Crary Industries, Inc.

From: zope-boun...@zope.org [mailto:zope-boun...@zope.org] On Behalf Of Ebbe 
Kvist
Sent: Friday, August 13, 2010 11:17 AM
To: zope@zope.org
Subject: [Zope] string formatting

Hi all,

I want to process a variable, signum2, which is picked up from a MySQL 
database. The content of the variable is
"B006".
The aim is to process this variable so the result will be
"B007" and it will then be saved as part of a new record in the database.
The core process is to increment the integer part of the variable "006" with 1.

I have successfully done this incrementation but I have not been able to create 
a new
correct content for the new varable new_xyz.




How can I from here create the correct content of the new variable? I need to 
bring the "B" part
with me and then the incremented integer part formatted with two preceeding 
zeroes. Does anyone know?

Best regards,

Ebbe Kvist
Stockholm

___
Hitta kärleken med hjälp av vårt matchningstest - Klicka 
här!<http://spray.matchaffinity.se/?mtcmk=614114>
___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] string formatting

2010-08-13 Thread Jaroslav Lukesh
It is easy:





DTML is simple and fine :)


- Puvodní zpráva - 
Od: Ebbe Kvist

I want to process a variable, signum2, which is picked up from a MySQL
database. The content of the variable is
"B006".
The aim is to process this variable so the result will be
"B007" and it will then be saved as part of a new record in the database.
The core process is to increment the integer part of the variable "006" with
1.

I have successfully done this incrementation but I have not been able to
create a new
correct content for the new varable new_xyz.




How can I from here create the correct content of the new variable? I need
to bring the "B" part
with me and then the incremented integer part formatted with two preceeding
zeroes. Does anyone know?

___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] string formatting

2010-08-13 Thread Andreas Jung
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jaroslav Lukesh wrote:
> It is easy:
> 
> 
> 
>  signumfix2)[1:] )">
> 
>

Hopefully such code won't be released :-)

- -aj
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxmOq4ACgkQCJIWIbr9KYy0uQCeId0CiRMj0xKmV9t3dGvkyqgp
r9gAoKiFkmFZVspPnwMAJMEcKFrAAE8o
=pblK
-END PGP SIGNATURE-
<>___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] string formatting

2010-08-14 Thread Jaroslav Lukesh

- Puvodní zpráva - 
Od: "Andreas Jung" 
>
> Jaroslav Lukesh wrote:
>> It is easy:
>>
>> 
>> 
>> > signumfix2)[1:] )">
>>
>>
>
> Hopefully such code won't be released :-)

It was for illustration only, here is the better one:



DTML is your friend, not evil.

JL.

___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] string formatting

2010-08-14 Thread Andreas Jung
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Jaroslav Lukesh wrote:
> 
> - Puvodní zpráva - Od: "Andreas Jung" 
>>
>> Jaroslav Lukesh wrote:
>>> It is easy:
>>>
>>> 
>>> 
>>> >> signumfix2)[1:] )">
>>>
>>>
>>
>> Hopefully such code won't be released :-)
> 
> It was for illustration only, here is the better one:
> 
>  _.int(signum2[1:]))[1:])">

Ugliness is in the eye of the beholder.

*shrug* :-)
- -aj
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxnfxEACgkQCJIWIbr9KYwQlACfX/BPuBMzMk+HfdfG1zrDl1D5
ALcAoIdzCYk8X+NsqGIm2p/2jK+Up8vW
=8jNW
-END PGP SIGNATURE-
<>___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] string formatting

2010-08-15 Thread robert rottermann
Am 14.08.2010 22:23, schrieb Jaroslav Lukesh:
> DTML is your friend, not evil.
>
> JL.
>
>
when I was a kid I used to spend my holidays with my grandfather. he was 
an old farmer and used to work with horse and carriage.
it was great and I loved the horses..



___
Zope maillist  -  Zope@zope.org
https://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope-dev )