-2

I’m getting a MemoryError when I try to read a large sql file in Python3.6 with this command:

with open(sql_file, ‘r’) as f:

Is there an alternative to this so I can correctly read my sql file ?

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
slidefizz
  • 257
  • 5
  • 12

1 Answers1

0

If you have the sql file you should import it into a database and than use a library like MySQLdb for python to make your database requests.

I would guess, that opening sql files directly is a good solution. If you want to work with files, I think csv files are the better solution.

Inuff
  • 35
  • 1
  • 9
  • Not the specific problem, but a better solution at all. It is obvious that large file needs more memory. To AVOID problems, it is a good way to give a person the opportunity to find a better solution. – Inuff Jul 09 '18 at 08:14
  • I need to create the database with python, i’m using psycopg2 to make the link between python and the postgres database. I also get a memoryerror when I execute the sql file with psycopg2 function directly. – slidefizz Jul 09 '18 at 08:17