Unable to compare two junk character string in Iron Python.Do I need to include any particular encoding.??

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to compare two junk character string in Iron Python.Do I need to include any particular encoding.??

saurabh rawat

HI,
I have problem while working with text containing the unknown characters
I have a method which compare the variable song with "some special character string"  and return true and false on the match and mismatch respectively.

example

(0)song = The goodgoddevil robzombie pfjsdfgolsdg á é ú
(1)if song == "The goodgoddevil robzombie pfjsdfgolsdg á é ú"

it exits as soon as it tries to execute the line (1)


I have go-ogled and found that something like this is to be  included
#!/usr/bin/python
# -*- coding: ascii -*-

But still the same behavior, i think some problem with the coding - encoding standard.
Could plz somebody help.

Rgds,
Saurabh
                                
               " The ultimate test of a relationship is to disagree but to hold hands...............
              
 

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: Unable to compare two junk character string in Iron Python.Do I need to include any particular encoding.??

Lukas Cenovsky
You should use the same encoding as has you special character string.
Have you tried using utf-8 instead of ascii?

--
-- Lukáš


On 26.4.2011 11:56, saurabh rawat wrote:

HI,
I have problem while working with text containing the unknown characters
I have a method which compare the variable song with "some special character string"  and return true and false on the match and mismatch respectively.

example

(0)song = The goodgoddevil robzombie pfjsdfgolsdg á é ú
(1)if song == "The goodgoddevil robzombie pfjsdfgolsdg á é ú"

it exits as soon as it tries to execute the line (1)


I have go-ogled and found that something like this is to be  included
#!/usr/bin/python
# -*- coding: ascii -*-

But still the same behavior, i think some problem with the coding - encoding standard.
Could plz somebody help.

Rgds,
Saurabh
                                
               " The ultimate test of a relationship is to disagree but to hold hands...............
              
 
_______________________________________________ Users mailing list [hidden email] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: Unable to compare two junk character string in Iron Python.Do I need to include any particular encoding.??

saurabh rawat

Hmm..you mean to say # -*- coding: utf-8-*- like this..will give it a try..i have actually but no success or may be I am missing the correct way to specify it.
Thanks and Rgds,
Saurabh
                                
               " The ultimate test of a relationship is to disagree but to hold hands...............
              
 


--- On Tue, 26/4/11, Lukas Cenovsky <[hidden email]> wrote:

From: Lukas Cenovsky <[hidden email]>
Subject: Re: [IronPython] Unable to compare two junk character string in Iron Python.Do I need to include any particular encoding.??
To: "Discussion of IronPython" <[hidden email]>
Date: Tuesday, 26 April, 2011, 4:46 PM

You should use the same encoding as has you special character string.
Have you tried using utf-8 instead of ascii?

--
-- Lukáš


On 26.4.2011 11:56, saurabh rawat wrote:

HI,
I have problem while working with text containing the unknown characters
I have a method which compare the variable song with "some special character string"  and return true and false on the match and mismatch respectively.

example

(0)song = The goodgoddevil robzombie pfjsdfgolsdgâ¯â« á é ú
(1)if song == "The goodgoddevil robzombie pfjsdfgolsdgâ¯â« á é ú"

it exits as soon as it tries to execute the line (1)


I have go-ogled and found that something like this is to be  included
#!/usr/bin/python
# -*- coding: ascii -*-

But still the same behavior, i think some problem with the coding - encoding standard.
Could plz somebody help.

Rgds,
Saurabh
                                
               " The ultimate test of a relationship is to disagree but to hold hands...............
              
 

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

-----Inline Attachment Follows-----

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: Unable to compare two junk character string in Iron Python.Do I need to include any particular encoding.??

Jan-Philip Gehrcke
Saurabh,

first of all, you did not provide an error message, but it looks like a
decoding/unicode issue.

Visit:
http://stackoverflow.com/questions/368805/python-unicodedecodeerror-am-i-misunderstanding-encode
The first answer should help a lot.

Furthermore, this seems to be good literature on the field:
http://www.joelonsoftware.com/articles/Unicode.html
http://docs.python.org/howto/unicode.html

Regarding the application of # -*- coding: coding -*-, read here:
http://www.network-theory.co.uk/docs/pytut/SourceCodeEncoding.html

So, in your case it looks like a good idea to use e.g. UTF-8 as source
encoding. Check the settings of the text editor you are using and set
the source encoding to UTF-8 (if it does not allow this, you should use
another editor). Then, tell (Iron)Python that your source code is
encoded by UTF-8 by putting this into the file header: # -*- coding:
utf-8 -*-.

Cheers,

Jan-Philip


On 04/26/2011 01:51 PM, saurabh rawat wrote:

>
> Hmm..you mean to say # -*- coding: utf-8-*- like this..will give it a
> try..i have actually but no success or may be I am missing the correct
> way to specify it.
> Thanks and Rgds,
> Saurabh
>                                
>                " /*The ultimate test of a relationship is to disagree
> but to hold hands*............/..."
>              
>  
>
>
> --- On *Tue, 26/4/11, Lukas Cenovsky /<[hidden email]>/* wrote:
>
>
>     From: Lukas Cenovsky <[hidden email]>
>     Subject: Re: [IronPython] Unable to compare two junk character
>     string in Iron Python.Do I need to include any particular encoding.??
>     To: "Discussion of IronPython" <[hidden email]>
>     Date: Tuesday, 26 April, 2011, 4:46 PM
>
>     You should use the same encoding as has you special character string.
>     Have you tried using utf-8 instead of ascii?
>
>     --
>     -- Lukáš
>
>
>     On 26.4.2011 11:56, saurabh rawat wrote:
>>
>>     HI,
>>     I have problem while working with text containing the unknown
>>     characters
>>     I have a method which compare the variable song with "some special
>>     character string"  and return true and false on the match and
>>     mismatch respectively.
>>
>>     example
>>
>>     (0)song = The goodgoddevil robzombie pfjsdfgolsdgâ¯â« á é ú
>>     (1)if song == "The goodgoddevil robzombie pfjsdfgolsdgâ¯â« á é ú"
>>
>>     it exits as soon as it tries to execute the line (1)
>>
>>
>>     I have go-ogled and found that something like this is to be  included
>>     #!/usr/bin/python
>>     # -*- coding: ascii -*-
>>
>>     But still the same behavior, i think some problem with the coding
>>     - encoding standard.
>>     Could plz somebody help.
>>
>>     Rgds,
>>     Saurabh
>>                                    
>>                    " /*The ultimate test of a relationship is to
>>     disagree but to hold hands*............/..."
>>                  
>>      
>>
>>
>>     _______________________________________________
>>     Users mailing list
>>     [hidden email] </mc/compose?to=[hidden email]>
>>     http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>     -----Inline Attachment Follows-----
>
>     _______________________________________________
>     Users mailing list
>     [hidden email] </mc/compose?to=[hidden email]>
>     http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
> _______________________________________________
> Users mailing list
> [hidden email]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Reply | Threaded
Open this post in threaded view
|

Re: Unable to compare two junk character string in Iron Python.Do I need to include any particular encoding.??

saurabh rawat

An iron python script may sometimes retrieve values that may contain junk values such asThe Urbane fjnadlfkjsdglk pfjsdfgolsdg á é ú”.

Or you may assign such junk values to a variable ex: Artist = “The Urbane fjnadlfkjsdglk pfjsdfgolsdg á é ú”.

 

When you try to save the file we encounter an error which says “Invalid encoding, ascii saving as UTF-8”

 

Solution:

Close the script(.py)

Open it now with note pad

Click save as

You can see “Encoding” option

Select “Unicode” and click save

 

Run the script, it will work fine.

 

Note: You will not be able to open the script again with IDE. You can open it using note pad



This is the answer soem one has given to me , and it worked too....


rgds,

Saurabh



                                
               " The ultimate test of a relationship is to disagree but to hold hands...............
              
 


--- On Tue, 26/4/11, Jan-Philip Gehrcke <[hidden email]> wrote:

From: Jan-Philip Gehrcke <[hidden email]>
Subject: Re: [IronPython] Unable to compare two junk character string in Iron Python.Do I need to include any particular encoding.??
To: "Discussion of IronPython" <[hidden email]>
Date: Tuesday, 26 April, 2011, 5:50 PM

Saurabh,

first of all, you did not provide an error message, but it looks like a
decoding/unicode issue.

Visit:
http://stackoverflow.com/questions/368805/python-unicodedecodeerror-am-i-misunderstanding-encode
The first answer should help a lot.

Furthermore, this seems to be good literature on the field:
http://www.joelonsoftware.com/articles/Unicode.html
http://docs.python.org/howto/unicode.html

Regarding the application of # -*- coding: coding -*-, read here:
http://www.network-theory.co.uk/docs/pytut/SourceCodeEncoding.html

So, in your case it looks like a good idea to use e.g. UTF-8 as source
encoding. Check the settings of the text editor you are using and set
the source encoding to UTF-8 (if it does not allow this, you should use
another editor). Then, tell (Iron)Python that your source code is
encoded by UTF-8 by putting this into the file header: # -*- coding:
utf-8 -*-.

Cheers,

Jan-Philip


On 04/26/2011 01:51 PM, saurabh rawat wrote:

>
> Hmm..you mean to say # -*- coding: utf-8-*- like this..will give it a
> try..i have actually but no success or may be I am missing the correct
> way to specify it.
> Thanks and Rgds,
> Saurabh
>                                 
>                " /*The ultimate test of a relationship is to disagree
> but to hold hands*............/..."
>               

>
>
> --- On *Tue, 26/4/11, Lukas Cenovsky /<cenovsky@...>/* wrote:
>
>
>     From: Lukas Cenovsky <cenovsky@...>
>     Subject: Re: [IronPython] Unable to compare two junk character
>     string in Iron Python.Do I need to include any particular encoding.??
>     To: "Discussion of IronPython" <users@...>
>     Date: Tuesday, 26 April, 2011, 4:46 PM
>
>     You should use the same encoding as has you special character string.
>     Have you tried using utf-8 instead of ascii?
>
>     --
>     -- Lukáš
>
>
>     On 26.4.2011 11:56, saurabh rawat wrote:
>>
>>     HI,
>>     I have problem while working with text containing the unknown
>>     characters
>>     I have a method which compare the variable song with "some special
>>     character string"  and return true and false on the match and
>>     mismatch respectively.
>>
>>     example
>>
>>     (0)song = The goodgoddevil robzombie pfjsdfgolsdgâ¯â« á é ú
>>     (1)if song == "The goodgoddevil robzombie pfjsdfgolsdgâ¯â« á é ú"
>>
>>     it exits as soon as it tries to execute the line (1)
>>
>>
>>     I have go-ogled and found that something like this is to be  included
>>     #!/usr/bin/python
>>     # -*- coding: ascii -*-
>>
>>     But still the same behavior, i think some problem with the coding
>>     - encoding standard.
>>     Could plz somebody help.
>>
>>     Rgds,
>>     Saurabh
>>                                     
>>                    " /*The ultimate test of a relationship is to
>>     disagree but to hold hands*............/..."
>>                   
>>     
>>
>>
>>     _______________________________________________
>>     Users mailing list
>>     Users@... </mc/compose?to=Users@...>
>>     http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>     -----Inline Attachment Follows-----
>
>     _______________________________________________
>     Users mailing list
>     Users@... </mc/compose?to=Users@...>
>     http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
>
> _______________________________________________
> Users mailing list
> Users@...
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
Users@...
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
[hidden email]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com