FAQ
Hello,
this is my first post. I'm trying to learn Python language which I find great, but I have a big problem with its editors/IDEs.

I have tested IDLE (which installed with Python3 from ActiveState), Notepad++ and finally Komodo EDIT. I don't like IDLE GUI, but Notepad++ and Komodo EDIT looks nice for me.

Unfortunatelly there is something wrong with input() command when I'm using Komodo or Notepad. For example this code:

a = input("Wprowadz zmienna a: ")
b = input("Wprowadz zmienna b: ")
print("a to: ", a)
print("b to: ", b)
print(int(a) + int(b))

works well in IDLE, but when I'm switching to Notepad/Komodo I'm getting something like this:

Wprowadz zmienna a: 3
Wprowadz zmienna b: 2
a to: 3
b to: Wprowadz zmienna b: 2
Traceback (most recent call last):
File "c:\users\sunrrrise\Desktop\test.py", line 9, in <module>
print(int(a) + int(b))
ValueError: invalid literal for int() with base 10: 'Wprowadz zmienna b: 2'

I don't know what is going on. Any ideas or, better, solutions?

My OS: Windows 7 64bit, ActiveState Python 3.2, Notepad++ 5.9, Komodo Edit 6.1, coding: UTF-8

Regards,
sunrrrise

Search Discussions

  • Chris Angelico at May 22, 2011 at 10:49 pm

    On Mon, May 23, 2011 at 8:43 AM, sunrrrise wrote:
    Hello,
    this is my first post. I'm trying to learn Python language which I find great, but I have a big problem with its editors/IDEs. Welcome!
    b to: ?Wprowadz zmienna b: 2
    This looks wrong. Are you copying and pasting several lines, or simply
    pressing the 2 key followed by Enter?

    It's showing a lengthy string in the variable 'b', which - quite
    correctly - cannot be cast to int.

    Chris Angelico
  • Sunrrrise at May 22, 2011 at 10:59 pm
    Thank you for quick response!

    English is not my native language so I'm going to keep my explanations simple.

    This really simple script asks me for two variables called "a" and "b". For example, I type "4" for "a" and "3" for "b" and IDLE gives me that:

    Wprowadz zmienna a: 4
    Wprowadz zmienna b: 3
    a to: 4
    b to: 3
    7

    Works fine!

    But when I'm using Notepad (or Komodo) I get this:

    Wprowadz zmienna a: 4
    Wprowadz zmienna b: 3
    Traceback (most recent call last):
    File "c:\users\sunrrrise\Desktop\test.py", line 7, in <module>
    print(int(a) + int(b))
    ValueError: invalid literal for int() with base 10: 'Wprowadz zmienna b: 3'
    a to: 4
    b to: Wprowadz zmienna b: 3

    This is exactly the same script from the same file. I really don't get it.
  • Chris Angelico at May 22, 2011 at 11:21 pm

    On Mon, May 23, 2011 at 8:59 AM, sunrrrise wrote:
    Thank you for quick response!

    English is not my native language so I'm going to keep my explanations simple.
    No problem, your English is far better than my Polish. (I used Google
    Translate to figure out what "Wprowadz zmienna" means.)

    I tried copying and pasting your exact code, even down to using
    Notepad, but it worked fine. The interpreter I used was a
    freshly-downloaded Python 3.2, listing itself as r32:88445 dated Feb
    20 2011, 21:29:03.

    This may be a really specific bug. Can you email me the actual Python
    file you're having problems with, please? Off-list, as this list
    doesn't like attachments. I'll try running it on my system and see if
    it's any different.

    Chris Angelico
  • Chris Angelico at May 23, 2011 at 10:42 pm

    On Tue, May 24, 2011 at 1:44 AM, Aleksander Pietkiewicz wrote:
    Hello,
    I have googled your email address, I hope it is not a problem.
    Thank you for your help!
    I figured you would get it from my post, but either way works! My
    email address is fairly well known. Sorry for the delay in response;
    you caught me while I was asleep. :) I'm now responding on-list so
    that other people can help.
    I agree that can be very specific bug, I suspect it is matter of coding. I'm
    emailing you a *.py file as you asked and screenshot showing script being
    run.
    Unfortunately my Windows install doesn't have internationalization
    support, which may be an issue here. I ran your 'couting.py' and got
    errors back:
    Traceback (most recent call last):
    File "foo.py", line 11, in <module>
    n=input("Naci\u015bnij Enter aby zako\u0144czy\u0107...")
    File "C:\python32\lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
    UnicodeEncodeError: 'charmap' codec can't encode character '\u015b' in position
    4: character maps to <undefined>

    So I'm guessing that codepage 437 is just plain wrong. But that
    shouldn't affect your system.
    As you can see this problem occurs only with 3rd party software (like Komodo
    Edit).
    In, addition when I'm using Komodo or Notepad++ and input() function, Python
    miscount bytes. See attached.
    Once again thank you for your help!
    Kind regards,
    Aleksander Pietkiewicz
    My suspicion here is that your editor is saving using one encoding,
    and Python is expecting another. I recommend you put an encoding
    marker at the top of your source file:

    # coding=utf-8

    See http://www.python.org/dev/peps/pep-0263/ for details. With this in
    place, you should be able to guarantee that the bytestream is parsed
    the same way by editor and interpreter.

    Unfortunately that's all I could offer; I was unable to duplicate the
    exact problem you were seeing. The contents of 'couting.py' are simple
    enough, so I'll paste here in case anyone can spot a problem:


    s = (input('Enter something : '))
    z = input('Enter something : ')

    print('Length of the string s is', len(s))
    print('Length of the string z is', len(z))

    print(s)
    print(z)


    Point to note: On my Windows XP, the string lengths are one higher
    than expected, and they include a \r at the end. Is there any way that
    this could trigger a Unicode parse failure??

    Chris Angelico

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 22, '11 at 10:43p
activeMay 23, '11 at 10:42p
posts5
users2
websitepython.org

2 users in discussion

Chris Angelico: 3 posts Sunrrrise: 2 posts

People

Translate

site design / logo © 2022 Grokbase