Do you need help?

Notice Board

Per partecipare al corso di Fondamenti di programmazione 2021-22 loggatevi e attivatelo nella vostra pagina dei corsi preferiti. A quel punto il corso appare nel menĂ¹ personale cliccando sul proprio avatar. Per i materiali degli anni precedenti seguite lo stesso metodo.

To join the Programming/Lab 2021-22 course, log-on and select it on the my courses page. It will appear on the personal menu of your avatar. For earlier years use the same method.

VIDEOLEZIONI DEL CORSO DI FONDAMENTI DI PROGRAMMAZIONE AA20-21

PROGRAMMING COURSE VIDEOCONFERENCES AY20-21

What to do with output_file?

N
Nicholas Tiveron (1710 points)
2 5 8
in HW8 2nd chance by (1.7k points)
Hi!

I just wanted clarified what should be done with output_file of hw 8 rec. More precisely, I understood the process of creating the image (putting bg then the colors found while exploring but in opposite order) but I don't understand if we should create a new file with the name given by the parameter output_file or if we should do something else. For example, in hw 6 rec, we have to create a new image for the path taken and the text specifies this in the things that the program should do: "the path to a .png file (fname_out) to be created". As a matter of fact, if I create a matrix and I save it with images.save(...) it works and I am able to create images and save them in this way without getting errors. Conversely, if I try to do the same in hw 8 rec (the text doesn't specify anything on how to deal with the output_file so I assumed the process would be the same) I get the error "It's forbidden to open file '...' ", whereas if I try without images.save(...) I get the error "FileNotFound: No such file or directory: 'test_empty02.out.png' " (for the other tests, the name obviously changes).

Does anyone know how to create this file without using images.save(...) or is this something that shouldn't be happening?

Any input is appreciated and of course if one of the Professors could participate, it would be perfect.
235 views

3 Answers

angelo.spognardi (4720 points)
37 65 99
by (4.7k points)
Could you please explain when this kind of error appears?
N
Nicholas Tiveron (1710 points)
2 5 8
by (1.7k points)
When I try to run the tests. I'm assigning the matrix I created to output_file (which I don't know if it's correct). It looks like I only have to return an integer for the function ex1, which is why I don't know how the tests are supposed to find the new matrix and why I get the error described above.
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
- finally, given that the real estate registry needs to book-keep
    all the boundaries created, the program shall build an output
    image of the size of 1x(N+1). The image encodes as the first pixel
    the color of the background. Then it should encode "the color
    hierarchy" of all the N colors used to subdivide the patches of
    land. The hierarchy is defined by "visiting" first in depth the
    upper left patch, then upper right patch, then lower left, and
    lower right. The colors should be stored in reverse order with
    respect to the "visit" made. With reference to the previous
    semplified case, assuming a boundary color is described with a
    letter, the output image should contain:
             out_colors = bg b c a
iacopomasi (2780 points)
13 20 41
by (2.8k points)

Dear @Nicholas Tiveron ,

you should simply create a "new image" using the data structure that was mentioned in the class (list of lists) and save it as

images.save(new_img, output_file)

The new images should encode the information as mentioned in the text.

The program has to save the image before returning the #rects.

Given the errors that you posted (No such file or directory etc), I suggest you debug what happens in the testing phase or if the image is saved correctly. Can you clearly see the images saved in your filesystem? Can you open it with a simple editor? I suggest you place a breakpoint at the line of code where you get the error and proceed from there.

I hope this helps,

Yours,

iacopo

N
Nicholas Tiveron (1710 points)
2 5 8
by (1.7k points)
I wasn't able to find a solution to that specific problem, however, I found a workaround that seems to work. It includes having a function that only saves the new image in the way you described (output_file is passed as an argument to that function). In this way, I pass the first 3 tests, however, for all the others, I get the error "It's forbidden to open file '0' ". Do you know by any chance what that means? Just to clarify, if I go in the same directory as hw 8 rec, I can find the file '0', which is a copy of the image I create.
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
If you submit your HW I could have a look.
N
Nicholas Tiveron (1710 points)
2 5 8
by (1.7k points)
edited by
Thank you very much, I uploaded it.

P.S.: the function that I'm talking about is the last one, the error occurs there.
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
Have you tried to disable some safety tests by setting DEBUG=True in test_01.py and place some prints in your code?
N
Nicholas Tiveron (1710 points)
2 5 8
by (1.7k points)
By doing that, I get "bad file descriptor" and "the handle is invalid" when running the tests, even though I'm just saving the image as said before. The problem still seems to be the name with which I save the files, somehow.
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
Yes, you should check which filename value you pass to images.save

Try debugging it
N
Nicholas Tiveron (1710 points)
2 5 8
by (1.7k points)
Thank you, I was able to find how to fix it (since I added it later, the order of the arguments I was passing in the recursive function was wrong, so I was passing a counter initialized at 0 instead of the filename, hence the file "0.png": totally my fault). Just one small thing: is there a way to delete an image (since we can't create an empty one)? In some tests the new image gets added to the previous one (and I already tried emptying the original matrix but the problem is the file itself).
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
You mean in the VM?

Every time you submit the program all other files should be deleted.

Moreover, you cannot create a wrong filenames when DEBUG is off
N
Nicholas Tiveron (1710 points)
2 5 8
by (1.7k points)
Thank you so much, now I'm done, I just have to speed up my code a little bit.