Python Forum
How to make a test data file for the full length of definition?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make a test data file for the full length of definition?
#3
Thanks for weighing in.

I see the output from this python script comes as

of 2736 character length.

lengths = (10, 15, 20) defines the length of 3 fields.

The need is not to repeat these 3 sets many times upto 2736 characters

The record structure will have 70-80 fields with mixed types/length like

Name varchar (10)
Business Name varchar (15)
Address Varchar (20)
amount number(12,2)
amount2 number (7,2)
rate number (5,2)
C_name varchar (32)
*
*
*
*
*
*
*

goes to many field definitions upto 70-80



How do I make the output for

If Numeric like number (9,2) with digits

If a character like varchar (20) mix of alphabets & digits

some files use ASCII '\031' as a delimiter. How do I do that in above scripts.

Thanks for your help.

UPDATE
=======


I like to add clarifications to this question:

I have the required spec in a file like

colspec1.data

cat colspec1.data
10,x
15,u
20,p
10,9
22,w
18,r
15,9
This help me to add many rows as needed.

The changed Python script looks like

from csv import reader
final_string = ''
# read csv file as a list of lists
with open('colspec1.data', 'r') as read_obj:
    # pass the file object to reader() to get the reader object
    csv_reader = reader(read_obj)
    # Pass reader object to list() to get a list of lists
    data = list(map(tuple, csv_reader))

    for length, character in data:
        print(int(length))
        final_string += int(length) * str(character) + '|'

print(final_string)
The OUTPUT from this script is

10
15
20
10
22
18
15
xxxxxxxxxx|uuuuuuuuuuuuuuu|pppppppppppppppppppp|9999999999|wwwwwwwwwwwwwwwwwwwwww|rrrrrrrrrrrr
How can I change ASCII '\031' as delimiter instead of '|' in this code ?

Any suggestions for improvement in this script?

I am looking to add date data, amount like 9999999.99 as well.

Thanks for your guidance.

Thanks for your guidance.
Reply


Messages In This Thread
RE: How to make a test data file for the full length of definition? - by MDRI - Apr-01-2021, 03:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  class definition and problem with a method HerrAyas 2 291 Apr-01-2024, 03:34 PM
Last Post: HerrAyas
  mutable argument in function definition akbarza 1 511 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  error occuring in definition a class akbarza 3 747 Nov-26-2023, 09:28 AM
Last Post: Yoriz
  determine parameter type in definition function akbarza 1 609 Aug-24-2023, 01:46 PM
Last Post: deanhystad
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 980 Feb-15-2023, 05:34 PM
Last Post: zsousa
  shutil.move make data corrupt kucingkembar 0 822 Feb-01-2023, 01:30 PM
Last Post: kucingkembar
  [split] Explain the python code in this definition Led_Zeppelin 1 766 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  Explain the python code in this definition Led_Zeppelin 1 1,122 Oct-27-2022, 04:04 AM
Last Post: deanhystad
  How to sort .csv file test log which item first fail and paint color SamLiu 24 5,089 Sep-03-2022, 07:32 AM
Last Post: Pedroski55
  meaning of -> syntax in function definition DrakeSoft 5 2,008 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020