Re: exec() an locals() puzzle

2022-07-21 Thread george trojan
> accessible/visible from f's code. > > So, a few observations (by no means this is how the vm works): > > 1) each function has a set of variables defined by the code (let's call > this "code-defined locals" or "cdef-locals"). > 2) each function a

exec() an locals() puzzle

2022-07-20 Thread george trojan
I wish I could understand the following behaviour: 1. This works as I expect it to work: def f(): i = 1 print(locals()) exec('y = i; print(y); print(locals())') print(locals()) exec('y *= 2') print('ok:', eval('y')) f() {'i': 1} 1 {'i': 1, 'y': 1} {'i': 1, 'y': 1} ok: 2

Re: Multiprocessing performance question

2019-02-20 Thread george trojan
eorge On Thu, 21 Feb 2019 at 01:30, DL Neil wrote: > George > > On 21/02/19 1:15 PM, george trojan wrote: > > def create_box(x_y): > > return geometry.box(x_y[0] - 1, x_y[1], x_y[0], x_y[1] - 1) > > > > x_range = range(1, 1001) > > y_range = range(1,

Re: Multiprocessing performance question

2019-02-20 Thread george trojan
def create_box(x_y): return geometry.box(x_y[0] - 1, x_y[1], x_y[0], x_y[1] - 1) x_range = range(1, 1001) y_range = range(1, 801) x_y_range = list(itertools.product(x_range, y_range)) grid = list(map(create_box, x_y_range)) Which creates and populates an 800x1000 “grid” (represented as a fl

Re: Python3.6 tkinter bug

2017-01-31 Thread George Trojan - NOAA Federal
On 2017-01-31 18:02, MRAB wrote: On 2017-01-31 22:34, Christian Gollwitzer wrote: > >* Am 31.01.17 um 20:18 schrieb George Trojan - NOAA Federal: > *>>* Selection of button 'A' also selects button 'C'. Same goes for 'B' and > 'D'. >

Python3.6 tkinter bug?

2017-01-31 Thread George Trojan - NOAA Federal
The following program behaves differently under Python 3.6: ''' checkbutton test ''' import tkinter class GUI(tkinter.Tk): def __init__(self): tkinter.Tk.__init__(self) frame = tkinter.Frame(self) for tag in ('A', 'B'): w = tkinter.Checkbutton(frame, text=

Re: Splitting text into lines

2016-12-13 Thread George Trojan - NOAA Federal
> > Tell Python to keep the newline chars as seen with > open(filename, newline="") > For example: > >>> > * open("odd-newlines.txt", "rb").read() * > b'alpha\nbeta\r\r\ngamma\r\r\ndelta\n' > >>> > * open("odd-newlines.txt", "r", newline="").read().replace("\r", * > "").splitlines() > ['alpha', 'be

Re: Splitting text into lines

2016-12-13 Thread George Trojan - NOAA Federal
> > Are repeated newlines/carriage returns significant at all? What about > just using re and just replacing any repeated instances of '\r' or '\n' > with '\n'? I.e. something like > >>> # the_string is your file all read in > >>> import re > >>> re.sub("[\r\n]+", "\n", the_string) > and then co

Splitting text into lines

2016-12-13 Thread George Trojan - NOAA Federal
I have files containing ASCII text with line s separated by '\r\r\n'. Example: $ od -c FTAK31_PANC_131140.1481629265635 000 F T A K 3 1 P A N C 1 3 1 1 020 4 0 \r \r \n T A F A B E \r \r \n T A 040 F \r \r \n P A

Re: functools puzzle

2016-04-06 Thread George Trojan - NOAA Federal
16, at 6:57 PM, George Trojan - NOAA Federal < > george.tro...@noaa.gov> wrote: > > > > The module functools has partial() defined as above, then overrides the > > definition by importing partial from _functools. That would explain the > > above behaviour. My question

functools puzzle

2016-04-06 Thread George Trojan - NOAA Federal
Here is my test program: ''' generic test ''' import functools import inspect def f(): '''I am f''' pass g = functools.partial(f) g.__doc__ = '''I am g''' g.__name__ = 'g' def partial(func, *args, **keywords): def newfunc(*fargs, **fkeywords): newkeywords = keywords.copy()

How to make sphinx to recognize functools.partial?

2016-04-03 Thread George Trojan
Yet another sphinx question. I am a beginner here. I can't make sphinx to recognize the following (abbreviated) code: ''' module description :func:`~pipe` and :func:`~spipe` read data passed by LDM's `pqact`. ''' def _pipe(f, *args): '''doc string''' pass def _get_msg_spipe(): '

A tool to add diagrams to sphinx docs

2016-04-01 Thread George Trojan - NOAA Federal
What graphics editor would you recommend to create diagrams that can be included in sphinx made documentation? In the past I used xfig, but was not happy with font quality. My understanding is the diagrams would be saved in a .png file and I should use an image directive in the relevant .rst file.

Re: Python 3.1 test issue

2015-12-18 Thread George Trojan
On 12/16/2015 8:07 PM, Terry Reedy wrote: On 12/16/2015 1:22 PM, George Trojan wrote: I installed Python 3.1 on RHEL 7.2. According to the output below, you installed 3.5.1. Much better than the years old 3.1. This was not my only mistake. I ran the test on Fedora 19, not RHEL 7.2. The

Python 3.1 test issue

2015-12-16 Thread George Trojan
I installed Python 3.1 on RHEL 7.2. The command make test hangs (or takes a lot of time) on test_subprocess. [396/397] test_subprocess ^C Test suite interrupted by signal SIGINT. 5 tests omitted: test___all__ test_distutils test_site test_socket test_warnings 381 tests OK. 4 tests altered t

Re: tuples in conditional assignment (Ben Finney)

2015-11-24 Thread George Trojan
Ben Finney writes: Ben Finney Date: 11/24/2015 04:49 AM To: python-list@python.org George Trojan writes: The following code has bitten me recently: t=(0,1) x,y=t if t else 8, 9 print(x, y) (0, 1) 9 You can simplify this by taking assignment out of the picture:: >>>

tuples in conditional assignment

2015-11-23 Thread George Trojan
The following code has bitten me recently: >>> t=(0,1) >>> x,y=t if t else 8, 9 >>> print(x, y) (0, 1) 9 I was assuming that a comma has the highest order of evaluation, that is the expression 8, 9 should make a tuple. Why this is not the case? George -- https://mail.python.org/mailman/list

Re: Unbuffered stderr in Python 3

2015-11-03 Thread George Trojan
Forwarded Message Subject:Re: Unbuffered stderr in Python 3 Date: Tue, 03 Nov 2015 18:03:51 + From: George Trojan To: python-list@python.org On 11/03/2015 05:00 PM, python-list-requ...@python.org wrote: On Mon, 02 Nov 2015 18:52:55 +1100, Steven

Re: Unbuffered stderr in Python 3

2015-11-03 Thread George Trojan
On 11/03/2015 05:00 PM, python-list-requ...@python.org wrote: On Mon, 02 Nov 2015 18:52:55 +1100, Steven D'Aprano wrote: In Python 2, stderr is unbuffered. In most other environments (the shell, C...) stderr is unbuffered. It is usually considered a bad, bad thing for stderr to be buffered. W

problem with netCDF4 OpenDAP

2015-08-14 Thread George Trojan
Subject: problem with netCDF4 OpenDAP From: Tom P Date: 08/13/2015 10:32 AM To: python-list@python.org I'm having a problem trying to access OpenDAP files using netCDF4. The netCDF4 is installed from the Anaconda package. According to their changelog, openDAP is supposed to be supported. ne

Re: Re: anaconda bug?

2015-03-17 Thread George Trojan
On 03/16/2015 11:47 PM, memilanuk wrote: Might be just you... monte@machin-shin:~$ python Python 3.4.3 |Continuum Analytics, Inc.| (default, Mar 6 2015, 12:03:53) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tk

anaconda bug?

2015-03-16 Thread George Trojan
I am not sure it is just me or there is a bug in anaconda. I installed miniconda from http://conda.pydata.org/miniconda.html, then several python3.4.3 packages. Then created virtual environment. When I switch to that environment I can not create tk root window. Here is the traceback: (venv-3.4

strange numpy behaviour

2014-10-08 Thread George Trojan
This does not look right: dilbert@gtrojan> python3.4 Python 3.4.1 (default, Jul 7 2014, 15:47:25) [GCC 4.8.3 20140624 (Red Hat 4.8.3-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy as np >>> a=np.ma.array([0, 1], dtype=np.int8, mask=[1, 0]) >>

when to use == and when to use is

2014-03-10 Thread George Trojan
I know this question has been answered: http://stackoverflow.com/questions/6570371/when-to-use-and-when-to-use-is , but I still have doubts. Consider the following code: class A: def __init__(self, a): self._a = a #def __eq__(self, other): #return self._a != other._a ob

Re: parmiko problem

2010-07-19 Thread George Trojan
George Trojan wrote: I have a problem with connecting to a host without specifying password (but with ssh keys configured correctly. That is [tina src]$ sftp alice Connecting to alice... sftp> works, but the code import paramiko paramiko.util.log_to_file('/tmp/para

parmiko problem

2010-07-19 Thread George Trojan
I have a problem with connecting to a host without specifying password (but with ssh keys configured correctly. That is [tina src]$ sftp alice Connecting to alice... sftp> works, but the code import paramiko paramiko.util.log_to_file('/tmp/paramiko') t = paramiko.Transport(('alice', 22)) t.con

a question on building MySQL-python

2010-02-19 Thread George Trojan
During installation of MySQL-python-1.2.3c1 I encountered the following error: $ python2.6 setup.py build running build running build_py copying MySQLdb/release.py -> build/lib.linux-x86_64-2.6/MySQLdb running build_ext building '_mysql' extension creating build/temp.linux-x86_64-2.6 gcc -pthrea

Re: errno 107 socket.recv issue

2010-02-09 Thread George Trojan
Argument mismatch? Jordan Apgar wrote: servernegotiator = ServerNegotiator(host,HostID, port, key) class ServerNegotiator: def __init__(self, host, port, hostid, rsa_key, buf = 512): -- http://mail.python.org/mailman/listinfo/python-list

Re: site.py confusion

2010-01-27 Thread George Trojan
Arnaud Delobelle wrote: George Trojan writes: Inspired by the 'Default path for files' thread I tried to use sitecustomize in my code. What puzzles me is that the site.py's main() is not executed. My sitecustomize.py is def main(): print 'In Main()' main() and t

site.py confusion

2010-01-25 Thread George Trojan
Inspired by the 'Default path for files' thread I tried to use sitecustomize in my code. What puzzles me is that the site.py's main() is not executed. My sitecustomize.py is def main(): print 'In Main()' main() and the test program is import site #site.main() print 'Hi' The output is $ pytho

html code generation

2010-01-20 Thread George Trojan
I need an advice on table generation. The table is essentially a fifo, containing about 200 rows. The rows are inserted every few minutes or so. The simplest solution is to store row data per line and write directly html code: line = "value1value2>... " each run of the program would read the pr

Re: asyncore based port splitter code questions

2010-01-08 Thread George Trojan
Thanks for your help. Some comments below. George Giampaolo Rodola' wrote: On 4 Gen, 18:58, George Trojan wrote: Secondly, to temporarily "sleep" your connections *don't* remove anything from your map. The correct way of doing things here is to override readable() an

asyncore based port splitter code questions

2010-01-04 Thread George Trojan
The following code is a attempt at port splitter: I want to forward data coming on tcp connection to several host/port addresses. It sort of works, but I am not happy with it. asyncore based code is supposed to be simple, but I need while loops and a lot of try/except clauses. Also, I had to ad

Re: a simple unicode question

2009-10-20 Thread George Trojan
Thanks for all suggestions. It took me a while to find out how to configure my keyboard to be able to type the degree sign. I prefer to stick with pure ASCII if possible. Where are the literals (i.e. u'\N{DEGREE SIGN}') defined? I found http://www.unicode.org/Public/5.1.0/ucd/UnicodeData.txt Is

a simple unicode question

2009-10-19 Thread George Trojan
A trivial one, this is the first time I have to deal with Unicode. I am trying to parse a string s='''48° 13' 16.80" N'''. I know the charset is "iso-8859-1". To get the degrees I did >>> encoding='iso-8859-1' >>> q=s.decode(encoding) >>> q.split() [u'48\xc2\xb0', u"13'", u'16.80"', u'N'] >>> r=

Re: numpy f2py question

2009-10-05 Thread George Trojan
sturlamolden wrote: On 2 Okt, 22:41, George Trojan wrote: I have a problem with numpy's vectorize class and f2py wrapped old FORTRAN code. I found that the function _get_nargs() in site-packages/numpy/lib/function_base.py tries to find the number of arguments for a function from an

numpy f2py question

2009-10-02 Thread George Trojan
I have a problem with numpy's vectorize class and f2py wrapped old FORTRAN code. I found that the function _get_nargs() in site-packages/numpy/lib/function_base.py tries to find the number of arguments for a function from an error message generated when the function is invoked with no arguments

Re: supervisor 3.0a6 and Python2.6

2009-03-19 Thread George Trojan
Raymond Cote wrote: George Trojan wrote: 1. Is supervisor still developed? I note that, although the information on the site is pretty old, there have been some respository checkins in Feb and March of this year: <http://lists.supervisord.org/pipermail/supervisor-checkins/> -r I

supervisor 3.0a6 and Python2.6

2009-03-17 Thread George Trojan
Supervisor does not work with Python2.6. While running with the test configuration, supervisord prints traceback: 2009-03-17 15:12:31,927 CRIT Traceback (most recent call last): File "/usr/local/Python-2.6/lib/python2.6/site-packages/supervisor-3.0a6-py2.6.egg/supervisor/xmlrpc.py", line 367,

Re: Pexpect and telnet not communicating properly

2009-01-27 Thread George Trojan
David Anderson wrote: I am trying to automate the following session - to talk to my router: === telnet speedtouch Trying 192.168.1.254... Connected to speedtouch. Escape character is '^]'. Username : Administrator Password : ---

Re: tkinter: Round Button - Any idea?

2008-08-25 Thread George Trojan
akineko wrote: Hello everyone, I'm trying to implement a virtual instrument, which has buttons and displays, using Tkinter+Pmw. One of items on the virtual instrument is a round button. This is imitating a tact switch. Tkinter has a Button class, which I can assign a button image. However, when

Re: iterating "by twos"

2008-07-29 Thread George Trojan
kj wrote: Is there a special pythonic idiom for iterating over a list (or tuple) two elements at a time? I mean, other than for i in range(0, len(a), 2): frobnicate(a[i], a[i+1]) ? I think I once saw something like for (x, y) in forgotten_expression_using(a): frobnicate(x, y) Or may

frange() question

2007-09-20 Thread George Trojan
A while ago I found somewhere the following implementation of frange(): def frange(limit1, limit2 = None, increment = 1.): """ Range function that accepts floats (and integers). Usage: frange(-2, 2, 0.1) frange(10) frange(10, increment = 0.5) The returned value i

Re: Compiling python2.5 on IBM AIX

2007-07-17 Thread George Trojan
[EMAIL PROTECTED] wrote: >> I haven't compiled it myself, but I'm told that the installation I >> work with was compiled with: >> >> export PATH=$PATH:/usr/vacpp/bin:/usr/vacpp/lib >> ./configure --with-gcc="xlc_r -q64" --with-cxx="xlC_r -q64" --disable- >> ipv6 AR="ar -X64" >> make >> make install

setting environment from shell file in python

2007-05-29 Thread George Trojan
Is there a utility to parse a Bourne shell environment file, such as .bashrc, and set the environmental variables from within a Python script? What I mean is an equivalent to shell dot command. I don't think it would be too difficult to write a shell parser, but if such thing already exists...

Re: Dialog with a process via subprocess.Popen blocks forever

2007-03-01 Thread George Trojan
[EMAIL PROTECTED] wrote: > Okay, here is what I want to do: > > I have a C Program that I have the source for and want to hook with > python into that. What I want to do is: run the C program as a > subprocess. > The C programm gets its "commands" from its stdin and sends its state > to stdout. Th

python 2.5 build problem on AIX 5.3

2006-10-11 Thread George Trojan
Is there a known problem with ctypes module on AIX? Google did not help me to find anything. Here is part of the output from "make": building '_ctypes' extension xlc_r -q64 -DNDEBUG -O -I. -I/gpfs/m2/home/wx22gt/tools/src/Python-2.5-cc/./Include -Ibuild/temp.aix-5.3-2.5/libffi/include -Ibuild/t