[Tutor] Question about writing to Excel with slavic characters

Marko Limbek marko.limbek at valicon.net
Wed Mar 7 16:20:50 CET 2012


Hi,

I have been trying to use that programme but without success.
In Eclipse you usually create new project in two steps, first you
create new Pydev project, then inside you create new Pydev module.
I have created new project and new module 'crosstabs', where I want to
read spss file. My programme is the module.
Now I have put this ReaderWriter programme into the same Pydev project
as a another new module called 'rw' and then imported it into my
module 'crosstabs' with

import rw
from rw import SavReader

I don't even know, if I did that correctly. Actually I don't even know
how to implement that programme.
I put the recommended code

savFileName = "C:/dropbox/Exc_MarkoL_Zenel/Valicon/crosstabs/Tabela/ipk108_kosovo_data_finale_c1-1.sav"
with SavReader(savFileName) as sav:
    header = sav.next()
    for line in sav:
        process(line)


but I am get errors



I have however managed to compile the programme in the module, I just
had to comment more than 20 lines (because of that problem with
"employee data.sav" ).
I also don't know, if it was right to comment all those lines. Without
commenting them I can't even compile the module.


Maybe someone can tell me, how to actually implement that programme?
Where to put it in my Eclipse?


Is this programm ethe best way to read spss with Python?


Thank you so much,

Marko





On Tue, Mar 6, 2012 at 4:53 PM, Marko Limbek <marko.limbek at valicon.net> wrote:
> Hi Albert
>
> Two notes
> first I have used the promising looking package memics and the result
> is the same as foreign package. Reading in R is fine, but reading in
> rpy on Python27 unfortunatelly I get funny characters again like
> PRI�TINA
>
> second I have to run your programme and I get the following errors,
> that I send in attachment as printscreen. There is a file "employee
> data.sav" that I don't have and if I define my own file, I am asked in
> the next step about the variable "id" that I also don't have. So I
> would like to ask for your advise.
>
> Thanks,
> Marko
>
>
>
> On Mon, Mar 5, 2012 at 8:20 PM, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
>> Hi,
>>
>> The R package foreign, in particular the read.spss function has some known
>> problems reading spss system files. The memisc package also has a function
>> to read .sav files. The big advantage of that function is that you can
>> select rows and columns prior to actually reading the data into memory.
>>
>> If you're just using R and Rpy to read .sav files, you could also consider
>> using a Python program that I wrote a while ago:
>> http://code.activestate.com/recipes/577811-python-reader-writer-for-spss-sav-files-linux-mac-/
>> It runs on Windows, Mac and Linux and requires no installation of spss. I'd
>> be interested to hear your experiences.
>>
>> Regards,
>> Albert-Jan
>>
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> All right, but apart from the sanitation, the medicine, education, wine,
>> public order, irrigation, roads, a
>> fresh water system, and public health, what have the Romans ever done for
>> us?
>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>
>> ________________________________
>> From: Marko Limbek <marko.limbek at valicon.net>
>> To: cwitts at compuscan.co.za
>> Cc: tutor at python.org
>> Sent: Monday, March 5, 2012 2:05 PM
>> Subject: Re: [Tutor] Question about writing to Excel with slavic characters
>>
>> Thank you!
>>
>> That was easy. Now I have another problem.
>> I use RPy and read the spss database with method read.spss inside a
>> nested R code in Python, that looks like that:
>>
>>
>> import rpy
>>
>> r("""
>>
>> library(foreign)
>>
>> baza <- read.spss(""" + analysis[0] + """)
>>
>> print(baza$demo_izob0)
>>
>> """)
>>
>> Now when my text data labels in spss have slavic characters, they are
>> not recognised and output is something like that:
>>
>> stiriletna srednja �ola
>> nedokon�ana osnovna �ola
>>
>>
>> What should I do here?
>>
>>
>> Thanks a lot,
>>
>>
>> Marko
>>
>>
>>
>>
>> On Mon, Mar 5, 2012 at 1:46 PM, Christian Witts <cwitts at compuscan.co.za>
>> wrote:
>>> On 2012/03/05 02:37 PM, Marko Limbek wrote:
>>>
>>> Hi everyone.
>>>
>>>
>>> I am new to list and few months old to Python. I am writing some text
>>> to Excel and I open the new book and try to write to the book and the
>>> save it using
>>>
>>> book.save
>>>
>>> Now when I write slavic characters in the text to Excel (č, š, ž, for
>>> instance 0xc5), I get an error, I can't save it.
>>> I have declared appropriate encoding
>>>
>>> # -*- coding: utf-8 -*-
>>> # coding=<utf-8>
>>> #!/E:/Python
>>>
>>> and those characters appear normally in the code, but there seems to
>>> be the problem with the function book.save.
>>> Does anyone have any ideas, what would be the problem and how to solve
>>> it? Some additional encoding or some changes or parameters to the
>>> book.save method?
>>>
>>> Is that the right forum for my question?
>>>
>>>
>>> Thank you,
>>>
>>> Marko
>>> _______________________________________________
>>> Tutor maillist  -  Tutor at python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>> What package are you using to create your Excel workbook ?
>>> If it's xlwt you can set your encoding type when you create your workbook
>>> book = xlwt.Workbook(encoding="utf-8")
>>> --
>>>
>>> Christian Witts
>>> Python Developer
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>


More information about the Tutor mailing list