Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
10803 Zobrazení

Hi, I'm trying to create a file and write to it, but the file is not created. Here's my code:

            f=open('test.txt','w')
            f.write("this is a test")
            f.close()

This code works well outside openerp, but it's not working when it's integrated into a module, the file is not created. Any help would be appreciated.

Avatar
Zrušit
Nejlepší odpověď

Hi, you can also do with following :

open('/home/xxx/xxxx/test.txt','wb').write('Testing')

Avatar
Zrušit
Autor

Thank you, but that code does not work in Openerp, but works outside it:

I think there is something wrong at your end, i test the same code in openerp and its work perfectly to me.

Autor

I think that too. Where did you test your code? Did you write a custom module for that?

Actually that is not matter, you can write it anywhere in openerp, but for test in addons/sale/sale.py in def action_button_confirm(self, cr, uid, ids, context=None): in this just write like open('/home/xxx/xxxx/test.txt','wb').write('Testing') and its generate at the time of sale order confirming.

Autor

Yes, that worked in sale.py, thanks a lot. But it does not work in product_images.py in product_images_olbs module. So I have to find where to place my little piece of code into that file.

Nejlepší odpověď

Hi, you can use a TemporaryFile.

from tempfile import TemporaryFile
f = TemporaryFile('w+')
f.write("this is a test")
f.seek(0) # this will send you to the beginning of the file
print f.read()
f.close()
Avatar
Zrušit
Autor

Thank you for your answer, but unfortunately it does not work.

this code is tested and works well !

Autor

Is it tested in Openerp? Do you import only TemporaryFile? The two codes are correct, but the files are not created, I think that's a problem of file permissions or packages to import...

Autor

Thank you, but I have to work with normal files, not with temporary ones, As I said this code works in a separate script but not in Openerp. Did you write a wizard to run this code?

Related Posts Odpovědi Zobrazení Aktivita
1
pro 19
27744
1
kvě 22
3001
2
bře 19
11027
1
bře 15
5869
1
bře 15
6207