Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #30505

Re: unexpected error from Python 3.3.0

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'else:': 0.03; 'true,': 0.04; 'subject:Python': 0.05; 'below)': 0.07; 'column': 0.07; 'reason,': 0.07; 'width': 0.07; 'python': 0.09; "'''": 0.09; 'cmd': 0.09; 'exception,': 0.09; 'fails.': 0.09; 'referenced': 0.09; 'res': 0.09; 'rows': 0.09; 'skipping': 0.09; 'stderr': 0.09; 'sure,': 0.09; 'whole,': 0.09; 'bug': 0.10; 'cc:addr:python-list': 0.10; 'def': 0.10; 'subject:error': 0.11; 'value.': 0.15; 'weird': 0.15; '"invalid': 0.16; '"right"': 0.16; '.py': 0.16; '0).': 0.16; 'alexis': 0.16; 'attaching': 0.16; 'bufsize': 0.16; 'clause.': 0.16; 'inserting': 0.16; 'left,': 0.16; 'reproduce': 0.16; 'res:': 0.16; 'resizing': 0.16; 'row': 0.16; 'trace.': 0.16; 'win7': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'input': 0.18; '(or': 0.18; 'windows': 0.19; 'code.': 0.20; 'variable': 0.20; 'import': 0.21; 'error.': 0.21; 'ctypes': 0.22; 'fixing': 0.22; 'machine.': 0.22; 'struct': 0.22; 'cc:2**0': 0.23; 'errors': 0.23; 'installed': 0.23; 'thus': 0.24; 'cc:no real name:2**0': 0.24; 'script': 0.24; 'tried': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; '(see': 0.27; 'am,': 0.27; 'executing': 0.27; 'forgot': 0.27; "doesn't": 0.28; 'rest': 0.28; 'actual': 0.28; 'equivalent,': 0.29; 'initialized': 0.29; 'skip:_ 10': 0.29; 'maybe': 0.29; 'function': 0.30; 'error': 0.30; 'expect': 0.31; 'sense': 0.31; 'file': 0.32; 'avoiding': 0.33; 'explains': 0.33; 'handle': 0.33; 'problem': 0.33; 'version': 0.34; 'screen': 0.34; 'whatever': 0.35; 'false': 0.35; 'returning': 0.35; 'sometimes': 0.35; 'something': 0.35; 'should': 0.36; 'problems': 0.36; 'skip:p 20': 0.36; 'does': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'received:192': 0.39; 'called': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'bottom': 0.60; 'skip:w 30': 0.61; 'first': 0.61; 'launching': 0.62; 'between': 0.63; 'skip:n 10': 0.63; 'more': 0.63; 'show': 0.63; 'here': 0.65; 'header:Reply-To:1': 0.68; 'below.': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'clicking': 0.75; '100%': 0.76; 'click': 0.76; 'trial': 0.81; 'console,': 0.84; 'concluded': 0.91
Date Sat, 29 Sep 2012 12:29:59 -0400
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0
MIME-Version 1.0
To Alexis Lopez-Garcia <alexis.lopezgarcia@gmail.com>
Subject Re: unexpected error from Python 3.3.0
References <CAD4s32s5G_6As-=rz9EpRys8i0p9hSMQJGd8e-x2ofEzbt1oPg@mail.gmail.com>
In-Reply-To <CAD4s32s5G_6As-=rz9EpRys8i0p9hSMQJGd8e-x2ofEzbt1oPg@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:6wVN9x4dH90iTEp4qnn5Qjq7zDkt/NbCJX4dSK4bg9n VEFKJdZSVTKKsj/zCwpVkzJ0hY3/HAxqk5JRJlEQRPRslxj2HC V2BdLJr7VtC8fn/NV+xoZK8ppkiUJj2t+BbAKJpa37F9NcQfDT b3SK2tWLAMGz8KzMGwpv6k0gECvJd/9E/Mi0Bstu9i9dqlPWxi vKJldMFTg7Xr/o2K37ZTRIfovjd1o7c+cSzyz3zUNn/vJsgH+t EKz5I3CUCD3w+MwjDEPfi1/n8CX0YFd9vIM3BOrHKfonxr2jKw h/NEoiXN5Tdk0Fze+VLUzo+cAK5kOFgwijM/F5Pxo+5IzBBRQ= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1637.1348936228.27098.python-list@python.org> (permalink)
Lines 105
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1348936228 news.xs4all.nl 6961 [2001:888:2000:d::a6]:38279
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:30505

Show key headers only | View raw


On 09/29/2012 10:19 AM, Alexis Lopez-Garcia wrote:
> Hi.
>
> I installed Python3.3.0 with python-3.3.0.amd64.msi on a win7 machine.
>
> While using this funcion (see below) from a script called by double
> clicking on the .py file I get a "invalid variable "right" referenced
> before assignment" error.

You forgot to include the whole, actual error trace.

> The weird thing is that launching the script from a cmd windows does no
> give the error and if you repeactedly double click on the .py file
> sometimes the error does not reproduce so I concluded it was a timing issue
> between win7 and python.
> So by trial and error I ended up fixing it by inserting a time.sleep(0.5)
> on the function and now it works 100% of the time.
>
> These error did not show in Python3.2.3 and thus I don't know if I just
> found a new bug or what.
> I write it here so that more knowledgeable people could:
>
> 1. explains to me why the errors is happening
see below.
> 2. deems it a bug and maybe reports it on the Python site.

Sure, report it to Microsoft.  For whatever reason, your call to

GetConsoleScreenBufferInfo() is returning false (or something equivalent, like 0).  What does the Windows 7 documentation say about not attaching a console for a while?


> below is the particular function giving the error with the fix line, which
> is not in the original version
>
> def console_resize(width=80, height=24, buffer_height=600):
>     '''Sets up the console size and buffer height.
>
>     @param width {int} Width of console in column value.
>     @param height {int} Height of console in row value.
>     @param buffer_height {int} Buffer console height in row value.
>     '''
>     from ctypes import windll, byref, create_string_buffer
>     from ctypes.wintypes import SMALL_RECT, _COORD
>     # Active console screen buffer
>     # STD_OUTPUT_HANDLE -> -11, STD_ERROR_HANDLE -> -12)
>     STDERR = -12
>     # SMALL_RECT input
>     LEFT = 0
>     TOP = 0
>     RIGHT = width - 1
>     BOTTOM = height - 1
>     # handle
>     hdl = windll.kernel32.GetStdHandle(STDERR)
>     csbi = create_string_buffer(22)
>
>     time.sleep(0.5)  # <--- FIX IS THIS LINE
>
>     res = windll.kernel32.GetConsoleScreenBufferInfo(hdl, csbi)
>
>     if res:
>         import struct
>         (bufx, bufy, curx, cury, wattr,
>          left, top, right, bottom,
>          maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)

Your problem is you don't have an else clause.  How did you expect bufs,
bufy, etc. to be initialized without executing that code.  So if the
rest of the function doesn't make sense without a console, you should be
skipping it, or throwing an exception, or returning, or something.



>
>     current_width = right - left + 1

This happens to be the first time you tried to use one of those
non-variables.  Naturally, it fails.

>     current_height = bottom - top + 1
>     current_buffer_height = bufy
>
>     if buffer_height < height:
>         buffer_height = height
>     # order of resizing avoiding some problems
>     if current_buffer_height > buffer_height:
>         rect = SMALL_RECT(LEFT, TOP, RIGHT, BOTTOM)  # (left, top, right,
> bottom)
>         windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect))
>
>         bufsize = _COORD(width, buffer_height)  # columns, rows
>         windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize)
>     else:
>         bufsize = _COORD(width, buffer_height)  # columns, rows
>         windll.kernel32.SetConsoleScreenBufferSize(hdl, bufsize)
>
>         rect = SMALL_RECT(LEFT, TOP, RIGHT, BOTTOM)  # (left, top, right,
> bottom)
>         windll.kernel32.SetConsoleWindowInfo(hdl, True, byref(rect))
>
>
>
-- 

DaveA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: unexpected error from Python 3.3.0 Dave Angel <d@davea.name> - 2012-09-29 12:29 -0400

csiph-web