Kurt B. Kaiser | 2 Jun 2004 02:48
Picon
Favicon

Re: Python 2.3 IDLE is randomly freezing.

Markus Ingvarsson <markus.ingvarsson <at> lugn.nu> writes:

>> Sounds like a Tk problem in the Sid environment.  Try setting up a
>> Tk text widget without using IDLE and see if you can reproduce the
>> problem.
>
> I created a window with just a textbox in it and pressed a key for
> quite some time, erased and typing randomly, it didn't hang.  IDLE
> usually hangs after a few seconds if I do this.
>
> I say _usually_ because I've been trying different ways to provoke the
> bug.
>
> If I open a new window (no syntax highlighting), I can type for all I
> care without it hanging.  But in PyShell or when editing a file
> (syntax highlighting), it hangs sooner or later - especially when
> holding a key pressed for a while.

OK, so you are narrowing it down to a Tk problem which shows up when
using tags.  Keep at it!  (It's getting to be more work, now :)

Thanks,
--

-- 
KBK
Kurt B. Kaiser | 2 Jun 2004 02:54
Picon
Favicon

Re: IDLE Backspace not working correctly in Win2000

"Hopkins, Jason (MED, GEMS-IT)" <Jason.Hopkins <at> med.ge.com> writes:

> I am running IDLE 1.0.2 & Python 2.3.3 in Win2000 and XP.  On my XP box I
> don't have any problems, but in Win2000 when I hit backspace or when I hit
> Enter to start a new line a small square box appears.  When I hit backspace
> the letter to the left becomes a box and then I'm set back to the same
> position I was when I started.  Looks like this:
>  
>>>> backspace
>>>> backspac
>  
> The hex is 08, so it looks like a backspace, but I don't know why it doesn't
> work.
>  
> Return creates a new line then puts a box on that line.  It's hex is 0d, so
> it looks like a newline, again, I don't understand why this works on XP, but
> not on my 2k box.

Man, I don't know.  IDLE works OK on my W2K and XP boxes.  All your
other apps are OK?  How about creating a Tk text widget without using
IDLE and see how that functions?

--

-- 
KBK
Grégoire Dooms | 14 Jun 2004 10:29
Picon

Re: Feature request, evaluate an expression when stopped at a breakpoint

Sorry for multiple posts, but the original mail has been retained by 
moderator, I got no news from it and I could not delete it.

Al Schapira a.d.schapira at worldnet.att.net
wrote on Thu Apr 1 14:23:47 EST 2004 :

> I've been using IDLE both for debugging my own code and for learning
> about how other folks code works.  There is a feature that I'm looking
> for that is so basic I believe it must be possible, but I haven't seen
> it described anywhere:  the ability to enter and evaluate an expression
> when stopped at a breakpoint.  The expression would be evaluated in the
> context of the current breakpoint.
>
I would need this too.
I currently uses the simple pdb comand line debugger included in python
to do this.
I mostly use it under ipython to benefit from its 'debug at uncaught
exception' feature.

> Building on this would be the *automatic* evaluation of one or more 
> previously entered expressions every time a breakpoint was hit.

> I envision an additional subwindow of the idle window in which each
> user's expression and its value would be automatically displayed when
> stopped at a breakpoint. The expressions to be evaluated could be
> entered or changed whenever idle is stopped at any breakpoint.
>
> Other debuggers I used (for C debugging) have a similar capability.

If you are referring a feature similar to breakpoint command lists in
(Continue reading)

Grégoire Dooms | 14 Jun 2004 10:43
Picon

Qualified name autocompletion

Sorry for multiple posts, but the original mail has been retained by 
moderator, I got no news from him and I could not delete it.

Hi,
I intend to use IDLE for a python course.
I patched it so it supports qualified names autocompletion using
namespace inspection a la CallTips.py.

I was about to submit the patch to the python patch manager when I
discovered that this feature is covered (more in-depth) by a large patch
(patch 906702) which covers a lot of features.

I have been using IDLE with this patch for a few days, and I think it's 
quite good though I did not review the source code (quite a big patch). 
The patch is a little hard to apply (had to do a couple diffs by hand), 
I may submit a context diff against CVS HEAD or any python release if 
you are interrested.

I have just a small comment about the AutoCompleteWindow : I should not 
pop-up when the word behind the cursor is not a prefix of any word in 
the list. Currently the window pops up and the item selected is the one 
where the partial word would be listed if it was present. (Hope I'm clear)

Do you think mine is worth posting (to this list  or to the patch tracker) ?

--
Grégoire Dooms
Kurt B. Kaiser | 15 Jun 2004 20:42
Picon
Favicon

Re: Qualified name autocompletion

Grégoire Dooms <dooms <at> info.ucl.ac.be> writes:

> Sorry for multiple posts, but the original mail has been retained by
> moderator, I got no news from him and I could not delete it.

I didn't see your posts in the spam I cleared out (that's the reason
for the 'moderation').  Not sure what happened to them.  But now you've
joined the list, that's the best way.  Welcome!

> Hi, I intend to use IDLE for a python course.  I patched it so it
>supports qualified names autocompletion using namespace inspection a
>la CallTips.py.
>
> I was about to submit the patch to the python patch manager when I
> discovered that this feature is covered (more in-depth) by a large patch
> (patch 906702) which covers a lot of features.

I expect that this patch will be applied.  I've been working with it for
awhile, and I do have a number of comments which will need to be addressed
before it can be incorporated.

> I have been using IDLE with this patch for a few days, and I think
>it's quite good though I did not review the source code (quite a big
>patch). The patch is a little hard to apply (had to do a couple diffs
>by hand), I may submit a context diff against CVS HEAD or any python
>release if you are interrested.

You could send your diff to Noam Raphael.

Noam has a group of people who are developing and testing this patch.
(Continue reading)

Dragonfirebane | 29 Jun 2004 09:24
Picon
Favicon

(IOError: [Errno 9] Bad file descriptor) in IDLE

I've run across this a couple times while running my programs on IDLE and i was recommended by dyoo <at> hkn.eecs.berkeley.edu to post it here. I was running Python 2.3.4c1 at the time. Since then, I've downloaded the final version and the problem does not appear to persist there. Attached is the code for one of the programs I was trying to use (please excuse the un-updated, and therefore useless, commenting).
 
>>> Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\PROGRA~1\PYTHON~1.4C1\lib\lib-tk\Tkinter.py", line 1345, in __call__
    return self.func(*args)
  File "C:\PROGRA~1\PYTHON~1.4C1\lib\idlelib\ScriptBinding.py", line 135, in run_module_event
    code = self.checksyntax(filename)
  File "C:\PROGRA~1\PYTHON~1.4C1\lib\idlelib\ScriptBinding.py", line 96, in checksyntax
    return compile(source, filename, "exec")
  File "C:\PROGRA~1\PYTHON~1.4C1\lib\warnings.py", line 116, in warn_explicit
    showwarning(message, category, filename, lineno)
  File "C:\PROGRA~1\PYTHON~1.4C1\lib\idlelib\PyShell.py", line 55, in idle_showwarning
    file.write(warnings.formatwarning(message, category, filename, lineno))
IOError: [Errno 9] Bad file descriptor
 
-Orri
 
Email: dragonfirebane <at> aol.com
AIM: singingxduck
Programming Python for the fun of it.
##########################################################################
##                              Multivert                               ##
##########################################################################

##########################################################################
##                                                                      ##
##  To - Do:                                                            ##
##  --------                                                            ##
##                                                                      ##
##  1.  Get converthex(whichconv) to work.                              ##
##  2.  Change convertnum(whichconv) and convertbin(whichconv) so that  ##
##      when a carat (^) is seen, that number goes up by enough so that ##
##      it is considered uppercase.                                     ##
##  3.  Treat decimal numbers separated by a space as separate          ##
##      (original.split()) so that each separate unit can be converted  ##
##      to its own letter (includes removing int(original) tests early  ##
##      on).                                                            ##
##  4.  Implement change in spaces around punctuation in all modules so ##
##      that 3 will work.                                               ##
##  5.  Allow a calculation to be performed after a conversion          ##
##      until user declines.                                            ##
##  6.  Allow convertbin(whichconv) to recognize punctuation.           ##
##  7.  Print '\xba' (degrees sign) from string.letters when character  ##
##      or number isn't recognized (or '[?]' . . . probably easier to   ##
##      do that one).                                                   ##
##                                                                      ##
##########################################################################

##to see comments, maximize window or scroll all the way to the right
def calc(manip):
    global counter
    global allcalc
    if manip == 'exponents':
        base = float(raw_input("Please enter the base. "))
        expon = float(raw_input("Please enter the exponent. "))
        results = base ** expon
        Sitemlist = []
        Sitemlist.append("%d to the power of %d equals %d." % (base, expon, results))
        Sitemlist = ''.join(Sitemlist)
        print Sitemlist
        allcalc.append('____Calculation %d: . . . ' % counter + Sitemlist)
        manip = 'end'
    elif manip == 'multiplication':
        leng = int(raw_input("Please enter number of items to be multiplied: "))
        itemlist = []
        item1 = float(raw_input("Please enter first item to multiply: "))
        itemlist.append(item1)
        Sitemlist = []
        Sitemlist.append(str(item1))
        for i in range (1, leng):
            item2 = float(raw_input("Please enter next item to multiply: "))
            itemlist.append(item2)
            Sitemlist.append(str(item2))
        for x in itemlist[:]:
            try:
                results = itemlist[0] * itemlist[1]
                itemlist.remove(itemlist[0])
                itemlist.remove(itemlist[0])
                itemlist.insert(0, results)
            except IndexError:
                pass
        Sitemlist = ' times '.join(Sitemlist)
        Sitemlist += ' equals ' + str(results) + '.'
        print Sitemlist
        allcalc.append('____Calculation %d: . . . ' % counter + str(Sitemlist))
        manip = 'end'
    elif manip == 'division':
        leng = int(raw_input("Please enter the number of items to be divided: "))
        itemlist = []
        item1 = float(raw_input("Please enter number to divide. "))
        itemlist.append(item1)
        Sitemlist = []
        Sitemlist.append(str(item1))
        for i in range (1, leng):
            try:
                item2 = float(raw_input("Please enter number to divide by (default is 10). "))
            except ValueError:
                item2 = 10.0
            itemlist.append(item2)
            Sitemlist.append(str(item2))
        for x in itemlist[:]:
            try:
                results = itemlist[0] / itemlist[1]
                itemlist.remove(itemlist[0])
                itemlist.remove(itemlist[0])
                itemlist.insert(0, results)
            except IndexError:
                pass
        Sitemlist = ' divided by '.join(Sitemlist)
        Sitemlist += ' equals ' + str(results) + '.'
        print Sitemlist
        allcalc.append('____Calculation %d: . . . ' % counter + str(Sitemlist))
        manip = 'end'
    elif manip == 'addition':
        pass
        manip = 'end'
    elif manip == 'subtraction':
        pass
        manip = 'end'
    if manip == 'end':
        more = raw_input("Would you like to perform more calculations [y/n]? ")
        if more in 'Yy':
            counter += 1
        elif more in 'Nn':
            global again
            again = False
            allcal = raw_input("Would you like to see all calculations made this session [y/n]? ")
            if allcal in 'Yy':
                allcalc = ''.join(allcalc)
                print allcalc
            elif allcal in 'Nn':
                pass
            conv = raw_input("Would you like to perform a conversion [y/n]? ")
            if conv in 'Yy':
                global cal
                cal = 'conversion'
            elif conv in 'Nn':
                pass
def convertbin(whichconv):
    global res
    global original
    original = original.split()
    m = 0
    for x in original:
        if whichconv == 'Decimal':
            asNum = str(long(str(original[m]),2))
            res += asNum
            res += ' '
            m += 1
        elif whichconv == 'Hexadecimal':
            asHex = str(long(str(original[m]),2))
            if int(asHex) <= 0:
                res += '-'
                asHex = -int(asHex)
            asHex = "%X" % int(asHex)
            res += asHex
            res += ' '
            m += 1
        elif whichconv == 'Text':
            asNum = str(long(str(original[m]),2))
            if int(asNum) == 0:
                res += '%s' % chr(int(asNum) + 32)
            elif 0 < int(asNum) <= 26:
                res += '%s' % chr(int(asNum) + 96)
            elif 26 < int(asNum) <= 52:
                res += '%s' % chr(int(original) + 38)
            m += 1
        else:
            print """Sorry, you didn't enter a valid number.
Please enter only numbers between one and 26
"""
def convertnum(whichconv):                                                                          ##converts numbers
    from string import split
    if whichconv == 'Binary':                                                                       ##if user wants to convert to binary
        global original
        if int(original) <= 0:                                                                      ##if negative number entered
            global res                                                                              ##since res is redefined, tells python to use global res and not try to create a local one
            res += '-'                                                                              ##adds a minus sign to res
            original = -int(original)                                                               ##converts original to a positive number
        try:
            int(original)                                                                           ##currently redundant, eventually to discriminate between numbers and punctation
        except ValueError:
            x = 0
            for char in original:
                if char in punct:
                    res += char
                x += 1
        else:
            asOctal = "%o" % int(original)
            for char in asOctal:
                res += str(binary[char])
    elif whichconv == 'Hexadecimal':                                                                ##if user wants to convert to hex
        if int(original) <= 0:                                                                      ##global res/original already in module
            res += '-'
            original = -int(original)
        asHex = "%X" % int(original)
        res += asHex
    elif whichconv == 'Text':                                                                       ##if user wants to convert to text (only works one letter at a time)
        if int(original) == 0:                                                                      ##if number is 0
            res += '%s' % chr(int(original) + 32)                                                   ##adds a space to res 
        elif 0 < int(original) <= 26:                                                               ##if the number is 1-26
            res += '%s' % chr(int(original) + 96)                                                   ##prints corresponding letter
        elif 26 < int(original) <= 52:                                                              ##if number is between 26 and 52
            res += '%s' % chr(int(original) + 38)                                                   ##prints corresponding letter
        else:                                                                                       ##if its not one of those numbers
            print """Sorry, you didn't enter a valid number.
Please enter only numbers between 0 and 26.
"""                                                                                                 ##prints message
def converthex(whichconv):
    pass
def convertxt(whichconv):
    global res                                                                                      ##results list is modified, so this tells python to use the global list and not create a local one
    if whichconv == 'Binary':
        from string import split                                                                    ##so split and join work
        for char in original:                                                                       ##loops over the entire entry
            x = 0                                                                                   ##allows checking every character against the entire alphabet list
            if char in punct:                                                                       ##if character is punctuation
                res = split(res)                                                                    ##prints contents of res into a list and names it res
                res.append(' ')                                                                     ##adds a space at the end
                del res[-1]                                                                         ##deletes the space
                res = ' '.join(res)                                                                 ##returns res to string form
                res += char                                                                         ##adds punctuation
            elif char in alphabet:                                                                  ##if the character is in the alphabet
                while x == 0:
                    if char in alphabet[x]:
                        asOctal = "%o" % int(ord(char) - 32)
                        for char in asOctal:
                            res += binary[char]
                        res += ' '
                    x += 1
                while 0 < x <= 26:                                                                  ##if the character is  a lowercase letter or space
                    if char in alphabet[x]:                                                         ##redundant. only there to allow x += 1 to stay inside the while loop but outside the ifs
                        asOctal = "%o" % int(ord(char) - 96)                                        ##converts alphabet number (a = 1) to an unsigned octal
                        for char in asOctal:                                                        ##for character in resulting octal
                            res += binary[char]                                                     ##add the corresponding entry in the binary list to the res list
                        if char not in punct:                                                       ##if the character isn't punctuation
                            res += ' '                                                              ##add a space at the end to separate numbers
                    x += 1                                                                          ##adds 1 to the value of x so the loop doesnt go on forever
                while 26 < x <= 52:                                                                 ##if the character is an uppercase letter
                    if char in alphabet[x]:                                                         ##if the character is in the alphabet dictionary
                        res += '^'
                        asOctal = "%o" % int(ord(char) - 64)                                        ##converts alphabet number (A = 1) to an unsigned octal
                        for char in asOctal:
                            res += binary[char]
                        if char not in punct:
                            res += ' '
                    x += 1
    elif whichconv == 'Hexadecimal':                                                                ##convert text to hexadecimal
        from string import split
        for char in original:
            x = 0    
            if char in punct:
                res = split(res)                                    
                res.append(' ')                                     
                del res[-1]                                         
                res = ' '.join(res)                                 
                res += char                                         
            elif char in alphabet:
                while x == 0:
                    if char in alphabet[x]:
                        asHex = "%X" % int(ord(char) - 32)
                        res += asHex
                        res += ' '
                    x += 1
                while 0 < x <= 26:
                    if char in alphabet[x]:  
                        asHex = "%X" % int(ord(char) - 96)                                          ##convert alphabet number to corresponding Hexadecimal number
                        res += asHex                                                                ##add hexadecimal number to string
                        if char not in punct:
                            res += ' '
                    x += 1
                while 26 < x <= 52:
                    if char in alphabet[x]:
                        res += '^'
                        asHex = "%X" % int(ord(char) - 64)                                          ##convert alphabet number to corresponding hex number
                        res += asHex  
                        if char not in punct:     
                            res += ' '  
                    x += 1   
    elif whichconv == 'Decimal':                                                                    ##convert text to decimal
        from string import split
        for char in original:
            x = 0
            if char in punct:
                res = split(res)                                    
                res.append(' ')                                     
                del res[-1]                                         
                res = ' '.join(res)                                 
                res += char                                         
            elif char in alphabet:
                while x <= 52:   
                    if x == 0:
                        if char == alphabet[x]:                                                     ##if character is a space
                            res += '%d' % int(ord(char) - 32)                                       ##add a space to the string
                            if char not in punct:
                                res += ' '
                        x += 1
                    elif 0 < x <= 26:                                                               ##if character is a lowercase letter
                        if char in alphabet[x]:
                            res += '%d' % int(ord(char) - 96)                                       ##add corresponding number to string
                            if char not in punct:     
                                res += ' '  
                        x += 1   
                    elif 26 < x <= 52:                                                              ##if character is an uppercase letter
                        if char in alphabet[x]:  
                            res += '^'
                            res += '%d' % int(ord(char) - 64)                                       ##add corresponding number to string
                            if char not in punct:     
                                res += ' '  
                        x += 1   

import time                                                                                         ##for time.sleep(1.1) at end
import string                                                                                       ##for split(res), etc. in convertxt modules.

alphabet = ' ' + string.ascii_letters                                                               ##define alphabet string
punct = string.punctuation                                                                          ##define punctation string
binary = {'0':'000','1':'001','2':'010','3':'011','4':'100','5':'101','6':'110','7':'111'}         
##define the binary dictionary
number = string.digits

starmenu = {'1':'Binary','2':'Decimal','3':'Hexadecimal','4':'Text'}
bconmenu = {'1':'Decimal','2':'Hexadecimal','3':'Text'}
dconmenu = {'1':'Binary','2':'Hexadecimal','3':'Text'}
hconmenu = {'1':'Binary','2':'Decimal','3':'Text'}
tconmenu = {'1':'Binary','2':'Decimal','3':'Hexadecimal'}
counter = 1
allcalc = []
allconv = ''                                                                                        ##defines string containing all conversions
res = ''                                                                                            ##defines string containing single conversion
i = 0                                                                                               ##beginning condition for loop
again = True
cal = raw_input("Would you like to perform a conversion or a calculation? ")
while again:
    if cal == 'calculation':
        manip = raw_input("""Please enter intended manipulation (exponents, multiplication,
division, addition, or subtraction): """)
        calc(manip)
    if cal == 'conversion':
        res = ''                                                                                    ##empties the string so each conversion begins w/ an empty string
        startype = raw_input("""Which type of text would you like to convert?
1: Binary
2: Decimal
3: Hexadecimal
4: Text
... """)
        original = raw_input("Please enter %s to be converted. " % starmenu[startype].lower())      ##enter input to
be converted
        startype = starmenu[startype]
        if startype == 'Binary':
            whichconv = raw_input("""Convert to"
1: Decimal
2: Hexadecimal
3: Text
... """)
            whichconv = bconmenu[whichconv]
            convertbin(whichconv)
            print res
        elif startype == 'Decimal':
            whichconv = raw_input("""Convert to:
1: Binary
2: Hexadecimal
3: Text
... """)                                                                                            ##which conversion?
            whichconv = dconmenu[whichconv]
            convertnum(whichconv)                                                                   ##convert numbers to whatever
            print res                                                                               ##print string containing conversion
        elif startype == 'Hexadecimal':
            whichconv = raw_input("""Convert to:
1: Binary
2: Decimal
3: Text
... """)
            whichconv = hconmenu[whichconv]
            converthex(whichconv)
            print res
        elif startype == 'Text':
            whichconv = raw_input("""Convert to:
1: Binary
2: Decimal
3: Hexadecimal
... """)                                                                                            ##which conversion?
            whichconv = tconmenu[whichconv]
            convertxt(whichconv)
            print res                                                                               ##print the string containing the conversion
        i += 1
        original = ' '.join(original)
        allconv += ' ____Conversion %d: . . . ' % i + startype + ' => ' + whichconv + ' ... "' + original + '" => "' + res + '"'
                                                                                                    ##outside of try-except-else, inside while; adds each conversion to a master conversion list per session
        more = raw_input("Would you like to convert more text or numbers [y/n]? ")                  ##more?
        if more in 'Yy':                                                                            ##if so, continue loop
            pass
        elif more in 'Nn':                                                                          ##if not,
            again = False                                                                           ##break loop
callconv = raw_input("Would you like to see all the conversions performed during this session [y/n]? ")
if callconv in('y','Y','1','yes','Yes'):
    print allconv
else:
    pass
callcalcon = raw_input("""Would you like to see all the conversions and
calculations performed during this session [y/n]? """)
if callcalcon in 'Yy':
    print str(allcalc) + allconv
elif callcalcon in 'Nn':
    pass
try:
    exit = raw_input("""Hit enter or control-c to exit.
... """)
except KeyboardInterrupt:
    pass
else:
    pass
print "Thank you for using Multivert.  Multivert will now close."                                   ##loop broken, prints message
time.sleep(1.1)                                                                                     ##waits for 1.1 seconds so message can be read
                                                                                                    ##end of program; program closes
_______________________________________________
IDLE-dev mailing list
IDLE-dev <at> python.org
http://mail.python.org/mailman/listinfo/idle-dev
Vines, John (Civ,ARL/CISD | 29 Jun 2004 21:18
Picon

Import _socket error

        I have installed Python 2.3.2 on Irix64 and am trying to run the "idle" but keep getting an error stating "no module named _socket".  I believe I have my PYTHONPATH correct but am not sure.  Any help would be appreciated, thanx

John Vines
Computational Sciences and Engineering Branch
Scientific Visualization Team


_______________________________________________
IDLE-dev mailing list
IDLE-dev <at> python.org
http://mail.python.org/mailman/listinfo/idle-dev
Kurt B. Kaiser | 30 Jun 2004 08:35
Picon
Favicon

Re: Import _socket error

"Vines, John  (Civ,ARL/CISD)" <jvines <at> arl.army.mil> writes:

> 	I have installed Python 2.3.2 on Irix64 and am trying to run the
> "idle" but keep getting an error stating "no module named _socket".  I
> believe I have my PYTHONPATH correct but am not sure.  Any help would be
> appreciated, thanx

Without using IDLE, run Python:

hydra /home/kbk$ python
Python 2.2.1 (#1, Oct 17 2003, 16:36:36) 
[GCC 2.95.3 20010125 (prerelease, propolice)] on openbsd3
Type "help", "copyright", "credits" or "license" for more information.
>>> import _socket
>>> dir(_socket)
['AF_APPLETALK', 'AF_INET', 'AF_INET6'....

If you can't get that, Python isn't fully installed on your platform.  This doesn't
sound like an IDLE bug.

Check the output of the configure run when you built Python, look for a problem
with the socket module.
--

-- 
KBK
Dragonfirebane | 1 Jul 2004 13:00
Picon
Favicon

(IOError: [Errno 9] Bad file descriptor) in IDLE for Python 2.3.4 (final)

Although previously I believed the error to be confined to the IDLE packaged with the RC version of Python 2.3.4, after using IDLE 1.0.3, as packaged with Python 2.3.4 (final) to work out problems with one of my programs, I ran into the same error as I had with the previous version:
 
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\PROGRA~1\lib\lib-tk\Tkinter.py", line 1345, in __call__
    return self.func(*args)
  File "C:\PROGRA~1\lib\idlelib\ScriptBinding.py", line 135, in run_module_event
    code = self.checksyntax(filename)
  File "C:\PROGRA~1\lib\idlelib\ScriptBinding.py", line 96, in checksyntax
    return compile(source, filename, "exec")
  File "C:\PROGRA~1\lib\warnings.py", line 116, in warn_explicit
    showwarning(message, category, filename, lineno)
  File "C:\PROGRA~1\lib\idlelib\PyShell.py", line 55, in idle_showwarning
    file.write(warnings.formatwarning(message, category, filename, lineno))
IOError: [Errno 9] Bad file descriptor
 
The current Tk version is 8.4, although i do not know the version Tk involved with the previous error. At the time of the error, i had pressed 'F5' to run the attached program. Please excuse bad commenting in program as it is very much a work in progress.
 
Email: dragonfirebane <at> aol.com
AIM: singingxduck
Programming Python for the fun of it.
##########################################################################
##                              Multivert                               ##
##########################################################################

##########################################################################
##                                                                      ##
##  To - Do:                                                            ##
##  --------                                                            ##
##                                                                      ##
##  1.  Get converthex(whichconv) to work.  CHECK                       ##
##  2.  Change convertnum(whichconv) and convertbin(whichconv) so that  ##
##      when a carat (^) is seen, that number goes up by enough so that ##
##      it is considered uppercase.                                     ##
##  3.  Treat decimal numbers separated by a space as separate          ##
##      (original.split()) so that each separate unit can be converted  ##
##      to its own letter (includes removing int(original) tests early  ##
##      on).    CHECK                                                   ##
##  4.  Implement change in spaces around punctuation in all modules so ##
##      that 3 will work.                                               ##
##  5.  Allow a calculation to be performed after a conversion          ##
##      until user declines.    CHECK                                   ##
##  6.  Allow convertbin(whichconv) to recognize punctuation.           ##
##  7.  Print '\xba' (degrees sign) from string.letters when character  ##
##      or number isn't recognized (or '[?]' . . . probably easier to   ##
##      do that one).                                                   ##
##  8.  Allow default of 10 in multiplication (calc(manip)).    CHECK   ##
##  9.  If no conversions(/calculations), don't prompt for seeing all   ##
##      of said manipulations.  CHECK                                   ##
##                                                                      ##
##########################################################################

##to see comments, maximize window or scroll all the way to the right
def calc(manip):
    global counter
    global allcalc
    if manip == 'exponents':
        base = float(raw_input("Please enter the base. "))
        expon = float(raw_input("Please enter the exponent. "))
        results = base ** expon
        Sitemlist = []
        Sitemlist.append("%d to the power of %d equals %d." % (base, expon, results))
        Sitemlist = ''.join(Sitemlist)
        print Sitemlist
        allcalc.append('____Calculation %d: . . . ' % counter + Sitemlist)
        manip = 'end'
    elif manip == 'multiplication':
        leng = int(raw_input("Please enter number of items to be multiplied: "))
        itemlist = []
        item1 = float(raw_input("Please enter first item to multiply: "))
        itemlist.append(item1)
        Sitemlist = []
        Sitemlist.append(str(item1))
        for i in range (1, leng):
            try:
                item2 = float(raw_input("Please enter next item to multiply (default is 10): "))
            except ValueError:
                item2 = 10
            itemlist.append(item2)
            Sitemlist.append(str(item2))
        for x in itemlist[:]:
            try:
                results = itemlist[0] * itemlist[1]
                itemlist.remove(itemlist[0])
                itemlist.remove(itemlist[0])
                itemlist.insert(0, results)
            except IndexError:
                pass
        Sitemlist = ' times '.join(Sitemlist)
        Sitemlist += ' equals ' + str(results) + '.'
        print Sitemlist
        allcalc.append('____Calculation %d: . . . ' % counter + str(Sitemlist))
        manip = 'end'
    elif manip == 'division':
        leng = int(raw_input("Please enter the number of items to be divided: "))
        itemlist = []
        item1 = float(raw_input("Please enter number to divide. "))
        itemlist.append(item1)
        Sitemlist = []
        Sitemlist.append(str(item1))
        for i in range (1, leng):
            try:
                item2 = float(raw_input("Please enter number to divide by (default is 10). "))
            except ValueError:
                item2 = 10.0
            itemlist.append(item2)
            Sitemlist.append(str(item2))
        for x in itemlist[:]:
            try:
                results = itemlist[0] / itemlist[1]
                itemlist.remove(itemlist[0])
                itemlist.remove(itemlist[0])
                itemlist.insert(0, results)
            except IndexError:
                pass
        Sitemlist = ' divided by '.join(Sitemlist)
        Sitemlist += ' equals ' + str(results) + '.'
        print Sitemlist
        allcalc.append('____Calculation %d: . . . ' % counter + str(Sitemlist))
        manip = 'end'
    elif manip == 'addition':
        pass
        manip = 'end'
    elif manip == 'subtraction':
        pass
        manip = 'end'
    if manip == 'end':
        more = raw_input("Would you like to perform more calculations [y/n]? ")
        if more in 'Yy':
            pass
        elif more in 'Nn':
            global again
            conv = raw_input("Would you like to perform a conversion [y/n]? ")
            if conv in 'Yy':
                global cal
                cal = 'conversion'
            elif conv in 'Nn':
                again = False
def convertbin(whichconv):
    global res
    global original
    original = original.split()
    m = 0
    for x in original:
        if whichconv == 'Decimal':
            asNum = str(long(str(original[m]),2))
            res += asNum
            res += ' '
            m += 1
        elif whichconv == 'Hexadecimal':
            asHex = str(long(str(original[m]),2))
            if int(asHex) <= 0:
                res += '-'
                asHex = -int(asHex)
            asHex = "%X" % int(asHex)
            res += asHex
            res += ' '
            m += 1
        elif whichconv == 'Text':
            try:
                asNum = str(long(str(original[m]),2))
                if int(asNum) == 0:
                    res += '%s' % chr(int(asNum) + 32)
                elif 0 < int(asNum) <= 26:
                    res += '%s' % chr(int(asNum) + 96)
                elif 26 < int(asNum) <= 52:
                    res += '%s' % chr(int(asNum) + 38)
            except ValueError:
                global original
                if x in punct:
                    res += x
                else:
                    for char in x:
                        if char == '^':
                            x = ' '.join(x)
                            x = x.split()
                            x.remove(char)
                            x = ''.join(x)
                            asNum = int(long(str(x),2))
                            asNum += 26
                            asOctal = "%o" % int(asNum)
                            original[m] = ''
                            for char in asOctal:
                                original[m] += str(binary[char])
                            original[m] = str(original[m])
                            m -= 1
##                    res += '\xba'
            m += 1
        else:
            print """Sorry, you didn't enter a valid number.
Please enter only numbers between one and 26
"""
def convertnum(whichconv):                                                                          ##converts numbers
    from string import split
    if whichconv == 'Binary':                                                                       ##if user wants to convert to binary
        global original
        original = original.split()
        q = 0
        for char in original:
            asBin = str(original[q])
            if int(asBin) <= 0:                                                                      ##if negative number entered
                global res                                                                              ##since res is redefined, tells python to use global res and not try to create a local one
                res += '-'                                                                              ##adds a minus sign to res
                asBin = -int(asBin)                                                               ##converts original to a positive number
            try:
                int(asBin)                                                                           ##currently redundant, eventually to discriminate between numbers and punctation
            except ValueError:
                x = 0
                for char in original:
                    if char in punct:
                        res += char
                    x += 1
            else:
                asOctal = "%o" % int(asBin)
                for char in asOctal:
                    res += str(binary[char])
            q += 1
            res += ' '
    elif whichconv == 'Hexadecimal':                                                                ##if user wants to convert to hex
        original = original.split()
        x = 0
        for char in original:
            asHex = str(original[x])
            if int(asHex) <= 0:                                                                      ##global res/original already in module
                res += '-'
                asHex = -int(asHex)
            asHex = "%X" % int(asHex)
            res += asHex
            res += ' '
            x += 1
    elif whichconv == 'Text':                                                                       ##if user wants to convert to text (only works one letter at a time)
        original = original.split()
        x = 0
        for char in original:
            asText = str(original[x])
            if int(asText) == 0:                                                                      ##if number is 0
                res += '%s' % chr(int(asText) + 32)                                                   ##adds a space to res 
            elif 0 < int(asText) <= 26:                                                               ##if the number is 1-26
                res += '%s' % chr(int(asText) + 96)                                                   ##prints corresponding letter
            elif 26 < int(asText) <= 52:                                                              ##if number is between 26 and 52
                res += '%s' % chr(int(asText) + 38)                                                   ##prints corresponding letter
            else:                                                                                       ##if its not one of those numbers
                print """Sorry, you didn't enter a valid number.
Please enter only numbers between 0 and 26.
"""                                                                                                 ##prints message
            x += 1
def converthex(whichconv):
    global res
    global original
    original = original.split()
    m = 0
    for x in original:
        if whichconv == 'Binary':
            asBin = str(long(str(original[m]),16))
            if int(asBin) <= 0:
                res += '-'
                asBin = -int(asBin)
            try:
                int(asBin)                                                                           ##currently redundant, eventually to discriminate between numbers and punctation
            except ValueError:
                x = 0
                for char in original:
                    if char in punct:
                        res += char
                    x += 1
            else:
                asOctal = "%o" % int(asBin)
                for char in asOctal:
                    res += str(binary[char])
        elif whichconv == 'Decimal':
            asNum = str(long(str(original[m]),16))
            res += asNum
            res += ' '
            m += 1
        elif whichconv == 'Text':
            asNum = str(long(str(original[m]),16))
            if int(asNum) == 0:
                res += '%s' % chr(int(asNum) + 32)
            elif 0 < int(asNum) <= 26:
                res += '%s' % chr(int(asNum) + 96)
            elif 26 < int(asNum) <= 52:
                res += '%s' % chr(int(original) + 38)
            m += 1
        else:
            print """Sorry, you didn't enter a valid number.
Please enter only numbers between one and 26
"""
def convertxt(whichconv):
    global res                                                                                      ##results list is modified, so this tells python to use the global list and not create a local one
    if whichconv == 'Binary':
        from string import split                                                                    ##so split and join work
        for char in original:                                                                       ##loops over the entire entry
            x = 0                                                                                   ##allows checking every character against the entire alphabet list
            if char in punct:                                                                       ##if character is punctuation
                res += char                                                                         ##adds punctuation
                res += ' '
            elif char in alphabet:                                                                  ##if the character is in the alphabet
                while x == 0:
                    if char in alphabet[x]:
                        asOctal = "%o" % int(ord(char) - 32)
                        for char in asOctal:
                            res += binary[char]
                        res += ' '
                    x += 1
                while 0 < x <= 26:                                                                  ##if the character is  a lowercase letter or space
                    if char in alphabet[x]:                                                         ##redundant. only there to allow x += 1 to stay inside the while loop but outside the ifs
                        asOctal = "%o" % int(ord(char) - 96)                                        ##converts alphabet number (a = 1) to an unsigned octal
                        for char in asOctal:                                                        ##for character in resulting octal
                            res += binary[char]                                                     ##add the corresponding entry in the binary list to the res list
                        if char not in punct:                                                       ##if the character isn't punctuation
                            res += ' '                                                              ##add a space at the end to separate numbers
                    x += 1                                                                          ##adds 1 to the value of x so the loop doesnt go on forever
                while 26 < x <= 52:                                                                 ##if the character is an uppercase letter
                    if char in alphabet[x]:                                                         ##if the character is in the alphabet dictionary
                        res += '^'
                        asOctal = "%o" % int(ord(char) - 64)                                        ##converts alphabet number (A = 1) to an unsigned octal
                        for char in asOctal:
                            res += binary[char]
                        if char not in punct:
                            res += ' '
                    x += 1
    elif whichconv == 'Hexadecimal':                                                                ##convert text to hexadecimal
        from string import split
        for char in original:
            x = 0    
            if char in punct:
                res = split(res)                                    
                res.append(' ')                                     
                del res[-1]                                         
                res = ' '.join(res)                                 
                res += char                                         
            elif char in alphabet:
                while x == 0:
                    if char in alphabet[x]:
                        asHex = "%X" % int(ord(char) - 32)
                        res += asHex
                        res += ' '
                    x += 1
                while 0 < x <= 26:
                    if char in alphabet[x]:  
                        asHex = "%X" % int(ord(char) - 96)                                          ##convert alphabet number to corresponding Hexadecimal number
                        res += asHex                                                                ##add hexadecimal number to string
                        if char not in punct:
                            res += ' '
                    x += 1
                while 26 < x <= 52:
                    if char in alphabet[x]:
                        res += '^'
                        asHex = "%X" % int(ord(char) - 64)                                          ##convert alphabet number to corresponding hex number
                        res += asHex  
                        if char not in punct:     
                            res += ' '  
                    x += 1   
    elif whichconv == 'Decimal':                                                                    ##convert text to decimal
        from string import split
        for char in original:
            x = 0
            if char in punct:
                res = split(res)                                    
                res.append(' ')                                     
                del res[-1]                                         
                res = ' '.join(res)                                 
                res += char                                         
            elif char in alphabet:
                while x <= 52:   
                    if x == 0:
                        if char == alphabet[x]:                                                     ##if character is a space
                            res += '%d' % int(ord(char) - 32)                                       ##add a space to the string
                            if char not in punct:
                                res += ' '
                        x += 1
                    elif 0 < x <= 26:                                                               ##if character is a lowercase letter
                        if char in alphabet[x]:
                            res += '%d' % int(ord(char) - 96)                                       ##add corresponding number to string
                            if char not in punct:     
                                res += ' '  
                        x += 1   
                    elif 26 < x <= 52:                                                              ##if character is an uppercase letter
                        if char in alphabet[x]:  
                            res += '^'
                            res += '%d' % int(ord(char) - 64)                                       ##add corresponding number to string
                            if char not in punct:     
                                res += ' '  
                        x += 1   

import time                                                                                         ##for time.sleep(1.1) at end
import string                                                                                       ##for split(res), etc. in convertxt modules.

alphabet = ' ' + string.ascii_letters                                                               ##define alphabet string
punct = string.punctuation                                                                          ##define punctation string
binary = {'0':'000','1':'001','2':'010','3':'011','4':'100','5':'101','6':'110','7':'111'}         
##define the binary dictionary
number = string.digits

starmenu = {'1':'Binary','2':'Decimal','3':'Hexadecimal','4':'Text'}
bconmenu = {'1':'Decimal','2':'Hexadecimal','3':'Text'}
dconmenu = {'1':'Binary','2':'Hexadecimal','3':'Text'}
hconmenu = {'1':'Binary','2':'Decimal','3':'Text'}
tconmenu = {'1':'Binary','2':'Decimal','3':'Hexadecimal'}
counter = 1
manip = ''
allcalc = []
allconv = ''                                                                                        ##defines string containing all conversions
res = ''                                                                                            ##defines string containing single conversion
i = 0                                                                                               ##beginning condition for loop
again = True
print """What would you like to do:
1:  Calculation
2:  Conversion
3:  Exit"""
cal = raw_input("...    ")
if cal == '1':
    cal = 'calculation'
if cal == '2':
    cal = 'conversion'
if cal == '3':
    cal = 'none'
while again:
    if cal == 'calculation':
        print """Please enter intended manipulation:
1:  Exponents
2:  Multiplication
3:  Division
4:  Addition
5:  Subtraction
6:  None"""
        manip = raw_input("...    ")
        if manip == '1':
            manip = 'exponents'
        if manip == '2':
            manip = 'multiplication'
        if manip == '3':
            manip = 'division'
        if manip == '4':
            manip = 'addition'
        if manip == '5':
            manip = 'subtraction'
        if manip == '6':
            break
        calc(manip)
        counter += 1
    if cal == 'conversion':
        res = ''                                                                                    ##empties the string so each conversion begins w/ an empty string
        print """Which type of text would you like to convert?
1:  Binary
2:  Decimal
3:  Hexadecimal
4:  Text"""
        startype = raw_input("...    ")
        original = raw_input("Please enter %s to be converted. " % starmenu[startype].lower())      ##enter input to
be converted
        startype = starmenu[startype]
        if startype == 'Binary':
            print """Convert to:
1:  Decimal
2:  Hexadecimal
3:  Text"""
            whichconv = raw_input("...    ")
            whichconv = bconmenu[whichconv]
            convertbin(whichconv)
            print res
        elif startype == 'Decimal':
            print """Convert to:
1:  Binary
2:  Hexadecimal
3:  Text"""
            whichconv = raw_input("...    ")                                                                                            ##which conversion?
            whichconv = dconmenu[whichconv]
            convertnum(whichconv)                                                                   ##convert numbers to whatever
            print res                                                                               ##print string containing conversion
        elif startype == 'Hexadecimal':
            print """Convert to:
1:  Binary
2:  Decimal
3:  Text"""
            whichconv = raw_input("...    ")
            whichconv = hconmenu[whichconv]
            converthex(whichconv)
            print res
        elif startype == 'Text':
            print """Convert to:
1:  Binary
2:  Decimal
3:  Hexadecimal"""
            whichconv = raw_input("...    ")                                                                                            ##which conversion?
            whichconv = tconmenu[whichconv]
            convertxt(whichconv)
            print res                                                                               ##print the string containing the conversion
        i += 1
        original = ' '.join(str(original))
        allconv += ' ____Conversion %d: . . . ' % i + startype + ' => ' + whichconv + ' ... "' + original + '" => "' + res + '"'
                                                                                                    ##outside of try-except-else, inside while; adds each conversion to a master conversion list per session
        more = raw_input("Would you like to convert more text or numbers [y/n]? ")                  ##more?
        if more in 'Yy':                                                                            ##if so, continue loop
            pass
        elif more in 'Nn':                                                                          ##if not,
            calcu = raw_input("Would you like to perform a calculation [y/n]? ")
            if calcu in 'Yy':
                cal = 'calculation'
            elif calcu in 'Nn':
                again = False                                                                       ##break loop
    if cal == 'none':
        break
    if cal not in ('calculation', 'conversion','none'):
        cal = raw_input("""You may either perform a conversion or a calculation.
Please enter which one you would like to do: """)
allcon = 'a'
allcal = 'a'
if allcalc == []:
    allcal = ''
if allconv == '':
    allcal = ''
if allcal != '':
        callcalcon = raw_input("""Would you like to see all the calculations and conversions
performed during this session [y/n]? """)
        if callcalcon in 'Yy':
            print ''.join(allcalc) + allconv
        elif callcalcon in 'Nn':
            pass
elif allcal == '':
    if allconv != '':
        callconv = raw_input("""Would you like to see all the conversions performed during
this session [y/n]? """)
        if callconv in 'Yy':
            print allconv
        elif callcalcon in 'Nn':
            pass
    elif allconv == '':
        callcalc = raw_input("""Would you like to see all the calculations performed during
this session [y/n]? """)
        if callcalc in 'Yy':
            print ''.join(allcalc)
try:
    exit = raw_input("""Hit enter or control-c to exit.
... """)
except KeyboardInterrupt:
    pass
else:
    pass
print "Thank you for using Multivert.  Multivert will now close."                                   ##loop broken, prints message
time.sleep(1.1)                                                                                     ##waits for 1.1 seconds so message can be read
                                                                                                    ##end of program; program closes
_______________________________________________
IDLE-dev mailing list
IDLE-dev <at> python.org
http://mail.python.org/mailman/listinfo/idle-dev

Gmane