473,573 Members | 3,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

range with variable leading zeros

I want to generate a range with variable leading zeros
x = [0010, 0210]
padding = len(x[1])

for j in range(x[0], x[1]):
print (url).join('%0( pad)d(jj)'+'.jp g') %{'pad':padding , 'jj':j}
This is syntactically incorrect, you can't insert a variable into the
string format options. Any ideas?
Jun 27 '08 #1
3 3751
On May 8, 10:42*pm, yhvh <yhvh2...@googl email.comwrote:
I want to generate a range with variable leading zeros

x = [0010, 0210]
You do realize that this is octal, right?
padding = len(x[1])
len is undefined for integers. Perhaps you meant "len(str(x[1]))".
for j in range(x[0], x[1]):
* * print (url).join('%0( pad)d(jj)'+'.jp g') %{'pad':padding , 'jj':j}

This is syntactically incorrect, you can't insert a variable into the
string format options. Any ideas?
You can, however, do this:
>>'%0*d' % (5, 123)
'00123'
Jun 27 '08 #2
On May 9, 1:42 pm, yhvh <yhvh2...@googl email.comwrote:
I want to generate a range with variable leading zeros

x = [0010, 0210]
padding = len(x[1])

for j in range(x[0], x[1]):
print (url).join('%0( pad)d(jj)'+'.jp g') %{'pad':padding , 'jj':j}

This is syntactically incorrect, you can't insert a variable into the
string format options. Any ideas?
Concatenate the parts of the pattern string first:

pat = '%0' + str(padding) + 'd'
Jun 27 '08 #3
x = [0010, 0210]
>
You do realize that this is octal, right?
It's unfortunate I choose that, the numbers go beyond octal
len is undefined for integers. *Perhaps you meant "len(str(x[1]))".
Yes sorry it was late at night :P

You can, however, do this:
>'%0*d' % (5, 123)
'00123'
This is exactly what I needed Thank-you kindly
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
11491
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in anticipation, Regards,
5
499
by: samik_tanik | last post by:
I need to export a datagrid to Excel. I could did this. But, also need to keep the leading zeros in the data. How can I acheive this? Any help would be appreciated. -- Thanking you in anticipation, Regards,
6
7741
by: JimmyKoolPantz | last post by:
Task: Customer wants a script of the data that was processed in a "CSV" file. Problem: Zip-Code leading zeros are dropped Basically we have a client that has requested a custom script for each file that he has us process. He wants this in a Comma Delimited Format.
0
4082
by: Monty | last post by:
Hi All, I am having a problem with leading zeros being stripped from fields in a CSV file when I bring them in using Jet/OleDB. In VB.Net/VS 2008, I am accessing a CSV file like so: sSQL = "SELECT * FROM " sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ Microsoft.VisualBasic.FileIO.FileSystem.GetParentPath(msFile) & _
0
7687
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7777
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6413
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3731
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3731
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2203
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1039
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.