Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I modify the python code so that it creates the Book2.csv file into a directory of a Docker volume (myvol)?

What I have tried:

Python Code

Python
import pandas as pd
import numpy as np
from csv import writer
import time

for i in range(1000):
    num = np.random.normal()
    with open('Book2.csv' , 'a+', newline='') as fd:
        csv_writer = writer(fd)
        csv_writer.writerow([num])
        print(num)
    fd.close()
    time.sleep(10)


Dockerfile

FROM python

RUN pip install pandas

WORKDIR /mydata

COPY DataGen.py ./

CMD python DataGen.py
Posted
Updated 1-May-20 1:04am

1 solution

This is the same issue as Linking a container to a volume in docker[^], and I already gave you a suggestion to look in your system to find out where the file is being saved. If you want the file saved in a specific location then add the path to the file name in your code.
 
Share this answer
 
Comments
Richard MacCutchan 1-May-20 12:14pm    
Then you need to study the documentation.
Member 14816525 1-May-20 12:31pm    
Okay I finally got it to work. But now the issue is when I run my second code to show me the result every 10 seconds, it doesn't show anything in real time. But it will show me all the results at once, after it has stopped. So how can I see the results?
Richard MacCutchan 1-May-20 12:51pm    
Sorry, no idea. What is the other application doing?
Member 14816525 1-May-20 13:05pm    
it's just showing the average of the all the random numbers being generated in the CSV file.
Member 14816525 1-May-20 17:27pm    
Nvm, I got it to work. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900