0

I have a question about the approach of my problem and if I am understanding or if I'm not if anyone can help me understand it better:

For my course in python I was tasked with having to make a 1 GB file with six columns where

  • first column id needs to be auto increment
  • second column needs to to be a random integer 1-100
  • third and fourth column are random 6 letter strings
  • fifth and six columns are a combination of letters and numbers combined.

The output file should have a header row I can use a comma as a delimiter.

My thought process was to use aws use their Linux AMI then download mysql server on to it and create table of 6 columns and then read data into the .csv This is where I get lost am I suppose to use a mysqlconnector to link the table I create to python.

Beri
  • 11,470
  • 4
  • 35
  • 57
  • 1
    You either misunderstood your assignment or failed to correctly explain it. This should be a relatively straightforward task with the `csv` module. – Wayne Werner Sep 21 '17 at 15:10

2 Answers2

3

IMO the task you are asekd to do doesnot have anything to do with a mysql database and can be solved much more straightforward. I would suggest to open a file and write the necessary number of lines. So you start with writing a header line and then write the next (1GB)/(bites per line) lines with the necessary entries in each columns and close the file.

For how to connect to the database: How do I connect to a MySQL Database in Python?

1

If you do not understand this task, then adding MySQL to it would give more complexity. This is a straightforward excersise, where you need to:

  • define a method that writes a line to csv file
  • compute how much each line will take memory (according to the description, each line will take same length), with that you can compute how many lines your csv file needs
  • define methods to generate random fixed-size string, number 1-100, etc

Then you simply need to run everything in one loop (incremented value can be taken from this loop).

Helpful links:

Beri
  • 11,470
  • 4
  • 35
  • 57