From frank at chagford.com Wed Mar 1 00:39:19 2017 From: frank at chagford.com (Frank Millman) Date: Wed, 1 Mar 2017 07:39:19 +0200 Subject: asyncio does not always show the full traceback In-Reply-To: <72209011-db09-4ba2-9c5b-f576a30e2d09@googlegroups.com> References: <72209011-db09-4ba2-9c5b-f576a30e2d09@googlegroups.com> Message-ID: John Ladasky wrote in message news:72209011-db09-4ba2-9c5b-f576a30e2d09 at googlegroups.com... > > Does anyone know what I must change to get the full traceback? > > Three years ago, I had a similar issue with incomplete tracebacks while > using multiprocessing.Pool. The discussion is here: > > https://groups.google.com/forum/#!msg/comp.lang.python/qKTNNt8uKKU/biNyslh19ncJ;context-place=msg/comp.lang.python/qKTNNt8uKKU/c6K8kVdfTw4J > > Other, better Python programmers than myself were treating this as a bug > that needed to be fixed, and were doing so for Python 3.4. The linked > discussion contains a link to the developers' bug reports. It appears > that the bug was addressed, but I don't know if it was backported to every > version of Python. What version of Python are you using? I am using 3.6, so maybe it is a different issue, or maybe a similar one but the fix was not applied to the asyncio module. I will study the thread you quoted, and report back. Thanks Frank From dieter at handshake.de Wed Mar 1 01:28:29 2017 From: dieter at handshake.de (dieter) Date: Wed, 01 Mar 2017 07:28:29 +0100 Subject: asyncio does not always show the full traceback References: Message-ID: <87fuix33zm.fsf@handshake.de> "Frank Millman" writes: > I use asyncio in my project, so most of my functions start with > 'async' and most of my calls are preceded by 'await'. > > If an exception is raised, I usually get the full traceback, but > sometimes I just get something like the following - > > Traceback (most recent call last): > File "C:\Users\User\aib\aib\test_data.py", line 645, in > loop.run_until_complete(main(company)) > File > "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", > line 466, in run_until_complete > return future.result() > ValueError: not enough values to unpack (expected 2, got 1) > > It does not show the line where the ValueError occurs, and I have not > managed to narrow down exactly when this happens. Not sure whether this applies to your case: things like your observation are common when C level code is involved. C level code does not have line numbers (Python knows about). Therefore, you get the exception but the traceback only covers the Python code path. From flebber.crue at gmail.com Wed Mar 1 01:41:34 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 28 Feb 2017 22:41:34 -0800 (PST) Subject: How to flatten only one sub list of list of lists Message-ID: <2c513652-c365-4a92-b204-d986fa41b7a0@googlegroups.com> How can I flatten just a specific sublist of each list in a list of lists? So if I had this data [ ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 $277790.00']], ['46295', 'Dark Eyes', '5', '59', '83', ['6', '4', '1', '0 $105625.00']], ['46295', 'Machinegun Jubs', '6', '53', '77', ['6', '2', '1', '1 $71685.00']], ['46295', 'Zara Bay', '1', '53', '77', ['12', '2', '3', '3 $112645.00']]] How can I make it be [ ['46295', 'Montauk', '3', '60', '85', '19', '5', '1', '0 $277790.00'], ['46295', 'Dark Eyes', '5', '59', '83', '6', '4', '1', '0 $105625.00'], ['46295', 'Machinegun Jubs', '6', '53', '77', '6', '2', '1', '1 $71685.00'], ['46295', 'Zara Bay', '1', '53', '77', '12', '2', '3', '3 $112645.00']] Been looking around but most solutions just entirely flatten everything. This was popular on SO but yeah it flattens everything I want to be more selective def flatten(lst): for elem in lst: if type(elem) in (tuple, list): for i in flatten(elem): yield i else: yield elem What I am thinking is that if for each list the sublist should be at index 1, so [0][1] [1][1] [2][1] for item in list: item[1] - somehow flatten. Thoughts? Sayth From ethan at stoneleaf.us Wed Mar 1 01:43:23 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 28 Feb 2017 22:43:23 -0800 Subject: [ANN] Aenum 2.0 Message-ID: <58B66D8B.6050000@stoneleaf.us> For those following the latest Python releases you may have noticed that Python 3.6 Enum got two new types: - Flag - IntFlag Those classes have now been added to aenum (along with a bunch of bug fixes). aenum is available at: https://pypi.python.org/pypi/aenum Besides the four Enum types from the stdlib (Enum, IntEnum, Flag, IntFlag), there is also a class-based NamedTuple and a NamedConstant (when you want named constants but don't need an Enum). The README is included below. ----------------------------- aenum --- support for advanced enumerations, namedtuples, and constants =========================================================================== Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants aenum includes a Python stdlib Enum-compatible data type, as well as a metaclass-based NamedTuple implementation and a NamedConstant class. An Enum is a set of symbolic names (members) bound to unique, constant values. Within an enumeration, the members can be compared by identity, and the enumeration itself can be iterated over. If using Python 3 there is built-in support for unique values, multiple values, auto-numbering, and suspension of aliasing (members with the same value are not identical), plus the ability to have values automatically bound to attributes. A NamedTuple is a class-based, fixed-length tuple with a name for each possible position accessible using attribute-access notation as well as the standard index notation. A NamedConstant is a class whose members cannot be rebound; it lacks all other Enum capabilities, however; consequently, it can have duplicate values. Module Contents --------------- ``NamedTuple`` ^^^^^^^^^^^^^^ Base class for ``creating NamedTuples``, either by subclassing or via it's functional API. ``NamedConstant`` ^^^^^^^^^^^^ Constant class for creating groups of constants. These names cannot be rebound to other values. ``Enum`` ^^^^^^^^ Base class for creating enumerated constants. See section ``Enum Functional API`` for an alternate construction syntax. ``IntEnum`` ^^^^^^^^^^^ Base class for creating enumerated constants that are also subclasses of ``int``. ``AutoNumberEnum`` ^^^^^^^^^^^^^^^^^^ Derived class that automatically assigns an ``int`` value to each member. ``OrderedEnum`` ^^^^^^^^^^^^^^^ Derived class that adds ``<``, ``<=``, ``>=``, and ``>`` methods to an ``Enum``. ``UniqueEnum`` ^^^^^^^^^^^^^^ Derived class that ensures only one name is bound to any one value. ``IntFlag`` ^^^^^^^^^^^ Base class for creating enumerated constants that can be combined using the bitwise operators without losing their ``IntFlag`` membership. ``IntFlag`` members are also subclasses of ``int``. ``Flag`` ^^^^^^^^ Base class for creating enumerated constants that can be combined using the bitwise operations without losing their ``Flag`` membership. ``unique`` ^^^^^^^^^^ Enum class decorator that ensures only one name is bound to any one value. ``constant`` ^^^^^^^^^^^^ Descriptor to add constant values to an ``Enum`` ``convert`` ^^^^^^^^^^^ Helper to transform target global variables into an ``Enum``. ``enum`` ^^^^^^^^ Helper for specifying keyword arguments when creating ``Enum`` members. ``export`` ^^^^^^^^^^ Helper for inserting ``Enum`` members into a namespace (usually ``globals()``. ``extend_enum`` ^^^^^^^^^^^^^^^ Helper for adding new ``Enum`` members after creation. ``module`` ^^^^^^^^^^ Function to take a ``NamedConstant`` or ``Enum`` class and insert it into ``sys.modules`` with the affect of a module whose top-level constant and member names cannot be rebound. ``skip`` ^^^^^^^^ Descriptor to add a normal (non-``Enum`` member) attribute to an ``Enum`` or ``NamedConstant``. Creating an Enum ---------------- Enumerations can be created using the ``class`` syntax, which makes them easy to read and write. To define an enumeration, subclass ``Enum`` as follows:: >>> from aenum import Enum >>> class Color(Enum): ... RED = 1 ... GREEN = 2 ... BLUE = 3 The ``Enum`` class is also callable, providing the following functional API:: >>> Animal = Enum('Animal', 'ANT BEE CAT DOG') >>> Animal >>> Animal.ANT >>> Animal.ANT.value 1 >>> list(Animal) [, , , ] Note that ``Enum`` members are boolean ``True`` unless the ``__nonzero__`` (Python 2) or ``__bool__`` (Python 3) method is overridden to provide different semantics. Creating a Flag --------------- ``Flag`` (and ``IntFlag``) has members that can be combined with each other using the bitwise operators (&, |, ^, ~). ``IntFlag`` members can be combined with ``int`` and other ``IntFlag`` members. While it is possible to specify the values directly it is recommended to use ``auto`` as the value and let ``(Int)Flag`` select an appropriate value:: >>> from enum import Flag >>> class Color(Flag): ... RED = auto() ... BLUE = auto() ... GREEN = auto() ... >>> Color.RED & Color.GREEN >>> bool(Color.RED & Color.GREEN) False >>> Color.RED | Color.BLUE If you want to name the empty flag, or various combinations of flags, you may:: >>> class Color(Flag): ... BLACK = 0 ... RED = auto() ... BLUE = auto() ... GREEN = auto() ... WHITE = RED | BLUE | GREEN ... >>> Color.BLACK >>> Color.WHITE Note that ``(Int)Flag`` zero-value members have the usual boolean value of ``False``. Creating NamedTuples -------------------- Simple ^^^^^^ The most common way to create a new NamedTuple will be via the functional API:: >>> from aenum import NamedTuple >>> Book = NamedTuple('Book', 'title author genre', module=__name__) Advanced ^^^^^^^^ The simple method of creating ``NamedTuples`` requires always specifying all possible arguments when creating instances; failure to do so will raise exceptions. However, it is possible to specify both docstrings and default values when creating a ``NamedTuple`` using the class method:: >>> class Point(NamedTuple): ... x = 0, 'horizontal coordinate', 0 ... y = 1, 'vertical coordinate', 0 ... >>> Point() Point(x=0, y=0) Creating Constants ------------------ ``NamedConstant`` is similar to ``Enum``, but do not support the ``Enum`` protocols, and have no restrictions on duplications:: >>> class K(NamedConstant): ... PI = 3.141596 ... TAU = 2 * PI ... >>> K.TAU 6.283192 -- ~Ethan~ From jussi.piitulainen at helsinki.fi Wed Mar 1 02:19:59 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 01 Mar 2017 09:19:59 +0200 Subject: How to flatten only one sub list of list of lists References: <2c513652-c365-4a92-b204-d986fa41b7a0@googlegroups.com> Message-ID: Sayth Renshaw writes: > How can I flatten just a specific sublist of each list in a list of lists? > > So if I had this data > > > [ ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 $277790.00']], > ['46295', 'Dark Eyes', '5', '59', '83', ['6', '4', '1', '0 $105625.00']], > ['46295', 'Machinegun Jubs', '6', '53', '77', ['6', '2', '1', '1 $71685.00']], > ['46295', 'Zara Bay', '1', '53', '77', ['12', '2', '3', '3 $112645.00']]] > > > How can I make it be > > > [ ['46295', 'Montauk', '3', '60', '85', '19', '5', '1', '0 $277790.00'], > ['46295', 'Dark Eyes', '5', '59', '83', '6', '4', '1', '0 $105625.00'], > ['46295', 'Machinegun Jubs', '6', '53', '77', '6', '2', '1', '1 $71685.00'], > ['46295', 'Zara Bay', '1', '53', '77', '12', '2', '3', '3 $112645.00']] Here's two ways. First makes a copy, second flattens each list in place, both assume it's the last member (at index -1) of the list that needs flattening. datami = [ ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 $277790.00']], ['46295', 'Dark Eyes', '5', '59', '83', ['6', '4', '1', '0 $105625.00']], ['46295', 'Machinegun Jubs', '6', '53', '77', ['6', '2', '1', '1 $71685.00']], ['46295', 'Zara Bay', '1', '53', '77', ['12', '2', '3', '3 $112645.00']]] flat = [ data[:-1] + data[-1] for data in datami ] for data in datami: data.extend(data.pop()) print('flat copy of datami:', *flat, sep = '\n') print('flattened datami:', *datami, sep = '\n') From __peter__ at web.de Wed Mar 1 02:41:06 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 01 Mar 2017 08:41:06 +0100 Subject: How to flatten only one sub list of list of lists References: <2c513652-c365-4a92-b204-d986fa41b7a0@googlegroups.com> Message-ID: Sayth Renshaw wrote: > How can I flatten just a specific sublist of each list in a list of lists? > > So if I had this data > > > [ ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 > [ [$277790.00']], > ['46295', 'Dark Eyes', '5', '59', '83', ['6', '4', '1', '0 > [$105625.00']], '46295', 'Machinegun Jubs', '6', '53', '77', ['6', > ['2', '1', '1 $71685.00']], '46295', 'Zara Bay', '1', '53', '77', > [['12', '2', '3', '3 $112645.00']]] > > > How can I make it be > > > [ ['46295', 'Montauk', '3', '60', '85', '19', '5', '1', '0 $277790.00'], > ['46295', 'Dark Eyes', '5', '59', '83', '6', '4', '1', '0 > [$105625.00'], '46295', 'Machinegun Jubs', '6', '53', '77', '6', '2', > ['1', '1 $71685.00'], '46295', 'Zara Bay', '1', '53', '77', '12', '2', > ['3', '3 $112645.00']] > > Been looking around but most solutions just entirely flatten everything. > This was popular on SO but yeah it flattens everything I want to be more > selective > > def flatten(lst): > for elem in lst: > if type(elem) in (tuple, list): > for i in flatten(elem): > yield i > else: > yield elem > > What I am thinking is that if for each list the sublist should be at index > 1, so > > [0][1] > [1][1] > [2][1] > > for item in list: > item[1] - somehow flatten. > > Thoughts? Replace the slice row[index:index+1] with row[index], either by building a new list or in place: >>> def show(data): ... for item in data: print(item) ... >>> def flatten_one(rows, index): ... return [r[:index] + r[index] + r[index+1:] for r in rows] ... >>> show(data) ['46295', 'Montauk', '3', '60', '85', ['19', '5', '1', '0 $277790.00']] ['46295', 'Dark Eyes', '5', '59', '83', ['6', '4', '1', '0 $105625.00']] ['46295', 'Machinegun Jubs', '6', '53', '77', ['6', '2', '1', '1 $71685.00']] ['46295', 'Zara Bay', '1', '53', '77', ['12', '2', '3', '3 $112645.00']] >>> show(flatten_one(data, 5)) ['46295', 'Montauk', '3', '60', '85', '19', '5', '1', '0 $277790.00'] ['46295', 'Dark Eyes', '5', '59', '83', '6', '4', '1', '0 $105625.00'] ['46295', 'Machinegun Jubs', '6', '53', '77', '6', '2', '1', '1 $71685.00'] ['46295', 'Zara Bay', '1', '53', '77', '12', '2', '3', '3 $112645.00'] >>> def flatten_inplace(rows, index): ... for row in rows: ... row[index:index+1] = row[index] ... >>> flatten_inplace(data, 5) >>> show(data) ['46295', 'Montauk', '3', '60', '85', '19', '5', '1', '0 $277790.00'] ['46295', 'Dark Eyes', '5', '59', '83', '6', '4', '1', '0 $105625.00'] ['46295', 'Machinegun Jubs', '6', '53', '77', '6', '2', '1', '1 $71685.00'] ['46295', 'Zara Bay', '1', '53', '77', '12', '2', '3', '3 $112645.00'] From flebber.crue at gmail.com Wed Mar 1 03:14:46 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 1 Mar 2017 00:14:46 -0800 (PST) Subject: How to flatten only one sub list of list of lists In-Reply-To: References: <2c513652-c365-4a92-b204-d986fa41b7a0@googlegroups.com> Message-ID: <0da00e1e-574e-4564-a705-adcb7d86bda0@googlegroups.com> > Replace the slice row[index:index+1] with row[index], either by building a new list or in place: > > >>> def show(data): > ... for item in data: print(item) > ... > >>> def flatten_one(rows, index): > ... return [r[:index] + r[index] + r[index+1:] for r in rows] > ... > >>> def flatten_inplace(rows, index): > ... for row in rows: > ... row[index:index+1] = row[index] > ... > >>> flatten_inplace(data, 5) > >>> show(data) > ['46295', 'Montauk', '3', '60', '85', '19', '5', '1', '0 $277790.00'] > ['46295', 'Dark Eyes', '5', '59', '83', '6', '4', '1', '0 $105625.00'] > ['46295', 'Machinegun Jubs', '6', '53', '77', '6', '2', '1', '1 $71685.00'] > ['46295', 'Zara Bay', '1', '53', '77', '12', '2', '3', '3 $112645.00'] I went for the one I can understand which was inplace def flatten_inplace(rows, index): for row in rows: row[index:index + 1] = row[index] return rows See now if I can make it more adaptable to use it in some other situations, quite useful. Thanks Sayth From tjreedy at udel.edu Wed Mar 1 05:50:57 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 1 Mar 2017 05:50:57 -0500 Subject: Exposing all methods of a class In-Reply-To: References: <3afdc9ac-0679-f970-b604-e3367ca9788f@stridebird.com> Message-ID: The class listing provided by the pydoc module browser, also in help(someclass), do list all methods. Try >>> import tkinter >>> help(tkinter.Text) for instance. On 2/28/2017 7:16 PM, Rick Johnson wrote: > IDLE has a "class browser" feature (@GUI_XY = File-> > Class_Browser) that displays a GUI tree of the currently > opened module, although, and unfortunately for you, the > scope of detail ends at the physical borders of the module. I'd like to rename that 'module browser after enhancing coverage of functions a bit. > However, by utilizing the introspection power of python > (`import inspect`, for instance), you could probably > implement something akin to "comprehensive introspection > reform". A real class browser, with the same info as in the help output, but more interactive, would be interesting. -- Terry Jan Reedy From steve+python at pearwood.info Wed Mar 1 06:18:42 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 01 Mar 2017 22:18:42 +1100 Subject: Looking for documentation on how Python assigns to function parameters Message-ID: <58b6ae14$0$1607$c3e8da3$5496439d@news.astraweb.com> Given a function like this: def func(alpha, beta, gamma, delta=4, *args, **kw): ... which is called in some fashion: # say func(1, 2, gamma=3, epsilon=5) which may or may not be valid: func(1, 2, alpha=0) how does Python match up the formal parameters in the `def` statement with the arguments given in the call to `func`? I'm looking for official docs, if possible. So far I've had no luck finding anything. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Mar 1 06:22:20 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 01 Mar 2017 22:22:20 +1100 Subject: Looking for documentation on how Python assigns to function parameters References: <58b6ae14$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58b6aeed$0$1607$c3e8da3$5496439d@news.astraweb.com> On Wed, 1 Mar 2017 10:18 pm, Steve D'Aprano wrote: [...] > how does Python match up the formal parameters in the `def` statement with > the arguments given in the call to `func`? > > I'm looking for official docs, if possible. So far I've had no luck > finding anything. Never mind, I found it about 30 seconds after hitting send. https://docs.python.org/3/reference/expressions.html#calls -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jussi.piitulainen at helsinki.fi Wed Mar 1 06:27:29 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 01 Mar 2017 13:27:29 +0200 Subject: Looking for documentation on how Python assigns to function parameters References: <58b6ae14$0$1607$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano writes: > Given a function like this: > > > def func(alpha, beta, gamma, delta=4, *args, **kw): > ... > > > which is called in some fashion: > > # say > func(1, 2, gamma=3, epsilon=5) > > which may or may not be valid: > > func(1, 2, alpha=0) > > how does Python match up the formal parameters in the `def` statement with > the arguments given in the call to `func`? > > I'm looking for official docs, if possible. So far I've had no luck finding > anything. Possibly https://docs.python.org/3/reference/expressions.html#calls Python 3.6.0 documentation, Language Reference 6. Expressions 6.3 Primaries 6.3.4 Calls From python.list at tim.thechases.com Wed Mar 1 06:54:52 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 1 Mar 2017 05:54:52 -0600 Subject: Exposing all methods of a class In-Reply-To: References: <3afdc9ac-0679-f970-b604-e3367ca9788f@stridebird.com> Message-ID: <20170301055452.75c02dec@bigbox.christie.dr> On 2017-03-01 05:50, Terry Reedy wrote: > The class listing provided by the pydoc module browser, also in > help(someclass), do list all methods. Try > >>> import tkinter > >>> help(tkinter.Text) > for instance. I've been stung by opaque objects a couple times: 1) when the method comes from calculation via __getattr__ type methods class Foo(object): def __getattr__(self, attr): if attr.startswith("say_"): utterance = attr[4:] def method(): return "Hello, %s" % utterance return method f = Foo() f.say_Bob() dir(f) # no "say_Bob" method 2) when the underlying object is written in C and doesn't expose the dir() properly (I'm looking at mod_python's objects in particular which didn't allow inspection the last time I used it; though in fairness, this was 7-9yrs ago) -tkc From frank at chagford.com Wed Mar 1 09:25:11 2017 From: frank at chagford.com (Frank Millman) Date: Wed, 1 Mar 2017 16:25:11 +0200 Subject: asyncio does not always show the full traceback In-Reply-To: References: Message-ID: "Frank Millman" wrote in message news:o93vs2$smi$1 at blaine.gmane.org... > > I use asyncio in my project, so most of my functions start with 'async' > and most of my calls are preceded by 'await'. > > If an exception is raised, I usually get the full traceback, but sometimes > I just get something like the following - > > Traceback (most recent call last): > File "C:\Users\User\aib\aib\test_data.py", line 645, in > loop.run_until_complete(main(company)) > File > "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", > line 466, in run_until_complete > return future.result() > ValueError: not enough values to unpack (expected 2, got 1) > > It does not show the line where the ValueError occurs, and I have not > managed to narrow down exactly when this happens. > I have narrowed it down a bit. Here is a fairly simple example, based on some code I had lying around - import asyncio from itertools import count async def aenumerate(aiterable): counter = count() async for x in aiterable: yield next(counter), x await asyncio.sleep(0.5) async def gen(n): for i in range(100, 100+n): yield i async def aenum(): g = gen(5) async for a, x in aenumerate(g): print(a, x) print('done') async def main(): await aenum() loop = asyncio.get_event_loop() loop.run_until_complete(main()) If you run this as is, it works. I added '1/0' at various points, to force an exception. If I put it in main() or in aenum(), I do not get the full traceback. If I put it in aenumerate() or in gen(), I do get the traceback. I hope this enables someone cleverer than me to figure out what is going on. Frank From steve+python at pearwood.info Wed Mar 1 09:38:14 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 02 Mar 2017 01:38:14 +1100 Subject: Exposing all methods of a class References: <3afdc9ac-0679-f970-b604-e3367ca9788f@stridebird.com> Message-ID: <58b6dcd7$0$1620$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Feb 2017 07:15 am, Pete Dowdell wrote: > I use Python, mainly with Django, for work. I was wondering if anyone > has encountered an editor that could display a class with all inherited > methods included in the editor's view of the class code. Python 3.5 (if not earlier) can do most of the heavy lifting for this. Here's a proof of concept: import inspect def expose(obj): if isinstance(obj, type): cls = obj else: cls = type(obj) attrs = inspect.classify_class_attrs(cls) by_class = {} for attr in attrs: if attr.name.startswith('_'): continue by_class.setdefault(attr.defining_class, []).append(attr) print("%s object %r" % (type(obj), obj)) for K in by_class: print("Inheriting from: %s" % K) for attr in by_class[K]: print(" ", attr.name, attr.kind) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From storchaka at gmail.com Wed Mar 1 15:36:34 2017 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 1 Mar 2017 22:36:34 +0200 Subject: Manual parameter substitution in sqlite3 In-Reply-To: References: Message-ID: On 28.02.17 19:28, Skip Montanaro wrote: > Most of the time (well, all the time if you're smart), you let the > database adapter do parameter substitution for you to avoid SQL > injection attacks (or stupid users). So: > > curs.execute("select * from mumble where key = ?", (key,)) > > If you want to select from several possible keys, it would be nice to > be able to do this: > > curs.execute("select * from mumble where key in (?)", (keys,)) > > but that doesn't work. Instead, you need to do your own parameter > substitution. The quick-and-insecure way to do this is: > > curs.execute("select * from mumble where key in (%s)" % > ",".join([repr(k) for k in keys])) > > I'm pretty sure that's breakable. curs.execute("select * from mumble where %s" % " or ".join(["key = ?"] * len(keys)), *keys) From robert at forzasilicon.com Wed Mar 1 16:55:04 2017 From: robert at forzasilicon.com (robert at forzasilicon.com) Date: Wed, 1 Mar 2017 13:55:04 -0800 (PST) Subject: Using re to perform grep functionality in Python Message-ID: <7ba17723-6c85-4649-9485-bcab2842081e@googlegroups.com> Hi All, I'm relatively new to Python, and I am having some trouble with one of my scripts. Basically, this script connects to a server via ssh, runs Dell's omreport output, and then externally pipes it to a mail script in cron. The script uses an external call to grep via subprocess, but I would like to internalize everything to run in Python. I've read that re can accomplish the filtering, but I am having trouble getting it to duplicate what I already have. ##### USING EXTERNAL GREP ##### # display RAID controller info cmd = ['ssh root at server.ip -C \"/opt/dell/srvadmin/sbin/omreport storage vdisk\"'] print '########## Array Status ##########' p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) if call(["grep", "-i", "ID"], stdin=p.stdout) != 0: print final sys.stdout.write(p) p.wait() ###### END ####### This gives me: ####### Array Status ########## ID : 0 Layout : RAID-1 Associated Fluid Cache State : Not Applicable ---- vs the full output of: ########## Array Status ########## List of Virtual Disks in the System Controller PERC H310 Mini (Embedded) ID : 0 Status : Ok Name : Main State : Ready Hot Spare Policy violated : Not Assigned Encrypted : Not Applicable Layout : RAID-1 Size : 2,794.00 GB (3000034656256 bytes) T10 Protection Information Status : No Associated Fluid Cache State : Not Applicable Device Name : /dev/sda Bus Protocol : SATA Media : HDD Read Policy : No Read Ahead Write Policy : Write Through Cache Policy : Not Applicable Stripe Element Size : 64 KB Disk Cache Policy : Enabled ##### END #### I've been tinkering around with re, and the only code that I've come up with that doesn't give me a type error is this: cmd = ['ssh root at server.ip -C \"/opt/dell/srvadmin/sbin/omreport storage vdisk\"'] print '########## Array Status ##########' p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) for line in p.stdout: final = re.findall('ID', line, re.DOTALL) print final p.wait() Which returns this: ########## Array Status ########## [] [] [] ['ID'] [] [] [] [] [] ['ID'] [] [] [] [] [] [] [] [] [] [] [] Obviously, not what I want. Can anyone feed some input? From rosuav at gmail.com Wed Mar 1 17:29:17 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Mar 2017 09:29:17 +1100 Subject: Using re to perform grep functionality in Python In-Reply-To: <7ba17723-6c85-4649-9485-bcab2842081e@googlegroups.com> References: <7ba17723-6c85-4649-9485-bcab2842081e@googlegroups.com> Message-ID: On Thu, Mar 2, 2017 at 8:55 AM, wrote: > Hi All, > > I'm relatively new to Python, and I am having some trouble with one of my scripts. Basically, this script connects to a server via ssh, runs Dell's omreport output, and then externally pipes it to a mail script in cron. The script uses an external call to grep via subprocess, but I would like to internalize everything to run in Python. I've read that re can accomplish the filtering, but I am having trouble getting it to duplicate what I already have. > > p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) > if call(["grep", "-i", "ID"], stdin=p.stdout) != 0: This means "filter for lines that contain ID, case insensitively". > for line in p.stdout: > final = re.findall('ID', line, re.DOTALL) > print final > p.wait() This part doesn't have the case sensitivity flag set. But if this is the only thing you're doing with grep, you don't need a regex at all. You can simply check if "ID" exists in the string. Since you're using Python 2, I'm going to assume a naive byte-based case insensitivity is sufficient for you, as you're probably working with English-only and ASCII-only here. for line in p.stdout: if "ID" in line.upper(): print(line) p.wait() Give that a try :) Oh, and if case insensitivity isn't an issue to you (if you don't actually want "fluid" to show up), you can remove the .upper and just write: if "ID" in line: Very clean and pretty, IMO. ChrisA From robert at forzasilicon.com Wed Mar 1 17:41:20 2017 From: robert at forzasilicon.com (robert at forzasilicon.com) Date: Wed, 1 Mar 2017 14:41:20 -0800 (PST) Subject: Using re to perform grep functionality in Python In-Reply-To: <7ba17723-6c85-4649-9485-bcab2842081e@googlegroups.com> References: <7ba17723-6c85-4649-9485-bcab2842081e@googlegroups.com> Message-ID: Thanks, Chris. That was nice and easy and very simple. From cs at zip.com.au Wed Mar 1 17:54:42 2017 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 2 Mar 2017 09:54:42 +1100 Subject: Using re to perform grep functionality in Python In-Reply-To: <7ba17723-6c85-4649-9485-bcab2842081e@googlegroups.com> References: <7ba17723-6c85-4649-9485-bcab2842081e@googlegroups.com> Message-ID: <20170301225442.GA47587@cskk.homeip.net> On 01Mar2017 13:55, robert at forzasilicon.com wrote: >I'm relatively new to Python, and I am having some trouble with one of my >scripts. Basically, this script connects to a server via ssh, runs Dell's >omreport output, and then externally pipes it to a mail script in cron. The >script uses an external call to grep via subprocess, but I would like to >internalize everything to run in Python. I've read that re can accomplish the >filtering, but I am having trouble getting it to duplicate what I already >have. > >##### USING EXTERNAL GREP ##### > ># display RAID controller info >cmd = ['ssh root at server.ip -C \"/opt/dell/srvadmin/sbin/omreport storage >vdisk\"'] > >print '########## Array Status ##########' >p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) Might I recommend that you drop the shell quotes and invoke ssh directly? cmdargs = [ 'ssh', 'root at server.ip', '-C', '/opt/dell/srvadmin/sbin/omreport storage vdisk' ] p = subprocess.Popen(cmdargs, shell=False, stdout=subprocess.PIPE) And since shell=False is the default you can leave it off. It is just generally better to avoid using the shell for commands as it introduces a layer of quoting and escaping, usually pointlessly and always with a risk of misuse. >if call(["grep", "-i", "ID"], stdin=p.stdout) != 0: You're just looking for "id" in any case. That's fairly loose. More commentry below the output... [...] >This gives me: >ID : 0 >Layout : RAID-1 >Associated Fluid Cache State : Not Applicable >---- > >vs the full output of: > >########## Array Status ########## >List of Virtual Disks in the System > >Controller PERC H310 Mini (Embedded) >ID : 0 >Status : Ok >Name : Main >State : Ready >Hot Spare Policy violated : Not Assigned >Encrypted : Not Applicable >Layout : RAID-1 >Size : 2,794.00 GB (3000034656256 bytes) >T10 Protection Information Status : No >Associated Fluid Cache State : Not Applicable >Device Name : /dev/sda >Bus Protocol : SATA >Media : HDD >Read Policy : No Read Ahead >Write Policy : Write Through >Cache Policy : Not Applicable >Stripe Element Size : 64 KB >Disk Cache Policy : Enabled > >##### END #### > >I've been tinkering around with re, and the only code that I've come up with that doesn't give me a type error is this: [...] >for line in p.stdout: > final = re.findall('ID', line, re.DOTALL) > print final [...] >[] >[] >[] >['ID'] [...] Findall returns a list of all the matches. What you want is "if findall found anything, print the whole line", and for that you would only need find() (since it is enough to find just one match, not all of them). Might I suggest you don't use re at all? It has its uses but for your initial needs it is not necessary, and regexps are easy to get wrong (not to mention slow). Do a fixed string split: # trim the trailing newline and other padding if any line = line.strip() try: lhs, rhs = split(line, ':', 1) except ValueError: # no colon, probably a heading ... handle a heading, if you care ... else: field = lhs.strip() value = rhs.strip() if field == 'ID': ... note the controller id ... elif field == 'Layout': ... note the layout value ... ... whatever other fields you care about ... You can see that in this way you can handle fields very specificly as you see fit. Some RAID monitoring tools produce quite long reports, so you can also track state (what heading/controller/raidset am I in at present?) and build a data structure for better reporting. As an example, have a gander at this: https://pypi.python.org/pypi/cs.app.megacli/20160310 which I wrote for IBM MegaRAIDs; it also does Dell PowerEdge (PERC) controllers. It is deliberately Python 2 BTW, because it had to run on RHEL 5 which had Python 2.4 as the vendor supplied python. Cheers, Cameron Simpson Some people, when confronted with a problem, think "I know, I'll use regular expressions. Now they have two problems." - Jamie Zawinski, in alt.religion.emacs From torriem at gmail.com Wed Mar 1 19:13:18 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 1 Mar 2017 17:13:18 -0700 Subject: Using re to perform grep functionality in Python In-Reply-To: <7ba17723-6c85-4649-9485-bcab2842081e@googlegroups.com> References: <7ba17723-6c85-4649-9485-bcab2842081e@googlegroups.com> Message-ID: <8caae486-7d9d-c6e0-5c89-b663247e35f8@gmail.com> On 03/01/2017 02:55 PM, robert at forzasilicon.com wrote: > Obviously, not what I want. Can anyone feed some input? You've already got some good answers, but I just wanted to point you at this good resource: http://www.dabeaz.com/generators/ Pretty much anything you do in a shell script that involves piping through filters you can do in Python with flexible generator functions. It's pretty neat. From rantingrickjohnson at gmail.com Wed Mar 1 21:41:29 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 1 Mar 2017 18:41:29 -0800 (PST) Subject: Exposing all methods of a class In-Reply-To: References: <3afdc9ac-0679-f970-b604-e3367ca9788f@stridebird.com> Message-ID: <39784395-a0fb-4af0-a410-417565cf38e5@googlegroups.com> On Wednesday, March 1, 2017 at 4:51:34 AM UTC-6, Terry Reedy wrote: > The class listing provided by the pydoc module browser, > also in help(someclass), do list all methods. Try > >>> import tkinter > >>> help(tkinter.Text) > for instance. > > On 2/28/2017 7:16 PM, Rick Johnson wrote: > > IDLE has a "class browser" feature (@GUI_XY = File- > > Class_Browser) that displays a GUI tree of the currently > > opened module, although, and unfortunately for you, the > > scope of detail ends at the physical borders of the > > module. > > I'd like to rename that 'module browser after enhancing > coverage of functions a bit. Agreed. "Module Browser" is a far more intuitive name. And since we all aware that IDLE needs an industrial quality spit-shine, this could be a good first step! A nice bonus feature (but potentially resource heavy) would be a "include external dependancies" Checkbox that would optionally expand the tree to include all imported module structure as well (something akin to what the OP wanted, but less "class centric"). Sure, it might be really slow if the module has a ton of nested dependencies, but, it's not something you'd need every day -- only when you're trying to get a bird's-eye-view of an entire library, or package. And this is where categorical methodologies like "Level Of Detail" (LOD) become paramount to R&D. Because, you can quickly become lost in a "sea of nodes" if the interface is not properly designed. > > However, by utilizing the introspection power of python > > (`import inspect`, for instance), you could probably > > implement something akin to "comprehensive introspection > > reform". > > A real class browser, with the same info as in the help > output, but more interactive, would be interesting. Sure would. And a GUI interface affords you more latitude to display complex/nested data structures in a manner that is more conducive to eyeball-parsing -- as opposed to the archaic and crass tactic of: sys.stdout.dump(umpteen_pages_of_text) Nobody likes to be dumped on. ;-) From auriocus at gmx.de Thu Mar 2 03:55:54 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 2 Mar 2017 09:55:54 +0100 Subject: Manual parameter substitution in sqlite3 In-Reply-To: References: Message-ID: Am 28.02.17 um 18:28 schrieb Skip Montanaro: > Most of the time (well, all the time if you're smart), you let the > database adapter do parameter substitution for you to avoid SQL > injection attacks (or stupid users). So: > > curs.execute("select * from mumble where key = ?", (key,)) > > If you want to select from several possible keys, it would be nice to > be able to do this: > > curs.execute("select * from mumble where key in (?)", (keys,)) > > but that doesn't work. Instead of building the query on the fly (with quoting hell etc.), you could do it "the (theoretical) right way", which is using another table. Insert your keys into a table, maybe temporary one, and then do select * from mumble where key in (select key from keytable) In theory that should also be faster, but unless you have a thousand keys, there will be no noticeable difference. Christian From python.list at tim.thechases.com Thu Mar 2 06:59:01 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 2 Mar 2017 05:59:01 -0600 Subject: Manual parameter substitution in sqlite3 In-Reply-To: References: Message-ID: <20170302055901.1ca6dd58@bigbox.christie.dr> On 2017-03-02 09:55, Christian Gollwitzer wrote: > you could do it "the (theoretical) right way", which is using > another table. Insert your keys into a table, maybe temporary one, > and then do > > select * from mumble where key in (select key from keytable) > > In theory that should also be faster, but unless you have a > thousand keys, there will be no noticeable difference. It would depend on the frequency with which the same query is issued. Bulk inserts, followed by the query, followed by cleaning up the data would almost certainly be slower. Bulk inserting the data and then issuing thousands of queries against it could prove much faster (though as with all things performance-related, test, don't guess). But if the set of criteria changes frequently, the overhead of inserting/deleting the data will almost certainly swamp any potential speed-up. -tkc From songofacandy at gmail.com Thu Mar 2 07:31:32 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Thu, 2 Mar 2017 21:31:32 +0900 Subject: asyncio does not always show the full traceback In-Reply-To: References: Message-ID: I can't reproduce it on Linux. Maybe, it's windows specific bug? On Wed, Mar 1, 2017 at 11:25 PM, Frank Millman wrote: > "Frank Millman" wrote in message news:o93vs2$smi$1 at blaine.gmane.org... >> >> >> I use asyncio in my project, so most of my functions start with 'async' >> and > > most of my calls are preceded by 'await'. >> >> >> If an exception is raised, I usually get the full traceback, but sometimes >> I > > just get something like the following - >> >> >> Traceback (most recent call last): >> File "C:\Users\User\aib\aib\test_data.py", line 645, in >> loop.run_until_complete(main(company)) >> File >> "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\asyncio\base_events.py", >> line 466, in run_until_complete >> return future.result() >> ValueError: not enough values to unpack (expected 2, got 1) >> >> It does not show the line where the ValueError occurs, and I have not >> managed to narrow down exactly when this happens. >> > > I have narrowed it down a bit. > > Here is a fairly simple example, based on some code I had lying around - > > import asyncio > from itertools import count > > async def aenumerate(aiterable): > counter = count() > async for x in aiterable: > yield next(counter), x > await asyncio.sleep(0.5) > > async def gen(n): > for i in range(100, 100+n): > yield i > > async def aenum(): > g = gen(5) > async for a, x in aenumerate(g): > print(a, x) > print('done') > > async def main(): > await aenum() > > loop = asyncio.get_event_loop() > loop.run_until_complete(main()) > > If you run this as is, it works. > > I added '1/0' at various points, to force an exception. > > If I put it in main() or in aenum(), I do not get the full traceback. > > If I put it in aenumerate() or in gen(), I do get the traceback. > > I hope this enables someone cleverer than me to figure out what is going on. > > Frank > > > -- > https://mail.python.org/mailman/listinfo/python-list From frank at chagford.com Thu Mar 2 07:55:46 2017 From: frank at chagford.com (Frank Millman) Date: Thu, 2 Mar 2017 14:55:46 +0200 Subject: asyncio does not always show the full traceback In-Reply-To: References: Message-ID: "INADA Naoki" wrote in message news:CAEfz+TyUdWJesyttqZg2_ROMPhmJRxqaGA2ULgFQV5QbpiiiXQ at mail.gmail.com... > > I can't reproduce it on Linux. > Maybe, it's windows specific bug? > > import asyncio > from itertools import count > > async def aenumerate(aiterable): > counter = count() > async for x in aiterable: > yield next(counter), x > await asyncio.sleep(0.5) > > async def gen(n): > for i in range(100, 100+n): > yield i > > async def aenum(): > g = gen(5) > async for a, x in aenumerate(g): > print(a, x) > print('done') > > async def main(): > await aenum() > > loop = asyncio.get_event_loop() > loop.run_until_complete(main()) > Thanks for the reply. I tried it out on linux (Fedora 22, Python 3.6.0b4), and I get the same result as I do on Windows. If I place '1/0' in main(), this is the traceback - Traceback (most recent call last): File "test_db1a.py", line 25, in loop.run_until_complete(main()) File "/usr/local/lib/python3.6/asyncio/base_events.py", line 466, in run_until_complete return future.result() ZeroDivisionError: division by zero If I place '1/0' in gen(), this is the traceback - Traceback (most recent call last): File "test_db1a.py", line 25, in loop.run_until_complete(main()) File "/usr/local/lib/python3.6/asyncio\base_events.py", line 466, in run_until_complete return future.result() File "test_db1a.py", line 17, in aenum async for a, x in aenumerate(g): File "test_db1a.py", line 6, in aenumerate async for x in aiterable: File "test_db1a.py", line 11, in gen 1/0 ZeroDivisionError: division by zero Can anyone else confirm whether they can reproduce my results? Thanks Frank From songofacandy at gmail.com Thu Mar 2 08:05:24 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Thu, 2 Mar 2017 22:05:24 +0900 Subject: asyncio does not always show the full traceback In-Reply-To: References: Message-ID: Could you use 3.6.0 instead of b4? I added 1/0 at: ... async def main(): 1/0 await aenum() ... then: $ pyenv/versions/3.6.0/bin/python3 -VV Python 3.6.0 (default, Jan 16 2017, 19:41:10) [GCC 6.2.0 20161005] $ pyenv/versions/3.6.0/bin/python3 a.py Traceback (most recent call last): File "a.py", line 25, in loop.run_until_complete(main()) File "/home/inada-n/pyenv/versions/3.6.0/lib/python3.6/asyncio/base_events.py", line 466, in run_until_complete return future.result() File "a.py", line 21, in main 1/0 ZeroDivisionError: division by zero From rosuav at gmail.com Thu Mar 2 08:06:15 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Mar 2017 00:06:15 +1100 Subject: asyncio does not always show the full traceback In-Reply-To: References: Message-ID: On Thu, Mar 2, 2017 at 11:55 PM, Frank Millman wrote: > If I place '1/0' in main(), this is the traceback - > > Traceback (most recent call last): > File "test_db1a.py", line 25, in > loop.run_until_complete(main()) > File "/usr/local/lib/python3.6/asyncio/base_events.py", line 466, in > run_until_complete > return future.result() > ZeroDivisionError: division by zero > > Can anyone else confirm whether they can reproduce my results? Not replicated. Python 3.7.0a0 (default:cebc9c7ad195+, Feb 28 2017, 01:09:27) [GCC 6.2.0 20161027] on linux Traceback (most recent call last): File "acrash.py", line 25, in loop.run_until_complete(main()) File "/usr/local/lib/python3.7/asyncio/base_events.py", line 465, in run_until_complete return future.result() File "acrash.py", line 21, in main 1/0 ZeroDivisionError: division by zero That's inserting 1/0 just before "await aenum()". Switching the order of the lines also produces the expected result - delayed output, then an exception that shows the crashing line. ChrisA From frank at chagford.com Thu Mar 2 08:08:22 2017 From: frank at chagford.com (Frank Millman) Date: Thu, 2 Mar 2017 15:08:22 +0200 Subject: asyncio does not always show the full traceback In-Reply-To: References: Message-ID: "Frank Millman" wrote in message news:o994og$84k$1 at blaine.gmane.org... > > If I place '1/0' in main(), this is the traceback - > > Traceback (most recent call last): > File "test_db1a.py", line 25, in > loop.run_until_complete(main()) > File "/usr/local/lib/python3.6/asyncio/base_events.py", line 466, in > run_until_complete > return future.result() > ZeroDivisionError: division by zero > > If I place '1/0' in gen(), this is the traceback - > > Traceback (most recent call last): > File "test_db1a.py", line 25, in > loop.run_until_complete(main()) > File "/usr/local/lib/python3.6/asyncio\base_events.py", line 466, in > run_until_complete > return future.result() > File "test_db1a.py", line 17, in aenum > async for a, x in aenumerate(g): > File "test_db1a.py", line 6, in aenumerate > async for x in aiterable: > File "test_db1a.py", line 11, in gen > 1/0 > ZeroDivisionError: division by zero For completeness, if I place '1/0' in aenum(), I get exactly the same traceback as the first one above. Frank From formisc at gmail.com Thu Mar 2 11:02:45 2017 From: formisc at gmail.com (Andrew Zyman) Date: Thu, 2 Mar 2017 08:02:45 -0800 (PST) Subject: list of the lists - append after search Message-ID: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> Hello, please advise. I'd like search and append the internal list in the list-of-the-lists. Example: ll =[ [a,1], [b,2], [c,3], [blah, 1000] ] i want to search for the internal [] based on the string field and, if matches, append that list with a value. if internal_list[0] == 'blah': ll[ internal_list].append = [ 'new value'] End result: ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] I came up with the following, but the second stmnt is not correct: print [x for x in ll if x[0]== 'blah'] print ll.index([x for x in ll if x[0]=='blah']) output: ValueError: [['blah', 1]] is not in list thank you AZ From formisc at gmail.com Thu Mar 2 11:08:31 2017 From: formisc at gmail.com (Andrew Zyman) Date: Thu, 2 Mar 2017 08:08:31 -0800 (PST) Subject: spam issue Message-ID: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> Why is this group have such an obscene number of spam posts ? I'm subscribed to a few other google groups and this is the only one that has this issue. From songofacandy at gmail.com Thu Mar 2 11:11:40 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Fri, 3 Mar 2017 01:11:40 +0900 Subject: asyncio does not always show the full traceback In-Reply-To: References: Message-ID: > For completeness, if I place '1/0' in aenum(), I get exactly the same > traceback as the first one above. > I can't reproduce it too. Did you 3.6.0 this time? Or did you used 3.6b4 again? Please don't use beta when asking question or reporting bug. From songofacandy at gmail.com Thu Mar 2 11:14:55 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Fri, 3 Mar 2017 01:14:55 +0900 Subject: asyncio does not always show the full traceback In-Reply-To: References: Message-ID: FYI, you can easily find this changelog of Python 3.6rc1: - bpo-28843: Fix asyncio C Task to handle exceptions __traceback__. See also: https://bugs.python.org/issue28843 On Fri, Mar 3, 2017 at 1:11 AM, INADA Naoki wrote: >> For completeness, if I place '1/0' in aenum(), I get exactly the same >> traceback as the first one above. >> > > I can't reproduce it too. > Did you 3.6.0 this time? Or did you used 3.6b4 again? > Please don't use beta when asking question or reporting bug. From __peter__ at web.de Thu Mar 2 11:26:56 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Mar 2017 17:26:56 +0100 Subject: list of the lists - append after search References: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> Message-ID: Andrew Zyman wrote: > Hello, > please advise. > > I'd like search and append the internal list in the list-of-the-lists. > > Example: > ll =[ [a,1], [b,2], [c,3], [blah, 1000] ] > > i want to search for the internal [] based on the string field and, if > matches, append that list with a value. > > if internal_list[0] == 'blah': > ll[ internal_list].append = [ 'new value'] > > End result: > ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] >>> for inner in outer: ... if inner[0] == "blah": ... inner.append("new value") ... >>> outer [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] While this is what you are asking for it will get slower as the list grows. A better solution uses a dictionary: >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] >>> lookup = {inner[0]: inner[1:] for inner in outer} >>> lookup {'a': [1], 'blah': [1000], 'b': [2], 'c': [3]} >>> lookup["blah"].append("whatever") >>> lookup {'a': [1], 'blah': [1000, 'whatever'], 'b': [2], 'c': [3]} From chololennon at hotmail.com Thu Mar 2 13:31:32 2017 From: chololennon at hotmail.com (Cholo Lennon) Date: Thu, 2 Mar 2017 15:31:32 -0300 Subject: spam issue References: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> Message-ID: On 02/03/17 13:08, Andrew Zyman wrote: > Why is this group have such an obscene number of spam posts ? > I'm subscribed to a few other google groups and this is the only one that has this issue. > Google groups act like a "web frontend" for nntp protocol (on which this group is based). I suppose Google doesn't filter spam messages in its interface. Try using a newsreader like Mozilla Thunderbird and point it to a news server. In my case I use "news.aioe.org", it's free and it doesn't have spam. The only minor problem is its retention policy (a couple of months or so, but any newsreader can cache messages in your computer the time you want) Regards -- Cholo Lennon Bs.As. ARG From rosuav at gmail.com Thu Mar 2 13:39:39 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Mar 2017 05:39:39 +1100 Subject: spam issue In-Reply-To: References: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> Message-ID: On Fri, Mar 3, 2017 at 5:31 AM, Cholo Lennon wrote: > Google groups act like a "web frontend" for nntp protocol (on which this > group is based). I suppose Google doesn't filter spam messages in its > interface. Try using a newsreader like Mozilla Thunderbird and point it to a > news server. In my case I use "news.aioe.org", it's free and it doesn't have > spam. The only minor problem is its retention policy (a couple of months or > so, but any newsreader can cache messages in your computer the time you > want) > Or the mailing list, depending on how you like to read things. The list has some additional filtering and moderation, which I appreciate. ChrisA From stamnik at gmail.com Thu Mar 2 13:52:35 2017 From: stamnik at gmail.com (stamnik at gmail.com) Date: Thu, 2 Mar 2017 10:52:35 -0800 (PST) Subject: dnspython update dns record issue Message-ID: <19859589-fb36-4d81-a2e3-22d3aa234af9@googlegroups.com> I'm trying to use dnspython to do a TSIG based dynamic DNS update. I've followed the example code : #!/usr/bin/env python import sys import dns.update import dns.query import dns.tsigkeyring keyring = dns.tsigkeyring.from_text({ 'keyname.' : 'VarFF=2Xts7T5Vb/xd&8ir==' }) update = dns.update.Update('domain_name', keyring=keyring) update.replace('myserver', 30, 'a', '88.88.88.88') response = dns.query.tcp(update, 'dns_ip',timeout=10) and here is what I got: response = dns.query.tcp(update, 'dns_ip',timeout=10) File "/root/bck/dnspython/dns/query.py", line 475, in tcp q.keyring, q.mac) File "/root/bck/dnspython/dns/query.py", line 412, in receive_tcp one_rr_per_rrset=one_rr_per_rrset) File "/root/bck/dnspython/dns/message.py", line 821, in from_wire reader.read() File "/root/bck/dnspython/dns/message.py", line 749, in read self._get_section(self.message.additional, adcount) File "/root/bck/dnspython/dns/message.py", line 701, in _get_section self.message.first) File "/root/bck/dnspython/dns/tsig.py", line 198, in validate raise BadSignature dns.tsig.BadSignature: The TSIG signature fails to verify. Thanks in advance to anyone who can help! From formisc at gmail.com Thu Mar 2 13:57:07 2017 From: formisc at gmail.com (Andrew Zyman) Date: Thu, 2 Mar 2017 10:57:07 -0800 (PST) Subject: spam issue In-Reply-To: References: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> Message-ID: On Thursday, March 2, 2017 at 1:39:54 PM UTC-5, Chris Angelico wrote: > On Fri, Mar 3, 2017 at 5:31 AM, Cholo Lennon wrote: > > Google groups act like a "web frontend" for nntp protocol (on which this > > group is based). I suppose Google doesn't filter spam messages in its > > interface. Try using a newsreader like Mozilla Thunderbird and point it to a > > news server. In my case I use "news.aioe.org", it's free and it doesn't have > > spam. The only minor problem is its retention policy (a couple of months or > > so, but any newsreader can cache messages in your computer the time you > > want) > > > > Or the mailing list, depending on how you like to read things. The > list has some additional filtering and moderation, which I appreciate. > > ChrisA you mean on python.org ? From rosuav at gmail.com Thu Mar 2 14:04:22 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Mar 2017 06:04:22 +1100 Subject: spam issue In-Reply-To: References: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> Message-ID: On Fri, Mar 3, 2017 at 5:57 AM, Andrew Zyman wrote: >> Or the mailing list, depending on how you like to read things. The >> list has some additional filtering and moderation, which I appreciate. >> >> ChrisA > > > you mean on python.org ? Yeah. You can sign up here: https://mail.python.org/mailman/listinfo/python-list The content is the same as on the newsgroup, modulo the differences in filtering/moderation, so you can make a stylistic choice to read it as a newsgroup or as a mailing list. ChrisA From formisc at gmail.com Thu Mar 2 14:07:57 2017 From: formisc at gmail.com (Andrew Zyman) Date: Thu, 2 Mar 2017 11:07:57 -0800 (PST) Subject: list of the lists - append after search In-Reply-To: References: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> Message-ID: <26642604-2a86-4d3a-abeb-0d7491f5ab97@googlegroups.com> On Thursday, March 2, 2017 at 11:27:34 AM UTC-5, Peter Otten wrote: > Andrew Zyman wrote: > ..... > ..... > > End result: > > ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] > > >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] > >>> for inner in outer: > ... if inner[0] == "blah": > ... inner.append("new value") thank you. this will do. Just curious, is the above loop can be done in a one-liner? > While this is what you are asking for it will get slower as the list grows. > A better solution uses a dictionary: > >>> lookup = {inner[0]: inner[1:] for inner in outer} Yes, understood, i don't expect the list to grow above a few thousand entries. But i do agree that utilizing the dict is more efficient. From __peter__ at web.de Thu Mar 2 14:21:48 2017 From: __peter__ at web.de (Peter Otten) Date: Thu, 02 Mar 2017 20:21:48 +0100 Subject: list of the lists - append after search References: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> <26642604-2a86-4d3a-abeb-0d7491f5ab97@googlegroups.com> Message-ID: Andrew Zyman wrote: > On Thursday, March 2, 2017 at 11:27:34 AM UTC-5, Peter Otten wrote: >> Andrew Zyman wrote: >> ..... >> ..... >> > End result: >> > ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] >> >> >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] >> >>> for inner in outer: >> ... if inner[0] == "blah": >> ... inner.append("new value") > > thank you. this will do. > Just curious, is the above loop can be done in a one-liner? Ah, that newbie obsession ;) >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] >>> [inner + ["new value"] if inner[0] == "blah" else inner for inner in outer] [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] Note that there is a technical difference to be aware of -- matching lists are replaced rather than modified. >> While this is what you are asking for it will get slower as the list >> grows. A better solution uses a dictionary: > >> >>> lookup = {inner[0]: inner[1:] for inner in outer} > > Yes, understood, i don't expect the list to grow above a few thousand > entries. But i do agree that utilizing the dict is more efficient. From breamoreboy at gmail.com Thu Mar 2 14:27:55 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Thu, 2 Mar 2017 11:27:55 -0800 (PST) Subject: spam issue In-Reply-To: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> References: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> Message-ID: <5d5288da-ab29-474f-a808-63ab1befa4f5@googlegroups.com> On Thursday, March 2, 2017 at 4:08:44 PM UTC, Andrew Zyman wrote: > Why is this group have such an obscene number of spam posts ? > I'm subscribed to a few other google groups and this is the only one that has this issue. The bulk having lots of block capitals and in Italian? Been happening for years. Just use gmane, gives you access to hundreds of Python lists and thousands of others in one hit. Kindest regards. Mark Lawrence. From rosuav at gmail.com Thu Mar 2 14:33:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Mar 2017 06:33:58 +1100 Subject: Python3.6 a little conundrum In-Reply-To: References: Message-ID: On Fri, Mar 3, 2017 at 6:01 AM, Gilmeh Serda wrote: > After compiling and NOT installing (need to keep the 2.7 around, > undisturbed). > > Just testing something out: > > $ python36 > Python 3.6.0 (default, Mar 1 2017, 22:11:43) > [GCC 4.6.3] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> s = 'testing' > > Then, I'm used to pressing the up arrow to get the same row again, only I > get this: > >>>> ^[[A > > Other than that, it seems to be working fine. Sounds like you don't have readline. You're compiling on Linux, so most likely you need to use your package manager to install the readline development libraries. On my Debian, it's: sudo apt-get install libreadline-dev On Ubuntu and related, it's likely to be the same. On other distros, check your package manager for something talking about "readline" and "dev", and it's probably that. ChrisA From jussi.piitulainen at helsinki.fi Thu Mar 2 14:56:51 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 02 Mar 2017 21:56:51 +0200 Subject: list of the lists - append after search References: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> <26642604-2a86-4d3a-abeb-0d7491f5ab97@googlegroups.com> Message-ID: Peter Otten <__peter__ at web.de> writes: > Andrew Zyman wrote: > >> On Thursday, March 2, 2017 at 11:27:34 AM UTC-5, Peter Otten wrote: >>> Andrew Zyman wrote: >>> ..... >>> ..... >>> > End result: >>> > ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] >>> >>> >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] >>> >>> for inner in outer: >>> ... if inner[0] == "blah": >>> ... inner.append("new value") >> >> thank you. this will do. >> Just curious, is the above loop can be done in a one-liner? > > Ah, that newbie obsession ;) > >>>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] >>>> [inner + ["new value"] if inner[0] == "blah" else inner for inner in > outer] > [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] > > Note that there is a technical difference to be aware of -- matching > lists are replaced rather than modified. I take it you are too sane, or too kind, to suggest the obvious solution: >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] >>> [inner.append("new value") for inner in outer if inner[0] == "blah"] [None] >>> outer [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] [snip] From formisc at gmail.com Thu Mar 2 15:06:39 2017 From: formisc at gmail.com (Andrew Zyman) Date: Thu, 2 Mar 2017 12:06:39 -0800 (PST) Subject: spam issue In-Reply-To: <5d5288da-ab29-474f-a808-63ab1befa4f5@googlegroups.com> References: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> <5d5288da-ab29-474f-a808-63ab1befa4f5@googlegroups.com> Message-ID: <6e6b9e01-31ff-4147-bff7-83b50837d56f@googlegroups.com> On Thursday, March 2, 2017 at 2:28:04 PM UTC-5, bream... at gmail.com wrote: > On Thursday, March 2, 2017 at 4:08:44 PM UTC, Andrew Zyman wrote: > > Why is this group have such an obscene number of spam posts ? > > I'm subscribed to a few other google groups and this is the only one that has this issue. > > The bulk having lots of block capitals and in Italian? Been happening for years. Just use gmane, gives you access to hundreds of Python lists and thousands of others in one hit. > > Kindest regards. > > Mark Lawrence. thank you gents! From formisc at gmail.com Thu Mar 2 15:11:23 2017 From: formisc at gmail.com (Andrew Zyman) Date: Thu, 2 Mar 2017 12:11:23 -0800 (PST) Subject: list of the lists - append after search In-Reply-To: References: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> <26642604-2a86-4d3a-abeb-0d7491f5ab97@googlegroups.com> Message-ID: <6c2c8b07-55de-432e-816a-54da65243f52@googlegroups.com> On Thursday, March 2, 2017 at 2:57:02 PM UTC-5, Jussi Piitulainen wrote: > Peter Otten <__peter__ at web.de> writes: > > > Andrew Zyman wrote: > > > >> On Thursday, March 2, 2017 at 11:27:34 AM UTC-5, Peter Otten wrote: > >>> Andrew Zyman wrote: > >>> ..... > >>> ..... > >>> > End result: > >>> > ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] > >>> > >>> >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] > >>> >>> for inner in outer: > >>> ... if inner[0] == "blah": > >>> ... inner.append("new value") > >> > >> thank you. this will do. > >> Just curious, is the above loop can be done in a one-liner? > > > > Ah, that newbie obsession ;) > > > >>>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] > >>>> [inner + ["new value"] if inner[0] == "blah" else inner for inner in > > outer] > > [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] > > > > Note that there is a technical difference to be aware of -- matching > > lists are replaced rather than modified. > > I take it you are too sane, or too kind, to suggest the obvious > solution: > > >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] > >>> [inner.append("new value") for inner in outer if inner[0] == "blah"] > [None] > >>> outer > [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] > > [snip] Arh!!! this is it :) I'm sure i'll regret this line of code in 2 weeks - after i successfully forget what i wanted to achieve :) From jussi.piitulainen at helsinki.fi Thu Mar 2 15:31:27 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 02 Mar 2017 22:31:27 +0200 Subject: list of the lists - append after search References: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> <26642604-2a86-4d3a-abeb-0d7491f5ab97@googlegroups.com> <6c2c8b07-55de-432e-816a-54da65243f52@googlegroups.com> Message-ID: Andrew Zyman writes: > On Thursday, March 2, 2017 at 2:57:02 PM UTC-5, Jussi Piitulainen wrote: >> Peter Otten <__peter__ at web.de> writes: >> >> > Andrew Zyman wrote: >> > >> >> On Thursday, March 2, 2017 at 11:27:34 AM UTC-5, Peter Otten wrote: >> >>> Andrew Zyman wrote: >> >>> ..... >> >>> ..... >> >>> > End result: >> >>> > ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] >> >>> >> >>> >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] >> >>> >>> for inner in outer: >> >>> ... if inner[0] == "blah": >> >>> ... inner.append("new value") >> >> >> >> thank you. this will do. >> >> Just curious, is the above loop can be done in a one-liner? >> > >> > Ah, that newbie obsession ;) >> > >> >>>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] >> >>>> [inner + ["new value"] if inner[0] == "blah" else inner for inner in >> > outer] >> > [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] >> > >> > Note that there is a technical difference to be aware of -- matching >> > lists are replaced rather than modified. >> >> I take it you are too sane, or too kind, to suggest the obvious >> solution: >> >> >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] >> >>> [inner.append("new value") for inner in outer if inner[0] == "blah"] >> [None] >> >>> outer >> [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] >> >> [snip] > > Arh!!! this is it :) > > I'm sure i'll regret this line of code in 2 weeks - after i > successfully forget what i wanted to achieve :) Jokes aside, you should strive to express your intention in your code. Be kind to your future self. Write the three-line loop if you want in-place modification. I use comprehensions a lot, but not to save lines. I might make Peter's expression above a four-liner to make its structure more visible: res = [ ( inner + ["new value"] if inner[0] == "blah" else inner ) for inner in outer ] Maybe. From formisc at gmail.com Thu Mar 2 15:53:16 2017 From: formisc at gmail.com (Andrew Zyman) Date: Thu, 2 Mar 2017 12:53:16 -0800 (PST) Subject: list of the lists - append after search In-Reply-To: References: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> <26642604-2a86-4d3a-abeb-0d7491f5ab97@googlegroups.com> <6c2c8b07-55de-432e-816a-54da65243f52@googlegroups.com> Message-ID: On Thursday, March 2, 2017 at 3:31:36 PM UTC-5, Jussi Piitulainen wrote: > Andrew Zyman writes: > > > On Thursday, March 2, 2017 at 2:57:02 PM UTC-5, Jussi Piitulainen wrote: > >> Peter Otten <__peter__ at web.de> writes: > >> > >> > Andrew Zyman wrote: > >> > > >> >> On Thursday, March 2, 2017 at 11:27:34 AM UTC-5, Peter Otten wrote: > >> >>> Andrew Zyman wrote: > >> >>> ..... > >> >>> ..... > >> >>> > End result: > >> >>> > ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] > >> >>> > >> >>> >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] > >> >>> >>> for inner in outer: > >> >>> ... if inner[0] == "blah": > >> >>> ... inner.append("new value") > >> >> > >> >> thank you. this will do. > >> >> Just curious, is the above loop can be done in a one-liner? > >> > > >> > Ah, that newbie obsession ;) > >> > > >> >>>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] > >> >>>> [inner + ["new value"] if inner[0] == "blah" else inner for inner in > >> > outer] > >> > [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] > >> > > >> > Note that there is a technical difference to be aware of -- matching > >> > lists are replaced rather than modified. > >> > >> I take it you are too sane, or too kind, to suggest the obvious > >> solution: > >> > >> >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] > >> >>> [inner.append("new value") for inner in outer if inner[0] == "blah"] > >> [None] > >> >>> outer > >> [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] > >> > >> [snip] > > > > Arh!!! this is it :) > > > > I'm sure i'll regret this line of code in 2 weeks - after i > > successfully forget what i wanted to achieve :) > > Jokes aside, you should strive to express your intention in your code. > Be kind to your future self. Write the three-line loop if you want > in-place modification. > > I use comprehensions a lot, but not to save lines. I might make Peter's > expression above a four-liner to make its structure more visible: > > res = [ ( inner + ["new value"] > if inner[0] == "blah" > else inner ) > for inner in outer ] > > Maybe. thank you gentlemen. This is very helpful discussion and i appreciate your explanations - helped a lot. From frank at chagford.com Fri Mar 3 00:40:07 2017 From: frank at chagford.com (Frank Millman) Date: Fri, 3 Mar 2017 07:40:07 +0200 Subject: asyncio does not always show the full traceback In-Reply-To: References: Message-ID: "INADA Naoki" wrote in message news:CAEfz+Tz8hVwmh5CF17mv3aCcdqThj1AXDDga8UmnZnUUWESbfg at mail.gmail.com... > > For completeness, if I place '1/0' in aenum(), I get exactly the same > > traceback as the first one above. > > > > I can't reproduce it too. > Did you 3.6.0 this time? Or did you used 3.6b4 again? > Please don't use beta when asking question or reporting bug. > My humble apologies. I had downloaded 3.6.0 for Windows, and I really thought I had installed it, but I was running 3.6.0b4 on Windows as well :-( I confirm that after downloading and installing the correct version on both platforms, the problem no longer exists. Sorry for wasting your time. Frank From rosuav at gmail.com Fri Mar 3 01:19:00 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Mar 2017 17:19:00 +1100 Subject: Python3.6 a little conundrum In-Reply-To: References: Message-ID: On Fri, Mar 3, 2017 at 4:56 PM, Gilmeh Serda wrote: > I'll check if I can get that into the mix, eventually. Python's already > installed, so I guess I have to backtrack to remove it. Further > investigation required. You didn't install, so you should be able to rerun ./configure and make to rebuild with new libraries. BTW, once you get the code built to your liking, I would recommend running this: $ sudo make altinstall That will install as python3.6 without replacing the symlink python3, so whatever your system Python 3 is, it'll still be there, untouched. And regardless of whether you use "make install" or "make altinstall", your Python 2.7 won't be affected. ChrisA From murthy919 at gmail.com Fri Mar 3 07:52:33 2017 From: murthy919 at gmail.com (Murthy Jn) Date: Fri, 3 Mar 2017 04:52:33 -0800 (PST) Subject: Insert blob data from one db to other db in oracle In-Reply-To: <6590d3ae-ce09-49dd-a458-fcce1a449e64@googlegroups.com> References: <6590d3ae-ce09-49dd-a458-fcce1a449e64@googlegroups.com> Message-ID: No One don't no ? how to insert data from one table to another table using oracle? From mal at europython.eu Fri Mar 3 07:58:25 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 3 Mar 2017 13:58:25 +0100 Subject: EuroPython 2017: Official dates available Message-ID: <4632f626-a379-78bf-035b-bc4a1f26e948@europython.eu> We are very happy to officially announce the confirmed dates for EuroPython 2017 in Rimini, Italy: EuroPython 2017: July 9-16 2017 *** http://ep2017.europython.eu/ *** The conference will be held at the Rimini PalaCongressi and structured as follows: * July 9 - Workshops and Beginners? Day * July 10-14 - Conference and training days * July 15-16 - Sprints Conference tickets will allow attending Beginners? Day, keynotes, talks, trainings, poster sessions, interactive sessions, panels and sprints. Please subscribe to our various EuroPython channels for updates on the conference. We will start putting out more information about the conference in the coming days. Enjoy, ? EuroPython 2017 Team http://ep2017.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/837641810994397184 Thanks. From g.starck at gmail.com Fri Mar 3 08:06:45 2017 From: g.starck at gmail.com (gst) Date: Fri, 3 Mar 2017 05:06:45 -0800 (PST) Subject: asyncio does not always show the full traceback In-Reply-To: References: Message-ID: Le mercredi 1 mars 2017 09:25:48 UTC-5, Frank Millman a ?crit?: > "Frank Millman" wrote in message news:o93vs2$smi$1 at blaine.gmane.org... SNIP > > If you run this as is, it works. > > I added '1/0' at various points, to force an exception. > > If I put it in main() or in aenum(), I do not get the full traceback. > > If I put it in aenumerate() or in gen(), I do get the traceback. > Hi, I ran your snippet, using 3.6 under Linux, and get the correct (imo) full traceback in all cases : ZeroDivisionError Traceback (most recent call last) in () 25 26 loop = asyncio.get_event_loop() ---> 27 loop.run_until_complete(main()) /opt/softs/python/3.6/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future) 464 raise RuntimeError('Event loop stopped before Future completed.') 465 --> 466 return future.result() 467 468 def stop(self): in main() 22 23 async def main(): ---> 24 await aenum() 25 26 loop = asyncio.get_event_loop() in aenum() 14 15 async def aenum(): ---> 16 1/0 17 g = gen(5) 18 async for a, x in aenumerate(g): ZeroDivisionError: division by zero In [5]: BUT ! There is one time where I got a RuntimeError, and it's with 1/0 placed inside aenumerate() (after the yield) : In [8]: ...: import asyncio ...: from itertools import count ...: ...: async def aenumerate(aiterable): ...: counter = count() ...: async for x in aiterable: ...: yield next(counter), x ...: await asyncio.sleep(0.5) ...: 1/0 ...: ...: async def gen(n): ...: for i in range(100, 100+n): ...: yield i ...: ...: async def aenum(): ...: g = gen(5) ...: async for a, x in aenumerate(g): ...: print(a, x) ...: print('done') ...: ...: async def main(): ...: ...: await aenum() ...: ...: loop = asyncio.get_event_loop() ...: loop.run_until_complete(main()) ...: 0 100 --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) in () 25 26 loop = asyncio.get_event_loop() ---> 27 loop.run_until_complete(main()) /opt/softs/python/3.6/lib/python3.6/asyncio/base_events.py in run_until_complete(self, future) 462 future.remove_done_callback(_run_until_complete_cb) 463 if not future.done(): --> 464 raise RuntimeError('Event loop stopped before Future completed.') 465 466 return future.result() RuntimeError: Event loop stopped before Future completed. In [9]: I tried reproducing it but couldn't. Other trials now always show the full traceback up to the 1/0 expression. Not sure this helps you though.. From grant.b.edwards at gmail.com Fri Mar 3 12:13:04 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Fri, 3 Mar 2017 17:13:04 +0000 (UTC) Subject: Odd wording it docs for shutil.move? Message-ID: At https://docs.python.org/2/library/shutil.html it says: shutil.move(src, dst) Recursively move a file or directory (src) to another location (dst). [...] If the destination is on the current filesystem, then os.rename() is used. Otherwise, src is copied (using shutil.copy2()) to dst and then removed. What does the current filesystem have to do with anything? Surely, what matters is whether and are on the same filesystem? -- Grant Edwards grant.b.edwards Yow! Now we can become at alcoholics! gmail.com From kwpolska at gmail.com Fri Mar 3 12:22:04 2017 From: kwpolska at gmail.com (Chris Warrick) Date: Fri, 3 Mar 2017 18:22:04 +0100 Subject: Odd wording it docs for shutil.move? In-Reply-To: References: Message-ID: On 3 March 2017 at 18:13, Grant Edwards wrote: > At https://docs.python.org/2/library/shutil.html it says: > > shutil.move(src, dst) > > Recursively move a file or directory (src) to another location > (dst). > > [...] > > If the destination is on the current filesystem, then os.rename() > is used. Otherwise, src is copied (using shutil.copy2()) to dst > and then removed. > > What does the current filesystem have to do with anything? > > Surely, what matters is whether and are on the same > filesystem? For the same reason it matters for /bin/mv. If the source and target are on the same filesystem, the files are just renamed, which is usually instantaneous (only file metadata needs to be changed). But if they are on different filesystems, ?move? really means ?copy and delete original?, which takes much longer. >From macOS/BSD manpages, mv(1): As the rename(2) call does not work across file systems, mv uses cp(1) and rm(1) to accomplish the move. See also: https://en.wikipedia.org/wiki/Mv -- Chris Warrick PGP: 5EAAEA16 From rhodri at kynesim.co.uk Fri Mar 3 12:27:29 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Fri, 3 Mar 2017 17:27:29 +0000 Subject: Odd wording it docs for shutil.move? In-Reply-To: References: Message-ID: On 03/03/17 17:22, Chris Warrick wrote: > On 3 March 2017 at 18:13, Grant Edwards wrote: >> At https://docs.python.org/2/library/shutil.html it says: >> >> shutil.move(src, dst) >> >> Recursively move a file or directory (src) to another location >> (dst). >> >> [...] >> >> If the destination is on the current filesystem, then os.rename() >> is used. Otherwise, src is copied (using shutil.copy2()) to dst >> and then removed. >> >> What does the current filesystem have to do with anything? >> >> Surely, what matters is whether and are on the same >> filesystem? > > For the same reason it matters for /bin/mv. If the source and target > are on the same filesystem, the files are just renamed, which is > usually instantaneous (only file metadata needs to be changed). But if > they are on different filesystems, ?move? really means ?copy and > delete original?, which takes much longer. Exactly Grant's point. The shutil.move documentation talks about the *current* filesystem, not the filesystem on which is located. -- Rhodri James *-* Kynesim Ltd From formisc at gmail.com Fri Mar 3 13:58:43 2017 From: formisc at gmail.com (Andrew Zyman) Date: Fri, 3 Mar 2017 10:58:43 -0800 (PST) Subject: list of the lists - append after search In-Reply-To: References: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> <26642604-2a86-4d3a-abeb-0d7491f5ab97@googlegroups.com> <6c2c8b07-55de-432e-816a-54da65243f52@googlegroups.com> Message-ID: On Thursday, March 2, 2017 at 3:53:25 PM UTC-5, Andrew Zyman wrote: > On Thursday, March 2, 2017 at 3:31:36 PM UTC-5, Jussi Piitulainen wrote: > > Andrew Zyman writes: > > > > > On Thursday, March 2, 2017 at 2:57:02 PM UTC-5, Jussi Piitulainen wrote: > > >> Peter Otten <__peter__ at web.de> writes: > > >> > > >> > Andrew Zyman wrote: > > >> > > > >> >> On Thursday, March 2, 2017 at 11:27:34 AM UTC-5, Peter Otten wrote: > > >> >>> Andrew Zyman wrote: > > >> >>> ..... > > >> >>> ..... > > >> >>> > End result: > > >> >>> > ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] > > >> >>> > > >> >>> >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] > > >> >>> >>> for inner in outer: > > >> >>> ... if inner[0] == "blah": > > >> >>> ... inner.append("new value") > > >> >> > > >> >> thank you. this will do. > > >> >> Just curious, is the above loop can be done in a one-liner? > > >> > > > >> > Ah, that newbie obsession ;) > > >> > > > >> >>>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] > > >> >>>> [inner + ["new value"] if inner[0] == "blah" else inner for inner in > > >> > outer] > > >> > [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] > > >> > > > >> > Note that there is a technical difference to be aware of -- matching > > >> > lists are replaced rather than modified. > > >> > > >> I take it you are too sane, or too kind, to suggest the obvious > > >> solution: > > >> > > >> >>> outer = [["a", 1], ["b", 2], ["c", 3], ["blah", 1000]] > > >> >>> [inner.append("new value") for inner in outer if inner[0] == "blah"] > > >> [None] > > >> >>> outer > > >> [['a', 1], ['b', 2], ['c', 3], ['blah', 1000, 'new value']] > > >> > > >> [snip] > > > > > > Arh!!! this is it :) > > > > > > I'm sure i'll regret this line of code in 2 weeks - after i > > > successfully forget what i wanted to achieve :) > > > > Jokes aside, you should strive to express your intention in your code. > > Be kind to your future self. Write the three-line loop if you want > > in-place modification. > > > > I use comprehensions a lot, but not to save lines. I might make Peter's > > expression above a four-liner to make its structure more visible: > > > > res = [ ( inner + ["new value"] > > if inner[0] == "blah" > > else inner ) > > for inner in outer ] > > > > Maybe. > > thank you gentlemen. This is very helpful discussion and i appreciate your explanations - helped a lot. Well, i'll take my earlier statement ( about using lists ) back . 100K search/expend on list is taking way too much time ( over 4 minutes ). i'll follow your advice and move the processing to dict. Thanx again. From eryksun at gmail.com Fri Mar 3 16:05:46 2017 From: eryksun at gmail.com (eryk sun) Date: Fri, 3 Mar 2017 21:05:46 +0000 Subject: Odd wording it docs for shutil.move? In-Reply-To: References: Message-ID: On Fri, Mar 3, 2017 at 5:13 PM, Grant Edwards wrote: > At https://docs.python.org/2/library/shutil.html it says: > > shutil.move(src, dst) > > Recursively move a file or directory (src) to another location > (dst). > > [...] > > If the destination is on the current filesystem, then os.rename() > is used. Otherwise, src is copied (using shutil.copy2()) to dst > and then removed. > > What does the current filesystem have to do with anything? > > Surely, what matters is whether and are on the same > filesystem? The source filesystem was probably the current filesystem in the OP's thinking, in which case it made sense at the time of writing. Open an issue if you want to improve the docs with better phrasing. In Python 2 on Windows, os.rename can move a file across filesystems, but this is no longer the case in 3.3+ on Windows. Also, os.rename never replaces an existing file on Windows. (shutil.move should be using os.replace in Python 3.) It would be more accurate in general if the shutil.move docs stated only that os.rename is used if the operation is allowed. From rambiusparkisanius at gmail.com Fri Mar 3 23:16:59 2017 From: rambiusparkisanius at gmail.com (Ivan "Rambius" Ivanov) Date: Sat, 4 Mar 2017 06:16:59 +0200 Subject: Getting stdout and stderr from subprocess in correct order Message-ID: Dear colleagues, I using subprocess module and I am wondering how I can get the output of the spawned process's stdout and stderr in the right order. Here are my sample programs: $ cat subprc.py import subprocess import sys f = 'hw.py' p = subprocess.run([sys.executable, f], stdout=subprocess.PIPE, stderr=subprocess.PIPE) print(p.stdout) print(p.stderr) $ cat hw.py import sys print("a", file=sys.stdout) print("b", file=sys.stderr) print("c", file=sys.stdout) print("d", file=sys.stderr) When i run hw.py I get $ ./hw.py a b c d When I run it through subprc.py, I do get standard out and standard errors streams, but they are separated and not in the order above: $ ./subprc.py b'a\nc\n' b'b\nd\n' How should I use subprocess in order to get the outputs in the correct order? Thank you for your help in advance. Regards Rambius -- Tangra Mega Rock: http://www.radiotangra.com From ben+python at benfinney.id.au Sat Mar 4 00:17:30 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 04 Mar 2017 16:17:30 +1100 Subject: Getting stdout and stderr from subprocess in correct order References: Message-ID: <85lgslk4d1.fsf@benfinney.id.au> "Ivan \"Rambius\" Ivanov" writes: > When I run it through subprc.py, I do get standard out and standard > errors streams, but they are separated and not in the order above That's right. You have two entirely distinct streams, they don't attempt to co-ordinate and none of the information in the stream inherently relates to any other stream. Note that your experience: > When i run hw.py I get > > $ ./hw.py > a > b > c > d is not something your program has access to. For all that it knows, you could be redirecting each stream to separate files:: $ ./hw.py 1> foo.out 2> bar.out and then the absence of any relation between the content in each stream becomes more obvious. > How should I use subprocess in order to get the outputs in the correct > order? The ?correct? order is something additional that you're wanting to impose. So you'll need to define that yourself. If you want some correspondence between the content in different streams, you will need to decide for yourself what that correspondence will be. One obvious way to do it is to put a timestamp as part of the content written to each stream:: print( "{timestamp}: a".format(timestamp=datetime.datetime.now()), file=sys.stdout) Then, the ordering of content in the output can be inferred later by comparing the timestamps. If that's of interest, you should probably stop using plain ?print? and instead look into the ?logging? module, which has good support for multiple streams, timestamped messages, and many other related things . -- \ ?We live in capitalism. Its power seems inescapable. So did the | `\ divine right of kings.? ?Ursula K. LeGuin, National Book Awards | _o__) acceptance speech, 2014-11-19 | Ben Finney From dieter at handshake.de Sat Mar 4 03:55:30 2017 From: dieter at handshake.de (dieter) Date: Sat, 04 Mar 2017 09:55:30 +0100 Subject: Getting stdout and stderr from subprocess in correct order References: Message-ID: <87lgsla0al.fsf@handshake.de> "Ivan \"Rambius\" Ivanov" writes: > ... > I using subprocess module and I am wondering how I can get the output > of the spawned process's stdout and stderr in the right order. Here > are my sample programs: > > $ cat subprc.py > import subprocess > import sys > > f = 'hw.py' > p = subprocess.run([sys.executable, f], stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > print(p.stdout) > print(p.stderr) > ... > How should I use subprocess in order to get the outputs in the correct > order? Thank you for your help in advance. If the order really is important and it is not important from which stream the data comes, then you can try to map "stdout" and "stderr" to the same file. Note that this still may not give you the hoped for result: "stderr" is typically written unbuffered, "stdout" is typically written either "line buffered" (output to a terminal) or "fully buffered". Thus, you can see "stdout" output only after the buffer content is given over to the operationg system (when the buffer is full, explicitely flushed or the file closed). To do this with "subprocess", you need to create a pipe outside the "subprocess.run" (--> "r_fd, w_fd = os.pipe()") and pass the output part ("w_fd") to the "run". You can then read the input part ("r_fd"). Note, that the "*_fd" are file descriptors (represented as integers), not Python "file" objects. You can use either "os.read" (to read the input directly) or "os.fdopen" (to turn a file descriptor into a Python file object). Alternatively, you can spawn two threads for reading input from "stdout" and "stderr", respectively - as soon as one becomes available and merge them in a data structure of your own. Then, you can tag the data with an indication from which stream the output came. Note, the remarks about buffering in the first paragraphe of my response (you can read only what has been previously given over to the operating system -- things still in an output buffer cannot be accessed). From piet-l at pietvanoostrum.com Sat Mar 4 10:37:27 2017 From: piet-l at pietvanoostrum.com (Piet van Oostrum) Date: Sat, 04 Mar 2017 16:37:27 +0100 Subject: Getting stdout and stderr from subprocess in correct order References: Message-ID: "Ivan \"Rambius\" Ivanov" writes: > Dear colleagues, > > I using subprocess module and I am wondering how I can get the output > of the spawned process's stdout and stderr in the right order. Here > are my sample programs: > > $ cat subprc.py > import subprocess > import sys > > f = 'hw.py' > p = subprocess.run([sys.executable, f], stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > print(p.stdout) > print(p.stderr) > > $ cat hw.py > import sys > > print("a", file=sys.stdout) > print("b", file=sys.stderr) > print("c", file=sys.stdout) > print("d", file=sys.stderr) > > When i run hw.py I get > > $ ./hw.py > a > b > c > d > > When I run it through subprc.py, I do get standard out and standard > errors streams, but they are separated and not in the order above: > > $ ./subprc.py > b'a\nc\n' > b'b\nd\n' > > How should I use subprocess in order to get the outputs in the correct > order? Thank you for your help in advance. > If you want them in the order they are produced then you have to put them through a single channel with stderr=subprocess.STDOUT. p = subprocess.run([sys.executable, f], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='ascii') I added an encoding so that it will be read as a text file rather than binary. And of course you should read only stdout (stderr will give None) Moreover you must make sure that each write is flushed. This can be done in three ways: 1. Add the flush=True argument to the print statements. print("a", file=sys.stdout, flush=True) print("b", file=sys.stderr, flush=True) print("c", file=sys.stdout, flush=True) print("d", file=sys.stderr, flush=True) 2. Change the files to a line buffered version. import os sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 1) 3. Add a flush() call after each print statement, like sys.stdout.flush() Then you get them in order. $ python3 subprc.py a b c d Of course you won't be able to tell from which stream each line comes. The streams are byte streams, not message streams. You would have to put extra information, e.g. a prefix, in your print statements. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From wanderer at dialup4less.com Sat Mar 4 11:22:34 2017 From: wanderer at dialup4less.com (Wanderer) Date: Sat, 4 Mar 2017 08:22:34 -0800 (PST) Subject: FYI: Removing posts with All Cap Authors Message-ID: <52cca5af-5b8e-4be9-b0e9-370f66dcd793@googlegroups.com> I mostly just lurk and view the post titles to see if something interesting is being discussed. This code gets me a web page without the spam. You need to compile it to a pyc file and create a bookmark. Probably not useful for most people who don't use their browsers the way I do, but here it is. # remove authors with mostly caps import urllib2 import webbrowser import os from bs4 import BeautifulSoup USERAGENTBASE = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:40.0) Gecko/20100101 ' BROWSERPATH = 'C:\\"Program Files"\\Waterfox\\waterfox.exe' FILENAME = 'C:\\PyStuff\\pygroup.htm' WEBPAGE = "https://groups.google.com/forum/?_escaped_fragment_=forum/comp.lang.python" def getUserAgentVersion(): """ get the useragent version returns agentVersion -- user agent version in format Firefox/51.0.1 Waterfox/51.0.1 """ bvers = os.popen(BROWSERPATH + " -v").read() bversList = bvers.split() agentVersion = 'Firefox/' + bversList[2] + ' ' + bversList[1] + '/' + bversList[2] return agentVersion def getwebpage(url): """ Open a webpage url -- the url to the webpage returns page -- the source for the webpage """ user_agent = USERAGENTBASE + getUserAgentVersion() headers = { 'User-Agent' : user_agent } req = urllib2.Request(url, None, headers) response = urllib2.urlopen(req) page = response.read() return page def removeAllCaps(html_doc): """ Remove posts from google group by authors that is mostly caps html_doc -- an html document """ soup = BeautifulSoup(html_doc) #print soup.prettify() post = soup.find("tr") while post is not None: author = post.find("td", "author") print author aname = author.get_text() numCaps = 1.0 * sum(1 for c in aname if c.isupper()) ratio = numCaps/(1.0*len(aname)) print ratio oldpost = post post = post.find_next_sibling('tr') if ratio > 0.7: oldpost.decompose() print "BIG" f = open(FILENAME, 'w') f.write(soup.prettify().encode('ascii', 'ignore')) f.close() def main(): html_doc = getwebpage(WEBPAGE) removeAllCaps(html_doc) webbrowser.open(FILENAME) print 'done' if __name__ == "__main__": main() From rosuav at gmail.com Sat Mar 4 11:30:50 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Mar 2017 03:30:50 +1100 Subject: FYI: Removing posts with All Cap Authors In-Reply-To: <52cca5af-5b8e-4be9-b0e9-370f66dcd793@googlegroups.com> References: <52cca5af-5b8e-4be9-b0e9-370f66dcd793@googlegroups.com> Message-ID: On Sun, Mar 5, 2017 at 3:22 AM, Wanderer wrote: > I mostly just lurk and view the post titles to see if something interesting is being discussed. This code gets me a web page without the spam. You need to compile it to a pyc file and create a bookmark. Probably not useful for most people who don't use their browsers the way I do, but here it is. > > # remove authors with mostly caps > > USERAGENTBASE = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:40.0) Gecko/20100101 ' > BROWSERPATH = 'C:\\"Program Files"\\Waterfox\\waterfox.exe' > FILENAME = 'C:\\PyStuff\\pygroup.htm' > WEBPAGE = "https://groups.google.com/forum/?_escaped_fragment_=forum/comp.lang.python" > Interesting. Any particular reason to screen-scrape Google Groups rather than start with the netnews protocol? You can get a machine-readable version of the newsgroup much more simply that way, I would have thought. ChrisA From wanderer at dialup4less.com Sat Mar 4 11:37:24 2017 From: wanderer at dialup4less.com (Wanderer) Date: Sat, 4 Mar 2017 08:37:24 -0800 (PST) Subject: FYI: Removing posts with All Cap Authors In-Reply-To: References: <52cca5af-5b8e-4be9-b0e9-370f66dcd793@googlegroups.com> Message-ID: On Saturday, March 4, 2017 at 11:31:13 AM UTC-5, Chris Angelico wrote: > On Sun, Mar 5, 2017 at 3:22 AM, Wanderer wrote: > > I mostly just lurk and view the post titles to see if something interesting is being discussed. This code gets me a web page without the spam. You need to compile it to a pyc file and create a bookmark. Probably not useful for most people who don't use their browsers the way I do, but here it is. > > > > # remove authors with mostly caps > > > > USERAGENTBASE = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:40.0) Gecko/20100101 ' > > BROWSERPATH = 'C:\\"Program Files"\\Waterfox\\waterfox.exe' > > FILENAME = 'C:\\PyStuff\\pygroup.htm' > > WEBPAGE = "https://groups.google.com/forum/?_escaped_fragment_=forum/comp.lang.python" > > > > Interesting. Any particular reason to screen-scrape Google Groups > rather than start with the netnews protocol? You can get a > machine-readable version of the newsgroup much more simply that way, I > would have thought. > > ChrisA I don't know what a netnews protocol is. I use Google Groups to look at usenet. From rurpy at yahoo.com Sat Mar 4 11:48:03 2017 From: rurpy at yahoo.com (rurpy at yahoo.com) Date: Sat, 4 Mar 2017 08:48:03 -0800 (PST) Subject: FYI: Removing posts with All Cap Authors In-Reply-To: References: <52cca5af-5b8e-4be9-b0e9-370f66dcd793@googlegroups.com> Message-ID: <2e94d6d5-9468-4142-a502-d3cc36d6fdc5@googlegroups.com> On Saturday, March 4, 2017 at 9:37:35 AM UTC-7, Wanderer wrote: > On Saturday, March 4, 2017 at 11:31:13 AM UTC-5, Chris Angelico wrote: > > On Sun, Mar 5, 2017 at 3:22 AM, Wanderer wrote: > > > I mostly just lurk and view the post titles to see if something interesting is being discussed. This code gets me a web page without the spam. You need to compile it to a pyc file and create a bookmark. Probably not useful for most people who don't use their browsers the way I do, but here it is. > > > > > > # remove authors with mostly caps > > > > > > USERAGENTBASE = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:40.0) Gecko/20100101 ' > > > BROWSERPATH = 'C:\\"Program Files"\\Waterfox\\waterfox.exe' > > > FILENAME = 'C:\\PyStuff\\pygroup.htm' > > > WEBPAGE = "https://groups.google.com/forum/?_escaped_fragment_=forum/comp.lang.python" > > > > > > > Interesting. Any particular reason to screen-scrape Google Groups > > rather than start with the netnews protocol? You can get a > > machine-readable version of the newsgroup much more simply that way, I > > would have thought. > > > > ChrisA > > I don't know what a netnews protocol is. I use Google Groups to look at usenet. As a lot of us do. From rambiusparkisanius at gmail.com Sat Mar 4 14:41:08 2017 From: rambiusparkisanius at gmail.com (Ivan "Rambius" Ivanov) Date: Sat, 4 Mar 2017 21:41:08 +0200 Subject: Getting stdout and stderr from subprocess in correct order In-Reply-To: References: Message-ID: Hello, Thank you all for your suggestions. I will see what will apply to my use case. Regards Rambius On Sat, Mar 4, 2017 at 5:37 PM, Piet van Oostrum wrote: > "Ivan \"Rambius\" Ivanov" writes: > >> Dear colleagues, >> >> I using subprocess module and I am wondering how I can get the output >> of the spawned process's stdout and stderr in the right order. Here >> are my sample programs: >> >> $ cat subprc.py >> import subprocess >> import sys >> >> f = 'hw.py' >> p = subprocess.run([sys.executable, f], stdout=subprocess.PIPE, >> stderr=subprocess.PIPE) >> print(p.stdout) >> print(p.stderr) >> >> $ cat hw.py >> import sys >> >> print("a", file=sys.stdout) >> print("b", file=sys.stderr) >> print("c", file=sys.stdout) >> print("d", file=sys.stderr) >> >> When i run hw.py I get >> >> $ ./hw.py >> a >> b >> c >> d >> >> When I run it through subprc.py, I do get standard out and standard >> errors streams, but they are separated and not in the order above: >> >> $ ./subprc.py >> b'a\nc\n' >> b'b\nd\n' >> >> How should I use subprocess in order to get the outputs in the correct >> order? Thank you for your help in advance. >> > If you want them in the order they are produced then you have to put > them through a single channel with stderr=subprocess.STDOUT. > > p = subprocess.run([sys.executable, f], stdout=subprocess.PIPE, > stderr=subprocess.STDOUT, encoding='ascii') > > I added an encoding so that it will be read as a text file rather than > binary. And of course you should read only stdout (stderr will give > None) > > Moreover you must make sure that each write is flushed. This can be done > in three ways: > > 1. Add the flush=True argument to the print statements. > print("a", file=sys.stdout, flush=True) > print("b", file=sys.stderr, flush=True) > print("c", file=sys.stdout, flush=True) > print("d", file=sys.stderr, flush=True) > > 2. Change the files to a line buffered version. > import os > sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1) > sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 1) > > 3. Add a flush() call after each print statement, like > sys.stdout.flush() > > Then you get them in order. > $ python3 subprc.py > a > b > c > d > > Of course you won't be able to tell from which stream each line comes. > The streams are byte streams, not message streams. You would have to put > extra information, e.g. a prefix, in your print statements. > -- > Piet van Oostrum > WWW: http://pietvanoostrum.com/ > PGP key: [8DAE142BE17999C4] > -- > https://mail.python.org/mailman/listinfo/python-list -- Tangra Mega Rock: http://www.radiotangra.com From pkpearson at nowhere.invalid Sat Mar 4 16:05:46 2017 From: pkpearson at nowhere.invalid (Peter Pearson) Date: 4 Mar 2017 21:05:46 GMT Subject: FYI: Removing posts with All Cap Authors References: <52cca5af-5b8e-4be9-b0e9-370f66dcd793@googlegroups.com> Message-ID: On Sat, 4 Mar 2017 08:37:24 -0800 (PST), Wanderer wrote: > > I don't know what a netnews protocol is. I use Google Groups to look > at usenet. Just in case you're interested, the Network News Transfer Protocol, NNTP, is used to distribute posts over Usenet, a worldwide system for passing messages among computers that appeared in 1980. Since many of us are still using it to follow newsgroups, Lo, 37 years later, it must surely have succeeded beyond its creators' wildest hopes. I suspect I'm not the only fossil here who gets kinda misty contemplating NNTP's history. -- To email me, substitute nowhere->runbox, invalid->com. From bilmar19 at gmail.com Sat Mar 4 18:08:15 2017 From: bilmar19 at gmail.com (bilmar19 at gmail.com) Date: Sat, 4 Mar 2017 15:08:15 -0800 (PST) Subject: Basic Packaging strategy question Message-ID: I have a simple project that I want to package to put it on another machine but everything I have read so far about packaging ends up putting the whole install alongside with 'packages' - typically in .../site-packages. This seems a strange place to launch an app from! So, if I have an app with a main.py entry point is it ok for everything to be in .../site-packages/myproject? Or, should I put everything except main.py in a package and then copy main.py wherever I want and use PIP to install the package containing the rest of the app? simple example which ends up with needing to run: python /usr/local/lib/site_packages/myproject/main.py: myproject setup.py myproject __init__.py main.py utils.py config.py Is this the right way to go? Thanks Bill From rantingrickjohnson at gmail.com Sat Mar 4 21:11:02 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Sat, 4 Mar 2017 18:11:02 -0800 (PST) Subject: FYI: Removing posts with All Cap Authors In-Reply-To: References: <52cca5af-5b8e-4be9-b0e9-370f66dcd793@googlegroups.com> Message-ID: On Saturday, March 4, 2017 at 3:05:57 PM UTC-6, Peter Pearson wrote: > I suspect I'm not the only fossil here who gets kinda > misty contemplating NNTP's history. Yeah. Well... Python-list has developed quite a reputation within usenet antiquities circles for its highly coveted collection of rare artifacts and strange oddities. A perpetual freak show of sorts, suspended precariously in the "goldilocks zone" somewhere between the heavenly wonders of Guido's Time Machine and the absolute madness of ZeroDivisionError. From rosuav at gmail.com Sat Mar 4 21:17:19 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Mar 2017 13:17:19 +1100 Subject: FYI: Removing posts with All Cap Authors In-Reply-To: References: <52cca5af-5b8e-4be9-b0e9-370f66dcd793@googlegroups.com> Message-ID: On Sun, Mar 5, 2017 at 1:11 PM, Rick Johnson wrote: > On Saturday, March 4, 2017 at 3:05:57 PM UTC-6, Peter Pearson wrote: >> I suspect I'm not the only fossil here who gets kinda >> misty contemplating NNTP's history. > > Yeah. Well... Python-list has developed quite a reputation > within usenet antiquities circles for its highly coveted > collection of rare artifacts and strange oddities. A > perpetual freak show of sorts, suspended precariously in the > "goldilocks zone" somewhere between the heavenly wonders of > Guido's Time Machine and the absolute madness of > ZeroDivisionError. And "Ranting Rick Johnson" definitely counts as one of the freaks. ChrisA From pavel.aronsky at gmail.com Sat Mar 4 21:35:38 2017 From: pavel.aronsky at gmail.com (ddbug) Date: Sat, 4 Mar 2017 18:35:38 -0800 (PST) Subject: How to access installed scripts on Windows? In-Reply-To: References: Message-ID: <9dd2791f-5358-479f-b0e9-9e6c91e2e788@googlegroups.com> Thank you eryk sun for the reply. I am not so concerned by installing modules as by installing scripts ('entry points'). Per user. If the Windows GUI installer can add the per-user script dirs to PATH it may be acceptable solution. > The installer has an option to update PATH to include > this Scripts directory. > Is this the checkbox on the Advanced Options page, "Add Python to environment variables"? In my copy of 64-bit v3.6 installer this is UNchecked by default, and the text looks a bit vague. Might read more precise. > You can also develop using venv virtual environments. You can symlink > or shell-shortcut to the activation script of a virtual environment. > Interesting idea. But I have not seen any installers or guidance how to deploy something packaged as a venv to users. Can you share any pointers please? > I dislike the idea of automatically searching script directories, but > there could be a command-line option for this. I agree, but the current situation is dire IMHO. One of fundamental Python batteries is leaking :-( Right now I'm looking at IDLE and trying to figure out whether it can be used to solve this problem (like, run IDLE with a special start script or extension that will make these user-local scripts easy discoverable .... Maybe a extension that adds a new GUI menu etc. ) Regards, ddbug From pavel.aronsky at gmail.com Sat Mar 4 21:50:00 2017 From: pavel.aronsky at gmail.com (ddbug) Date: Sat, 4 Mar 2017 18:50:00 -0800 (PST) Subject: Basic Packaging strategy question In-Reply-To: References: Message-ID: On Sunday, March 5, 2017 at 1:08:25 AM UTC+2, bilm... at gmail.com wrote: > I have a simple project that I want to package to put it on another machine but everything I have read so far about packaging ends up putting the whole install alongside with 'packages' - typically in .../site-packages. > This seems a strange place to launch an app from! If your target OS is Windows - this is the question I have for long time without any good answer (see this thread: https://groups.google.com/forum/#!topic/comp.lang.python/Gwx6HA83bUE ) There is a zillion ways to specify modules search path, but no good options on Windows to place entry points. One cannot consider dropping entry points in obscure places where user cannot find them, as good. Since on Linux this is not an issue (or much lesser issue) it can be viewed as one of deficiencies of Windows - but otherwise Python has 1st class support for Windows, including the cute py launcher. > So, if I have an app with a main.py entry point is it ok for everything to be in .../site-packages/myproject? Nope, site-packages is the place for modules. You're asking about entry points. > Or, should I put everything except main.py in a package and then copy main.py wherever I want and use PIP to install the package containing the rest of the app? > > simple example which ends up with needing to run: > python /usr/local/lib/site_packages/myproject/main.py: Placing scripts under modules location is an option, and setuptools can automatically create 'entry points' that bootstrap the actual scripts. But this does not solve the root issue - where to place these entry points? I have not found a good solution yet. Regards, ddbug From arequipeno at gmail.com Sun Mar 5 00:09:15 2017 From: arequipeno at gmail.com (Ian Pilcher) Date: Sat, 4 Mar 2017 23:09:15 -0600 Subject: python-daemon and PID files Message-ID: Is it possible to get python-daemon to create "systemd style" PID file? I.e., systemd wants a daemon to write a file with a specific name that *contains* the PID of the child process. python-daemon, OTOH, seems to use its pidfile parameter as more of a lock file. Currently, I'm creating my PID file manually in the child process, but systemd complains, because it wants the PID file to exist before the parent exits. -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From rosuav at gmail.com Sun Mar 5 00:14:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Mar 2017 16:14:58 +1100 Subject: python-daemon and PID files In-Reply-To: References: Message-ID: On Sun, Mar 5, 2017 at 4:09 PM, Ian Pilcher wrote: > Is it possible to get python-daemon to create "systemd style" PID file? > > I.e., systemd wants a daemon to write a file with a specific name that > *contains* the PID of the child process. python-daemon, OTOH, seems to > use its pidfile parameter as more of a lock file. > > Currently, I'm creating my PID file manually in the child process, but > systemd complains, because it wants the PID file to exist before the > parent exits. Why do you need a pidfile? When I get systemd to start a process, I just have it not fork. Much easier. Forget about python-daemon - just run your script in the simple and straight-forward way. (Possibly that'll mean having it do different things depending on whether it's started from systemd or some other way, but that can be controlled with a parameter.) ChrisA From ethan at stoneleaf.us Sun Mar 5 00:39:52 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 04 Mar 2017 21:39:52 -0800 Subject: python-daemon and PID files In-Reply-To: References: Message-ID: <58BBA4A8.2040602@stoneleaf.us> On 03/04/2017 09:09 PM, Ian Pilcher wrote: > Is it possible to get python-daemon to create "systemd style" PID file? > > I.e., systemd wants a daemon to write a file with a specific name that > *contains* the PID of the child process. python-daemon, OTOH, seems to > use its pidfile parameter as more of a lock file. > > Currently, I'm creating my PID file manually in the child process, but > systemd complains, because it wants the PID file to exist before the > parent exits. I know my library, pandaemonium [1], will allow you to write the pid file complete with the daemon's PID, and I would be very surprised if Ben's python-daemon did not also allow that. Maybe it's just a timing issue -- have you tried having the parent process wait a few seconds to verify the file has been created and has the PID before exiting? -- ~Ethan~ [1] https://pypi.python.org/pypi/pandaemonium From nad at python.org Sun Mar 5 07:01:30 2017 From: nad at python.org (Ned Deily) Date: Sun, 5 Mar 2017 07:01:30 -0500 Subject: [RELEASE] Python 3.6.1rc1 is now available Message-ID: <50484B0A-BA03-42D0-B5EC-4D8E1CF1BC26@python.org> On behalf of the Python development community and the Python 3.6 release team, I would like to announce the availability of Python 3.6.1rc1. 3.6.1rc1 is the first release candidate for Python 3.6.1, the first maintenance release of Python 3.6. 3.6.0 was released on 2017-12-22 to great interest and now, three months later, we are providing the first set of bugfixes and documentation updates for it. While 3.6.1rc1 is a preview release and, thus, not intended for production environments, we encourage you to explore it and provide feedback via the Python bug tracker (https://bugs.python.org). Although it should be transparent to users of Python, 3.6.1 is the first release after some major changes to our development process so we ask users who build Python from source to be on the lookout for any unexpected differences. 3.6.1 is planned for final release on 2017-03-20 with the next maintenance release expected to follow in about 3 months. Please see "What?s New In Python 3.6" for more information: https://docs.python.org/3.6/whatsnew/3.6.html You can find Python 3.6.1rc1 here: https://www.python.org/downloads/release/python-361rc1/ More information about the 3.6 release schedule can be found here: https://www.python.org/dev/peps/pep-0494/ -- Ned Deily nad at python.org -- [] From arequipeno at gmail.com Sun Mar 5 07:12:01 2017 From: arequipeno at gmail.com (Ian Pilcher) Date: Sun, 5 Mar 2017 06:12:01 -0600 Subject: python-daemon and PID files In-Reply-To: References: Message-ID: On 03/04/2017 11:14 PM, Chris Angelico wrote: > Why do you need a pidfile? When I get systemd to start a process, I > just have it not fork. Much easier. Forget about python-daemon - just > run your script in the simple and straight-forward way. Because forking daemons was good enough for my grandpappy, and it ought to be good enough you young whippersnappers today. In other words ... facepalm. Thanks! -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From steve.dower at python.org Sun Mar 5 09:12:19 2017 From: steve.dower at python.org (Steve Dower) Date: Sun, 5 Mar 2017 06:12:19 -0800 Subject: [Python-Dev] [RELEASE] Python 3.6.1rc1 is now available In-Reply-To: <50484B0A-BA03-42D0-B5EC-4D8E1CF1BC26@python.org> References: <50484B0A-BA03-42D0-B5EC-4D8E1CF1BC26@python.org> Message-ID: I just want to emphasize that this is a *very* important release to test, as it is the first one made after migrating the project to github. Please spend a bit of time running it through your normal build/installation steps and let us know at https://bugs.python.org/ if anything seems off. Top-posted from my Windows Phone -----Original Message----- From: "Ned Deily" Sent: ?3/?5/?2017 4:08 To: "python-announce at python.org" ; "python-list at python.org" ; "Python-Dev" ; "python-committers" Subject: [Python-Dev] [RELEASE] Python 3.6.1rc1 is now available On behalf of the Python development community and the Python 3.6 release team, I would like to announce the availability of Python 3.6.1rc1. 3.6.1rc1 is the first release candidate for Python 3.6.1, the first maintenance release of Python 3.6. 3.6.0 was released on 2017-12-22 to great interest and now, three months later, we are providing the first set of bugfixes and documentation updates for it. While 3.6.1rc1 is a preview release and, thus, not intended for production environments, we encourage you to explore it and provide feedback via the Python bug tracker (https://bugs.python.org). Although it should be transparent to users of Python, 3.6.1 is the first release after some major changes to our development process so we ask users who build Python from source to be on the lookout for any unexpected differences. 3.6.1 is planned for final release on 2017-03-20 with the next maintenance release expected to follow in about 3 months. Please see "What?s New In Python 3.6" for more information: https://docs.python.org/3.6/whatsnew/3.6.html You can find Python 3.6.1rc1 here: https://www.python.org/downloads/release/python-361rc1/ More information about the 3.6 release schedule can be found here: https://www.python.org/dev/peps/pep-0494/ -- Ned Deily nad at python.org -- [] _______________________________________________ Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/steve.dower%40python.org From darcy at vex.net Sun Mar 5 10:41:07 2017 From: darcy at vex.net (D'Arcy Cain) Date: Sun, 5 Mar 2017 10:41:07 -0500 Subject: [RELEASE] Python 3.6.1rc1 is now available In-Reply-To: <50484B0A-BA03-42D0-B5EC-4D8E1CF1BC26@python.org> References: <50484B0A-BA03-42D0-B5EC-4D8E1CF1BC26@python.org> Message-ID: <9cdc9d93-9015-826f-fa32-cd4c2811f67a@vex.net> On 2017-03-05 07:01 AM, Ned Deily wrote: > On behalf of the Python development community and the Python 3.6 release > team, I would like to announce the availability of Python 3.6.1rc1. > 3.6.1rc1 is the first release candidate for Python 3.6.1, the first > maintenance release of Python 3.6. 3.6.0 was released on 2017-12-22 from __future__ import 3.6.0 Did Guido finally get that time machine working? -- D'Arcy J.M. Cain System Administrator, Vex.Net http://www.Vex.Net/ IM:darcy at Vex.Net VoIP: sip:darcy at Vex.Net From gvmcmt at gmail.com Sun Mar 5 11:09:01 2017 From: gvmcmt at gmail.com (gvmcmt at gmail.com) Date: Sun, 5 Mar 2017 08:09:01 -0800 (PST) Subject: list of the lists - append after search In-Reply-To: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> References: <9b6e552f-5584-4572-9ef6-c5f614ac497a@googlegroups.com> Message-ID: <5a16be92-849d-4ebf-ad17-60790147c4d4@googlegroups.com> On Thursday, March 2, 2017 at 9:33:14 PM UTC+5:30, Andrew Zyman wrote: > Hello, > please advise. > > I'd like search and append the internal list in the list-of-the-lists. > > Example: > ll =[ [a,1], [b,2], [c,3], [blah, 1000] ] > > i want to search for the internal [] based on the string field and, if matches, append that list with a value. > > if internal_list[0] == 'blah': > ll[ internal_list].append = [ 'new value'] > > End result: > ll =[ [a,1], [b,2], [c,3], [blah, 1000, 'new value'] ] > > > I came up with the following, but the second stmnt is not correct: > > print [x for x in ll if x[0]== 'blah'] > print ll.index([x for x in ll if x[0]=='blah']) > > output: > ValueError: [['blah', 1]] is not in list > > > > > thank you > AZ list_of_lists = [['a', 1], ['b', 2], ['c', 3], ['blah', 1000]] for sublist in list_of_lists: if sublist[0] == 'blah': sublist.append('new value') Hope that helps. From darcy at vex.net Sun Mar 5 11:53:39 2017 From: darcy at vex.net (D'Arcy Cain) Date: Sun, 5 Mar 2017 11:53:39 -0500 Subject: [RELEASE] Python 3.6.1rc1 is now available In-Reply-To: <50484B0A-BA03-42D0-B5EC-4D8E1CF1BC26@python.org> References: <50484B0A-BA03-42D0-B5EC-4D8E1CF1BC26@python.org> Message-ID: <5fe75c2f-d49a-16f2-c63f-82e26cfe5138@vex.net> On 2017-03-05 07:01 AM, Ned Deily wrote: > On behalf of the Python development community and the Python 3.6 release > team, I would like to announce the availability of Python 3.6.1rc1. > 3.6.1rc1 is the first release candidate for Python 3.6.1, the first > maintenance release of Python 3.6. 3.6.0 was released on 2017-12-22 from __future__ import 3.6.0 Did Guido finally get that time machine working? -- D'Arcy J.M. Cain System Administrator, Vex.Net http://www.Vex.Net/ IM:darcy at Vex.Net VoIP: sip:darcy at Vex.Net From darcy at VybeNetworks.com Sun Mar 5 11:57:17 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Sun, 5 Mar 2017 11:57:17 -0500 Subject: [RELEASE] Python 3.6.1rc1 is now available In-Reply-To: <50484B0A-BA03-42D0-B5EC-4D8E1CF1BC26@python.org> References: <50484B0A-BA03-42D0-B5EC-4D8E1CF1BC26@python.org> Message-ID: <4c8e52e9-2450-cf49-cec3-f6783418cc57@VybeNetworks.com> On 2017-03-05 07:01 AM, Ned Deily wrote: > On behalf of the Python development community and the Python 3.6 release > team, I would like to announce the availability of Python 3.6.1rc1. > 3.6.1rc1 is the first release candidate for Python 3.6.1, the first > maintenance release of Python 3.6. 3.6.0 was released on 2017-12-22 from __future__ import 3.6.0 Did Guido finally get that time machine working? -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From steve+python at pearwood.info Sun Mar 5 12:54:36 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 06 Mar 2017 04:54:36 +1100 Subject: str.title() fails with words containing apostrophes Message-ID: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> I'm trying to convert strings to Title Case, but getting ugly results if the words contain an apostrophe: py> 'hello world'.title() # okay 'Hello World' py> "i can't be having with this".title() # not okay "I Can'T Be Having With This" Anyone have any suggestions for working around this? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From python at mrabarnett.plus.com Sun Mar 5 14:38:54 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 5 Mar 2017 19:38:54 +0000 Subject: str.title() fails with words containing apostrophes In-Reply-To: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-03-05 17:54, Steve D'Aprano wrote: > I'm trying to convert strings to Title Case, but getting ugly results if the > words contain an apostrophe: > > > py> 'hello world'.title() # okay > 'Hello World' > py> "i can't be having with this".title() # not okay > "I Can'T Be Having With This" > > > Anyone have any suggestions for working around this? > A bit of regex? import re def title(string): return re.sub(r"\b'\w", lambda m: m.group().lower(), string.title()) From tjreedy at udel.edu Sun Mar 5 15:40:58 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 5 Mar 2017 15:40:58 -0500 Subject: str.title() fails with words containing apostrophes In-Reply-To: References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/5/2017 2:38 PM, MRAB wrote: > On 2017-03-05 17:54, Steve D'Aprano wrote: >> I'm trying to convert strings to Title Case, but getting ugly results >> if the >> words contain an apostrophe: >> >> >> py> 'hello world'.title() # okay >> 'Hello World' >> py> "i can't be having with this".title() # not okay >> "I Can'T Be Having With This" >> >> >> Anyone have any suggestions for working around this? >> > A bit of regex? > > import re > > def title(string): > return re.sub(r"\b'\w", lambda m: m.group().lower(), string.title()) Nice. It lowercases a word char that follows an "'" that follows a word without an intervening non-word char. It passes this test: print(title("'time' isn't 'timeless'!")) 'Time' Isn't 'Timeless'! It guess the reason not to bake this exception into str.title is that it is language specific and could even be wrong if someone used "'" to separate words (perhaps in a different alphabet). -- Terry Jan Reedy From eryksun at gmail.com Sun Mar 5 17:25:23 2017 From: eryksun at gmail.com (eryk sun) Date: Sun, 5 Mar 2017 22:25:23 +0000 Subject: How to access installed scripts on Windows? In-Reply-To: <9dd2791f-5358-479f-b0e9-9e6c91e2e788@googlegroups.com> References: <9dd2791f-5358-479f-b0e9-9e6c91e2e788@googlegroups.com> Message-ID: On Sun, Mar 5, 2017 at 2:35 AM, ddbug wrote: > >> You can also develop using venv virtual environments. You can symlink >> or shell-shortcut to the activation script of a virtual environment. > > Interesting idea. But I have not seen any installers or guidance how to deploy something packaged > as a venv to users. Can you share any pointers please? Are we talking about scripts for programmers to work with libraries that you publish (e.g. a command-line tool like cythonize), or applications for end users and IT staff? Virtual environments are primarily a solution for developers. For deployment to end users, take a look at what Paul Moore is doing with pylaunch and the embedded Python distribution: https://github.com/pfmoore/pylaunch https://docs.python.org/3/using/windows.html#embedded-distribution From jsf80238 at gmail.com Sun Mar 5 20:58:42 2017 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 5 Mar 2017 18:58:42 -0700 Subject: Online Python Editor with Live Syntax Checking In-Reply-To: <460d95fb-827c-4e1a-91bf-d4cc633a213b@googlegroups.com> References: <460d95fb-827c-4e1a-91bf-d4cc633a213b@googlegroups.com> Message-ID: > > I made a tool called PythonBuddy (http://pythonbuddy.com/). > > I made this so that MOOCs like edX or codecademy could easily embed and > use this on their courses so students wouldn't have to go through the > frustrations of setting up a Python environment and jump right into Python > programming. Also, professors and teachers could easily set up a server and > allow students to quickly test out their code with PythonBuddy online. > > Github repo: https://github.com/ethanche?/OnlinePythonLinterSyntaxChecker > Pretty cool. Your Github link did not work for me. This looks like Python 2. Is there a reason you did not go with 3? From nagle at animats.com Sun Mar 5 21:39:43 2017 From: nagle at animats.com (John Nagle) Date: Sun, 5 Mar 2017 18:39:43 -0800 Subject: Who still supports recent Python on shared hosting Message-ID: I'm looking for shared hosting that supports at least Python 3.4. Hostgator: Highest version is Python 3.2. Dreamhost: Highest version is Python 2.7. Bluehost: Install Python yourself. InMotion: Their documentation says 2.6. Is Python on shared hosting dead? I don't need a whole VM and something I have to sysadmin, just a small shared hosting account. John Nagle From rosuav at gmail.com Sun Mar 5 21:54:10 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Mar 2017 13:54:10 +1100 Subject: Who still supports recent Python on shared hosting In-Reply-To: References: Message-ID: On Mon, Mar 6, 2017 at 1:39 PM, John Nagle wrote: > I'm looking for shared hosting that supports > at least Python 3.4. > > Hostgator: Highest version is Python 3.2. > Dreamhost: Highest version is Python 2.7. > Bluehost: Install Python yourself. > InMotion: Their documentation says 2.6. > > Is Python on shared hosting dead? > I don't need a whole VM and something I > have to sysadmin, just a small shared > hosting account. Heroku supports a number of Python versions: https://devcenter.heroku.com/articles/python-support#supported-python-runtimes I'm not sure how to list *every* supported Python version (the docs only list the latest 2.7 and the latest 3.x at any given time), but I poked around in https://lang-python.s3.amazonaws.com/ and found a large number of versions that appear to be installable. You specify a version with a file in your repository called "runtime.txt", and they'll give you that version if they can, or kick back an error. ChrisA From darcy at VybeNetworks.com Mon Mar 6 01:31:30 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Mon, 6 Mar 2017 01:31:30 -0500 Subject: str.title() fails with words containing apostrophes In-Reply-To: References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0150fb7d-1dce-c107-9e11-c220d5fb3e95@VybeNetworks.com> On 2017-03-05 03:40 PM, Terry Reedy wrote: >> import re >> >> def title(string): >> return re.sub(r"\b'\w", lambda m: m.group().lower(), string.title()) > > Nice. It lowercases a word char that follows an "'" that follows a word > without an intervening non-word char. It passes this test: > print(title("'time' isn't 'timeless'!")) > 'Time' Isn't 'Timeless'! > > It guess the reason not to bake this exception into str.title is that it > is language specific and could even be wrong if someone used "'" to > separate words (perhaps in a different alphabet). Or, it doesn't handle exceptions. print title("My name is D'Arcy") Oops. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From darcy at VybeNetworks.com Mon Mar 6 01:32:46 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Mon, 6 Mar 2017 01:32:46 -0500 Subject: Who still supports recent Python on shared hosting In-Reply-To: References: Message-ID: <96741a7b-f23c-5dab-fc02-2b7b6cdfaf95@VybeNetworks.com> On 2017-03-05 09:39 PM, John Nagle wrote: > I'm looking for shared hosting that supports > at least Python 3.4. http://www.VybeNetworks.com/ We have Python 2.7 and 3.6 installed. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From petef4+usenet at gmail.com Mon Mar 6 02:14:52 2017 From: petef4+usenet at gmail.com (Pete Forman) Date: Mon, 06 Mar 2017 07:14:52 +0000 Subject: Who still supports recent Python on shared hosting References: Message-ID: John Nagle writes: > I'm looking for shared hosting that supports > at least Python 3.4. > > Hostgator: Highest version is Python 3.2. > Dreamhost: Highest version is Python 2.7. > Bluehost: Install Python yourself. > InMotion: Their documentation says 2.6. > > Is Python on shared hosting dead? > I don't need a whole VM and something I > have to sysadmin, just a small shared > hosting account. I use OpenShift from Red Hat on their free hosting package. They offer Python 3.5, 3.3 and 2.7. -- Pete Forman https://payg-petef.rhcloud.com From no.email at nospam.invalid Mon Mar 6 02:22:09 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 05 Mar 2017 23:22:09 -0800 Subject: Who still supports recent Python on shared hosting References: Message-ID: <87r32adg4e.fsf@nightsong.com> John Nagle writes: > I'm looking for shared hosting that supports at least Python 3.4. Open a ticket on buyshared.net and ask if they can install it for you. They're good about stuff like that. If it's for a cgi, you might alternatively be able to run it from your own directory (you get ssh access which gives some flexibility). From mail at timgolden.me.uk Mon Mar 6 03:24:02 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 6 Mar 2017 08:24:02 +0000 Subject: Who still supports recent Python on shared hosting In-Reply-To: References: Message-ID: On 06/03/2017 02:39, John Nagle wrote: > I'm looking for shared hosting that supports > at least Python 3.4. > > Hostgator: Highest version is Python 3.2. > Dreamhost: Highest version is Python 2.7. > Bluehost: Install Python yourself. > InMotion: Their documentation says 2.6. > > Is Python on shared hosting dead? > I don't need a whole VM and something I > have to sysadmin, just a small shared > hosting account. webfaction.com TJG From gvmcmt at gmail.com Mon Mar 6 03:52:46 2017 From: gvmcmt at gmail.com (gvmcmt at gmail.com) Date: Mon, 6 Mar 2017 00:52:46 -0800 (PST) Subject: str.title() fails with words containing apostrophes In-Reply-To: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> On Sunday, March 5, 2017 at 11:25:04 PM UTC+5:30, Steve D'Aprano wrote: > I'm trying to convert strings to Title Case, but getting ugly results if the > words contain an apostrophe: > > > py> 'hello world'.title() # okay > 'Hello World' > py> "i can't be having with this".title() # not okay > "I Can'T Be Having With This" > > > Anyone have any suggestions for working around this? > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. import string txt = "i can't be having with this" string.capwords(txt) That gives you "I Can't Be Having With This" Hope that helps. From jussi.piitulainen at helsinki.fi Mon Mar 6 04:07:00 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 06 Mar 2017 11:07:00 +0200 Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> Message-ID: gvmcmt at gmail.com writes: > On Sunday, March 5, 2017 at 11:25:04 PM UTC+5:30, Steve D'Aprano wrote: >> I'm trying to convert strings to Title Case, but getting ugly results >> if the words contain an apostrophe: >> >> >> py> 'hello world'.title() # okay >> 'Hello World' >> py> "i can't be having with this".title() # not okay >> "I Can'T Be Having With This" >> >> >> Anyone have any suggestions for working around this? [snip sig] > import string > > txt = "i can't be having with this" > string.capwords(txt) > > That gives you "I Can't Be Having With This" > > Hope that helps. Won't Steve D'aprano And D'arcy Cain Be Happy Now :) From gvmcmt at gmail.com Mon Mar 6 04:17:35 2017 From: gvmcmt at gmail.com (gvmcmt at gmail.com) Date: Mon, 6 Mar 2017 01:17:35 -0800 (PST) Subject: str.title() fails with words containing apostrophes In-Reply-To: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, March 5, 2017 at 11:25:04 PM UTC+5:30, Steve D'Aprano wrote: > I'm trying to convert strings to Title Case, but getting ugly results if the > words contain an apostrophe: > > > py> 'hello world'.title() # okay > 'Hello World' > py> "i can't be having with this".title() # not okay > "I Can'T Be Having With This" > > > Anyone have any suggestions for working around this? > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. import string txt = "i can't be having with this" string.capwords(txt) That gives you "I Can't Be Having With This" Alternatively txt = "i can't be having with this" ' '.join([word.capitalize() for word in txt.split()]) will result in: "I Can't Be Having With This" From gvmcmt at gmail.com Mon Mar 6 04:32:36 2017 From: gvmcmt at gmail.com (gvmcmt at gmail.com) Date: Mon, 6 Mar 2017 01:32:36 -0800 (PST) Subject: str.title() fails with words containing apostrophes In-Reply-To: References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> Message-ID: <1022b51d-b11e-443f-9698-5d659b1dda3e@googlegroups.com> On Monday, March 6, 2017 at 2:37:11 PM UTC+5:30, Jussi Piitulainen wrote: > gvmcmt at gmail.com writes: > > > On Sunday, March 5, 2017 at 11:25:04 PM UTC+5:30, Steve D'Aprano wrote: > >> I'm trying to convert strings to Title Case, but getting ugly results > >> if the words contain an apostrophe: > >> > >> > >> py> 'hello world'.title() # okay > >> 'Hello World' > >> py> "i can't be having with this".title() # not okay > >> "I Can'T Be Having With This" > >> > >> > >> Anyone have any suggestions for working around this? > > [snip sig] > > > import string > > > > txt = "i can't be having with this" > > string.capwords(txt) > > > > That gives you "I Can't Be Having With This" > > > > Hope that helps. > > Won't Steve D'aprano And D'arcy Cain Be Happy Now :) I found it at https://docs.python.org/3/library/string.html#string.capwords :) From jussi.piitulainen at helsinki.fi Mon Mar 6 04:52:17 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Mon, 06 Mar 2017 11:52:17 +0200 Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <1022b51d-b11e-443f-9698-5d659b1dda3e@googlegroups.com> Message-ID: gvmcmt at gmail.com writes: > On Monday, March 6, 2017 at 2:37:11 PM UTC+5:30, Jussi Piitulainen wrote: >> gvmcmt at gmail.com writes: >> >> > On Sunday, March 5, 2017 at 11:25:04 PM UTC+5:30, Steve D'Aprano wrote: >> >> I'm trying to convert strings to Title Case, but getting ugly results >> >> if the words contain an apostrophe: >> >> >> >> >> >> py> 'hello world'.title() # okay >> >> 'Hello World' >> >> py> "i can't be having with this".title() # not okay >> >> "I Can'T Be Having With This" >> >> >> >> >> >> Anyone have any suggestions for working around this? >> >> [snip sig] >> >> > import string >> > >> > txt = "i can't be having with this" >> > string.capwords(txt) >> > >> > That gives you "I Can't Be Having With This" >> > >> > Hope that helps. >> >> Won't Steve D'aprano And D'arcy Cain Be Happy Now :) > > > I found it at https://docs.python.org/3/library/string.html#string.capwords :) Sure, it's there, and that's a good point. It still mangles their names. It also mangles any whitespace in the string. That is probably mostly harmless. It also will capitalize all the little words in the string that are usually not capitalized in titles, even in the usual headlinese English variants. And all the acronyms and such that are usually written in all caps, or in even odder patterns. I guess it's a somewhat practical approximation to an AI-hard problem. (Mumble mumble str.swapcase, er, never mind me :) From __peter__ at web.de Mon Mar 6 05:04:48 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 06 Mar 2017 11:04:48 +0100 Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> Message-ID: Jussi Piitulainen wrote: > gvmcmt at gmail.com writes: > >> On Sunday, March 5, 2017 at 11:25:04 PM UTC+5:30, Steve D'Aprano wrote: >>> I'm trying to convert strings to Title Case, but getting ugly results >>> if the words contain an apostrophe: >>> >>> >>> py> 'hello world'.title() # okay >>> 'Hello World' >>> py> "i can't be having with this".title() # not okay >>> "I Can'T Be Having With This" >>> >>> >>> Anyone have any suggestions for working around this? > > [snip sig] > >> import string >> >> txt = "i can't be having with this" >> string.capwords(txt) >> >> That gives you "I Can't Be Having With This" >> >> Hope that helps. > > Won't Steve D'aprano And D'arcy Cain Be Happy Now :) Perhaps one could limit the conversion to go from lower to upper only, as names tend be in the desired case in the original text. >>> def first_up(s): ... return s[:1].upper() + s[1:] ... >>> def title(s): ... return re.compile(r"(?:\b'?)\w+").sub(lambda m: first_up(m.group()), s) ... >>> title("won't steve D'Aprano and d'arcy cain be 'happy' now?") "Won't Steve D'Aprano And D'arcy Cain Be 'Happy' Now?" Unfortunately this won't help with >>> title("admiral von schneider") 'Admiral Von Schneider' # von should be lower case From p.f.moore at gmail.com Mon Mar 6 05:29:45 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Mon, 6 Mar 2017 02:29:45 -0800 (PST) Subject: How to access installed scripts on Windows? In-Reply-To: References: <9dd2791f-5358-479f-b0e9-9e6c91e2e788@googlegroups.com> Message-ID: <8ae7e347-68d8-4de8-ba66-1ba140b3e5c1@googlegroups.com> On Sunday, 5 March 2017 22:26:17 UTC, eryk sun wrote: > On Sun, Mar 5, 2017 at 2:35 AM, ddbug wrote: > > > >> You can also develop using venv virtual environments. You can symlink > >> or shell-shortcut to the activation script of a virtual environment. > > > > Interesting idea. But I have not seen any installers or guidance how to deploy something packaged > > as a venv to users. Can you share any pointers please? > > Are we talking about scripts for programmers to work with libraries > that you publish (e.g. a command-line tool like cythonize), or > applications for end users and IT staff? Virtual environments are > primarily a solution for developers. For deployment to end users, take > a look at what Paul Moore is doing with pylaunch and the embedded > Python distribution: > > https://github.com/pfmoore/pylaunch > https://docs.python.org/3/using/windows.html#embedded-distribution To clarify the situation, the "entry point" facility is basically designed to provide a command line interface to a Python module you are distributing. The target audience is therefore people who are using Python as a language, and so are (somewhat) familiar with setting up PATH, maybe even using virtualenvs, etc. That's not always how entry points are used in practice, because a lot of the alternatives for other use cases are not well known and/or limited. So entry points get used for situations where they aren't always ideal for the target audience. If you're looking to deploy an application written in Python to users who don't really care about the implementation language, and just want to use the application, then entry points may not be the best option for you. If you can rely on your users having Python installed and set up correctly (as an analogy, when distributing a Java program, users need to have a Java runtime installed) and you don't use any C extensions, then a zipapp (see https://docs.python.org/3.6/library/zipapp.html) may be enough for you - Python 3.6 registers the ".pyz" and ".pyzw" extensions for zipapps, so they should be runnable via double click without much difficulty. In a similar manner, but with a little more effort, you can deploy your application as a runnable directory, which supports C extensions, but may need a launcher script to work easily. If you want to bundle Python with your application, so that it looks basically like a "native" executable, then py2exe and cx_Freeze are two projects that do this and have been round for quite some time. They may suit your needs better. My pylaunch project (that Eryk linked to) is a prototype approach that is intended for distributors that want more control over the build process, which provides a flexible set of tools for people to build applications using the (somewhat smaller, and completely self-contained) embeddable distribution that became available with recent Python 3.x builds. It's targeted at the soon-to-be-released Python 3.6.1 and later (there's a minor issue with 3.6.0 that makes putting the embedded distribution in a subdirectory a little fiddly). If you're interested in building your own custom solution, it's probably something you should look at, but it's definitely not a finished product yet. Hope this helps, Paul From ben+python at benfinney.id.au Mon Mar 6 05:50:06 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Mar 2017 21:50:06 +1100 Subject: python-daemon and PID files References: <58BBA4A8.2040602@stoneleaf.us> Message-ID: <85r32aisrl.fsf@benfinney.id.au> Ethan Furman writes: > On 03/04/2017 09:09 PM, Ian Pilcher wrote: > > > Is it possible to get python-daemon to create "systemd style" PID > > file? Short answer: No, that's the job of whatever ?pidfile? object you provide. Medium answer: Yes, by implementing that behaviour in the object you choose to present as the ?pidfile? option. The ?python-lockfile? library is suggested as one implementation, but there are of course others. Longer answer: Because ?python-daemon? is deliberately agnostic about what the ?pidfile? object does, you can give it any behaviour you like. The only thing the ?DaemonContext.pidfile? option is expected to do is be a context manager; what happens when that context manager is entered or exited is up to you. > I know my library, pandaemonium [1], will allow you to write the pid > file complete with the daemon's PID, and I would be very surprised if > Ben's python-daemon did not also allow that. It certainly allows it: put whatever behaviour your application needs in the context manager's methods. More about writing a context manager can be found at the documentation . -- \ ?If we listen only to those who are like us, we will squander | `\ the great opportunity before us: To live together peacefully in | _o__) a world of unresolved differences.? ?David Weinberger | Ben Finney From rosuav at gmail.com Mon Mar 6 06:07:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Mar 2017 22:07:33 +1100 Subject: str.title() fails with words containing apostrophes In-Reply-To: References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> Message-ID: On Mon, Mar 6, 2017 at 9:04 PM, Peter Otten <__peter__ at web.de> wrote: > Perhaps one could limit the conversion to go from lower to upper only, as > names tend be in the desired case in the original text. No, that just tends to make things confusing to use. > Unfortunately this won't help with > >>>> title("admiral von schneider") > 'Admiral Von Schneider' # von should be lower case On Mon, Mar 6, 2017 at 8:52 PM, Jussi Piitulainen wrote: > It also will capitalize all the little words in the string that are > usually not capitalized in titles, even in the usual headlinese English > variants. And all the acronyms and such that are usually written in all > caps, or in even odder patterns. Right. If you want true title casing, it has to be *extremely* linguistically-aware. Each of these highlights the fact that "title case" does not truly equate to "capitalize each whitespace-delimited word", so it's going to need some sort of intelligence. There's probably a linguistic library out there that does all of this, but it doesn't need to be in the stdlib. I am a little surprised by the "Don'T" from the OP, but I'm not at all surprised at "Admiral Von Schneider", nor of "How To Teach Css" and other "anomalies". Still, it's fun to discuss, if only to show why that kind of locale-aware transformation is important. ChrisA From python at bdurham.com Mon Mar 6 07:35:11 2017 From: python at bdurham.com (Malcolm Greene) Date: Mon, 06 Mar 2017 07:35:11 -0500 Subject: Who still supports recent Python on shared hosting In-Reply-To: References: Message-ID: <1488803711.144664.901821744.6453F1EE@webmail.messagingengine.com> Another endorsement for Webfaction. From marko at pacujo.net Mon Mar 6 09:03:07 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 06 Mar 2017 16:03:07 +0200 Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> Message-ID: <87innmzen8.fsf@elektro.pacujo.net> Chris Angelico : > Right. If you want true title casing, it has to be *extremely* > linguistically-aware. For instance, title case has no meaning in the context of Finnish. In other words, your internationalized program shouldn't even think of title case when localized in Finnish. This localization problem runs even deeper. My Windows Phone displays the time and date: 15:49 maanantai 6. maaliskuuta It gets many things right. However, in Finland, nobody ever spells out the month name in dates. "March 6" should be localized to "6.3.", preferably to "6.3.2017". > Still, it's fun to discuss, if only to show why that kind of > locale-aware transformation is important. Finland is a bilingual country. You often see street ads for the same product in Finnish and Swedish. What is notable is that the Finnish and Swedish variants can have completely different punchlines because a translation just wouldn't sound good either way. Marko From darcy at VybeNetworks.com Mon Mar 6 10:18:29 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Mon, 6 Mar 2017 10:18:29 -0500 Subject: str.title() fails with words containing apostrophes In-Reply-To: References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> Message-ID: <93afa0e5-a1d4-ac85-cded-0e1a8cc3722e@VybeNetworks.com> On 2017-03-06 05:04 AM, Peter Otten wrote: >> Won't Steve D'aprano And D'arcy Cain Be Happy Now :) > > Perhaps one could limit the conversion to go from lower to upper only, as > names tend be in the desired case in the original text. That would help with acronyms as well. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From iilaraja1286 at gmail.com Mon Mar 6 10:36:11 2017 From: iilaraja1286 at gmail.com (iilaraja1286 at gmail.com) Date: Mon, 6 Mar 2017 07:36:11 -0800 (PST) Subject: Export Event log via python in .txt Message-ID: I'm a student learning about python I would like to know how to export Security log Application and generate folder path via python please help From grant.b.edwards at gmail.com Mon Mar 6 11:28:45 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 6 Mar 2017 16:28:45 +0000 (UTC) Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> Message-ID: On 2017-03-06, Chris Angelico wrote: > Still, it's fun to discuss, if only to show why that kind of > locale-aware transformation is important. Besides locale-aware, it'll need to be style-guide-aware so that it knows whether you want MLA, Chicago, Strunk & White, NYT, Gregg, Mrs. Johnson from 9th grade English class, or any of a dozen or two others. And that's just for US English. [For all I know, most of the ones I listed agree completely on "title case", but I doubt it.] -- Grant Edwards grant.b.edwards Yow! FOOLED you! Absorb at EGO SHATTERING impulse gmail.com rays, polyester poltroon!! From steve+python at pearwood.info Mon Mar 6 18:07:47 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 07 Mar 2017 10:07:47 +1100 Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> Message-ID: <58bdebc4$0$1618$c3e8da3$5496439d@news.astraweb.com> On Tue, 7 Mar 2017 03:28 am, Grant Edwards wrote: > On 2017-03-06, Chris Angelico wrote: > >> Still, it's fun to discuss, if only to show why that kind of >> locale-aware transformation is important. > > Besides locale-aware, it'll need to be style-guide-aware so that it > knows whether you want MLA, Chicago, Strunk & White, NYT, Gregg, > Mrs. Johnson from 9th grade English class, or any of a dozen or two > others. And that's just for US English. [For all I know, most of the > ones I listed agree completely on "title case", but I doubt it.] As far as I am aware, there are only two conventions for title case in English: Initial Capitals For All The Words In A Sentence. Initial Capitals For All the Significant Words in a Sentence. For some unstated, subjective rule for "significant" which usually means "three or more letters, excluding the definite article ('the')". But of course there are exceptions: words which are necessarily in all-caps should stay in all-caps (e.g. NASA) and names. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From grant.b.edwards at gmail.com Mon Mar 6 18:28:56 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Mon, 6 Mar 2017 23:28:56 +0000 (UTC) Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <58bdebc4$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-03-06, Steve D'Aprano wrote: > On Tue, 7 Mar 2017 03:28 am, Grant Edwards wrote: > >> On 2017-03-06, Chris Angelico wrote: >> >>> Still, it's fun to discuss, if only to show why that kind of >>> locale-aware transformation is important. >> >> Besides locale-aware, it'll need to be style-guide-aware so that it >> knows whether you want MLA, Chicago, Strunk & White, NYT, Gregg, >> Mrs. Johnson from 9th grade English class, or any of a dozen or two >> others. And that's just for US English. [For all I know, most of the >> ones I listed agree completely on "title case", but I doubt it.] > > As far as I am aware, there are only two conventions for title case in > English: > > Initial Capitals For All The Words In A Sentence. > > Initial Capitals For All the Significant Words in a Sentence. > > For some unstated, subjective rule for "significant" which usually > means "three or more letters, excluding the definite article ('the')". > > But of course there are exceptions: words which are necessarily in > all-caps should stay in all-caps (e.g. NASA) and names. And you capitalize "insignificant" words at the beginning of the title or following a colon. And then there are special cases for hyphenated words, prepositions that belong to a phrasal verb, and so on and so forth. Plus a bunch of exceptions that have been imported from other languages (this is mostly covered by the "name" exception). The "name" one is probably the only one that many people will notice if it's wrong. Unfortunately, writing an algorithm that can decide what constitutes a "name" borders on the impossible. -- Grant Edwards grant.b.edwards Yow! I'm totally DESPONDENT at over the LIBYAN situation gmail.com and the price of CHICKEN ... From steve+python at pearwood.info Mon Mar 6 18:33:21 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 07 Mar 2017 10:33:21 +1100 Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <87innmzen8.fsf@elektro.pacujo.net> Message-ID: <58bdf1c3$0$1617$c3e8da3$5496439d@news.astraweb.com> On Tue, 7 Mar 2017 01:03 am, Marko Rauhamaa wrote: > Chris Angelico : > >> Right. If you want true title casing, it has to be *extremely* >> linguistically-aware. > > For instance, title case has no meaning in the context of Finnish. In > other words, your internationalized program shouldn't even think of > title case when localized in Finnish. If you read "title case" as *literally* as being only for titles (of books, for instance) then of course you are right. Finnish book titles are normally written in sentence case (initial capital, followed by all lowercase). But if you consider title case more widely, Finnish includes it too. Names are written in title case ("Marko Rauhamaa" rather than "Marko rauhamaa"). I imagine countries get the same treatment when needed. How do you write Saudi Arabia, United Kingdom, and North Korea? I came across this book title: T??ll? Pohjant?hden alla (?Here beneath the North Star?) http://www.booksfromfinland.fi/1980/12/the-strike/ which is partly title case, but I'm not sure what rule is being applied there. My guess is that "T??ll? Pohjant?hden" means "North Star" and it counts as a proper noun, like countries and people's names, and so takes initial caps for each word. Am I close? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From marko at pacujo.net Mon Mar 6 20:03:56 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 07 Mar 2017 03:03:56 +0200 Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <87innmzen8.fsf@elektro.pacujo.net> <58bdf1c3$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87efy9x5hf.fsf@elektro.pacujo.net> Steve D'Aprano : > On Tue, 7 Mar 2017 01:03 am, Marko Rauhamaa wrote: > If you read "title case" as *literally* as being only for titles (of > books, for instance) then of course you are right. Finnish book titles > are normally written in sentence case (initial capital, followed by > all lowercase). Yes. > But if you consider title case more widely, Finnish includes it too. > Names are written in title case ("Marko Rauhamaa" rather than "Marko > rauhamaa"). I imagine countries get the same treatment when needed. > How do you write Saudi Arabia, United Kingdom, and North Korea? The rules are a bit complicated. Sentence case is the basic rule. However, if the latter part of a compound name is a proper noun, both parts are capitalized and connected with a hyphen: Saudi-Arabia Pohjois-Korea Iso-Britannia As for the UK: Yhdistynyt kuningaskunta or: Ison-Britannian ja Pohjois-Irlannin yhdistynyt kuningaskunta Similarly, the University of Helsinki is: Helsingin yliopisto > I came across this book title: > > T??ll? Pohjant?hden alla (?Here beneath the North Star?) > > http://www.booksfromfinland.fi/1980/12/the-strike/ > > which is partly title case, but I'm not sure what rule is being > applied there. My guess is that "T??ll? Pohjant?hden" means "North > Star" and it counts as a proper noun, like countries and people's > names, and so takes initial caps for each word. Am I close? Correct. The sentence case rule is sometimes violated for historical or marketing reasons: Helsingin Sanomat (a newspaper) Suomen Kuvalehti (a magazine) Sutelan Kello ja Kulta (a jeweler) Helsingin Hautaustoimisto (an undertaker) Marko From eryksun at gmail.com Mon Mar 6 20:09:23 2017 From: eryksun at gmail.com (eryk sun) Date: Tue, 7 Mar 2017 01:09:23 +0000 Subject: Export Event log via python in .txt In-Reply-To: References: Message-ID: On Mon, Mar 6, 2017 at 3:36 PM, wrote: > I'm a student learning about python I would like to know how to export > Security log Application and generate folder path via python please help If you're asking about the Windows event logs, then it'll be easiest from a scripting POV to use wevtutil.exe [1] with an XPath query that outputs XML. Make sure to use the /uni:true option to get UTF-16 output; otherwise it outputs a lossy ANSI encoding. You can run it using subprocess.check_output. [1]: https://technet.microsoft.com/en-us/library/cc732848 As far as exporting the data, the standard library supports XML processing. Here's an example that logs a warning to the Application log using "Python" as the provider. Next it executes wevtutil.exe with a query for events logged by the "Python" provider. Then I parse the output using ElementTree. import logging import logging.handlers import subprocess import xml.etree.ElementTree as ET handler = logging.handlers.NTEventLogHandler('Python') logging.getLogger().addHandler(handler) logging.warn('?????') wevtutil = 'wevtutil.exe query-events Application /uni:true /q:"{}"' query = "*[System[Provider[@Name='Python']]]" out = subprocess.check_output(wevtutil.format(query)) root = ET.fromstring(out.decode('utf-16')) ns = {'event': 'http://schemas.microsoft.com/win/2004/08/events/event'} >>> root.find('.//event:Provider', ns).attrib {'Name': 'Python'} >>> root.find('.//event:Level', ns).text '3' >>> root.find('.//event:Channel', ns).text 'Application' >>> root.find('.//event:Data', ns).text '?????' From rosuav at gmail.com Mon Mar 6 20:18:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Mar 2017 12:18:13 +1100 Subject: str.title() fails with words containing apostrophes In-Reply-To: <87efy9x5hf.fsf@elektro.pacujo.net> References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <87innmzen8.fsf@elektro.pacujo.net> <58bdf1c3$0$1617$c3e8da3$5496439d@news.astraweb.com> <87efy9x5hf.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 7, 2017 at 12:03 PM, Marko Rauhamaa wrote: > > As for the UK: > > Yhdistynyt kuningaskunta About the only part of that that I understand is "kuning" == king/queen/kingdom. I swear, you like the letter 'y' more than the Welsh do... ChrisA From bilmar19 at gmail.com Mon Mar 6 20:44:59 2017 From: bilmar19 at gmail.com (bilmar19 at gmail.com) Date: Mon, 6 Mar 2017 17:44:59 -0800 (PST) Subject: Basic Packaging strategy question In-Reply-To: References: Message-ID: <0672695f-f7da-4e22-8a43-f7912fed376a@googlegroups.com> Thanks, It still seems strange to me that such a well documented ecosystem does not have an official way to package a complete app ( vs packages ). Bill From steve at pearwood.info Tue Mar 7 00:16:44 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 07 Mar 2017 05:16:44 GMT Subject: Basic Packaging strategy question References: Message-ID: <58be423c$0$1610$c3e8da3$5496439d@news.astraweb.com> On Sat, 04 Mar 2017 15:08:15 -0800, bilmar19 wrote: > I have a simple project that I want to package to put it on another > machine but everything I have read so far about packaging ends up > putting the whole install alongside with 'packages' - typically in > .../site-packages. > This seems a strange place to launch an app from! > > So, if I have an app with a main.py entry point is it ok for everything > to be in .../site-packages/myproject? Packaging is one of the more hairy areas of Python, but the general advice is that you give your package a __main__.py which is run as the "execute this package" entry point. A basic skeleton would be a directory like this: myproject/ +-- __init__.py +-- __main__.py +-- utils.py +-- config.py Notice that only "init" and "main" are special double-underscore names. The __main__.py file should look something like this: def main(): print("Hello world!") if __name__ == '__main__': main() Place the entire myproject directory under site-packages, and you can run it as a script as: python -m myproject from the system shell. Under Windows you may need to specify the path to python.exe, I don't really know, I'm not a Windows expert. If you want to provide a single name command for your users, I expect you can probably create a simple batch file containing the command, place it in the usual Windows executable path (My Applications or whatever it is called these days) and in theory it should Just Work. I expect that setuptools, pip, etc. should be able to install the batch file as well as the package, provided you have appropriate Admin access to write to My Applications (?), but I've never tried it myself. [...] > simple example which ends up with needing to run: > python /usr/local/lib/site_packages/myproject/main.py: Almost correct, it will be spelled __main__ not main, and site-packages with a hyphen, not underscore. -- Steve From steve at pearwood.info Tue Mar 7 00:18:19 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 07 Mar 2017 05:18:19 GMT Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <87innmzen8.fsf@elektro.pacujo.net> <58bdf1c3$0$1617$c3e8da3$5496439d@news.astraweb.com> <87efy9x5hf.fsf@elektro.pacujo.net> Message-ID: <58be429b$0$1610$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Mar 2017 12:18:13 +1100, Chris Angelico wrote: > On Tue, Mar 7, 2017 at 12:03 PM, Marko Rauhamaa > wrote: >> >> As for the UK: >> >> Yhdistynyt kuningaskunta > > About the only part of that that I understand is "kuning" == > king/queen/kingdom. I swear, you like the letter 'y' more than the Welsh > do... But do Finns like 'y' more than the English like 'e'? -- Steve From marko at pacujo.net Tue Mar 7 00:57:29 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 07 Mar 2017 07:57:29 +0200 Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <87innmzen8.fsf@elektro.pacujo.net> <58bdf1c3$0$1617$c3e8da3$5496439d@news.astraweb.com> <87efy9x5hf.fsf@elektro.pacujo.net> Message-ID: <877f41wrw6.fsf@elektro.pacujo.net> Chris Angelico : > On Tue, Mar 7, 2017 at 12:03 PM, Marko Rauhamaa wrote: >> >> As for the UK: >> >> Yhdistynyt kuningaskunta > > About the only part of that that I understand is "kuning" == > king/queen/kingdom. I swear, you like the letter 'y' more than the > Welsh do... The Proto-Finnic borrowed the word "kuningas" from the Proto-Germanic, where it was "kuningaz". The Germanic descendant languages have mangled the original quite a bit: English: king German: K?nig Swedish: kung See also: . The word "yhdistynyt" ultimately comes from the Proto-Uralic word "*?kte" ("one"). The word "kunta" ("society") is in its Proto-Uralic form. Marko From rosuav at gmail.com Tue Mar 7 00:58:18 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Mar 2017 16:58:18 +1100 Subject: str.title() fails with words containing apostrophes In-Reply-To: <58be429b$0$1610$c3e8da3$5496439d@news.astraweb.com> References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <87innmzen8.fsf@elektro.pacujo.net> <58bdf1c3$0$1617$c3e8da3$5496439d@news.astraweb.com> <87efy9x5hf.fsf@elektro.pacujo.net> <58be429b$0$1610$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 7, 2017 at 4:18 PM, Steven D'Aprano wrote: > On Tue, 07 Mar 2017 12:18:13 +1100, Chris Angelico wrote: > >> On Tue, Mar 7, 2017 at 12:03 PM, Marko Rauhamaa >> wrote: >>> >>> As for the UK: >>> >>> Yhdistynyt kuningaskunta >> >> About the only part of that that I understand is "kuning" == >> king/queen/kingdom. I swear, you like the letter 'y' more than the Welsh >> do... > > > But do Finns like 'y' more than the English like 'e'? Perhaps not. And certainly not as much as Calculus likes 'e'. ChrisA From gregcouch at gmail.com Tue Mar 7 01:00:41 2017 From: gregcouch at gmail.com (Greg Couch) Date: Mon, 6 Mar 2017 22:00:41 -0800 (PST) Subject: spam issue In-Reply-To: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> References: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> Message-ID: <111d8b71-7bd1-430e-8f2b-068158da2c53@googlegroups.com> On Thursday, March 2, 2017 at 8:08:44 AM UTC-8, Andrew Zyman wrote: > Why is this group have such an obscene number of spam posts ? > I'm subscribed to a few other google groups and this is the only one that has this issue. If you do use google groups, please "Report abuse" for these messages. And maybe google will get get a clue. Wishful thinking, I know. From jussi.piitulainen at helsinki.fi Tue Mar 7 02:12:38 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 07 Mar 2017 09:12:38 +0200 Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <58bdebc4$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano writes: > On Tue, 7 Mar 2017 03:28 am, Grant Edwards wrote: >> >> Besides locale-aware, it'll need to be style-guide-aware so that it >> knows whether you want MLA, Chicago, Strunk & White, NYT, Gregg, >> Mrs. Johnson from 9th grade English class, or any of a dozen or two >> others. And that's just for US English. [For all I know, most of >> the ones I listed agree completely on "title case", but I doubt it.] > > As far as I am aware, there are only two conventions for title case in > English: > > Initial Capitals For All The Words In A Sentence. > > Initial Capitals For All the Significant Words in a Sentence. > > For some unstated, subjective rule for "significant" which usually > means "three or more letters, excluding the definite article ('the')". That's where the variation is hidden. I browsed three sites to see what they do. One doesn't title-capitalize anything. One capitalizes everything. One was more interesting. I think it has human editors who pay attention to these matters. They do not capitalize these short words: 'a', 'an', 'at', 'the', 'in', 'of', 'on', 'for', 'to', 'and', 'vs.'; they capitalize longer prepositions: 'From', 'Into', 'With', 'Through'. Also auxiliary verbs and copulas even when short. A 'Nor' was capitalized in the middle of a title, but there was a sentence boundary just before the 'Nor'. I'd classify 'nor' with 'and' otherwise, but they might base the non-capitalization on frequency for all I know. Some two-letter words: 'Is', 'Am', 'Do', 'So', 'No', 'He', 'We', 'It', 'My', 'Up'; also 'Au Revoir', 'Oi Oi Oi', 'Ay Ay Ay'. Then there is 'Grown-Ups' and 'Contrary-to-Fact' but 'X-ing'. Sometimes a hyphen makes a word boundary, sometimes not. > But of course there are exceptions: words which are necessarily in > all-caps should stay in all-caps (e.g. NASA) and names. There may be lots of these if you are handling something like a tech news site that talks about people and companies and institutions from all over the world. Names are tricky. From jussi.piitulainen at helsinki.fi Tue Mar 7 02:21:17 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 07 Mar 2017 09:21:17 +0200 Subject: str.title() fails with words containing apostrophes References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <87innmzen8.fsf@elektro.pacujo.net> <58bdf1c3$0$1617$c3e8da3$5496439d@news.astraweb.com> <87efy9x5hf.fsf@elektro.pacujo.net> Message-ID: Marko Rauhamaa writes: > Steve D'Aprano wrote: >> I came across this book title: >> >> T??ll? Pohjant?hden alla (?Here beneath the North Star?) >> >> http://www.booksfromfinland.fi/1980/12/the-strike/ >> >> which is partly title case, but I'm not sure what rule is being >> applied there. My guess is that "T??ll? Pohjant?hden" means "North >> Star" and it counts as a proper noun, like countries and people's >> names, and so takes initial caps for each word. Am I close? > > Correct. Not quite. "T??ll?" is "here", "Pohjant?hden" is "North Star". So it's just a first word and a name. ("Pohja" and "t?hti" correspond to "North" and "Star".) From p.f.moore at gmail.com Tue Mar 7 04:09:05 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 7 Mar 2017 01:09:05 -0800 (PST) Subject: Basic Packaging strategy question In-Reply-To: <0672695f-f7da-4e22-8a43-f7912fed376a@googlegroups.com> References: <0672695f-f7da-4e22-8a43-f7912fed376a@googlegroups.com> Message-ID: <6e3eedc3-372c-488d-9a15-58185d4e97d9@googlegroups.com> On Tuesday, 7 March 2017 01:45:10 UTC, bilm... at gmail.com wrote: > It still seems strange to me that such a well documented ecosystem does not have an official way to package a complete app ( vs packages ). Well, it's a combination of history, the fact that the whole thing is platform dependent, and best practices are changing over time. If you want an answer for Windows only, that's been around for ages and works well for major applications like Mercurial, you should probably just go with py2exe. Paul From borysova.mary at gmail.com Tue Mar 7 07:45:12 2017 From: borysova.mary at gmail.com (borysova.mary at gmail.com) Date: Tue, 7 Mar 2017 04:45:12 -0800 (PST) Subject: Importing with ctypes in Python: fighting overflows Message-ID: <1e532a81-acd0-4102-9408-b76332344e92@googlegroups.com> Importing with ctypes in Python: fighting overflows: https://www.cossacklabs.com/blog/fighting-ctypes-overflows.html Best cases of boring technical debt are understood when reflected properly. This post addresses a simple one: inelegant flags in core C library ended up breaking Python tests. This is no small case to us: tests breaking sometimes might end up in things seeming to work, but not really working. Not something you can afford yourself when you're doing cryptography, do you? From gheskett at shentel.net Tue Mar 7 08:57:57 2017 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 7 Mar 2017 08:57:57 -0500 Subject: spam issue In-Reply-To: <111d8b71-7bd1-430e-8f2b-068158da2c53@googlegroups.com> References: <1ea22f17-cd73-4e52-80f2-dde488d6913c@googlegroups.com> <111d8b71-7bd1-430e-8f2b-068158da2c53@googlegroups.com> Message-ID: <201703070857.57962.gheskett@shentel.net> On Tuesday 07 March 2017 01:00:41 Greg Couch wrote: > On Thursday, March 2, 2017 at 8:08:44 AM UTC-8, Andrew Zyman wrote: > > Why is this group have such an obscene number of spam posts ? > > I'm subscribed to a few other google groups and this is the only one > > that has this issue. > > If you do use google groups, please "Report abuse" for these messages. > And maybe google will get get a clue. Wishful thinking, I know. I don't get any more spam on this list, I send anything from google groups to /dev/null before it gets to /var/spool/mail/. Much more peacefull now, for about 2 years... Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From eryksun at gmail.com Tue Mar 7 09:11:38 2017 From: eryksun at gmail.com (eryk sun) Date: Tue, 7 Mar 2017 14:11:38 +0000 Subject: Importing with ctypes in Python: fighting overflows In-Reply-To: <1e532a81-acd0-4102-9408-b76332344e92@googlegroups.com> References: <1e532a81-acd0-4102-9408-b76332344e92@googlegroups.com> Message-ID: On Tue, Mar 7, 2017 at 12:45 PM, wrote: > Importing with ctypes in Python: fighting overflows: > https://www.cossacklabs.com/blog/fighting-ctypes-overflows.html C int is 32-bit on all platforms currently supported by CPython -- both 32-bit and 64-bit. It's the default result type and the default integer-argument conversion type in ctypes. Since themis_status_t is a typedef for a C int, the proper way to define the constant is as follows: >>> THEMIS_SCOMPARE_MATCH = ctypes.c_int(0xf0f0f0f0).value >>> THEMIS_SCOMPARE_MATCH -252645136 This has ctypes convert the value for you, which will be consistent with how it converts a themis_status_t result. From Gabriel.Ganne at enea.com Tue Mar 7 09:47:22 2017 From: Gabriel.Ganne at enea.com (Gabriel Ganne) Date: Tue, 7 Mar 2017 14:47:22 +0000 Subject: custom setup.py link argument order Message-ID: Hi, I'm currently writing a python C module which has a chained dependency: - mymodule requires libb - libb requires liba To that effect, within setup.py, I link against both liba and libb libraries=['a', 'b'], Also, as I'm working on Ubuntu, I want to add -Wl,--no-as-needed to make sure that the symbols not immediately needed will still be stripped. extra_link_args=['-Wl,--no-as-needed'], However, it seems that the extra_link_args are systematically appended at the end of the link line, but for this to work, the '-Wl,--no-as-needed' argument need to be *before* the link against my two libraries. How can I choose the order of my link arguments that I pass to gcc using setup.py ? Best regards, -- Gabriel Ganne From bintacomputers at gmail.com Tue Mar 7 13:47:24 2017 From: bintacomputers at gmail.com (Umar Yusuf) Date: Tue, 7 Mar 2017 10:47:24 -0800 (PST) Subject: Need help generating Contour and HeatMap plots Message-ID: Hello house, I kindly need your input here >> http://stackoverflow.com/questions/42655870/matplotlib-convert-scatter-plot-to-contour-and-heatmap-plots From gliesian66 at gmail.com Tue Mar 7 14:21:14 2017 From: gliesian66 at gmail.com (Robert James Liguori) Date: Tue, 7 Mar 2017 11:21:14 -0800 (PST) Subject: Oracle Database Message-ID: What is the easiest way to connect to an Oracle Database using python in order to run queries? From rosuav at gmail.com Tue Mar 7 14:34:27 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Mar 2017 06:34:27 +1100 Subject: Oracle Database In-Reply-To: References: Message-ID: On Wed, Mar 8, 2017 at 6:21 AM, Robert James Liguori wrote: > What is the easiest way to connect to an Oracle Database using python in order to run queries? There's a Python package called cx_oracle that provides a standardized interface. You can run queries using that. https://pypi.python.org/pypi/cx_Oracle ChrisA From maria.katic at gmail.com Tue Mar 7 16:15:06 2017 From: maria.katic at gmail.com (maria.katic at gmail.com) Date: Tue, 7 Mar 2017 13:15:06 -0800 (PST) Subject: Invitation to support our research (by responding to the questionnaire) on analogy based code reuse Message-ID: At Birkbeck, University of London in collaboration with the Faculty of Electrical Engineering and Computing, University of Zagreb, we are doing research on reusing source code based on analogical reasoning. We appreciate the importance of your time and we hope you will be able to invest approximately 15 minutes of your time and fill in our questionnaire. The questionnaire will be available in the next few weeks. We did our best to reduce the amount of questions to the most important ones of our interest. Please note that your feedback is critical to the success of this research. Your answers are completely anonymous. Please follow this link to fill in the questionnaire: https://docs.google.com/forms/d/e/1FAIpQLSc0A_z8Z2zOeElqA_dWBijc04Fh5qARy9PdV63D7QzpFq3rbA/viewform?usp=send_form Thank you very much in advance for your time and for supporting our research. Kind regards, Marija, Martin and Mario From nagle at animats.com Tue Mar 7 17:05:15 2017 From: nagle at animats.com (John Nagle) Date: Tue, 7 Mar 2017 14:05:15 -0800 Subject: Unicode support in Python 2.7.8 - 16 bit Message-ID: How do I test if a Python 2.7.8 build was built for 32-bit Unicode? (I'm dealing with shared hosting, and I'm stuck with their provided versions.) If I give this to Python 2.7.x: sy = u'\U0001f60f' len(sy) is 1 on a Ubuntu 14.04LTS machine, but 2 on the Red Hat shared hosting machine. I assume "1" indicates 32-bit Unicode capability, and "2" indicates 16-bit. It looks like Python 2.x in 16-bit mode is using a UTF-16 pair encoding, like Java. Is that right? Is it documented somewhere? (Annoyingly, while the shared host has a Python 3, it's 3.2.3, which rejects "u" Unicode string constants and has other problems in the MySQL area.) John Nagle From joaquin.henriquez at countercept.com Tue Mar 7 17:16:48 2017 From: joaquin.henriquez at countercept.com (Joaquin Henriquez) Date: Tue, 7 Mar 2017 22:16:48 +0000 Subject: Oracle Database Message-ID: <20170307221647.18350138.55614.146@countercept.com> ? Original Message ? >What is the easiest way to connect to an Oracle Database >using python in order to run queries? ?You should check module cx_Oracle From rosuav at gmail.com Tue Mar 7 17:21:14 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Mar 2017 09:21:14 +1100 Subject: Unicode support in Python 2.7.8 - 16 bit In-Reply-To: References: Message-ID: On Wed, Mar 8, 2017 at 9:05 AM, John Nagle wrote: > How do I test if a Python 2.7.8 build was built for 32-bit > Unicode? (I'm dealing with shared hosting, and I'm stuck > with their provided versions.) > > If I give this to Python 2.7.x: > > sy = u'\U0001f60f' > > len(sy) is 1 on a Ubuntu 14.04LTS machine, but 2 on the > Red Hat shared hosting machine. I assume "1" indicates > 32-bit Unicode capability, and "2" indicates 16-bit. > It looks like Python 2.x in 16-bit mode is using a UTF-16 > pair encoding, like Java. Is that right? Is it documented > somewhere? That's correct. A narrow build will treat that as a pair of surrogates. You may also be able to check this way: >>> sys.maxunicode 1114111 > (Annoyingly, while the shared host has a Python 3, it's > 3.2.3, which rejects "u" Unicode string constants and > has other problems in the MySQL area.) Yeah, you'll do well to get a newer Py3 than that. Fortunately, any Linux old enough to be shipping 3.2 is likely to not depend on it in any way, so you can install a new Py3 (maybe even 3.6) and shadow the name "python3" with that. That's what I did when I was on Debian.... Squeeze, I think? and nothing newer than 3.2 was available. Soon as you hit 3.3, the u"..." prefix becomes legal again, and subsequent versions have added even more compatibility. ChrisA From tjreedy at udel.edu Tue Mar 7 17:31:43 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 7 Mar 2017 17:31:43 -0500 Subject: Unicode support in Python 2.7.8 - 16 bit In-Reply-To: References: Message-ID: On 3/7/2017 5:05 PM, John Nagle wrote: > How do I test if a Python 2.7.8 build was built for 32-bit > Unicode? (I'm dealing with shared hosting, and I'm stuck > with their provided versions.) > > If I give this to Python 2.7.x: > > sy = u'\U0001f60f' > > len(sy) is 1 on a Ubuntu 14.04LTS machine, but 2 on the > Red Hat shared hosting machine. I assume "1" indicates > 32-bit Unicode capability, and "2" indicates 16-bit. Correct > It looks like Python 2.x in 16-bit mode is using a UTF-16 > pair encoding, like Java. Is that right? Is it documented > somewhere? Yes, surrogate pairs. Probably > (Annoyingly, while the shared host has a Python 3, it's > 3.2.3, which rejects "u" Unicode string constants and > has other problems in the MySQL area.) ;Very annoying. 3.2 on *nix can also have either narrow or wide build. 3.3+ use new flexible string representation on all platforms. -- Terry Jan Reedy From darcy at VybeNetworks.com Tue Mar 7 18:56:01 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Tue, 7 Mar 2017 18:56:01 -0500 Subject: str.title() fails with words containing apostrophes In-Reply-To: <58bdf1c3$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <58bc50de$0$1609$c3e8da3$5496439d@news.astraweb.com> <7172474a-ece2-42af-8edb-ba477e858e86@googlegroups.com> <87innmzen8.fsf@elektro.pacujo.net> <58bdf1c3$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <25dcce68-7633-3619-331f-a605a6de014d@VybeNetworks.com> On 2017-03-06 06:33 PM, Steve D'Aprano wrote: > If you read "title case" as *literally* as being only for titles (of books, I believe there is only one conclusion to be drawn from this thread - There is still a place for human proofreaders. I'm taking that as good news. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From selphiron at gmail.com Tue Mar 7 20:06:03 2017 From: selphiron at gmail.com (selphiron at gmail.com) Date: Tue, 7 Mar 2017 17:06:03 -0800 (PST) Subject: Questions about API documentation Message-ID: Hello, I am trying to understand how to write good API documentation. I have read ?7. Documenting Python? in the python developers guide [1] and skimmed the Doc-SIG email archives, but I still have some questions and I would appreciate your help. (Whenever I refer to me in the following questions, I mean documentation authors in general) 1) How much should I (or a documentation author in general) go into detail? I don?t want to bore experienced users, but I don?t want to scare beginners away either. 2) Should I give a code example for each method and object? 3) I recognize 2 different kinds of examples: Some are rather small and right under the object or method description and some are quite long and at the end of a module in a use case. Which kind is encouraged at which conditions? 4) The documentation of the Python Standard Library is quite verbose or like a book / tutorial. Some other documentations like JavaDoc [2] or PerlDoc [3] use a more reference-like documentation. Why did Python choose a different approach? Was this discussed before? 5) Do you have any other advice? Are there things I should be aware of? Regards Ahmet [1] https://docs.python.org/devguide/documenting.html [2] http://docs.oracle.com/javase/8/docs/api/index.html [3] http://perldoc.perl.org/ From schneiderw at law.byu.edu Tue Mar 7 20:24:10 2017 From: schneiderw at law.byu.edu (schneiderw at law.byu.edu) Date: Tue, 7 Mar 2017 18:24:10 -0700 Subject: No module named 'encodings' Python 3.6 on Windows 10 failure In-Reply-To: <58bf578f.02a7630a.4c208.60a1@mx.google.com> References: <58bf578f.02a7630a.4c208.60a1@mx.google.com> Message-ID: <58bf5d87.8c2b620a.1a52b.649a@mx.google.com> Every attempt to make Python 3.6.0 or 3.6.1rc1 to run on Windows 10 has resulted in the error message shown below.? I was running Python 3.5.2 successfully and wanted to upgrade.? C:\Python36-32>python Fatal Python error: Py_Initialize: unable to load the file system codec ModuleNotFoundError: No module named 'encodings' Current thread 0x00001774 (most recent call first): C:\Python36-32> From eryksun at gmail.com Tue Mar 7 21:21:56 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 8 Mar 2017 02:21:56 +0000 Subject: No module named 'encodings' Python 3.6 on Windows 10 failure In-Reply-To: <58bf5d87.8c2b620a.1a52b.649a@mx.google.com> References: <58bf578f.02a7630a.4c208.60a1@mx.google.com> <58bf5d87.8c2b620a.1a52b.649a@mx.google.com> Message-ID: On Wed, Mar 8, 2017 at 1:24 AM, wrote: > > Every attempt to make Python 3.6.0 or 3.6.1rc1 to run on Windows 10 > has resulted in the error message shown below. I was running Python > 3.5.2 successfully and wanted to upgrade. > > C:\Python36-32>python > Fatal Python error: Py_Initialize: unable to load the file system codec > ModuleNotFoundError: No module named 'encodings' You probably have the environment variable PYTHONHOME pointing at some other Python installation, or a previous installation. Permanently defining PYTHONHOME is wrong. Unset this value in the environment-variable editor and open a new command prompt. From flebber.crue at gmail.com Tue Mar 7 21:28:59 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 7 Mar 2017 18:28:59 -0800 (PST) Subject: Better way to do this dict comprehesion Message-ID: Hi I have got this dictionary comprehension and it works but how can I do it better? from collections import Counter def find_it(seq): counts = dict(Counter(seq)) a = [(k, v) for k,v in counts.items() if v % 3 == 0] return a[0][0] test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5] so this returns 5 which is great and the point of the problem I was doing. Can also do it like this def find_it(seq): counts = dict(Counter(seq)) a = [(k) for k,v in counts.items() if v % 3 == 0] return a[0] But the given problem states there will always only be one number appearing an odd number of times given that is there a neater way to get the answer? Thanks Sayth From python at mrabarnett.plus.com Tue Mar 7 21:31:54 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 8 Mar 2017 02:31:54 +0000 Subject: No module named 'encodings' Python 3.6 on Windows 10 failure In-Reply-To: <58bf5d87.8c2b620a.1a52b.649a@mx.google.com> References: <58bf578f.02a7630a.4c208.60a1@mx.google.com> <58bf5d87.8c2b620a.1a52b.649a@mx.google.com> Message-ID: <4fefef18-afb2-fc03-362d-1af8f9571a11@mrabarnett.plus.com> On 2017-03-08 01:24, schneiderw at law.byu.edu wrote: > > Every attempt to make Python 3.6.0 or 3.6.1rc1 to run on Windows 10 has resulted in the error message shown below. I was running Python 3.5.2 successfully and wanted to upgrade. > > > C:\Python36-32>python > Fatal Python error: Py_Initialize: unable to load the file system codec > ModuleNotFoundError: No module named 'encodings' > > Current thread 0x00001774 (most recent call first): > > C:\Python36-32> > Which installer did you download? I've installed both the 32-bit and 64-bit versions of Python 3.6.0 (using python-3.6.0.exe and python-3.6.0-amd64.exe respectively) and they're both working perfectly. In \Lib there's a folder called "encodings". If I rename it, Python fails. Does that folder exist? Does it contain a load of .py files? If not, there's something wrong... Maybe your installer got corrupted somehow. Uninstall it, check that all traces of that installation have gone, download the installer again, and try installing it again. From rosuav at gmail.com Tue Mar 7 21:37:23 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Mar 2017 13:37:23 +1100 Subject: Better way to do this dict comprehesion In-Reply-To: References: Message-ID: On Wed, Mar 8, 2017 at 1:28 PM, Sayth Renshaw wrote: > I have got this dictionary comprehension and it works but how can I do it better? > > from collections import Counter > > def find_it(seq): > counts = dict(Counter(seq)) > a = [(k, v) for k,v in counts.items() if v % 3 == 0] > return a[0][0] > > test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5] > > so this returns 5 which is great and the point of the problem I was doing. > > Can also do it like this > def find_it(seq): > counts = dict(Counter(seq)) > a = [(k) for k,v in counts.items() if v % 3 == 0] > return a[0] > > But the given problem states there will always only be one number appearing an odd number of times given that is there a neater way to get the answer? Take a step back for a moment. Are you trying to find something that appears an odd number of times, or a number of times that counts by three? First figure that out, THEN see if there's a better way to do what you're doing. To find an unpaired number in linear time with minimal space, try stepping through the list and either adding to a set or removing from it. At the end, your set should contain exactly one element. I'll let you write the actual code :) ChrisA From python at mrabarnett.plus.com Tue Mar 7 21:55:14 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 8 Mar 2017 02:55:14 +0000 Subject: Better way to do this dict comprehesion In-Reply-To: References: Message-ID: <8636d078-224f-7a04-b4a1-acf269946377@mrabarnett.plus.com> On 2017-03-08 02:37, Chris Angelico wrote: > On Wed, Mar 8, 2017 at 1:28 PM, Sayth Renshaw wrote: >> I have got this dictionary comprehension and it works but how can I do it better? >> >> from collections import Counter >> >> def find_it(seq): >> counts = dict(Counter(seq)) >> a = [(k, v) for k,v in counts.items() if v % 3 == 0] >> return a[0][0] >> >> test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5] >> >> so this returns 5 which is great and the point of the problem I was doing. >> >> Can also do it like this >> def find_it(seq): >> counts = dict(Counter(seq)) >> a = [(k) for k,v in counts.items() if v % 3 == 0] >> return a[0] >> >> But the given problem states there will always only be one number appearing an odd number of times given that is there a neater way to get the answer? > > Take a step back for a moment. Are you trying to find something that > appears an odd number of times, or a number of times that counts by > three? First figure that out, THEN see if there's a better way to do > what you're doing. > > To find an unpaired number in linear time with minimal space, try > stepping through the list and either adding to a set or removing from > it. At the end, your set should contain exactly one element. I'll let > you write the actual code :) > Using Counter seems like a simpler way to me. I wouldn't bother about other ways unless that way wasn't "good enough" for some reason. From rosuav at gmail.com Tue Mar 7 21:57:43 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Mar 2017 13:57:43 +1100 Subject: Better way to do this dict comprehesion In-Reply-To: <8636d078-224f-7a04-b4a1-acf269946377@mrabarnett.plus.com> References: <8636d078-224f-7a04-b4a1-acf269946377@mrabarnett.plus.com> Message-ID: On Wed, Mar 8, 2017 at 1:55 PM, MRAB wrote: > Using Counter seems like a simpler way to me. I wouldn't bother about other > ways unless that way wasn't "good enough" for some reason. Maybe. But without being sure what the goal is, it's hard to say. ChrisA From flebber.crue at gmail.com Wed Mar 8 00:02:24 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Tue, 7 Mar 2017 21:02:24 -0800 (PST) Subject: Better way to do this dict comprehesion In-Reply-To: References: Message-ID: <43bc9a64-d343-48d6-a916-5d53b8e74cb9@googlegroups.com> > > But the given problem states there will always only be one number appearing an odd number of times given that is there a neater way to get the answer? > > Take a step back for a moment. Are you trying to find something that > appears an odd number of times, or a number of times that counts by > three? First figure that out, THEN see if there's a better way to do > what you're doing. A number that appears an odd number of times. > > To find an unpaired number in linear time with minimal space, try > stepping through the list and either adding to a set or removing from > it. At the end, your set should contain exactly one element. I'll let > you write the actual code :) > > ChrisA ChrisA the way it sounds through the list is like filter with map and a lambda. http://www.python-course.eu/lambda.php Haven't had a good go yet... will see how it goes. Thanks Sayth From steve at pearwood.info Wed Mar 8 02:32:29 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 08 Mar 2017 07:32:29 GMT Subject: Unicode support in Python 2.7.8 - 16 bit References: Message-ID: <58bfb38d$0$1610$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Mar 2017 14:05:15 -0800, John Nagle wrote: > How do I test if a Python 2.7.8 build was built for 32-bit Unicode? sys.maxunicode will be 1114111 if it is a "wide" (32-bit) build and 65535 if it is a "narrow" (16-bit) build. You can double-check with: unichr(0x10FFFF) # will raise ValueError in a narrow build len(u'\U0010FFFF') # return 1 in a wide build, or 2 in a narrow build but the maxunicode test is the right way to do it. > (I'm dealing with shared hosting, and I'm stuck with their provided > versions.) > > If I give this to Python 2.7.x: > > sy = u'\U0001f60f' > > len(sy) is 1 on a Ubuntu 14.04LTS machine, but 2 on the Red Hat shared > hosting machine. I assume "1" indicates 32-bit Unicode capability, and > "2" indicates 16-bit. > It looks like Python 2.x in 16-bit mode is using a UTF-16 pair > encoding, like Java. Is that right? Correct. > Is it documented somewhere? https://docs.python.org/2/library/sys.html#sys.maxunicode https://docs.python.org/3/library/sys.html#sys.maxunicode Here's the PEP that introduced the distinction in the first place: https://www.python.org/dev/peps/pep-0261/ And here's the PEP that removes the distinction once and for all (at least in CPython): https://www.python.org/dev/peps/pep-0393/ I know the narrow/wide distinction was documented in the build instructions for when you compiled Python from source; that's obsolete since 3.3. I believe the compiler options were --enable-unicode=ucs4 and --enable-unicode=ucs2 (but don't quote me on that). -- Steve From steve at pearwood.info Wed Mar 8 02:37:35 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 08 Mar 2017 07:37:35 GMT Subject: Questions about API documentation References: Message-ID: <58bfb4be$0$1610$c3e8da3$5496439d@news.astraweb.com> On Tue, 07 Mar 2017 17:06:03 -0800, selphiron wrote: > Hello, > > I am trying to understand how to write good API documentation. Nice questions! > 1) How much should I (or a documentation author in general) go into > detail? I don?t want to bore experienced users, but I don?t want to > scare beginners away either. It depends on who you are writing documentation for. If you're writing a tutorial, you should go into less technical detail and more examples. But generally I expect that the official documentation for a module or library should be aimed at experienced developers, not beginners. No need to babysit them and hold their hand through everything: you can assume they are competent at Python, but not experienced with your library. > 2) Should I give a code example for each method and object? I believe that every function, class and method should have two lots of documentation: the docstring, which is available for runtime introspection (e.g. using help(obj) at the interactive interpreter) and more extensive, detailed documentation for non-interactive use. I try to include at least one simple example in the docstring of every method and function. This is both documentation and testing. To me, doctests do not need to be exhaustive: no need to show every possible case or option. They are primarily documentation. But some people, including the writer of the original doctest module for Python Tim Peters, uses doctests as exhaustive unit tests. Large, complex examples should go into the non-interactive docs (when needed). Simple examples should go into docstrings, but not necessarily into the regular documentation: it depends on *how* simple. For example, having demonstrated how x += 1 works in the docs, I probably wouldn't bother to do the same for x -= 1. But that's a judgment call and I don't expect everyone will agree. > 3) I recognize 2 different kinds of examples: Some are rather small and > right under the object or method description and some are quite long and > at the end of a module in a use case. Which kind is encouraged at which > conditions? Both, I would say. Use short examples for simple things, and larger examples for more complex things. -- Steve From dieter at handshake.de Wed Mar 8 03:20:07 2017 From: dieter at handshake.de (dieter) Date: Wed, 08 Mar 2017 09:20:07 +0100 Subject: Questions about API documentation References: Message-ID: <871su8i3ig.fsf@handshake.de> selphiron at gmail.com writes: > I am trying to understand how to write good API documentation. I have read ?7. Documenting Python? in the python developers guide [1] and skimmed the Doc-SIG email archives, but I still have some questions and I would appreciate your help. (Whenever I refer to me in the following questions, I mean documentation authors in general) I fear that has much to do with preference -- both on the side of the author as on the side of the user. Personally, I prefer documentation of the following kind: * an overview document gives the grand picture (architecture, primary concepts, building blocks) * detail documentation is terse - based mainly on well chosen names with some additional information where this is necessary * if necessary, e.g. for a specific target audience, an additional document give usage/configuration examples > 1) How much should I (or a documentation author in general) go into detail? I don?t want to bore experienced users, but I don?t want to scare beginners away either. You go into details where a typical user would get at a loss without the detail. What is "typical" depends on your target audience. It is more an experienced user when the target audience is "senior developer" (e.g. for a module like "ctypes"); it is more a beginner when the target audience is "occasional developer". > 2) Should I give a code example for each method and object? Only, if it is non trivial -- or in a separate document/part of the documentation targeted at less experienced users. > 3) I recognize 2 different kinds of examples: Some are rather small and right under the object or method description and some are quite long and at the end of a module in a use case. Which kind is encouraged at which conditions? My preferences would say: the first kind is likely unnecessary altogether. The second kind may be good in non obvious cases. > 4) The documentation of the Python Standard Library is quite verbose or like a book / tutorial. Some other documentations like JavaDoc [2] or PerlDoc [3] use a more reference-like documentation. Why did Python choose a different approach? Was this discussed before? The Python library documentation is rather heterogenous in this respect -- likely because many different people with different preferences have contributed. > 5) Do you have any other advice? Are there things I should be aware of? I should say that there is a big camp with completely different preferences from mine. I mean the "doctest" camp. It favours to combine documentation and testing and advices to have executable docstrings covering all test cases. This gives a very detailed documentation. As you can imagine I do not like this advice and the resulting documentation at all. From my point of view, the requirements for good documentation (overview, compactness, concept based) are quite different from those for testing (completeness) and for me such documentation is difficult to read. From __peter__ at web.de Wed Mar 8 03:20:24 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 08 Mar 2017 09:20:24 +0100 Subject: Better way to do this dict comprehesion References: Message-ID: Sayth Renshaw wrote: > Hi > > I have got this dictionary comprehension and it works but how can I do it > better? List comprehensions (that's what you have) are nice, but overused. > from collections import Counter > > def find_it(seq): > counts = dict(Counter(seq)) There is no need to convert Counter to dict. > a = [(k, v) for k,v in counts.items() if v % 3 == 0] > return a[0][0] > > test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5] > > so this returns 5 which is great and the point of the problem I was doing. > > Can also do it like this > def find_it(seq): > counts = dict(Counter(seq)) > a = [(k) for k,v in counts.items() if v % 3 == 0] > return a[0] > > But the given problem states there will always only be one number > appearing an odd number of times given that is there a neater way to get > the answer? If you mean there is only one number satisfying the v % 3 == 0 condition then there is no need to go through the whole sequence. The clearest way to express that is for k, v in counts.items(): if v % 3 == 0: return k raise ValueError but it = (k for k, v in counts.items() if v % 3 == 0) try: return next(it) except StopIteration: pass raise ValueError is also possible. The parens (...) instead of [...] make "it" generator expression which is evaluated lazily. Both alternatives shown above ensure that at least one value satisfies the condition "number of occurencies divides by three without rest". If you want to play it safe and verify that there is exactly one such key you may keep the listcomp, preferably that from your second implementation. a = [...] if len(a) != 1: raise ValueError return a[0] or [result] = a # will raise a ValueError if len(a) != 1 The complete code: >>> from collections import Counter >>> def find_it(seq): ... [result] = [k for k, v in Counter(seq).items() if v % 3 == 0] ... return result ... >>> test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5] >>> find_it(test_seq) 5 From saatomic at keemail.me Wed Mar 8 03:36:53 2017 From: saatomic at keemail.me (saatomic at keemail.me) Date: Wed, 8 Mar 2017 09:36:53 +0100 (CET) Subject: Alternative to signals in threads Message-ID: I've been unsuccessfully looking for an alternative for signals, that works in threads. After updating a script of mine from being single-threaded to being multi-threaded, I realised that signals do not work in threads. I've used signals to handle blocking operations that possibly take forever like: signal.signal(signal.SIGALRM, wait_timeout) # wait_timeout simply does: raise Exception("timeout") signal.setitimer(signal.ITIMER_REAL,5) # So a timer of 5 seconds start and I run my operation try: ??? ?? p = Popen(["tool", "--param"], stdin=PIPE, stdout=PIPE, stderr=STDOUT) ??? ?? for line in p.stdout: ??? ?????? ??? if "STRING" in str(line): ??? ?? ??? ?? ??? ?? signal.setitimer(signal.ITIMER_REAL,0) ??? ?? ??? ?? ??? ?? p.terminate() ??? ?? ??? ?? ??? ?? print("Success") except: ??? ?? p.terminate() ??? ?? print("Timeout") Now this works great with a single thread, but doesn't work at all with multiple threads. A more throughout example can be found here: https://gist.github.com/saatomic/841ddf9c5142a7c75b03daececa8eb17 What can I use instead of signals in this case? Thanks and kind regards, SaAtomic From yanyouhui at gmail.com Wed Mar 8 04:03:13 2017 From: yanyouhui at gmail.com (yanyouhui at gmail.com) Date: Wed, 8 Mar 2017 01:03:13 -0800 (PST) Subject: Run Python in iPad/iPhone Message-ID: <70b50a7d-3cfd-4cae-8197-07701b3e18fb@googlegroups.com> Analyser is the only iOS app that integrated both Python and R engines. build-in popular Python modules for stats/machine learning/image processing: numpy,scipy,matplotlib,scikit-learn,scikit-image,pandas,pymc,nilearn,astroML,statsmodels,astropy...... https://itunes.apple.com/cn/app/fen-xi-zhe/id1083042861?mt=8 If you just want get a testing version, pls let me know the email address of your Apple ID. From flebber.crue at gmail.com Wed Mar 8 04:52:30 2017 From: flebber.crue at gmail.com (Sayth Renshaw) Date: Wed, 8 Mar 2017 01:52:30 -0800 (PST) Subject: Better way to do this dict comprehesion In-Reply-To: References: Message-ID: <412d91cb-e90c-4e08-a8f5-f2f1e25ce48a@googlegroups.com> Peter I really like this The complete code: >>> from collections import Counter >>> def find_it(seq): ... [result] = [k for k, v in Counter(seq).items() if v % 3 == 0] ... return result ... >>> test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5] >>> find_it(test_seq) But what may be the smallest thing in this i had no idea I could do [result] = blah and get a generator on the return variable that seems insane. Cheers Sayth From __peter__ at web.de Wed Mar 8 05:36:46 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 08 Mar 2017 11:36:46 +0100 Subject: Better way to do this dict comprehesion References: <412d91cb-e90c-4e08-a8f5-f2f1e25ce48a@googlegroups.com> Message-ID: Sayth Renshaw wrote: > Peter I really like this > > The complete code: > >>>> from collections import Counter >>>> def find_it(seq): > ... [result] = [k for k, v in Counter(seq).items() if v % 3 == 0] > ... return result > ... >>>> test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5] >>>> find_it(test_seq) > > But what may be the smallest thing in this i had no idea I could do > [result] = blah and get a generator on the return variable that seems > insane. Usually this is done with tuples >>> left, sep, right = "foo.bar".partition(".") # looks familiar? rather than the alternative spelling >>> [left, sep, right] = "foo.bar".partition(".") However, a 1-tuple is just a trailing comma and easy to overlook, so i prefer >>> items = [42] >>> [foo] = items >>> foo 42 over >>> bar, = items >>> bar 42 From jussi.piitulainen at helsinki.fi Wed Mar 8 06:57:05 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 08 Mar 2017 13:57:05 +0200 Subject: Better way to do this dict comprehesion References: <412d91cb-e90c-4e08-a8f5-f2f1e25ce48a@googlegroups.com> Message-ID: Sayth Renshaw writes: > Peter I really like this > > The complete code: > >>>> from collections import Counter >>>> def find_it(seq): > ... [result] = [k for k, v in Counter(seq).items() if v % 3 == 0] > ... return result You confirmed to Chris that you want the item that occurs an odd number of times. The test for that is v % 2 == 1. Or just v % 2, given that 0 and 1 are considered false and true, resp. But v % 3 == 0 is something else. From jussi.piitulainen at helsinki.fi Wed Mar 8 07:13:04 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 08 Mar 2017 14:13:04 +0200 Subject: Better way to do this dict comprehesion References: <43bc9a64-d343-48d6-a916-5d53b8e74cb9@googlegroups.com> Message-ID: Sayth Renshaw writes: >> To find an unpaired number in linear time with minimal space, try >> stepping through the list and either adding to a set or removing from >> it. At the end, your set should contain exactly one element. I'll let >> you write the actual code :) >> >> ChrisA > > ChrisA the way it sounds through the list is like filter with map and > a lambda. http://www.python-course.eu/lambda.php Haven't had a good go > yet... will see how it goes. You mean reduce(xor, map(lambda o : {o}. With suitable imports. I think Chris is suggesting the same thing but in the piecemeal way of updating a set at each element. You can test for membership, o in res, and then res.add(o) or res.remove(o) depending on the test. And you need to say set() to make an empty set, because {} is dict(). Your input sequence is guaranteed non-empty, but it's simply easier to start with an empty res. From cl at isbd.net Wed Mar 8 14:27:17 2017 From: cl at isbd.net (Chris Green) Date: Wed, 8 Mar 2017 19:27:17 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? Message-ID: I have a fairly simple application that populates a GUI window with fields from a database table. The fields are defined/configured by a dictionary as follows:- # # # Address Book field details, dictionary key is the database column # dbcol = {} dbcol['firstname'] = col('First Name', True, False) dbcol['lastname'] = col('Last Name', True, False) dbcol['email'] = col('E-Mail', True, True) dbcol['phone'] = col('Phone', True, True) dbcol['mobile'] = col('Mobile', True, True) dbcol['address'] = col('Address', True, False) dbcol['town'] = col('Town/City', True, False) dbcol['county'] = col('County/Region', True, False) dbcol['postcode'] = col('PostCode', True, False) dbcol['country'] = col('Country', True, False) dbcol['notes'] = col('Notes', True, False) dbcol['www'] = col('Web Page', True, True) dbcol['categories'] = col('Categories', True, True) How can I get the fields in the GUI window in the order I want rather than the fairly random order that they appear in at the moment? Currently the GUI fields are populated by a for loop as follows:- # # # Put values into the fields # i = 0 for col, field in abookdb.dbcol.items(): print(field.heading) if (i > numkeys/2): self.addfieldentry(col, address, field, self.rtable, i-numkeys/2) else: self.addfieldentry(col, address, field, self.ltable, i) i = i + 1 The for loop gets the items from the dictionary in an order that isn't what I want. How can I configure things so they're in the order I want? -- Chris Green ? From ethan at stoneleaf.us Wed Mar 8 14:40:48 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 08 Mar 2017 11:40:48 -0800 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: Message-ID: <58C05E40.80807@stoneleaf.us> On 03/08/2017 11:27 AM, Chris Green wrote: > The for loop gets the items from the dictionary in an order that isn't > what I want. How can I configure things so they're in the order I want? What order do you want? -- ~Ethan~ From jussi.piitulainen at helsinki.fi Wed Mar 8 14:48:13 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 08 Mar 2017 21:48:13 +0200 Subject: What's the neatest way of getting dictionary entries in a specified order? References: Message-ID: Chris Green writes: > I have a fairly simple application that populates a GUI window with > fields from a database table. The fields are defined/configured by a > dictionary as follows:- > > # > # > # Address Book field details, dictionary key is the database column > # > dbcol = {} > dbcol['firstname'] = col('First Name', True, False) > dbcol['lastname'] = col('Last Name', True, False) > dbcol['email'] = col('E-Mail', True, True) > dbcol['phone'] = col('Phone', True, True) > dbcol['mobile'] = col('Mobile', True, True) > dbcol['address'] = col('Address', True, False) > dbcol['town'] = col('Town/City', True, False) > dbcol['county'] = col('County/Region', True, False) > dbcol['postcode'] = col('PostCode', True, False) > dbcol['country'] = col('Country', True, False) > dbcol['notes'] = col('Notes', True, False) > dbcol['www'] = col('Web Page', True, True) > dbcol['categories'] = col('Categories', True, True) > > How can I get the fields in the GUI window in the order I want rather > than the fairly random order that they appear in at the moment? Look up OrderedDict in the collections module. From cl at isbd.net Wed Mar 8 15:23:35 2017 From: cl at isbd.net (Chris Green) Date: Wed, 8 Mar 2017 20:23:35 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? References: <58C05E40.80807@stoneleaf.us> Message-ID: <7r56pd-6ag.ln1@esprimo.zbmc.eu> Ethan Furman wrote: > On 03/08/2017 11:27 AM, Chris Green wrote: > > > The for loop gets the items from the dictionary in an order that isn't > > what I want. How can I configure things so they're in the order I want? > > What order do you want? > Well probably the First Name and Last Name, then phone or E-Mail. But it hardly matters, I just want to be able to specify the order. -- Chris Green ? From cl at isbd.net Wed Mar 8 15:28:07 2017 From: cl at isbd.net (Chris Green) Date: Wed, 8 Mar 2017 20:28:07 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? References: Message-ID: Jussi Piitulainen wrote: > Chris Green writes: > > > I have a fairly simple application that populates a GUI window with > > fields from a database table. The fields are defined/configured by a > > dictionary as follows:- > > > > # > > # > > # Address Book field details, dictionary key is the database column > > # > > dbcol = {} > > dbcol['firstname'] = col('First Name', True, False) > > dbcol['lastname'] = col('Last Name', True, False) > > dbcol['email'] = col('E-Mail', True, True) > > dbcol['phone'] = col('Phone', True, True) > > dbcol['mobile'] = col('Mobile', True, True) > > dbcol['address'] = col('Address', True, False) > > dbcol['town'] = col('Town/City', True, False) > > dbcol['county'] = col('County/Region', True, False) > > dbcol['postcode'] = col('PostCode', True, False) > > dbcol['country'] = col('Country', True, False) > > dbcol['notes'] = col('Notes', True, False) > > dbcol['www'] = col('Web Page', True, True) > > dbcol['categories'] = col('Categories', True, True) > > > > How can I get the fields in the GUI window in the order I want rather > > than the fairly random order that they appear in at the moment? > > Look up OrderedDict in the collections module. Thanks, that's what I need. -- Chris Green ? From gvmcmt at gmail.com Wed Mar 8 15:42:45 2017 From: gvmcmt at gmail.com (gvmcmt at gmail.com) Date: Wed, 8 Mar 2017 12:42:45 -0800 (PST) Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: Message-ID: <6f9ad905-c632-4759-8bd1-ccd80dedbf74@googlegroups.com> On Thursday, March 9, 2017 at 1:03:31 AM UTC+5:30, Chris Green wrote: > I have a fairly simple application that populates a GUI window with > fields from a database table. The fields are defined/configured by a > dictionary as follows:- > > # > # > # Address Book field details, dictionary key is the database column > # > dbcol = {} > dbcol['firstname'] = col('First Name', True, False) > dbcol['lastname'] = col('Last Name', True, False) > dbcol['email'] = col('E-Mail', True, True) > dbcol['phone'] = col('Phone', True, True) > dbcol['mobile'] = col('Mobile', True, True) > dbcol['address'] = col('Address', True, False) > dbcol['town'] = col('Town/City', True, False) > dbcol['county'] = col('County/Region', True, False) > dbcol['postcode'] = col('PostCode', True, False) > dbcol['country'] = col('Country', True, False) > dbcol['notes'] = col('Notes', True, False) > dbcol['www'] = col('Web Page', True, True) > dbcol['categories'] = col('Categories', True, True) > > How can I get the fields in the GUI window in the order I want rather > than the fairly random order that they appear in at the moment? > > Currently the GUI fields are populated by a for loop as follows:- > > # > # > # Put values into the fields > # > i = 0 > for col, field in abookdb.dbcol.items(): > print(field.heading) > if (i > numkeys/2): > self.addfieldentry(col, address, field, self.rtable, i-numkeys/2) > else: > self.addfieldentry(col, address, field, self.ltable, i) > i = i + 1 > > The for loop gets the items from the dictionary in an order that isn't > what I want. How can I configure things so they're in the order I want? > > -- > Chris Green > ? There is OrderedDict. https://docs.python.org/2/library/collections.html#collections.OrderedDict https://docs.python.org/3/library/collections.html#collections.OrderedDict From rosuav at gmail.com Wed Mar 8 15:52:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Mar 2017 07:52:16 +1100 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: Message-ID: On Thu, Mar 9, 2017 at 6:27 AM, Chris Green wrote: > dbcol['firstname'] = col('First Name', True, False) > dbcol['lastname'] = col('Last Name', True, False) http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ ChrisA From cl at isbd.net Wed Mar 8 16:25:34 2017 From: cl at isbd.net (Chris Green) Date: Wed, 8 Mar 2017 21:25:34 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? References: Message-ID: Chris Angelico wrote: > On Thu, Mar 9, 2017 at 6:27 AM, Chris Green wrote: > > dbcol['firstname'] = col('First Name', True, False) > > dbcol['lastname'] = col('Last Name', True, False) > > http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ > Yes, I'm well aware of these issues, but it's my personal address book so I can avoid many/most of them. -- Chris Green ? From rosuav at gmail.com Wed Mar 8 17:10:18 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Mar 2017 09:10:18 +1100 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: Message-ID: On Thu, Mar 9, 2017 at 8:25 AM, Chris Green wrote: > Chris Angelico wrote: >> On Thu, Mar 9, 2017 at 6:27 AM, Chris Green wrote: >> > dbcol['firstname'] = col('First Name', True, False) >> > dbcol['lastname'] = col('Last Name', True, False) >> >> http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ >> > Yes, I'm well aware of these issues, but it's my personal address book > so I can avoid many/most of them. So you assume that you'll never meet someone from another culture? Okay. I'm pretty sure that counts as bigoted, but sure :) As a general rule, it's safest to just have a single "name" field and have done with it. ChrisA From woooee at gmail.com Wed Mar 8 21:25:46 2017 From: woooee at gmail.com (woooee at gmail.com) Date: Wed, 8 Mar 2017 18:25:46 -0800 (PST) Subject: Alternative to signals in threads In-Reply-To: References: Message-ID: Use multiprocessing since you want to do multiple things at once https://pymotw.com/2/multiprocessing/basics.html If I understand you correctly, once the string is found you would terminate the process, so you would have to signal the calling portion of the code using a Manager dictionary or list.. I am not that knowledgeable about multiprocessing, so this is probably the long way around the barn. import time from multiprocessing import Process, Manager def test_f(test_d): ctr=0 while True: ctr += 1 print "test_f", test_d["QUIT"], ctr time.sleep(1.0) if ctr > 5: test_d["QUIT"]=True if __name__ == '__main__': ## define the dictionary to be used to communicate manager = Manager() test_d = manager.dict() test_d["QUIT"] = False ## start the process p = Process(target=test_f, args=(test_d,)) p.start() ## check the dictionary every half-second while not test_d["QUIT"]: time.sleep(0.5) p.terminate() From torriem at gmail.com Wed Mar 8 23:31:00 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 8 Mar 2017 21:31:00 -0700 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: Message-ID: <8f090d66-b3d2-00ac-ca5b-5745d96a11b7@gmail.com> On 03/08/2017 12:27 PM, Chris Green wrote: > I have a fairly simple application that populates a GUI window with > fields from a database table. The fields are defined/configured by a > dictionary as follows:- Instead of ordering the data in Python, why not rely on the GUI to do the sort? Most GUI's even have table widgets that let you click on the headings to sort arbitrarily. From mail at timgolden.me.uk Thu Mar 9 03:45:11 2017 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 9 Mar 2017 08:45:11 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: Message-ID: On 08/03/2017 22:10, Chris Angelico wrote: > On Thu, Mar 9, 2017 at 8:25 AM, Chris Green wrote: >> Chris Angelico wrote: >>> On Thu, Mar 9, 2017 at 6:27 AM, Chris Green wrote: >>>> dbcol['firstname'] = col('First Name', True, False) >>>> dbcol['lastname'] = col('Last Name', True, False) >>> >>> http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ >>> >> Yes, I'm well aware of these issues, but it's my personal address book >> so I can avoid many/most of them. > > So you assume that you'll never meet someone from another culture? > Okay. I'm pretty sure that counts as bigoted, but sure :) Chris: I think that remark was uncalled for. You'd made a perfectly valid point about names not always working how we think. At that point, I think it's up to each person to decide their own approach based on their own knowledge of their own circumstances. TJG From rosuav at gmail.com Thu Mar 9 04:01:43 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Mar 2017 20:01:43 +1100 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: Message-ID: On Thu, Mar 9, 2017 at 7:45 PM, Tim Golden wrote: >> So you assume that you'll never meet someone from another culture? >> Okay. I'm pretty sure that counts as bigoted, but sure :) > > > Chris: I think that remark was uncalled for. You'd made a perfectly valid > point about names not always working how we think. At that point, I think > it's up to each person to decide their own approach based on their own > knowledge of their own circumstances. Yep. He's free to assume that not one of his friends will be from any culture other than his own. It just happens to be a bigoted viewpoint. I wonder, would people treat it differently if the address book took a traditional binary view of gender, and required that everyone be precisely "male" or "female"? Would that be called bigoted, or is it perfectly reasonable to demand that all of your friends fit this? ChrisA From therealmushmouth at gmail.com Thu Mar 9 04:24:16 2017 From: therealmushmouth at gmail.com (Patrick McFarling) Date: Thu, 9 Mar 2017 01:24:16 -0800 (PST) Subject: Web Frameworks Message-ID: I would like to know what are the pros and cons of the web frameworks made in python. The one I tend to lean towards is Flask. From david.froger.ml at mailoo.org Thu Mar 9 04:49:50 2017 From: david.froger.ml at mailoo.org (David Froger) Date: Thu, 09 Mar 2017 10:49:50 +0100 Subject: Web Frameworks In-Reply-To: References: Message-ID: <148905299090.7517.11776694963655039718@david.securactive.lan> There is a free ebook on the subject on O'Reilly: http://www.oreilly.com/web-platform/free/python-web-frameworks.csp Hope it helps, David Quoting Patrick McFarling (2017-03-09 10:24:16) > I would like to know what are the pros and cons of the web frameworks made in python. > The one I tend to lean towards is Flask. > -- > https://mail.python.org/mailman/listinfo/python-list From antoon.pardon at rece.vub.ac.be Thu Mar 9 04:58:18 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Mar 2017 10:58:18 +0100 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: Message-ID: Op 09-03-17 om 10:01 schreef Chris Angelico: > On Thu, Mar 9, 2017 at 7:45 PM, Tim Golden wrote: >>> So you assume that you'll never meet someone from another culture? >>> Okay. I'm pretty sure that counts as bigoted, but sure :) >> >> Chris: I think that remark was uncalled for. You'd made a perfectly valid >> point about names not always working how we think. At that point, I think >> it's up to each person to decide their own approach based on their own >> knowledge of their own circumstances. > Yep. He's free to assume that not one of his friends will be from any > culture other than his own. It just happens to be a bigoted viewpoint. He didn't make that assumption. -- Antoon Pardon From rosuav at gmail.com Thu Mar 9 06:32:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Mar 2017 22:32:33 +1100 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: Message-ID: On Thu, Mar 9, 2017 at 8:58 PM, Antoon Pardon wrote: > Op 09-03-17 om 10:01 schreef Chris Angelico: >> On Thu, Mar 9, 2017 at 7:45 PM, Tim Golden wrote: >>>> So you assume that you'll never meet someone from another culture? >>>> Okay. I'm pretty sure that counts as bigoted, but sure :) >>> >>> Chris: I think that remark was uncalled for. You'd made a perfectly valid >>> point about names not always working how we think. At that point, I think >>> it's up to each person to decide their own approach based on their own >>> knowledge of their own circumstances. >> Yep. He's free to assume that not one of his friends will be from any >> culture other than his own. It just happens to be a bigoted viewpoint. > > He didn't make that assumption. He did. On Thu, Mar 9, 2017 at 8:25 AM, Chris Green wrote: > Yes, I'm well aware of these issues, but it's my personal address book > so I can avoid many/most of them. The justification "it's *my* personal address book" is saying "none of *my* friends have weird names, so I'm fine". So, yeah, he did. This is a design flaw on par with assuming that a byte is identical to a character; you can pretend it so long as you don't get any "funny characters". And then you can blame the non-ASCII characters for breaking your program, or force someone's name to fit into your predefined scheme. ChrisA From antoon.pardon at rece.vub.ac.be Thu Mar 9 07:06:58 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Mar 2017 13:06:58 +0100 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: Message-ID: <87fb0788-f071-2d3f-963b-ef6f8c646bb3@rece.vub.ac.be> Op 09-03-17 om 12:32 schreef Chris Angelico: > On Thu, Mar 9, 2017 at 8:25 AM, Chris Green wrote: >> Yes, I'm well aware of these issues, but it's my personal address book >> so I can avoid many/most of them. > The justification "it's *my* personal address book" is saying "none of > *my* friends have weird names, so I'm fine". So, yeah, he did. No he didn't, you are reading conclusions into his words that aren't there. An other possibility is that it is his personal address book, so he is at liberty to handle those weird names as he sees fit. He doesn't own anyone an explanation of how he organises his own personal address book. Just because you can only think of one conclusion to draw from his words, doesn't mean that is the only possible conclusion. -- Antoon Pardon. From rosuav at gmail.com Thu Mar 9 07:16:32 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Mar 2017 23:16:32 +1100 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: <87fb0788-f071-2d3f-963b-ef6f8c646bb3@rece.vub.ac.be> References: <87fb0788-f071-2d3f-963b-ef6f8c646bb3@rece.vub.ac.be> Message-ID: On Thu, Mar 9, 2017 at 11:06 PM, Antoon Pardon wrote: > Op 09-03-17 om 12:32 schreef Chris Angelico: > >> On Thu, Mar 9, 2017 at 8:25 AM, Chris Green wrote: >>> Yes, I'm well aware of these issues, but it's my personal address book >>> so I can avoid many/most of them. >> The justification "it's *my* personal address book" is saying "none of >> *my* friends have weird names, so I'm fine". So, yeah, he did. > > No he didn't, you are reading conclusions into his words that aren't > there. An other possibility is that it is his personal address book, > so he is at liberty to handle those weird names as he sees fit. He > doesn't own anyone an explanation of how he organises his own personal > address book. > You're still assuming that there are such things as "weird names". As of Python 3, we've finally moved beyond the notion that there are "weird characters" that don't fit into our nice tidy system where one character is the same as one byte. We need to give people's names the same courtesy. They are not "weird" names. They are 100% legitimate names that should be welcomed into any system that accepts names. (That said, though, I think it's not unreasonable to demand that names be represented entirely in Unicode - falsehood #11 - as it's extremely hard to deal with non-Unicode text. But you have to understand that you'll be asking some number of people to represent themselves differently for the convenience of your code.) ChrisA From cl at isbd.net Thu Mar 9 08:03:54 2017 From: cl at isbd.net (Chris Green) Date: Thu, 9 Mar 2017 13:03:54 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? References: Message-ID: Chris Angelico wrote: > On Thu, Mar 9, 2017 at 8:25 AM, Chris Green wrote: > > Chris Angelico wrote: > >> On Thu, Mar 9, 2017 at 6:27 AM, Chris Green wrote: > >> > dbcol['firstname'] = col('First Name', True, False) > >> > dbcol['lastname'] = col('Last Name', True, False) > >> > >> http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ > >> > > Yes, I'm well aware of these issues, but it's my personal address book > > so I can avoid many/most of them. > > So you assume that you'll never meet someone from another culture? > Okay. I'm pretty sure that counts as bigoted, but sure :) > > As a general rule, it's safest to just have a single "name" field and > have done with it. > Which doesn't work at all for me as I want to:- Sort on family/last name Separate first and family name so I can write addresses etc. I've lived in quite a few different places where names are not formatted like ours. I'm aiming to add 'nameprefix' and 'namesuffix' fields to handle different formats more completely, the layout I showed here is just a prototype. -- Chris Green ? From cl at isbd.net Thu Mar 9 08:07:51 2017 From: cl at isbd.net (Chris Green) Date: Thu, 9 Mar 2017 13:07:51 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? References: Message-ID: <7m08pd-mk4.ln1@esprimo.zbmc.eu> Chris Angelico wrote: > On Thu, Mar 9, 2017 at 7:45 PM, Tim Golden wrote: > >> So you assume that you'll never meet someone from another culture? > >> Okay. I'm pretty sure that counts as bigoted, but sure :) > > > > > > Chris: I think that remark was uncalled for. You'd made a perfectly valid > > point about names not always working how we think. At that point, I think > > it's up to each person to decide their own approach based on their own > > knowledge of their own circumstances. > > Yep. He's free to assume that not one of his friends will be from any > culture other than his own. It just happens to be a bigoted viewpoint. > I think I probably have more friends from 'other cultures' than most as I lived in the arab world for ten years and have spent a considerable time in various other places too. I personally am not upset when people elsewhere have a problem with my name because it doesn't fit *their* norms so I don't expect them to get all upset when the same happens the other way around. It's inevitable that things like this will happen, one just lives with it or works around it. -- Chris Green ? From cl at isbd.net Thu Mar 9 08:09:50 2017 From: cl at isbd.net (Chris Green) Date: Thu, 9 Mar 2017 13:09:50 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? References: <8f090d66-b3d2-00ac-ca5b-5745d96a11b7@gmail.com> Message-ID: Michael Torrie wrote: > On 03/08/2017 12:27 PM, Chris Green wrote: > > I have a fairly simple application that populates a GUI window with > > fields from a database table. The fields are defined/configured by a > > dictionary as follows:- > > Instead of ordering the data in Python, why not rely on the GUI to do > the sort? Most GUI's even have table widgets that let you click on the > headings to sort arbitrarily. > How would it sort it? The order I want is arbitrary, or at least not alphabetical or anything, I just want the order to be the way I listed it. -- Chris Green ? From borysova.mary at gmail.com Thu Mar 9 08:34:21 2017 From: borysova.mary at gmail.com (borysova.mary at gmail.com) Date: Thu, 9 Mar 2017 05:34:21 -0800 (PST) Subject: Database security tool for Python apps with PostgreSQL backend. Message-ID: <088e9111-9dba-476b-8961-6b3418d1f799@googlegroups.com> Database security tool for Python apps with PostgreSQL backend: https://www.cossacklabs.com/blog/presenting-acra.html From antoon.pardon at rece.vub.ac.be Thu Mar 9 08:58:25 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Thu, 9 Mar 2017 14:58:25 +0100 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: <87fb0788-f071-2d3f-963b-ef6f8c646bb3@rece.vub.ac.be> Message-ID: <3ce5cf56-a403-4130-8cbf-747a743148b0@rece.vub.ac.be> Op 09-03-17 om 13:16 schreef Chris Angelico: > On Thu, Mar 9, 2017 at 11:06 PM, Antoon Pardon > wrote: >> Op 09-03-17 om 12:32 schreef Chris Angelico: >> >>> On Thu, Mar 9, 2017 at 8:25 AM, Chris Green wrote: >>>> Yes, I'm well aware of these issues, but it's my personal address book >>>> so I can avoid many/most of them. >>> The justification "it's *my* personal address book" is saying "none of >>> *my* friends have weird names, so I'm fine". So, yeah, he did. >> No he didn't, you are reading conclusions into his words that aren't >> there. An other possibility is that it is his personal address book, >> so he is at liberty to handle those weird names as he sees fit. He >> doesn't own anyone an explanation of how he organises his own personal >> address book. >> > You're still assuming that there are such things as "weird names". You are the one that started to use the word "weird". Please don't draw conclusions about what I assume, just because I followed your word choice. > As > of Python 3, we've finally moved beyond the notion that there are > "weird characters" that don't fit into our nice tidy system where one > character is the same as one byte. We need to give people's names the > same courtesy. They are not "weird" names. They are 100% legitimate > names that should be welcomed into any system that accepts names. > > (That said, though, I think it's not unreasonable to demand that names > be represented entirely in Unicode - falsehood #11 - as it's extremely > hard to deal with non-Unicode text. But you have to understand that > you'll be asking some number of people to represent themselves > differently for the convenience of your code.) But you don't know whether he is using unicode or not. And if he is not, it still is his own personal address book and he is allowed to transliterate the names he enters any way he likes. If he has a French friend with the name "Pi?rre", he is allowed to enter it as "Pjair" in his personal address book if he thinks that would help him to pronounce it more correctly. So he is not asking a number of people to represent themselves differently because this is not something for different people to use, it is his personal address book. -- Antoon Pardon. From dbastos at toledo.com Thu Mar 9 13:44:23 2017 From: dbastos at toledo.com (Daniel Bastos) Date: Thu, 09 Mar 2017 15:44:23 -0300 Subject: "Best" websocket implementation for Python 2.x? References: Message-ID: <86tw72guig.fsf@toledo.com> Skip Montanaro writes: [...] > These two packages would appear to have stalled. Looking around, I also > found > > ws4py > websockets - Python 3.3 or later > autobahn.websocket > > There are probably others I haven't yet stumbled upon. (I'd continue poking > around PyPI, but it seems the server is having problems.) It seems you didn't Tornado yet. http://www.tornadoweb.org/en/stable/ [...] From saxri89 at gmail.com Thu Mar 9 14:15:18 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Thu, 9 Mar 2017 11:15:18 -0800 (PST) Subject: python/gui question Message-ID: <6d76725d-284e-4013-ac83-3e2c872352de@googlegroups.com> i want to create a very simple python plugin using QT designer but i an not sure how to connect my variable from gui to my python script. my gui is simple have only one lineEdit and ok or cancel. in the gui (widget): 20 90 171 31 def run(self): self.dlg.show() result = self.dlg.exec_() if result: distance = self.dlg.lineEdit.value() if distance == 0: #do something else: #do sothing else pass i test this code but dont work dont show me anything. any idea ? From therealmushmouth at gmail.com Thu Mar 9 15:29:29 2017 From: therealmushmouth at gmail.com (Patrick McFarling) Date: Thu, 9 Mar 2017 12:29:29 -0800 (PST) Subject: Web Frameworks In-Reply-To: References: <148905299090.7517.11776694963655039718@david.securactive.lan> Message-ID: <89d4810f-d48e-4cde-a83b-d71ea9d01c2b@googlegroups.com> On Thursday, 9 March 2017 05:05:37 UTC-5, David Froger wrote: > There is a free ebook on the subject on O'Reilly: > http://www.oreilly.com/web-platform/free/python-web-frameworks.csp > > Hope it helps, > David > > > Quoting Patrick McFarling (2017-03-09 10:24:16) > > I would like to know what are the pros and cons of the web frameworks made in python. > > The one I tend to lean towards is Flask. > > -- > > https://mail.python.org/mailman/listinfo/python-list Thanks for the book! From cl at isbd.net Thu Mar 9 15:48:25 2017 From: cl at isbd.net (Chris Green) Date: Thu, 9 Mar 2017 20:48:25 +0000 Subject: Gtk.Label text positioning Message-ID: Is there any way to postion different lines of text in a Gtk.Label in different ways? E.g. is it possible to centre one line of text and left justify the remainder? Or does one simply have two Gtk.Label instances, one with centred text and one with left justified text. -- Chris Green ? From hpj at urpla.net Thu Mar 9 16:03:29 2017 From: hpj at urpla.net (Hans-Peter Jansen) Date: Thu, 09 Mar 2017 22:03:29 +0100 Subject: keyrings.cryptfile released on github Message-ID: <2356566.kSNyJECJKv@xrated> Hi, since the PyCrypto ML is dead, I'm looking for advise/feedback from some cryptography aware people. I've released a keyring companion package today: https://github.com/frispete/keyrings.cryptfile Its primary purpose is a decent encrypted file backend for python keyrings. As such, it uses manually parameterized argon2 hashes as KDF, and AES in OCB mode as stream cipher (well, it just encrypts the password for a given service/user name). Granted, the advantages of OCB are not /that/ crucial here :wink:, but apart from technical factors, the exclusion of military uses by its license is rather *attractive* from my POV(!). But I'm open for discussions of course. Still interested? Here we go: To get you started, I expect you to have a python3 environment and git available. You might want to provide the packages argon2-cffi, keyring, pycryptodome and their dependencies (most notably SecretStorage and cryptography, or use a local venv, but that will depend on a compiler and some development packages. Example session, create an encrypted keyring: $ git clone https://github.com/frispete/keyrings.cryptfile $ cd keyrings.cryptfile $ pyvenv env $ . env/bin/activate (env) $ pip install -e . [...] # should succeed, some development packages might be missing otherwise (env) $ python3 Python 3.4.5 (default, Jul 03 2016, 12:57:15) [GCC] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from keyrings.cryptfile.cryptfile import CryptFileKeyring >>> kr = CryptFileKeyring() >>> kr.set_password("service", "user", "secret") Please set a password for your new keyring: Please confirm the password: >>> ^d Second session, retrieve the stored secret from the keyring: (env) $ python3 Python 3.4.5 (default, Jul 03 2016, 12:57:15) [GCC] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from keyrings.cryptfile.cryptfile import CryptFileKeyring >>> kr = CryptFileKeyring() >>> kr.get_password("service", "user") Please enter password for encrypted keyring: 'secret' >>> ^d Note, that the KDF might delay the {set,get}_password() operations for a few seconds (~1 sec. on a capable system). The resulting file is located here (by default) and might look similar to: (env) $ cat ~/.local/share/python_keyring/cryptfile_pass.cfg [keyring_2Dsetting] password_20reference = eyJub25jZSI6ICJQdVdWVUIwUHNYbEFqYUUxZ2l2RlxuIiwgIm1hYyI6ICIvVTFIVDBWTnRheTFl TjA5TVlHb0dRPT1cbiIsICJzYWx0IjogIklMdDNBU1hMUENrbWZ2NzFudmtBSUE9PVxuIiwgImRh dGEiOiAidW1EQkNvQ2dRUTk5WEVaNkZ4NWt3NXRkSUZDOHFIUE5ZOHhWXG4ifQ== scheme = PyCryptodome [Argon2] AES OCB version = 1.0 [service] user = eyJub25jZSI6ICI5SUU3UGp2eDU2SXNQdHlLUGRtaFxuIiwgIm1hYyI6ICJKcFR1NXMxaDd0UGlW OW9XL3d5cFdBPT1cbiIsICJzYWx0IjogIlpBeEhJdXlqYnRuTkgzb3BMNTFvdkE9PVxuIiwgImRh dGEiOiAiT2I3Z1JJbXR5aVJLXG4ifQ== The values can be decoded like this: (env) $ python3 >>> import base64 >>> base64.decodebytes(b""" ... eyJub25jZSI6ICI5SUU3UGp2eDU2SXNQdHlLUGRtaFxuIiwgIm1hYyI6ICJKcFR1NXMxaDd0UGlW ... OW9XL3d5cFdBPT1cbiIsICJzYWx0IjogIlpBeEhJdXlqYnRuTkgzb3BMNTFvdkE9PVxuIiwgImRh ... dGEiOiAiT2I3Z1JJbXR5aVJLXG4ifQ==""") b'{"nonce": "9IE7Pjvx56IsPtyKPdmh\\n", "mac": "JpTu5s1h7tPiV9oW/wypWA==\\n", "salt": "ZAxHIuyjbtnNH3opL51ovA==\\n", "data": "Ob7gRImtyiRK\\n"}' The items should be self explanatory. In theory, it should be considerable hard to get back to the plain values of data without knowing the password. Any cryptography experts attending? What do you think? The class hierarchy is inherited from keyrings.alt, and not exactly easy to follow, but the interesting parts are all in cryptfile, which is quite brief. I would be glad to hear something from you about my handling of cryptography. Is it ready for the public in that form or should I better locked away? :wink: TIA, Pete From python at lucidity.plus.com Thu Mar 9 17:30:01 2017 From: python at lucidity.plus.com (Erik) Date: Thu, 9 Mar 2017 22:30:01 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: <8f090d66-b3d2-00ac-ca5b-5745d96a11b7@gmail.com> Message-ID: <4c80c74c-16f3-26d5-0a31-2cdeef0216fa@lucidity.plus.com> On 09/03/17 13:09, Chris Green wrote: > Michael Torrie wrote: >> On 03/08/2017 12:27 PM, Chris Green wrote: >>> I have a fairly simple application that populates a GUI window with >>> fields from a database table. The fields are defined/configured by a >>> dictionary as follows:- >> >> Instead of ordering the data in Python, why not rely on the GUI to do >> the sort? Most GUI's even have table widgets that let you click on the >> headings to sort arbitrarily. >> > How would it sort it? The order I want is arbitrary, or at least not > alphabetical or anything, I just want the order to be the way I > listed it. To be fair to Michael, you did not state your required order in the message that he replied to. You just kept saying "the order I want". If you're going to make people guess, don't chastise them for guessing wrong :D E. From contact.ng0 at cryptolab.net Thu Mar 9 18:09:09 2017 From: contact.ng0 at cryptolab.net (ng0) Date: Thu, 9 Mar 2017 23:09:09 +0000 Subject: keyrings.cryptfile released on github In-Reply-To: <2356566.kSNyJECJKv@xrated> References: <2356566.kSNyJECJKv@xrated> Message-ID: <20170309230909.hl3zg2llxazwiypu@abyayala> Hans-Peter Jansen transcribed 3.8K bytes: > Hi, > > since the PyCrypto ML is dead, I'm looking for advise/feedback from some > cryptography aware people. > > I've released a keyring companion package today: > > https://github.com/frispete/keyrings.cryptfile > > Its primary purpose is a decent encrypted file backend for python keyrings. > As such, it uses manually parameterized argon2 hashes as KDF, and AES in OCB > mode as stream cipher (well, it just encrypts the password for a given > service/user name). Granted, the advantages of OCB are not /that/ crucial > here :wink:, but apart from technical factors, the exclusion of military uses I was looking for some proprietary EULA or something else locked down license and instead just saw the Expat license. I assume that you are aware that no anti-mil clause exists in co-existence with free software licenses and your sentence was just written in an odd way? > by its license is rather *attractive* from my POV(!). But I'm open for > discussions of course. [...] > What do you think? The class hierarchy is inherited from keyrings.alt, and > not exactly easy to follow, but the interesting parts are all in cryptfile, > which is quite brief. > > I would be glad to hear something from you about my handling of cryptography. > Is it ready for the public in that form or should I better locked away? :wink: > > TIA, > Pete > > -- > https://mail.python.org/mailman/listinfo/python-list From no.email at nospam.invalid Thu Mar 9 19:24:12 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 09 Mar 2017 16:24:12 -0800 Subject: keyrings.cryptfile released on github References: <2356566.kSNyJECJKv@xrated> Message-ID: <87h932t1w3.fsf@nightsong.com> Hans-Peter Jansen writes: > I've released a keyring companion package today: > https://github.com/frispete/keyrings.cryptfile Interesting, I'll take a look at it. I wrote something like it many years ago but never did much with it. Thanks for posting! From loza_pl at hotmail.com Thu Mar 9 21:38:22 2017 From: loza_pl at hotmail.com (Pablo Lozano) Date: Fri, 10 Mar 2017 02:38:22 +0000 Subject: Unsubscribe to Python email list Message-ID: <6DD74957-1E1E-4EB3-A1C0-EF7F26392411@hotmail.com> Good day, I would like to unsubscribe this e-mail to the Python e-mail list. Kind regards From python at mrabarnett.plus.com Thu Mar 9 23:06:36 2017 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 10 Mar 2017 04:06:36 +0000 Subject: Unsubscribe to Python email list In-Reply-To: <6DD74957-1E1E-4EB3-A1C0-EF7F26392411@hotmail.com> References: <6DD74957-1E1E-4EB3-A1C0-EF7F26392411@hotmail.com> Message-ID: On 2017-03-10 02:38, Pablo Lozano wrote: > Good day, > > I would like to unsubscribe this e-mail to the Python e-mail list. > > Kind regards > You'll have to do it yourself. Read this: https://mail.python.org/mailman/listinfo/python-list The relevant bit is in the section titled "Python-list Subscribers". From cl at isbd.net Fri Mar 10 03:43:41 2017 From: cl at isbd.net (Chris Green) Date: Fri, 10 Mar 2017 08:43:41 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? References: <8f090d66-b3d2-00ac-ca5b-5745d96a11b7@gmail.com> <4c80c74c-16f3-26d5-0a31-2cdeef0216fa@lucidity.plus.com> Message-ID: Erik wrote: > On 09/03/17 13:09, Chris Green wrote: > > Michael Torrie wrote: > >> On 03/08/2017 12:27 PM, Chris Green wrote: > >>> I have a fairly simple application that populates a GUI window with > >>> fields from a database table. The fields are defined/configured by a > >>> dictionary as follows:- > >> > >> Instead of ordering the data in Python, why not rely on the GUI to do > >> the sort? Most GUI's even have table widgets that let you click on the > >> headings to sort arbitrarily. > >> > > How would it sort it? The order I want is arbitrary, or at least not > > alphabetical or anything, I just want the order to be the way I > > listed it. > > To be fair to Michael, you did not state your required order in the > message that he replied to. You just kept saying "the order I want". > > If you're going to make people guess, don't chastise them for guessing > wrong :D > OK. :-) However how else can one describe an order which isn't 'sorted'? ... other than as the order one wants? -- Chris Green ? From ethan at stoneleaf.us Fri Mar 10 04:53:14 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 10 Mar 2017 01:53:14 -0800 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: References: <8f090d66-b3d2-00ac-ca5b-5745d96a11b7@gmail.com> <4c80c74c-16f3-26d5-0a31-2cdeef0216fa@lucidity.plus.com> Message-ID: <58C2778A.60400@stoneleaf.us> On 03/10/2017 12:43 AM, Chris Green wrote: > Erik wrote: >> On 09/03/17 13:09, Chris Green wrote: >>> Michael Torrie wrote: >>>> On 03/08/2017 12:27 PM, Chris Green wrote: >>>>> I have a fairly simple application that populates a GUI window with >>>>> fields from a database table. The fields are defined/configured by a >>>>> dictionary as follows:- >>>> >>>> Instead of ordering the data in Python, why not rely on the GUI to do >>>> the sort? Most GUI's even have table widgets that let you click on the >>>> headings to sort arbitrarily. >>>> >>> How would it sort it? The order I want is arbitrary, or at least not >>> alphabetical or anything, I just want the order to be the way I >>> listed it. >> >> To be fair to Michael, you did not state your required order in the >> message that he replied to. You just kept saying "the order I want". >> >> If you're going to make people guess, don't chastise them for guessing >> wrong :D >> > OK. :-) > > However how else can one describe an order which isn't 'sorted'? ... > other than as the order one wants? I want the order to be the same as the order I enter them in. ;) -- ~Ethan~ From amit at phpandmore.net Fri Mar 10 05:37:49 2017 From: amit at phpandmore.net (Amit Yaron) Date: Fri, 10 Mar 2017 12:37:49 +0200 Subject: Unsubscribe to Python email list In-Reply-To: <6DD74957-1E1E-4EB3-A1C0-EF7F26392411@hotmail.com> References: <6DD74957-1E1E-4EB3-A1C0-EF7F26392411@hotmail.com> Message-ID: <58C281FD.1040600@phpandmore.net> On 10/03/17 04:38, Pablo Lozano wrote: > Good day, > > I would like to unsubscribe this e-mail to the Python e-mail list. > > Kind regards > You can set "Mail Delivery" to "disable" if you want to read posts on the Usenet, but not to receive e-mails. From amit at phpandmore.net Fri Mar 10 05:37:49 2017 From: amit at phpandmore.net (Amit Yaron) Date: Fri, 10 Mar 2017 12:37:49 +0200 Subject: Unsubscribe to Python email list In-Reply-To: <6DD74957-1E1E-4EB3-A1C0-EF7F26392411@hotmail.com> References: <6DD74957-1E1E-4EB3-A1C0-EF7F26392411@hotmail.com> Message-ID: <58C281FD.1040600@phpandmore.net> On 10/03/17 04:38, Pablo Lozano wrote: > Good day, > > I would like to unsubscribe this e-mail to the Python e-mail list. > > Kind regards > You can set "Mail Delivery" to "disable" if you want to read posts on the Usenet, but not to receive e-mails. From hpj at urpla.net Fri Mar 10 05:49:24 2017 From: hpj at urpla.net (Hans-Peter Jansen) Date: Fri, 10 Mar 2017 11:49:24 +0100 Subject: keyrings.cryptfile released on github In-Reply-To: <20170309230909.hl3zg2llxazwiypu@abyayala> References: <2356566.kSNyJECJKv@xrated> <20170309230909.hl3zg2llxazwiypu@abyayala> Message-ID: <4839007.k4Tbcrq13J@xrated> On Donnerstag, 9. M?rz 2017 23:09:09 ng0 wrote: > Hans-Peter Jansen transcribed 3.8K bytes: > > Hi, > > > > since the PyCrypto ML is dead, I'm looking for advise/feedback from some > > cryptography aware people. > > > > I've released a keyring companion package today: > > https://github.com/frispete/keyrings.cryptfile > > > > Its primary purpose is a decent encrypted file backend for python > > keyrings. > > As such, it uses manually parameterized argon2 hashes as KDF, and AES in > > OCB mode as stream cipher (well, it just encrypts the password for a > > given service/user name). Granted, the advantages of OCB are not /that/ > > crucial here :wink:, but apart from technical factors, the exclusion of > > military uses > I was looking for some proprietary EULA or something else locked down > license and instead just saw the Expat license. Don't get you here. Yes, the package contains just a MIT license file for now. > I assume that you are > aware that no anti-mil clause exists in co-existence with free software > licenses > and your sentence was just written in an > odd way? First, bear with me, as I'm not a native speaker. Sometimes, my expressions tend to confuse people. I'm sorry about that. Second, I'm not a lawyer. As long as I use OCB in OSS and does not sue somebody else about it, License 1 is granted, if I read the OCB license options correctly [1]. Anyway, I will add the OCB license to the package and add a note in the initial password retrieval dialog about it.. In this projects state, I would like to discuss the technical issues first. As said, I sympathize with the idea of the license, since I personally believe, that military conflicts doesn't solve any problems, but many todays problems originate from them. [1] http://web.cs.ucdavis.edu/~rogaway/ocb/license.htm > > by its license is rather *attractive* from my POV(!). But I'm open for > > discussions of course. Cheers, Pete From renesd at gmail.com Fri Mar 10 06:01:48 2017 From: renesd at gmail.com (=?UTF-8?Q?Ren=C3=A9_Dudfield?=) Date: Fri, 10 Mar 2017 12:01:48 +0100 Subject: https://pygame.org/ Message-ID: https://pygame.org/ From borysova.mary at gmail.com Fri Mar 10 09:07:43 2017 From: borysova.mary at gmail.com (borysova.mary at gmail.com) Date: Fri, 10 Mar 2017 06:07:43 -0800 (PST) Subject: Acra, new open source database security suite for PostgreSQL Message-ID: Acra, new database security suite for PostgreSQL: https://github.com/cossacklabs/acra From jorge.conrado at cptec.inpe.br Fri Mar 10 11:16:26 2017 From: jorge.conrado at cptec.inpe.br (jorge.conrado at cptec.inpe.br) Date: Fri, 10 Mar 2017 13:16:26 -0300 Subject: Pythos message Message-ID: <8b29c29a0815c40e401dec8b669e29aa@cptec.inpe.br> Hi, I have a test script netcdf_example.py and I run it. I have my figures on screen. But I had thse two emssages: /usr/lib/python2.7/site-packages/setuptools-18.3.1-py2.7.egg/pkg_resources/__init__.py:1256: UserWarning: /home/conrado/.python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable). /usr/lib64/python2.7/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison if self._edgecolors == str('face'): Please, how can I solve this. Thanks Conrado From ian.g.kelly at gmail.com Fri Mar 10 11:46:08 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 10 Mar 2017 09:46:08 -0700 Subject: https://pygame.org/ In-Reply-To: References: Message-ID: On Fri, Mar 10, 2017 at 4:01 AM, Ren? Dudfield wrote: > https://pygame.org/ Did you have a question, or something that you wish to discuss with regard to pygame? From cl at isbd.net Fri Mar 10 13:51:35 2017 From: cl at isbd.net (Chris Green) Date: Fri, 10 Mar 2017 18:51:35 +0000 Subject: Where to find python GTK+ 3 reference documentation? Message-ID: I'm using the excellent tutorial at https://python-gtk-3-tutorial.readthedocs.io and occasionally want reference documentation, is there reference documentation for this on line? -- Chris Green ? From pavel.aronsky at gmail.com Fri Mar 10 13:55:06 2017 From: pavel.aronsky at gmail.com (ddbug) Date: Fri, 10 Mar 2017 10:55:06 -0800 (PST) Subject: How to access installed scripts on Windows? In-Reply-To: <8ae7e347-68d8-4de8-ba66-1ba140b3e5c1@googlegroups.com> References: <9dd2791f-5358-479f-b0e9-9e6c91e2e788@googlegroups.com> <8ae7e347-68d8-4de8-ba66-1ba140b3e5c1@googlegroups.com> Message-ID: <0d35ba40-951b-4ba4-b2f8-8c640fe5d861@googlegroups.com> On Monday, March 6, 2017 at 12:29:54 PM UTC+2, Paul Moore wrote: > On Sunday, 5 March 2017 22:26:17 UTC, eryk sun wrote: > > On Sun, Mar 5, 2017 at 2:35 AM, ddbug wrote: ................. Thank you Paul and Eryk for your replies. My goal is definitely to expose the Python to my users. I want them to read the code and modify as needed - much like people use shell scripts in Linux - but I cannot expect them to install a heavy IDE. This is surprisingly easy in Ubuntu. The 'default' pip installer just does the right thing. The scripts go where the user expects them to be (~/bin or ~/.local/bin) - everything just works. I want to achieve the same on Windows - and hit a small but annoying obstacle: the default install location is not on PATH and not easy discoverable. Zipped applications is a good option (provides isolation and easier to grasp than virtualenvs) - but then I can stop using pip as deployment method and tell the users to check out my stuff from our version control system to the location of their choice. If their working copy is not in PATH - no problem. If/when we start to use 3rd party dependencies, I'll have to add the dependencies to my repository (kind of virtualenv) or ... learn to use the real virtualenv. I'm now looking at IDLE, trying to understand if it may be helpful for my Windows users for quick start. It is *almost* useful - but small crucial bit is missing again: no Change directory command in the GUI! and no easy way to specify a small 'set-up' code snippet for startup and every reset of the shell. This seems possible via fumbling with command options in shortcuts... but that's really lame. Can I ask somebody familiar with IDLE to look at this? Thank you once more. -- ddbug From best_lay at yahoo.com Fri Mar 10 14:26:47 2017 From: best_lay at yahoo.com (Wildman) Date: Fri, 10 Mar 2017 13:26:47 -0600 Subject: Where to find python GTK+ 3 reference documentation? References: Message-ID: On Fri, 10 Mar 2017 18:51:35 +0000, Chris Green wrote: > I'm using the excellent tutorial at https://python-gtk-3-tutorial.readthedocs.io > and occasionally want reference documentation, is there reference > documentation for this on line? https://developer.gnome.org/gtk3/ -- GNU/Linux user #557453 Hey Mr. Ed, why the long face? From cl at isbd.net Fri Mar 10 15:26:54 2017 From: cl at isbd.net (Chris Green) Date: Fri, 10 Mar 2017 20:26:54 +0000 Subject: Where to find python GTK+ 3 reference documentation? References: Message-ID: Wildman wrote: > On Fri, 10 Mar 2017 18:51:35 +0000, Chris Green wrote: > > > I'm using the excellent tutorial at https://python-gtk-3-tutorial.readthedocs.io > > and occasionally want reference documentation, is there reference > > documentation for this on line? > > https://developer.gnome.org/gtk3/ > Thanks, that's the C/C++ documentation which will probably tell me what I want. Isn't there proper Python documemtation for it? -- Chris Green ? From digitalfantasy.it86559 at digitalfantasy.it Fri Mar 10 15:32:29 2017 From: digitalfantasy.it86559 at digitalfantasy.it (Liste guru) Date: Fri, 10 Mar 2017 21:32:29 +0100 Subject: Where to find python GTK+ 3 reference documentation? In-Reply-To: References: Message-ID: <7d06ec73-914c-fe2e-d2df-16011850926b@digitalfantasy.it> Il 10/03/2017 20:26, Wildman via Python-list ha scritto: > On Fri, 10 Mar 2017 18:51:35 +0000, Chris Green wrote: > >> I'm using the excellent tutorial at https://python-gtk-3-tutorial.readthedocs.io >> and occasionally want reference documentation, is there reference >> documentation for this on line? > https://developer.gnome.org/gtk3/ > If you get the pygobject package from sourceforge, in the various packages there is devhelp with the documentation of all the libs (and many more, if I'm not wrong there is also the python doc installed), with particular section about python. As a reference I found it very useful. Daniele Forghieri From torriem at gmail.com Fri Mar 10 15:57:20 2017 From: torriem at gmail.com (Michael Torrie) Date: Fri, 10 Mar 2017 13:57:20 -0700 Subject: Where to find python GTK+ 3 reference documentation? In-Reply-To: References: Message-ID: <451c9a83-8624-4db6-4e92-d5286e6fdfd0@gmail.com> On 03/10/2017 01:26 PM, Chris Green wrote: > Wildman wrote: >> On Fri, 10 Mar 2017 18:51:35 +0000, Chris Green wrote: >> >>> I'm using the excellent tutorial at https://python-gtk-3-tutorial.readthedocs.io >>> and occasionally want reference documentation, is there reference >>> documentation for this on line? >> >> https://developer.gnome.org/gtk3/ >> > Thanks, that's the C/C++ documentation which will probably tell me > what I want. Isn't there proper Python documemtation for it? There used to be, for GTK2, at http://pygtk.org. But with the GTK3 bindings, they are now dynamic bindings using PyGObject, which itself is documented here: https://wiki.gnome.org/action/show/Projects/PyGObject. The resulting bound API closely resembles the GTK C API typically, which is convenient, but not as Pythonic as the PyGTK2 bindings were. I assume there must be a tool out there that can autogenerate API docs (in Python) for GTK3. According to https://wiki.gnome.org/Projects/PyGObject/IntrospectionPorting, there's a module called pygtkcompat that provides a very PyGTK-compatible API that you can use while making the transition from PyGTK-style code. From maria.katic at gmail.com Fri Mar 10 16:17:11 2017 From: maria.katic at gmail.com (maria.katic at gmail.com) Date: Fri, 10 Mar 2017 13:17:11 -0800 (PST) Subject: Invitation to support our research (by responding to the questionnaire) on analogy based code reuse Message-ID: <4574fe54-2716-48e9-8ac9-a3784247b363@googlegroups.com> At Birkbeck, University of London in collaboration with the Faculty of Electrical Engineering and Computing, University of Zagreb, we are doing research on reusing source code based on analogical reasoning. We appreciate the importance of your time and we hope you will be able to invest approximately 15 minutes of your time and fill in our questionnaire. The questionnaire will be available in the next few weeks. We did our best to reduce the amount of questions to the most important ones of our interest. Please note that your feedback is critical to the success of this research. Your answers are completely anonymous. Please follow this link to fill in the questionnaire: https://docs.google.com/forms/d/e/1FAIpQLSc0A_z8Z2zOeElqA_dWBijc04Fh5qARy9PdV63D7QzpFq3rbA/viewform?usp=send_form Thank you very much in advance for your time and for supporting our research. Kind regards, Marija, Martin and Mario From no.email at nospam.invalid Fri Mar 10 16:31:41 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 10 Mar 2017 13:31:41 -0800 Subject: keyrings.cryptfile released on github References: <2356566.kSNyJECJKv@xrated> <20170309230909.hl3zg2llxazwiypu@abyayala> <4839007.k4Tbcrq13J@xrated> Message-ID: <87tw70rf7m.fsf@nightsong.com> Hans-Peter Jansen writes: > [1] http://web.cs.ucdavis.edu/~rogaway/ocb/license.htm Oh that's interesting, he's expanded the free licenses. Still though, while OCB is very clever and it was important as the first satisfactory AEAD mode, I don't think it's that important these days. GCM is standardized, does similar things, and while it's potentially slower, some CPUs even have hardware support for it now. If you library doesn't support GCM (I haven't checked yet) then it probably should. From cl at isbd.net Fri Mar 10 16:47:05 2017 From: cl at isbd.net (Chris Green) Date: Fri, 10 Mar 2017 21:47:05 +0000 Subject: Where to find python GTK+ 3 reference documentation? References: <451c9a83-8624-4db6-4e92-d5286e6fdfd0@gmail.com> Message-ID: Michael Torrie wrote: > On 03/10/2017 01:26 PM, Chris Green wrote: > > Wildman wrote: > >> On Fri, 10 Mar 2017 18:51:35 +0000, Chris Green wrote: > >> > >>> I'm using the excellent tutorial at https://python-gtk-3-tutorial.readthedocs.io > >>> and occasionally want reference documentation, is there reference > >>> documentation for this on line? > >> > >> https://developer.gnome.org/gtk3/ > >> > > Thanks, that's the C/C++ documentation which will probably tell me > > what I want. Isn't there proper Python documemtation for it? > > There used to be, for GTK2, at http://pygtk.org. But with the GTK3 > bindings, they are now dynamic bindings using PyGObject, which itself is > documented here: https://wiki.gnome.org/action/show/Projects/PyGObject. > The resulting bound API closely resembles the GTK C API typically, > which is convenient, but not as Pythonic as the PyGTK2 bindings were. I > assume there must be a tool out there that can autogenerate API docs (in > Python) for GTK3. > > According to > https://wiki.gnome.org/Projects/PyGObject/IntrospectionPorting, there's > a module called pygtkcompat that provides a very PyGTK-compatible API > that you can use while making the transition from PyGTK-style code. > Thank you for the comprehensive explanation. :-) -- Chris Green ? From steve+python at pearwood.info Fri Mar 10 18:06:19 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 11 Mar 2017 10:06:19 +1100 Subject: What's the neatest way of getting dictionary entries in a specified order? References: <8f090d66-b3d2-00ac-ca5b-5745d96a11b7@gmail.com> <4c80c74c-16f3-26d5-0a31-2cdeef0216fa@lucidity.plus.com> <58C2778A.60400@stoneleaf.us> Message-ID: <58c3316d$0$1588$c3e8da3$5496439d@news.astraweb.com> On Fri, 10 Mar 2017 08:53 pm, Ethan Furman wrote: > On 03/10/2017 12:43 AM, Chris Green wrote: >> Erik wrote: >>> On 09/03/17 13:09, Chris Green wrote: >>>> Michael Torrie wrote: >>>>> On 03/08/2017 12:27 PM, Chris Green wrote: >>>>>> I have a fairly simple application that populates a GUI window with >>>>>> fields from a database table. The fields are defined/configured by a >>>>>> dictionary as follows:- >>>>> >>>>> Instead of ordering the data in Python, why not rely on the GUI to do >>>>> the sort? Most GUI's even have table widgets that let you click on >>>>> the headings to sort arbitrarily. >>>>> >>>> How would it sort it? The order I want is arbitrary, or at least not >>>> alphabetical or anything, I just want the order to be the way I >>>> listed it. >>> >>> To be fair to Michael, you did not state your required order in the >>> message that he replied to. You just kept saying "the order I want". >>> >>> If you're going to make people guess, don't chastise them for guessing >>> wrong :D >>> >> OK. :-) >> >> However how else can one describe an order which isn't 'sorted'? ... >> other than as the order one wants? > > I want the order to be the same as the order I enter them in. ;) That's not the same thing at all. I added Fred to the address book in January. I added Sue to the address book in February. I added George to the address book in March. But I want them to show up in the order Sue, George, Fred. As far as I can see, the only way to display the contents of a dict in some arbitrary order is to keep an auxilary list of the keys in the order you want it. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ethan at stoneleaf.us Fri Mar 10 18:18:31 2017 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 10 Mar 2017 15:18:31 -0800 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: <58c3316d$0$1588$c3e8da3$5496439d@news.astraweb.com> References: <8f090d66-b3d2-00ac-ca5b-5745d96a11b7@gmail.com> <4c80c74c-16f3-26d5-0a31-2cdeef0216fa@lucidity.plus.com> <58C2778A.60400@stoneleaf.us> <58c3316d$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58C33447.5000301@stoneleaf.us> On 03/10/2017 03:06 PM, Steve D'Aprano wrote: > On Fri, 10 Mar 2017 08:53 pm, Ethan Furman wrote: >> On 03/10/2017 12:43 AM, Chris Green wrote: >>> However how else can one describe an order which isn't 'sorted'? ... >>> other than as the order one wants? >> >> I want the order to be the same as the order I enter them in. ;) > > > That's not the same thing at all. > > I added Fred to the address book in January. I added Sue to the address book > in February. I added George to the address book in March. But I want them > to show up in the order Sue, George, Fred. The OP was talking about the field names, not the entire record. -- ~Ethan~ From dieter at handshake.de Sat Mar 11 02:53:13 2017 From: dieter at handshake.de (dieter) Date: Sat, 11 Mar 2017 08:53:13 +0100 Subject: Pythos message References: <8b29c29a0815c40e401dec8b669e29aa@cptec.inpe.br> Message-ID: <87efy4dzbq.fsf@handshake.de> jorge.conrado at cptec.inpe.br writes: > I have a test script netcdf_example.py and I run it. I have my figures > on screen. But I had thse two emssages: > > /usr/lib/python2.7/site-packages/setuptools-18.3.1-py2.7.egg/pkg_resources/__init__.py:1256: > UserWarning: /home/conrado/.python-eggs is writable by group/others > and vulnerable to attack when used with > get_resource_filename. Consider a more secure location (set with > .set_extraction_path or the PYTHON_EGG_CACHE environment variable). This warns you that part of your Python infrastructure (the content of "/home/conrado/.python-eggs") could be changed by other people (than you). You might not be concerned at all (if you act in a safe, trustfull environment). Otherwise, you have essentially two options: * prevent write access for others than you to "/home/conrado/.python-eggs" (--> "chmod" command) * move the part of your Python infrastructure to another location not writable by "other" and "group" - and tell your Python system where to find is (via "set_extraction_path" or envvar "PYTHON_EGG_CACHE"). > /usr/lib64/python2.7/site-packages/matplotlib/collections.py:590: > FutureWarning: elementwise comparison failed; returning scalar > instead, but in the future will perform elementwise comparison > if self._edgecolors == str('face'): A "FutureWarning" warns about something that may give an error in the future. >From this specific message, I guess (!), that "_edgecolors" consists in fact not of a single but of multiple components - but is compared here to a single value. The warning means, that the current behaviour (returning a scalar value) is likely to change in the future (returning a composite value for the elementwise comparison). Should this happen, the code will likely fail. This warning comes from "matplotlib" - i.e. it is outside of your immediate control. You can hope that a future version of "matplotlib" will correctly handle the changed behaviour in the future -- and ignore the problem until then. From cl at isbd.net Sat Mar 11 05:07:32 2017 From: cl at isbd.net (Chris Green) Date: Sat, 11 Mar 2017 10:07:32 +0000 Subject: What's the neatest way of getting dictionary entries in a specified order? References: <8f090d66-b3d2-00ac-ca5b-5745d96a11b7@gmail.com> <4c80c74c-16f3-26d5-0a31-2cdeef0216fa@lucidity.plus.com> <58C2778A.60400@stoneleaf.us> <58c3316d$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4sucpd-g59.ln1@esprimo.zbmc.eu> Steve D'Aprano wrote: > > I want the order to be the same as the order I enter them in. ;) > > > That's not the same thing at all. > > I added Fred to the address book in January. I added Sue to the address book > in February. I added George to the address book in March. But I want them > to show up in the order Sue, George, Fred. > The order I was asking about was the order of the *fields* of the heading (i.e. the column names) *not* the data. It won't get updated when new data is added. What I was after (and got) was a way that would allow me to extract the data for one entry in my address book in a particular order. -- Chris Green ? From torriem at gmail.com Sat Mar 11 09:21:28 2017 From: torriem at gmail.com (Michael Torrie) Date: Sat, 11 Mar 2017 07:21:28 -0700 Subject: What's the neatest way of getting dictionary entries in a specified order? In-Reply-To: <4sucpd-g59.ln1@esprimo.zbmc.eu> References: <8f090d66-b3d2-00ac-ca5b-5745d96a11b7@gmail.com> <4c80c74c-16f3-26d5-0a31-2cdeef0216fa@lucidity.plus.com> <58C2778A.60400@stoneleaf.us> <58c3316d$0$1588$c3e8da3$5496439d@news.astraweb.com> <4sucpd-g59.ln1@esprimo.zbmc.eu> Message-ID: On 03/11/2017 03:07 AM, Chris Green wrote: > The order I was asking about was the order of the *fields* of the > heading (i.e. the column names) *not* the data. It won't get updated > when new data is added. What I was after (and got) was a way that > would allow me to extract the data for one entry in my address book in > a particular order. Ahh. Now that's something I did not get out of the original message. Apparently others did, though, since they talked about ordered dicts. The order of the displayed fields is usually something set by the GUI API when you create the table widget. At least in most toolkits I'm familiar with. As well, when you add the row to the widget, you normally specify the fields (the data) individually, so I would think the order of the dict's fields does not matter since you'd manually specify each field's data. From phd at phdru.name Sat Mar 11 11:14:48 2017 From: phd at phdru.name (Oleg Broytman) Date: Sat, 11 Mar 2017 17:14:48 +0100 Subject: SQLObject 3.2.0 Message-ID: <20170311161448.GB19036@phdru.name> Hello! I'm pleased to announce version 3.2.0, the first stable release of branch 3.2 of SQLObject. What's new in SQLObject ======================= Contributor for this release is Neil Muller. Minor features -------------- * Drop table name from ``VACUUM`` command in SQLiteConnection: SQLite doesn't vacuum a single table and SQLite 3.15 uses the supplied name as the name of the attached database to vacuum. * Remove ``driver`` keyword from RdbhostConnection as it allows one driver ``rdbhdb``. * Add ``driver`` keyword for FirebirdConnection. Allowed values are 'fdb', 'kinterbasdb' and 'pyfirebirdsql'. Default is to test 'fdb' and 'kinterbasdb' in that order. pyfirebirdsql is supported but has problems. * Add ``driver`` keyword for MySQLConnection. Allowed values are 'mysqldb', 'connector', 'oursql' and 'pymysql'. Default is to test for mysqldb only. * Add support for `MySQL Connector `_ (pure python; `binary packages `_ are not at PyPI and hence are hard to install and test). * Add support for `oursql `_ MySQL driver (only Python 2.6 and 2.7 until oursql author fixes Python 3 compatibility). * Add support for `PyMySQL `_ - pure python mysql interface). * Add parameter ``timeout`` for MSSQLConnection (usable only with pymssql driver); timeouts are in seconds. * Remove deprecated ez_setup.py. Drivers (work in progress) -------------------------- * Extend support for PyGreSQL driver. There are still some problems. * Add support for `py-postgresql `_ PostgreSQL driver. There are still problems with the driver. * Add support for `pyfirebirdsql `_.There are still problems with the driver. Bug fixes --------- * Fix MSSQLConnection.columnsFromSchema: remove `(` and `)` from default value. * Fix MSSQLConnection and SybaseConnection: insert default values into a table with just one IDENTITY column. * Remove excessive NULLs from ``CREATE TABLE`` for MSSQL/Sybase. * Fix concatenation operator for MSSQL/Sybase (it's ``+``, not ``||``). * Fix MSSQLConnection.server_version() under Py3 (decode version to str). Documentation ------------- * The docs are now generated with Sphinx. * Move ``docs/LICENSE`` to the top-level directory so that Github recognizes it. Tests ----- * Rename ``py.test`` -> ``pytest`` in tests and docs. * Great Renaming: fix ``pytest`` warnings by renaming ``TestXXX`` classes to ``SOTestXXX`` to prevent ``pytest`` to recognize them as test classes. * Fix ``pytest`` warnings by converting yield tests to plain calls: yield tests were deprecated in ``pytest``. * Tests are now run at CIs with Python 3.5. * Drop ``Circle CI``. * Run at Travis CI tests with Firebird backend (server version 2.5; drivers fdb and firebirdsql). There are problems with tests. * Run tests at AppVeyor for windows testing. Run tests with MS SQL, MySQL, Postgres and SQLite backends; use Python 2.7, 3.4 and 3.5, x86 and x64. There are problems with MS SQL and MySQL. For a more complete list, please see the news: http://sqlobject.org/News.html What is SQLObject ================= SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Python 2.6, 2.7 or 3.4+ is required. Where is SQLObject ================== Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: https://pypi.python.org/pypi/SQLObject/3.2.0 News and changes: http://sqlobject.org/News.html Oleg. -- Oleg Broytman http://phdru.name/ phd at phdru.name Programmers don't die, they just GOSUB without RETURN. From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Sat Mar 11 17:01:02 2017 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Sat, 11 Mar 2017 22:01:02 +0000 Subject: Precision reading and writing data frames to csv Message-ID: Hi! I have a dir with lots of csv files. These files are updated +- once a day. I could see that some values are converted, during output, to very close values but with lots of digits. I understand that is caused by the internal bits' representation of the float/double values. Now my question is: Is it possible the occurrence of successive cumulative errors? I mean reading a file, adding lines or change few ones but keeping the most of the other lines untouched and, even so, existent untouched lines keep always changing? Thanks From python at mrabarnett.plus.com Sat Mar 11 18:06:28 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Mar 2017 23:06:28 +0000 Subject: Precision reading and writing data frames to csv In-Reply-To: References: Message-ID: On 2017-03-11 22:01, Paulo da Silva wrote: > Hi! > > I have a dir with lots of csv files. These files are updated +- once a > day. I could see that some values are converted, during output, to very > close values but with lots of digits. I understand that is caused by the > internal bits' representation of the float/double values. > > Now my question is: Is it possible the occurrence of successive > cumulative errors? I mean reading a file, adding lines or change few > ones but keeping the most of the other lines untouched and, even so, > existent untouched lines keep always changing? > If it's writing out _exactly_ what it's reading in, how can it be changing? From python at lucidity.plus.com Sat Mar 11 18:29:35 2017 From: python at lucidity.plus.com (Erik) Date: Sat, 11 Mar 2017 23:29:35 +0000 Subject: Precision reading and writing data frames to csv In-Reply-To: References: Message-ID: <446bb297-2940-975a-70bb-8c7b190e6138@lucidity.plus.com> Hi Paulo, On 11/03/17 22:01, Paulo da Silva wrote: > I have a dir with lots of csv files. These files are updated +- once a > day. I could see that some values are converted, during output, to very > close values but with lots of digits. I understand that is caused by the > internal bits' representation of the float/double values. > > Now my question is: Is it possible the occurrence of successive > cumulative errors? I mean reading a file, adding lines or change few > ones but keeping the most of the other lines untouched and, even so, > existent untouched lines keep always changing? Firstly, if the values are changing then they are being first written by a process that has a very strict decimal representation and then read in and re-written by something that has a less-strict representation (I'm guessing that by "float/double values", you mean IEEE 754). Because IEEE 754 can't represent all values *exactly*, some input values will change to something close as you have seen. However, if the input value matches something that IEEE 754 *can* represent exactly then it will not change. Whether you will see _cumulative_ errors depends on whether the output stage of the first pass truncates the output with a field width specifier or similar. If not, then you should see the initial change you've noticed and then nothing more after that for that particular datum. Having said all that, if you use Python's decimal.Decimal type instead of float/double for processing your files, then you are better off if absolute precision is what you need. E. From p_s_d_a_s_i_l_v_a_ns at netcabo.pt Sat Mar 11 21:26:28 2017 From: p_s_d_a_s_i_l_v_a_ns at netcabo.pt (Paulo da Silva) Date: Sun, 12 Mar 2017 02:26:28 +0000 Subject: Precision reading and writing data frames to csv References: <446bb297-2940-975a-70bb-8c7b190e6138@lucidity.plus.com> Message-ID: ?s 23:29 de 11-03-2017, Erik escreveu: > Hi Paulo, > > On 11/03/17 22:01, Paulo da Silva wrote: ... >> Now my question is: Is it possible the occurrence of successive >> cumulative errors? I mean reading a file, adding lines or change few >> ones but keeping the most of the other lines untouched and, even so, >> existent untouched lines keep always changing? > > Firstly, if the values are changing then they are being first written by > a process that has a very strict decimal representation and then read in > and re-written by something that has a less-strict representation (I'm > guessing that by "float/double values", you mean IEEE 754). I don't know. I can tell you that I'm using pandas data frame read_csv and to_csv to read and write. > > Because IEEE 754 can't represent all values *exactly*, some input values > will change to something close as you have seen. > However, if the input value matches something that IEEE 754 *can* > represent exactly then it will not change. > > Whether you will see _cumulative_ errors depends on whether the output > stage of the first pass truncates the output with a field width > specifier or similar. If not, then you should see the initial change > you've noticed and then nothing more after that for that particular datum. Ok, I like that. > > > Having said all that, if you use Python's decimal.Decimal type instead > of float/double for processing your files, then you are better off if > absolute precision is what you need. No, I don't think it is needed. It will unnecessarily complicate my scripts. They have lots of calculations (matrix like operations). I don't care about fine precision. Only cumulative changes. I was in doubt if the data was going to change over time. Thank you very much. From cl at isbd.net Sun Mar 12 08:14:32 2017 From: cl at isbd.net (Chris Green) Date: Sun, 12 Mar 2017 12:14:32 +0000 Subject: Does one create an event to notify parent window/GUI of something? Message-ID: <8mqfpd-4d7.ln1@esprimo.zbmc.eu> This is a rather a beginner question. I'm heavily modifying some code that was an LDAP address book to be a sqlite3 based address book. I have the basic GUI working and I'm now getting the database connections to work. This question relates to how one communicates between windows/GUIs. When the program starts theres a main GUI, class name abookgui. If you want to add new entries or modify existing entries an edit GUI is started in a separate window, class abookeditgui. I need the abookeditgui window to be able to tell the parent abookgui window that it has completed whatever it was doing. It has two basic possibilities 'Cancel', i.e. nothing was changed or 'Save' meaning there's a new/changed item in the database. The parent abookgui needs to know when one of these has happened. What's the 'right' way to do this? I can see several non-event driven ways of doing it badly but I'm not sure of the proper event driven way. The parent abookgui only has the name of the abookeditgui object, it can of course access the abookeditgui instance variables so it can hook (for example) a window exit event (I think!). There are (of course) event handlers for the 'Save' and 'Cancel' button click events in abookeditgui, what I need is hooks from these to run some code in abookgui after the abookeditgui has completed. How should one do this, is there a way for a class to call code in the class 'above' which instantiated it? -- Chris Green ? From cl at isbd.net Sun Mar 12 11:05:20 2017 From: cl at isbd.net (Chris Green) Date: Sun, 12 Mar 2017 15:05:20 +0000 Subject: Does one create an event to notify parent window/GUI of something? References: <8mqfpd-4d7.ln1@esprimo.zbmc.eu> Message-ID: Dennis Lee Bieber wrote: > On Sun, 12 Mar 2017 12:14:32 +0000, Chris Green declaimed the > following: > > >This is a rather a beginner question. I'm heavily modifying some code > >that was an LDAP address book to be a sqlite3 based address book. I > >have the basic GUI working and I'm now getting the database > >connections to work. > > > > > > > >There are (of course) event handlers for the 'Save' and 'Cancel' > >button click events in abookeditgui, what I need is hooks from these > >to run some code in abookgui after the abookeditgui has completed. How > >should one do this, is there a way for a class to call code in the > >class 'above' which instantiated it? > > > > 1) You fail to mention just which toolkit you are using -- things may > differ between wx, Tk, or any of the other toolkits (or meta-toolkits -- > Dabo is built on top of one of the other basic toolkits). (And, knowing my > luck, my decade old WxPython book is out-of-date as Wx updates are a new > architecture) > I'm using Python GTK, sorry I should have included this information. > 2) It sounds a bit like your edit window needs to be a modal window, > blocking the main window from responding to anything until the edit window > completes. In my Wx book, dialogs can be displayed using .showModal() -- > which blocks the parent window at that point. When the dialog goes away, > the return code (OK/Cancel) is provided as the result of the .showModal() > call, and the main code can now act upon it. That might well be one way of doing it, thanks. However I find modal windows *very* annoying at times so I'd prefer not to do it this way. The annoyance here would be (for example) needing to look up something elsewhere in the address book to fill in something on the new address, a modal edit box would prevent this. The logic of what you suggest is perfect, I want something to happen in the main code when the edit GUI window exits. -- Chris Green ? From rahulrasal at gmail.com Sun Mar 12 12:22:52 2017 From: rahulrasal at gmail.com (rahulrasal at gmail.com) Date: Sun, 12 Mar 2017 09:22:52 -0700 (PDT) Subject: Regular expression query Message-ID: Hi All, I have a string which looks like aaaaa,bbbbb,ccccc "4873898374", ddddd, eeeeee "3343,23,23,5,,5,45", fffff "5546,3434,345,34,34,5,34,543,7" It is comma saperated string, but some of the fields have a double quoted string as part of it (and that double quoted string can have commas). Above string have only 6 fields. First is aaaaa, second is bbbbb and last is fffff "5546,3434,345,34,34,5,34,543,7". How can I split this string in its fields using regular expression ? or even if there is any other way to do this, please speak out. Thanks in advance From larry.martell at gmail.com Sun Mar 12 12:28:41 2017 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 12 Mar 2017 12:28:41 -0400 Subject: Regular expression query In-Reply-To: References: Message-ID: On Sun, Mar 12, 2017 at 12:22 PM, wrote: > Hi All, > > I have a string which looks like > > aaaaa,bbbbb,ccccc "4873898374", ddddd, eeeeee "3343,23,23,5,,5,45", fffff "5546,3434,345,34,34,5,34,543,7" > > It is comma saperated string, but some of the fields have a double quoted string as part of it (and that double quoted string can have commas). > Above string have only 6 fields. First is aaaaa, second is bbbbb and last is fffff "5546,3434,345,34,34,5,34,543,7". > How can I split this string in its fields using regular expression ? or even if there is any other way to do this, please speak out. Use the csv module: https://docs.python.org/2.7/library/csv.html From eric.frederich at gmail.com Sun Mar 12 13:02:31 2017 From: eric.frederich at gmail.com (Eric Frederich) Date: Sun, 12 Mar 2017 13:02:31 -0400 Subject: Compiling new Pythons on old Windows compilers Message-ID: There is a commercial application which allows customizations through a C API. There are 3 different releases of this application each compiled with different versions of Visual Studio, 2008, 2010, and 2012. I'd like to release a customization which embeds a Python interpreter, but I'd like to use the same Python release across all 3 application versions. There may be versions of Python like 2.7 or something which compile on all 3 of those Visual Studio releases, but I'd really prefer to use Python 3. Any idea why compatibility was dropped recently? There used to be a PC directory with different VS directories in the source tree, now it isn't there any more. Thanks, ~Eric From jussi.piitulainen at helsinki.fi Sun Mar 12 13:24:56 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Sun, 12 Mar 2017 19:24:56 +0200 Subject: Regular expression query References: Message-ID: rahulrasal at gmail.com writes: > Hi All, > > I have a string which looks like > > aaaaa,bbbbb,ccccc "4873898374", ddddd, eeeeee "3343,23,23,5,,5,45", fffff "5546,3434,345,34,34,5,34,543,7" > > It is comma saperated string, but some of the fields have a double > quoted string as part of it (and that double quoted string can have > commas). Above string have only 6 fields. First is aaaaa, second is > bbbbb and last is fffff "5546,3434,345,34,34,5,34,543,7". How can I > split this string in its fields using regular expression ? or even if > there is any other way to do this, please speak out. If you have any control over the source of this data, try to change the source so that it writes proper CSV. Then you can use the csv module to parse the data. As it is, csv.reader failed me. Perhaps someone else knows how it should be parameterized to deal with this? len(next(csv.reader(io.StringIO(s)))) == 20 len(next(csv.reader(io.StringIO(s), doublequote = False))) == 20 Here's a regex solution that assumes that there is something in a field before the doublequoted part, then at most one doublequoted part and nothing after the doublequoted part. len(re.findall(r'([^",]+(?:"[^"]*")?)', s)) == 6 re.findall(r'([^",]+(?:"[^"]*")?)', s) ['aaaaa', 'bbbbb', 'ccccc "4873898374"', ' ddddd', ' eeeeee "3343,23,23,5,,5,45"', ' fffff "5546,3434,345,34,34,5,34,543,7"'] The outermost parentheses in the pattern make the whole pattern a capturing group. They are redundant above (with re.findall) but important in the following alternative (with re.split). re.split(r'([^",]+(?:"[^"]*")?)', s) ['', 'aaaaa', ',', 'bbbbb', ',', 'ccccc "4873898374"', ',', ' ddddd', ',', ' eeeeee "3343,23,23,5,,5,45"', ',', ' fffff "5546,3434,345,34,34,5,34,543,7"', ''] This splits the string with the pattern that matches the actual data. With the capturing group it also returns the actual data. One could then check that the assumptions hold and every other value is just a comma. I would make that check and throw an exception on failure. From steve+python at pearwood.info Sun Mar 12 13:48:58 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 13 Mar 2017 04:48:58 +1100 Subject: When will os.remove fail? Message-ID: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> On Linux, if I call os.remove on a file which I own but don't have write permission on, the file is still deleted: py> f = open('/tmp/no-write', 'w') py> os.path.exists('/tmp/no-write') True py> os.chmod('/tmp/no-write', 0) # Forbid ALL access. py> os.remove('/tmp/no-write') py> os.path.exists('/tmp/no-write') False It seems that os.remove on Linux will force the delete even if the file is read-only or unreadable, provided you own the file. Does os.remove work like this under Windows too? Under what circumstances will os.remove fail to remove a file? If you don't own the file and have no write permission, if it is on read-only media, anything else? Thanks, -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From lele at metapensiero.it Sun Mar 12 14:00:58 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Sun, 12 Mar 2017 19:00:58 +0100 Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8760jee5np.fsf@metapensiero.it> Steve D'Aprano writes: > Under what circumstances will os.remove fail to remove a file? > > If you don't own the file and have no write permission, if it is on > read-only media, anything else? I would say that what matter is the permission on the directory containing the file, not on the file itself. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From larry.martell at gmail.com Sun Mar 12 14:04:09 2017 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 12 Mar 2017 14:04:09 -0400 Subject: When will os.remove fail? In-Reply-To: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 12, 2017 at 1:48 PM, Steve D'Aprano wrote: > On Linux, if I call os.remove on a file which I own but don't have write > permission on, the file is still deleted: > > > py> f = open('/tmp/no-write', 'w') > py> os.path.exists('/tmp/no-write') > True > py> os.chmod('/tmp/no-write', 0) # Forbid ALL access. > py> os.remove('/tmp/no-write') > py> os.path.exists('/tmp/no-write') > False > > > It seems that os.remove on Linux will force the delete even if the file is > read-only or unreadable, provided you own the file. In Linux, I believe you need write permission on the dir to delete a file - the perms on the file do not matter. From alain at universite-de-strasbourg.fr.invalid Sun Mar 12 14:45:54 2017 From: alain at universite-de-strasbourg.fr.invalid (Alain Ketterlin) Date: Sun, 12 Mar 2017 19:45:54 +0100 Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87inne1ggt.fsf@universite-de-strasbourg.fr.invalid> Steve D'Aprano writes: > On Linux, if I call os.remove on a file which I own but don't have write > permission on, the file is still deleted: > > > py> f = open('/tmp/no-write', 'w') > py> os.path.exists('/tmp/no-write') > True > py> os.chmod('/tmp/no-write', 0) # Forbid ALL access. > py> os.remove('/tmp/no-write') > py> os.path.exists('/tmp/no-write') > False > > > It seems that os.remove on Linux will force the delete even if the file is > read-only or unreadable, provided you own the file. Your permissions on the file do not really matters. It's all about your permissions on the parent directory (removing a file is really modifying the parent dir). Actually, it is even slightly more complicated. Here is an excerpt of the unlink(2) call (which does the job) listing common error cases: | EACCES Write access to the directory containing pathname is not allowed | for the process's effective UID, or one of the directories in | pathname did not allow search permission. (See also path_reso? | lution(7).) | | ELOOP Too many symbolic links were encountered in translating path? | name. | | EPERM (Linux only) | The filesystem does not allow unlinking of files. | | EPERM or EACCES | The directory containing pathname has the sticky bit (S_ISVTX) | set and the process's effective UID is neither the UID of the | file to be deleted nor that of the directory containing it, and | the process is not privileged (Linux: does not have the | CAP_FOWNER capability). | | EROFS pathname refers to a file on a read-only filesystem. > Does os.remove work like this under Windows too? No, Windows has its own set of rules: https://msdn.microsoft.com/en-us/library/bb727008.aspx > Under what circumstances will os.remove fail to remove a file? > > If you don't own the file and have no write permission, if it is on > read-only media, anything else? I'm not sure which system you are asking about, here. See above. -- Alain. From python.list at tim.thechases.com Sun Mar 12 14:51:46 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 12 Mar 2017 13:51:46 -0500 Subject: Regular expression query In-Reply-To: References: Message-ID: <20170312135146.172545da@bigbox.christie.dr> On 2017-03-12 09:22, rahulrasal at gmail.com wrote: > aaaaa,bbbbb,ccccc "4873898374", ddddd, eeeeee "3343,23,23,5,,5,45", > fffff "5546,3434,345,34,34,5,34,543,7" > > It is comma saperated string, but some of the fields have a double > quoted string as part of it (and that double quoted string can have > commas). Above string have only 6 fields. First is aaaaa, second is > bbbbb and last is fffff "5546,3434,345,34,34,5,34,543,7". How can I > split this string in its fields using regular expression ? or even > if there is any other way to do this, please speak out. Your desired output seems to silently ignore the spaces after the commas (e.g. why is it "ddddd" instead of " ddddd"?). You also don't mention what should happen in the event there's an empty field: aaa,,ccc,ddd "ee",ff For a close approximation, you might try import re instr = 'aaaaa,bbbbb,ccccc "4873898374", ddddd, eeeeee "3343,23,23,5,,5,45", fffff "5546,3434,345,34,34,5,34,543,7"' desired = [ "aaaaa", "bbbbb", 'ccccc "4873898374"', "ddddd", 'eeeeee "3343,23,23,5,,5,45"', 'fffff "5546,3434,345,34,34,5,34,543,7"', ] r = re.compile(r'(?!,|$)(?:"[^"]*"|[^,])*') # result = r.findall(instr) # strip them because of the aforementioned leading-space issue result = [s.strip() for s in r.findall(instr)] assert len(result) == len(desired), str(result) assert result == desired, str(result) It doesn't address the empty field issue, but it's at least a start. -tkc From eryksun at gmail.com Sun Mar 12 16:45:34 2017 From: eryksun at gmail.com (eryk sun) Date: Sun, 12 Mar 2017 20:45:34 +0000 Subject: Compiling new Pythons on old Windows compilers In-Reply-To: References: Message-ID: On Sun, Mar 12, 2017 at 5:02 PM, Eric Frederich wrote: > Any idea why compatibility was dropped recently? There used to be a PC > directory with different VS directories in the source tree, now it isn't > there any more. CPython 3.5+ uses the Universal CRT on Windows, which is a system component in Vista and later (a recommended update for Windows versions prior to 10). See this blog post: http://stevedower.id.au/blog/building-for-python-3-5 From vlastimil.brom at gmail.com Sun Mar 12 16:47:25 2017 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 12 Mar 2017 21:47:25 +0100 Subject: Does one create an event to notify parent window/GUI of something? In-Reply-To: <8mqfpd-4d7.ln1@esprimo.zbmc.eu> References: <8mqfpd-4d7.ln1@esprimo.zbmc.eu> Message-ID: 2017-03-12 13:14 GMT+01:00 Chris Green : ... > > This question relates to how one communicates between windows/GUIs. > > When the program starts theres a main GUI, class name abookgui. If > you want to add new entries or modify existing entries an edit GUI is > started in a separate window, class abookeditgui. > > I need the abookeditgui window to be able to tell the parent abookgui > window that it has completed whatever it was doing. ... > > -- > Chris Green > ? > -- > https://mail.python.org/mailman/listinfo/python-list Hi, I am not sure, whether it counts as the "bad way" of doing it, you mentined, but the most obvious approach seems to be passing a reference to the parent object on creation of the child object (e.g. dialog window), that way you can have event handlers in the child class/gui, which can call methods of the parent class; it can then handle e.g. saving the data. Other than that, you can use specialised mechanisms like pubsub, especially for more complex requirements of event handling. I don't have experience with pygtk, but I believe, there might be similar principles like in other gui toolkits. You may find this more comprehensive explanation (refering to tkinter) useful: http://stackoverflow.com/a/33650527 The concept of controller is be more flexible for some usecases, however at the very basics you can couple the child class to the parent directly, such as in the following sample: http://stackoverflow.com/a/30690881 Note especially the referencing of objects between classes in the mentioned code: class Widgets(tk.Frame): def __init__(self, parent): ... self.parent = parent ... self.button = tk.Button(text='hello', command=self.parent.get_details) ... class App(tk.Frame): ... self.widgets = Widgets(self) ... def get_details(self): ... And of course, you could probably also use a global variable to reference the respective objects, but this would most likely count as the bad way to do it in some respect. I believe, others might give more specific answers, with respect to the gui you are using. hth, vbr From vlastimil.brom at gmail.com Sun Mar 12 17:20:30 2017 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Sun, 12 Mar 2017 22:20:30 +0100 Subject: Regular expression query In-Reply-To: References: Message-ID: 2017-03-12 17:22 GMT+01:00 : > Hi All, > > I have a string which looks like > > aaaaa,bbbbb,ccccc "4873898374", ddddd, eeeeee "3343,23,23,5,,5,45", fffff "5546,3434,345,34,34,5,34,543,7" > > It is comma saperated string, but some of the fields have a double quoted string as part of it (and that double quoted string can have commas). > Above string have only 6 fields. First is aaaaa, second is bbbbb and last is fffff "5546,3434,345,34,34,5,34,543,7". > How can I split this string in its fields using regular expression ? or even if there is any other way to do this, please speak out. > > Thanks in advance > -- > https://mail.python.org/mailman/listinfo/python-list Hi, would something like the following pattern fulfill the requirements? (It doesn't handle possible empty fields, as mentioned in other posts, the surrounding whitespace can be removed separately: >>> >>> re.findall(r'(?:(?:"[^"]*"|[^,]))+(?=,|$)', 'aaaaa,bbbbb,ccccc "4873898374", ddddd, eeeeee "3343,23,23,5,,5,45", fffff "5546,3434,345,34,34,5,34,543,7"') ['aaaaa', 'bbbbb', 'ccccc "4873898374"', ' ddddd', ' eeeeee "3343,23,23,5,,5,45"', ' fffff "5546,3434,345,34,34,5,34,543,7"'] >>> >>> for field in re.findall(r'(?:(?:"[^"]*"|[^,]))+(?=,|$)', 'aaaaa,bbbbb,ccccc "4873898374", ddddd, eeeeee "3343,23,23,5,,5,45", fffff "5546,3434,345,34,34,5,34,543,7"'): print(field.strip()) ... aaaaa bbbbb ccccc "4873898374" ddddd eeeeee "3343,23,23,5,,5,45" fffff "5546,3434,345,34,34,5,34,543,7" >>> hth, vbr From cl at isbd.net Sun Mar 12 17:32:48 2017 From: cl at isbd.net (Chris Green) Date: Sun, 12 Mar 2017 21:32:48 +0000 Subject: Does one create an event to notify parent window/GUI of something? References: <8mqfpd-4d7.ln1@esprimo.zbmc.eu> Message-ID: <0drgpd-8ag.ln1@esprimo.zbmc.eu> Vlastimil Brom wrote: > 2017-03-12 13:14 GMT+01:00 Chris Green : > ... > > > > This question relates to how one communicates between windows/GUIs. > > > > When the program starts theres a main GUI, class name abookgui. If > > you want to add new entries or modify existing entries an edit GUI is > > started in a separate window, class abookeditgui. > > > > I need the abookeditgui window to be able to tell the parent abookgui > > window that it has completed whatever it was doing. > ... > > > > -- > > Chris Green > > ? > > -- > > https://mail.python.org/mailman/listinfo/python-list > > Hi, > I am not sure, whether it counts as the "bad way" of doing it, you > mentined, but the most obvious approach seems to be passing a > reference to the parent object on creation of the child object (e.g. > dialog window), that way you can have event handlers in the child > class/gui, which can call methods of the parent class; it can then > handle e.g. saving the data. Yes, I saw this as one way of doing it but I wondered whether there was a neater way. What I have actually done is to pass a function as a paraemeter into the Edit GUI so that when the Edit GUI completes it can call the function that the 'parent' has passed to it. Similar really to what you have suggested. > Other than that, you can use specialised mechanisms like pubsub, > especially for more complex requirements of event handling. > I don't have experience with pygtk, but I believe, there might be > similar principles like in other gui toolkits. > You may find this more comprehensive explanation (refering to tkinter) useful: > http://stackoverflow.com/a/33650527 > > The concept of controller is be more flexible for some usecases, > however at the very basics you can couple the child class to the > parent directly, such as in the following sample: > http://stackoverflow.com/a/30690881 > > Note especially the referencing of objects between classes in the > mentioned code: > > class Widgets(tk.Frame): > def __init__(self, parent): > ... > self.parent = parent > ... > self.button = tk.Button(text='hello', command=self.parent.get_details) > > > > ... > > class App(tk.Frame): > ... > self.widgets = Widgets(self) > ... > def get_details(self): ... > > > And of course, you could probably also use a global variable to > reference the respective objects, but this would most likely count as > the bad way to do it in some respect. > Yes! :-) > I believe, others might give more specific answers, with respect to > the gui you are using. > > hth, Yes, thank you. -- Chris Green ? From cl at isbd.net Sun Mar 12 18:44:20 2017 From: cl at isbd.net (Chris Green) Date: Sun, 12 Mar 2017 22:44:20 +0000 Subject: How to iterate through the columns in a row using sqlite3.Row Message-ID: <4jvgpd-2dh.ln1@esprimo.zbmc.eu> This should be simple but I can't manage it at the moment! :-) I have opened a database connection and have set the row_factory to sqlite3.Row. So how do I actually iterate through a row of data having used fetchone to read a row. I.e. I have:- self.conn = sqlite3.connect(dbname) self.conn.row_factory = sqlite3.Row self.cursor = self.conn.cursor() self.table = table ... ... sql = "SELECT * FROM " + self.table + " WHERE firstName||lastName = ?" self.cursor.execute(sql, (name,)) row = self.cursor.fetchone() I want a for loop which gives me the column names and values. -- Chris Green ? From torriem at gmail.com Sun Mar 12 19:40:43 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 12 Mar 2017 17:40:43 -0600 Subject: Does one create an event to notify parent window/GUI of something? In-Reply-To: <8mqfpd-4d7.ln1@esprimo.zbmc.eu> References: <8mqfpd-4d7.ln1@esprimo.zbmc.eu> Message-ID: <9bcee537-82ab-dd92-fda1-c05b971b8e06@gmail.com> On 03/12/2017 06:14 AM, Chris Green wrote: > There are (of course) event handlers for the 'Save' and 'Cancel' > button click events in abookeditgui, what I need is hooks from these > to run some code in abookgui after the abookeditgui has completed. How > should one do this, is there a way for a class to call code in the > class 'above' which instantiated it? Sure. Have the child object emit custom signal that your parent object attaches to a callback. From python at mrabarnett.plus.com Sun Mar 12 20:28:46 2017 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 13 Mar 2017 00:28:46 +0000 Subject: How to iterate through the columns in a row using sqlite3.Row In-Reply-To: <4jvgpd-2dh.ln1@esprimo.zbmc.eu> References: <4jvgpd-2dh.ln1@esprimo.zbmc.eu> Message-ID: <822cbeb5-b1b7-ce77-87c0-7a30573119ee@mrabarnett.plus.com> On 2017-03-12 22:44, Chris Green wrote: > This should be simple but I can't manage it at the moment! :-) > > I have opened a database connection and have set the row_factory to > sqlite3.Row. > > So how do I actually iterate through a row of data having used > fetchone to read a row. > > I.e. I have:- > > self.conn = sqlite3.connect(dbname) > self.conn.row_factory = sqlite3.Row > self.cursor = self.conn.cursor() > self.table = table > ... > ... > sql = "SELECT * FROM " + self.table + " WHERE firstName||lastName = ?" > self.cursor.execute(sql, (name,)) > row = self.cursor.fetchone() > > I want a for loop which gives me the column names and values. > The docs tell you that the sqlite3.Row instances are like tuples, but with additional features, such as a .keys() method that will tell you the column names. Try: print(row.keys()) With a little experimentation you'll find that can pass it to dict. Try: print(dict(row)) From ben+python at benfinney.id.au Sun Mar 12 20:52:18 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 13 Mar 2017 11:52:18 +1100 Subject: Substitute a mock object for the metaclass of a class Message-ID: <857f3ugfr1.fsf@benfinney.id.au> How can I override the metaclass of a Python class, with a `unittest.mock.MagicMock` instance instead? I have a function whose job involves working with the metaclass of an argument:: # lorem.py class Foo(object): pass def quux(existing_class): ? metaclass = type(existing_class) new_class = metaclass(?) The unit tests for this function will need to assert that the calls to the metaclass go as expected, *without* actually calling a real class object. To write a unit test for this function, I want to temporarily override the metaclass of some classes in the system with a mock object instead. This will allow, for example, making assertions about how the metaclass was called, and ensuring no unwanted side effects. # test_lorem.py import unittest import unittest.mock import lorem class stub_metaclass(type): def __new__(metaclass, name, bases, namespace): return super().__new__(metaclass, name, bases, namespace) class quux_TestCase(unittest.TestCase): @unittest.mock.patch.object( lorem.Foo, '__class__', side_effect=stub_metaclass) def test_calls_expected_metaclass_with_class_name( self, mock_foo_metaclass, ): lorem.quux(lorem.Foo) mock_foo_metaclass.assert_called_with( 'Foo', unittest.mock.ANY, unittest.mock.ANY) When I try to mock the `__class__` attribute of an existing class, though, I get this error:: File "/usr/lib/python3/dist-packages/mock/mock.py", line 1500, in start result = self.__enter__() File "/usr/lib/python3/dist-packages/mock/mock.py", line 1460, in __enter__ setattr(self.target, self.attribute, new_attr) TypeError: __class__ must be set to a class, not 'MagicMock' object This is telling me that `unittest.mock.patch` is attempting to set the `__class__` attribute temporarily to a `MagicMock` instance, as I want; but Python is refusing that with a `TypeError`. But placing a mock object as the metaclass (the class's `__class__` attribute) is exactly what I'm trying to do, *in order that* the mock object will do all that it does: record calls, pretend valid behaviour, etc. How can I set a mock object in place of the class's `__class__` attribute, in order to instrument my code for testing metaclass operation? -- \ ?The problem with television is that the people must sit and | `\ keep their eyes glued on a screen: the average American family | _o__) hasn't time for it.? ?_The New York Times_, 1939 | Ben Finney From no.email at nospam.invalid Sun Mar 12 21:22:04 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Sun, 12 Mar 2017 18:22:04 -0700 Subject: How to iterate through the columns in a row using sqlite3.Row References: <4jvgpd-2dh.ln1@esprimo.zbmc.eu> Message-ID: <87mvcqots3.fsf@nightsong.com> Chris Green writes: > self.conn = sqlite3.connect(dbname) > self.conn.row_factory = sqlite3.Row > self.cursor = self.conn.cursor() > self.table = table > ... > ... > sql = "SELECT * FROM " + self.table + " WHERE firstName||lastName = ?" > self.cursor.execute(sql, (name,)) > row = self.cursor.fetchone() untested: with sqlite3.connect(dbname) as conn: sql = "SELECT * FROM " + self.table + " WHERE firstName||lastName = ?" cursor = conn.execute(sql, (name,)) row = cursor.fetchone() From steve+python at pearwood.info Sun Mar 12 21:51:01 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 13 Mar 2017 12:51:01 +1100 Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <87inne1ggt.fsf@universite-de-strasbourg.fr.invalid> Message-ID: <58c5fb06$0$1612$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Mar 2017 05:45 am, Alain Ketterlin wrote: > Steve D'Aprano writes: [...] >> It seems that os.remove on Linux will force the delete even if the file >> is read-only or unreadable, provided you own the file. > > Your permissions on the file do not really matters. It's all about your > permissions on the parent directory (removing a file is really modifying > the parent dir). Actually, it is even slightly more complicated. Here is > an excerpt of the unlink(2) call (which does the job) listing common > error cases: Thanks for the detailed explanation, and to everyone else who corrected my misunderstanding. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From torriem at gmail.com Sun Mar 12 23:26:31 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 12 Mar 2017 21:26:31 -0600 Subject: Compiling new Pythons on old Windows compilers In-Reply-To: References: Message-ID: On 03/12/2017 02:45 PM, eryk sun wrote: > On Sun, Mar 12, 2017 at 5:02 PM, Eric Frederich > wrote: >> Any idea why compatibility was dropped recently? There used to be a PC >> directory with different VS directories in the source tree, now it isn't >> there any more. > > CPython 3.5+ uses the Universal CRT on Windows, which is a system > component in Vista and later (a recommended update for Windows > versions prior to 10). See this blog post: > > http://stevedower.id.au/blog/building-for-python-3-5 Hmm, this is going to be a huge problem for Python users that work with proprietary software that is fixed to specific versions of MSCVRT. The idea that everyone should just update their builds to the latest universal runtime is a good one, but it's just not going to happen across the entire software industry anytime soon. Especially for existing releases. Looks like Python 3 is a no go for Eric. The runtime mixing issue has always been a problem for Windows developers. Not sure the universal runtime really solves it! From torriem at gmail.com Sun Mar 12 23:34:56 2017 From: torriem at gmail.com (Michael Torrie) Date: Sun, 12 Mar 2017 21:34:56 -0600 Subject: Compiling new Pythons on old Windows compilers In-Reply-To: References: Message-ID: <0a5783d8-cdc4-f94d-dfdf-a91719ec9444@gmail.com> On 03/12/2017 09:26 PM, Michael Torrie wrote: > On 03/12/2017 02:45 PM, eryk sun wrote: >> On Sun, Mar 12, 2017 at 5:02 PM, Eric Frederich >> wrote: >>> Any idea why compatibility was dropped recently? There used to be a PC >>> directory with different VS directories in the source tree, now it isn't >>> there any more. >> >> CPython 3.5+ uses the Universal CRT on Windows, which is a system >> component in Vista and later (a recommended update for Windows >> versions prior to 10). See this blog post: >> >> http://stevedower.id.au/blog/building-for-python-3-5 Did I read that right that you can link python statically so you can use the new universal runtime-based python to extend an app with another runtime (but requiring administrator access somehow?)? From cl at isbd.net Mon Mar 13 04:37:03 2017 From: cl at isbd.net (Chris Green) Date: Mon, 13 Mar 2017 08:37:03 +0000 Subject: Does one create an event to notify parent window/GUI of something? References: <8mqfpd-4d7.ln1@esprimo.zbmc.eu> <9bcee537-82ab-dd92-fda1-c05b971b8e06@gmail.com> Message-ID: Michael Torrie wrote: > On 03/12/2017 06:14 AM, Chris Green wrote: > > There are (of course) event handlers for the 'Save' and 'Cancel' > > button click events in abookeditgui, what I need is hooks from these > > to run some code in abookgui after the abookeditgui has completed. How > > should one do this, is there a way for a class to call code in the > > class 'above' which instantiated it? > > Sure. Have the child object emit custom signal that your parent object > attaches to a callback. > Thanks, I guess this is probably the 'proper' event driven way to do it. What I have actually done for the moment is to hand a function handle from the parent to the child so that the child can execute the code at the required time. -- Chris Green ? From cl at isbd.net Mon Mar 13 04:42:22 2017 From: cl at isbd.net (Chris Green) Date: Mon, 13 Mar 2017 08:42:22 +0000 Subject: How to iterate through the columns in a row using sqlite3.Row References: <4jvgpd-2dh.ln1@esprimo.zbmc.eu> <87mvcqots3.fsf@nightsong.com> Message-ID: Paul Rubin wrote: > Chris Green writes: > > self.conn = sqlite3.connect(dbname) > > self.conn.row_factory = sqlite3.Row > > self.cursor = self.conn.cursor() > > self.table = table > > ... > > ... > > sql = "SELECT * FROM " + self.table + " WHERE firstName||lastName = ?" > > self.cursor.execute(sql, (name,)) > > row = self.cursor.fetchone() > > untested: > > with sqlite3.connect(dbname) as conn: > sql = "SELECT * FROM " + self.table + " WHERE firstName||lastName = ?" > cursor = conn.execute(sql, (name,)) > row = cursor.fetchone() Ay? I've maybe not explained well. I want to iterate through row *after* the above code such that I can see the column names as 'keys' and the corresponding values. -- Chris Green ? From cl at isbd.net Mon Mar 13 04:43:55 2017 From: cl at isbd.net (Chris Green) Date: Mon, 13 Mar 2017 08:43:55 +0000 Subject: How to iterate through the columns in a row using sqlite3.Row References: <4jvgpd-2dh.ln1@esprimo.zbmc.eu> <822cbeb5-b1b7-ce77-87c0-7a30573119ee@mrabarnett.plus.com> Message-ID: MRAB wrote: > On 2017-03-12 22:44, Chris Green wrote: > > This should be simple but I can't manage it at the moment! :-) > > > > I have opened a database connection and have set the row_factory to > > sqlite3.Row. > > > > So how do I actually iterate through a row of data having used > > fetchone to read a row. > > > > I.e. I have:- > > > > self.conn = sqlite3.connect(dbname) > > self.conn.row_factory = sqlite3.Row > > self.cursor = self.conn.cursor() > > self.table = table > > ... > > ... > > sql = "SELECT * FROM " + self.table + " WHERE firstName||lastName = ?" > > self.cursor.execute(sql, (name,)) > > row = self.cursor.fetchone() > > > > I want a for loop which gives me the column names and values. > > > The docs tell you that the sqlite3.Row instances are like tuples, but > with additional features, such as a .keys() method that will tell you > the column names. Try: > > print(row.keys()) > > With a little experimentation you'll find that can pass it to dict. Try: > > print(dict(row)) > so are you saying that I should be able to write:- rowAsDict = dict(row) -- Chris Green ? From eryksun at gmail.com Mon Mar 13 05:47:45 2017 From: eryksun at gmail.com (eryk sun) Date: Mon, 13 Mar 2017 09:47:45 +0000 Subject: When will os.remove fail? In-Reply-To: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 12, 2017 at 5:48 PM, Steve D'Aprano wrote: > > Does os.remove work like this under Windows too? os.remove calls DeleteFile on Windows. This in turn calls NtOpenFile to instantiate a kernel File object that has delete access and return a handle to it. Next it calls NtSetInformationFile on the handle to set the file's "DeleteFile" disposition. Either of these operations can fail. One hurdle to getting delete access is the sharing mode. If there are existing File objects that reference the file, they all have to share delete access. Otherwise the open fails with a sharing violation. This is often the show stopper because the C runtime (and thus CPython, usually) opens files with read and write sharing but not delete sharing. Another hurdle is paging files, but a program really has no business trying to delete a critical system file. You'll get a sharing violation if a file is currently mapped as one of the system's paging files. Windows supports up to 16 paging files, each on a separate volume, so it's not like this is a common problem. Otherwise, getting delete access depends on the file system. If it doesn't implement security (e.g. FAT32), then delete access is always granted. If it does implement security (e.g. NTFS), then first I think we need to discuss the basics of NT security. ---- Secured objects have a security descriptor that contains the security identifier (SID) of the owner and (optionally) a primary group (not used by Windows). It also may contain a discretionary access control list (DACL) and a system access control list (SACL). Each of these contains a list of access control entries (ACEs) that either allow or deny the specified access mask for a given user/group SID (canonically, deny ACEs should be sorted before allow ACEs). For use with container objects, such as file-system directories, an ACE also has the following flags to control inheritance: object inherit, container inherit, no propagate inherit (i.e. clear the object/container inherit flags on inherited ACEs), and inherent only (i.e. don't apply this ACE to the object itself). An access mask is a 32-bit value, with one right mapped to each bit. The lower half defines up to 16 rights that are specific to an object type, such as File, Process, or Thread. The next 8 bits are standard rights (e.g. delete) that are defined the same for all objects. The upper 4 bits are for generic read (GR), write (GW), execute (GE), and all (GA) access. In an access check, generic rights should be translated to standard and specific rights according to a generic mapping that's defined for each type. Each process has a primary token, and each thread in a process optionally can have an impersonation token. An access token (and the associated logon session) is usually created by the local security authority (the lsass.exe process), which is coupled with the security monitor in the kernel. A token contains a list of user/group SIDs, which are used in an access check if they're flagged as either enabled or use-for-deny-only (i.e. only for deny ACEs). A token also has a list of privileges and their enable state. A token is itself a secured object; it's an instance of the Token type. A token is assigned an integrity level. The term "elevating" refers in part to starting a process with a token that has a higher integrity level, for which the available levels are low, medium (default), high, and system. A secured object's SACL can contain a mandatory label ACE, which sets its integrity level. The mask field of this ACE isn't a 32-bit access mask, but rather it consists of up to 3 flag values -- no-write-up, no-read-up, and no-execute-up -- that determine whether a token at a lower integrity level is allowed write/delete, read, or execute access. If a secured object doesn't have a mandatory label ACE, then it implicitly has a medium integrity level with no-write-up. ---- OK, that covers the basics. If the current token contains the privilege SeRestorePrivilege (e.g. a token for an elevated administrator), and it's enabled, then delete access will always be granted regardless of the file's security descriptor. The restore privilege is quite empowering, so enable it with caution. A file's DACL will either allow or explicitly deny delete access. If access isn't explicitly allowed, then it's implicitly denied. However, delete access will still be granted if the parent directory grants delete-child access. The delete-child right is specific to the File type -- specifically for directories. If the file's SACL mandatory access includes no-write-up, then a user at a lower integrity level will not be able to open the file for delete access, even if the file's DACL (discretionary access) otherwise allows it. However, delete access is still granted if the parent directory grants delete-child access to the user. Thus parent-level discretionary access trumps object-level mandatory access. The next step is setting the file's "DeleteFile" disposition. First let's take a close look at how this works. ---- In user mode, a kernel object such as a File instance is referenced as a handle. Duplicating the handle creates a new reference to the object. However, if you open the file/device again, you'll get a handle for a new object. All File objects that reference the same data file will share a file or link control block (FCB) structure that, among other things, is used to track sharing of read, write, and delete access and the file's delete disposition. When the delete disposition is set, no new File references can be instantiated (i.e. any level of access is denied, even just to read the file attributes), but the file isn't immediately unlinked. It's still listed in the parent directory. Any existing File reference that has delete access can unset the delete disposition. When all handle and pointer references to a File object are closed, the file system decrements the reference count on the FCB. When the FCB reference count drops to 0, if the delete disposition is currently set, then finally the file is unlinked from the parent directory. ---- I can think of a couple of cases in which setting the delete disposition will fail with access denied. If the file is currently memory-mapped as code or data (e.g. an EXE or DLL), but not for system paging, then you can open it for delete access, but only renaming the file will succeed (it can be renamed anywhere on the volume, but not to another volume). Setting the delete disposition will fail with access denied. The system won't allow a mapped file to be unlinked. Finally, I'm sure most people are familiar with the read-only file attribute. If this attribute is set you can still open a file with delete access to rename it, but setting the delete disposition will fail with access denied. You may complain that the system has granted the user delete access, so getting an access denied error is a breach of contract. You'd be right, but the kernel actually returns STATUS_CANNOT_DELETE. The Windows API maps this to ERROR_ACCESS_DENIED. STATUS_CANNOT_DELETE = 0xC0000121 ERROR_ACCESS_DENIED = 0x0005 >>> ntdll.RtlNtStatusToDosError(STATUS_CANNOT_DELETE) 5 It's often the case that useful information is lost when mapping a kernel status code to a Windows error code. This is an inherent problem with layered APIs. Even more information is lost when the C runtime maps the Windows error to a POSIX errno value such as EACCES. From marko at pacujo.net Mon Mar 13 06:08:37 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 13 Mar 2017 12:08:37 +0200 Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87k27tzdy2.fsf@elektro.pacujo.net> eryk sun : > On Sun, Mar 12, 2017 at 5:48 PM, Steve D'Aprano > wrote: >> >> Does os.remove work like this under Windows too? > > os.remove calls DeleteFile on Windows. [...] Fascinating info, Eryk. The difference between file removal in Linux and Windows is a bit like the difference between object destrution in C++ and Python. In C++, you destroy an object with a "delete" statement. In Python, you can't destroy an object, you can simply lose all references to it. Marko From __peter__ at web.de Mon Mar 13 06:26:19 2017 From: __peter__ at web.de (Peter Otten) Date: Mon, 13 Mar 2017 11:26:19 +0100 Subject: How to iterate through the columns in a row using sqlite3.Row References: <4jvgpd-2dh.ln1@esprimo.zbmc.eu> <822cbeb5-b1b7-ce77-87c0-7a30573119ee@mrabarnett.plus.com> Message-ID: Chris Green wrote: > MRAB wrote: >> On 2017-03-12 22:44, Chris Green wrote: >> > This should be simple but I can't manage it at the moment! :-) >> > >> > I have opened a database connection and have set the row_factory to >> > sqlite3.Row. >> > >> > So how do I actually iterate through a row of data having used >> > fetchone to read a row. >> > >> > I.e. I have:- >> > >> > self.conn = sqlite3.connect(dbname) >> > self.conn.row_factory = sqlite3.Row >> > self.cursor = self.conn.cursor() >> > self.table = table >> > ... >> > ... >> > sql = "SELECT * FROM " + self.table + " WHERE >> > firstName||lastName = ?" self.cursor.execute(sql, (name,)) >> > row = self.cursor.fetchone() >> > >> > I want a for loop which gives me the column names and values. >> > >> The docs tell you that the sqlite3.Row instances are like tuples, but >> with additional features, such as a .keys() method that will tell you >> the column names. Try: >> >> print(row.keys()) >> >> With a little experimentation you'll find that can pass it to dict. Try: >> >> print(dict(row)) >> > so are you saying that I should be able to write:- > > rowAsDict = dict(row) You can either forget about about the custom row_factory and use cursor.description >>> import sqlite3 >>> db = sqlite3.connect(":memory:") >>> cs = db.cursor() >>> cs.execute("select 1 foo, 2 bar") >>> names = [col[0] for col in cs.description] >>> names ['foo', 'bar'] >>> for row in cs: ... for name, value in zip(names, row): ... print(name, value, sep=": ") ... foo: 1 bar: 2 or use sqlite3.Row and its keys() method: >>> cs.row_factory = sqlite3.Row >>> for row in cs.execute("select 1 ham, 2 spam"): ... for name in row.keys(): ... print(name, row[name], sep=": ") ... ham: 1 spam: 2 From ssmadhu80 at gmail.com Mon Mar 13 07:25:50 2017 From: ssmadhu80 at gmail.com (Madhusudhanan Sambath) Date: Mon, 13 Mar 2017 04:25:50 -0700 (PDT) Subject: i got error while writing data to file Message-ID: hi to all, this is madhu...i am new to python this is my python code, where i labeled the reviews taken from amazon as positive, negative and neutral based on review score i have collected reviews and scores from amazon scrap prg, but i have problem while doing labelling.kindly help me import nltk import csv import ast data=[] positivedata=[] negativedata=[] neutraldata=[] with open('E:/amadown2py-master/reviews1.csv', 'r',encoding='UTF8') as csvfile: mycsv = csv.reader(csvfile) for row in mycsv: data = row[0] #print (data) try: score = ast.literal_eval(row[1]) if score > 3: cnt=0; #print (score) print (data) positivedata.append((data)) with open('E:/amadown2py-master/Sam7_pos_rev.txt',mode='wt') as myfile: myfile.writelines('\n'.join(positivedata)) myfile.close() the above program is able to create file but full reviews are not read from csv . if i print the details about 48kb size, i got more data , but in file it have only 3kb why?kinldy help me From falter_donald at bah.com Mon Mar 13 09:24:56 2017 From: falter_donald at bah.com (Falter, Donald [USA]) Date: Mon, 13 Mar 2017 13:24:56 +0000 Subject: [External] Unsubscribe to Python email list In-Reply-To: <6DD74957-1E1E-4EB3-A1C0-EF7F26392411@hotmail.com> References: <6DD74957-1E1E-4EB3-A1C0-EF7F26392411@hotmail.com> Message-ID: <93285AC0FA20BA47BE43FA54FCA5B321EDDBD84A@ASHBDAG2M3.resource.ds.bah.com> Yeah, I think I'm going to bail on this list too. Thanks -----Original Message----- From: Python-list [mailto:python-list-bounces+falter_donald=bah.com at python.org] On Behalf Of Pablo Lozano Sent: Thursday, March 9, 2017 9:38 PM To: python-list at python.org Subject: [External] Unsubscribe to Python email list Good day, I would like to unsubscribe this e-mail to the Python e-mail list. Kind regards -- https://mail.python.org/mailman/listinfo/python-list From torriem at gmail.com Mon Mar 13 11:15:39 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 13 Mar 2017 09:15:39 -0600 Subject: Does one create an event to notify parent window/GUI of something? In-Reply-To: References: <8mqfpd-4d7.ln1@esprimo.zbmc.eu> <9bcee537-82ab-dd92-fda1-c05b971b8e06@gmail.com> Message-ID: On 03/13/2017 02:37 AM, Chris Green wrote: > Michael Torrie wrote: >> On 03/12/2017 06:14 AM, Chris Green wrote: >>> There are (of course) event handlers for the 'Save' and 'Cancel' >>> button click events in abookeditgui, what I need is hooks from these >>> to run some code in abookgui after the abookeditgui has completed. How >>> should one do this, is there a way for a class to call code in the >>> class 'above' which instantiated it? >> >> Sure. Have the child object emit custom signal that your parent object >> attaches to a callback. >> > Thanks, I guess this is probably the 'proper' event driven way to do > it. What I have actually done for the moment is to hand a function > handle from the parent to the child so that the child can execute the > code at the required time. Sure. What you are doing is perfectly acceptable and is a common pattern. Callbacks are potentially faster than signals and slots (to use the Qt parlance) also. Makes me wonder in what cases are signals and slots desired vs callbacks. Async frameworks tend to use callbacks and they often chain them up just like signals can be connected to multiple slots. I suppose one advantage of signals and lots is that you can get a handle to each connection for disconnecting later, whereas with callback chains it's pretty opaque once you set them up (say in Twisted or something similar). From amit at phpandmore.net Mon Mar 13 12:19:05 2017 From: amit at phpandmore.net (Amit Yaron) Date: Mon, 13 Mar 2017 18:19:05 +0200 Subject: i got error while writing data to file In-Reply-To: References: Message-ID: <58C6C679.1030705@phpandmore.net> You open the file more than once for which row with score greater than 3. Every time you open a file for writing it truncates an existing one with the same name. On 13/03/17 13:25, Madhusudhanan Sambath wrote: > hi to all, > this is madhu...i am new to python > > this is my python code, where i labeled the reviews taken from amazon as positive, negative and neutral based on review score > > i have collected reviews and scores from amazon scrap prg, but i have problem while doing labelling.kindly help me > > import nltk > import csv > import ast > > data=[] > positivedata=[] > negativedata=[] > neutraldata=[] > > > > > with open('E:/amadown2py-master/reviews1.csv', 'r',encoding='UTF8') as csvfile: > mycsv = csv.reader(csvfile) > for row in mycsv: > data = row[0] > #print (data) > try: > score = ast.literal_eval(row[1]) > if score > 3: > cnt=0; > #print (score) > print (data) > positivedata.append((data)) > with open('E:/amadown2py-master/Sam7_pos_rev.txt',mode='wt') as myfile: > myfile.writelines('\n'.join(positivedata)) > myfile.close() > > > the above program is able to create file but full reviews are not read from csv . if i print the details about 48kb size, i got more data , but in file it have only 3kb why?kinldy help me > > From amit at phpandmore.net Mon Mar 13 12:19:05 2017 From: amit at phpandmore.net (Amit Yaron) Date: Mon, 13 Mar 2017 18:19:05 +0200 Subject: i got error while writing data to file In-Reply-To: References: Message-ID: <58C6C679.1030705@phpandmore.net> You open the file more than once for which row with score greater than 3. Every time you open a file for writing it truncates an existing one with the same name. On 13/03/17 13:25, Madhusudhanan Sambath wrote: > hi to all, > this is madhu...i am new to python > > this is my python code, where i labeled the reviews taken from amazon as positive, negative and neutral based on review score > > i have collected reviews and scores from amazon scrap prg, but i have problem while doing labelling.kindly help me > > import nltk > import csv > import ast > > data=[] > positivedata=[] > negativedata=[] > neutraldata=[] > > > > > with open('E:/amadown2py-master/reviews1.csv', 'r',encoding='UTF8') as csvfile: > mycsv = csv.reader(csvfile) > for row in mycsv: > data = row[0] > #print (data) > try: > score = ast.literal_eval(row[1]) > if score > 3: > cnt=0; > #print (score) > print (data) > positivedata.append((data)) > with open('E:/amadown2py-master/Sam7_pos_rev.txt',mode='wt') as myfile: > myfile.writelines('\n'.join(positivedata)) > myfile.close() > > > the above program is able to create file but full reviews are not read from csv . if i print the details about 48kb size, i got more data , but in file it have only 3kb why?kinldy help me > > From cannedham284 at hotmail.com Mon Mar 13 12:42:27 2017 From: cannedham284 at hotmail.com (Ben Iannitelli) Date: Mon, 13 Mar 2017 16:42:27 +0000 Subject: i got error while writing data to file In-Reply-To: References: Message-ID: Hi Madhu, I don't know much about web scraping but I can explain why your output is so much smaller than your input: you keep writing over your output file. The way I see it you have two options: 1. Where you wrote "mode='wt'", change "wt" to "at". The replacement "at" appends your output text, as opposed to "wt", which writes over your output text as if the file hadn't already existed. 2. Leave the file modes alone, but move the "with" statement further up the "for" block. If you use this option, your code should look more like below (if email didn't garble the formatting): with open('E:/amadown2py-master/reviews1.csv', 'r',encoding='UTF8') as csvfile: mycsv = csv.reader(csvfile) for row in mycsv: data = row[0] #print (data) with open('E:/amadown2py-master/Sam7_pos_rev.txt',mode='wt') as myfile:#Moved this! try: score = ast.literal_eval(row[1]) if score > 3: cnt=0; #print (score) print (data) positivedata.append((data)) myfile.writelines('\n'.join(positivedata)) #myfile.close()#You shouldn't need this, bc you're using "with" Of the two options, I would think that option 1 is easier. HTH, Ben I. From padawanwebdev at gmail.com Mon Mar 13 13:40:12 2017 From: padawanwebdev at gmail.com (padawanwebdev at gmail.com) Date: Mon, 13 Mar 2017 10:40:12 -0700 (PDT) Subject: Issues with in try except and excel spreadsheet Message-ID: Hello, I'm having a problem with a try except inside a while loop. The problem I see occuring has to do with an excel file the script tries to write to while the excel file is open. The exception captures and gives an error: OError: [Errno 13] Permission denied:'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' This is expected and is not the problem. However, the issue occurs when I close the excel file. As an example, if I run the script and the excel file is open thru 3 iterations, meaning that the script can't write to the excel file until the excel file is closed, then after the excel file is closed the script prints to the excel file 3 times. I don't need it to write to the excel file 3 times. I only need it to write just once. If the excel file is closed before I run the script than it works like its suppose too. I hope I made my case clear. I look forward to some feedback. Any would be greatly appreciated! here is part of the code: connectionResults = None returnResults = InternetQualityTest.connectionTest(connectionResults) if returnResults == True: try: execfile('assetMapping.py') time.sleep(4) sys.exit() except Exception as e: print "error",e time.sleep(20) FYI: The assetMapping.py runs another module from inside, and it's this module running from assetMapping that writes to the excel file. From cannedham284 at hotmail.com Mon Mar 13 13:45:53 2017 From: cannedham284 at hotmail.com (Ben Iannitelli) Date: Mon, 13 Mar 2017 17:45:53 +0000 Subject: i got error while writing data to file In-Reply-To: References: , Message-ID: Hello again, It seems I was a little too quick to hit "send". Option #2 of the two possible solutions I offered is not right. Here's what it should be (unless the formatting gets garbled): with open('E:/amadown2py-master/reviews1.csv', 'r',encoding='UTF8') as csvfile: with open('E:/amadown2py-master/Sam7_pos_rev.txt',mode='wt') as myfile:#Moved this! mycsv = csv.reader(csvfile) for row in mycsv: data = row[0] #print (data) try: score = ast.literal_eval(row[1]) if score > 3: cnt=0; #print (score) print (data) positivedata.append((data)) myfile.writelines('\n'.join(positivedata)) #myfile.close()#You shouldn't need this, bc you're using "with" ttfn, Ben I. From cl at isbd.net Mon Mar 13 13:58:08 2017 From: cl at isbd.net (Chris Green) Date: Mon, 13 Mar 2017 17:58:08 +0000 Subject: How to set initial size of gtk.TextView window? Message-ID: I have a series of data fields laid out in a Vbox, the size needs to vary, some need to be two lines high, others four lines or more. The code creating the fields is:- def __init__(self, multiline=0): self.multiline = multiline if (self.multiline): self.buffer = gtk.TextBuffer() self.view = gtk.TextView(self.buffer) self.widget = gtk.ScrolledWindow() self.widget.add(self.view) self.widget.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.widget.set_shadow_type(gtk.SHADOW_ETCHED_IN) else: self.widget = gtk.Entry() As can be seen there are single line boxes and multiline ones, what I want to be able to do is to have a parameter (or just use multiline) to set the initial number of lines in the TextView fields. Is it a matter of using gtk.Widget.set_size_request() or is there an easier way? -- Chris Green ? From rhodri at kynesim.co.uk Mon Mar 13 14:01:41 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Mon, 13 Mar 2017 18:01:41 +0000 Subject: Issues with in try except and excel spreadsheet In-Reply-To: References: Message-ID: On 13/03/17 17:40, padawanwebdev at gmail.com wrote: > Hello, I'm having a problem with a try except inside a while loop. The problem I see occuring has to do with an excel file the script tries to write to while the excel file is open. The exception captures and gives an error: > > OError: [Errno 13] Permission denied:'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' > > This is expected and is not the problem. However, the issue occurs when I close the excel file. As an example, if I run the script and the excel file is open thru 3 iterations, meaning that the script can't write to the excel file until the excel file is closed, then after the excel file is closed the script prints to the excel file 3 times. I don't need it to write to the excel file 3 times. I only need it to write just once. If the excel file is closed before I run the script than it works like its suppose too. > I hope I made my case clear. I look forward to some feedback. Any would be greatly appreciated! When you say "...the excel file is open thru 3 iterations", what do you mean? Three iterations of what? You haven't shown us a loop, so it's not obvious. How do you know it prints (writes?) to the excel file three times? Again, there's nothing in the code snippet that would tell you. > here is part of the code: > > connectionResults = None > returnResults = InternetQualityTest.connectionTest(connectionResults) > if returnResults == True: > try: > execfile('assetMapping.py') > time.sleep(4) > sys.exit() > except Exception as e: > print "error",e > time.sleep(20) This looks plausible, though honestly the execfile makes me feel icky for unrelated reasons. I repeat, though; this isn't a loop, and my crystal ball isn't up to telling me how it gets invoked. > FYI: The assetMapping.py runs another module from inside, and it's this module running from assetMapping that writes to the excel file. > -- Rhodri James *-* Kynesim Ltd From gordon at panix.com Mon Mar 13 14:04:56 2017 From: gordon at panix.com (John Gordon) Date: Mon, 13 Mar 2017 18:04:56 +0000 (UTC) Subject: What's the neatest way of getting dictionary entries in a specified order? References: <8f090d66-b3d2-00ac-ca5b-5745d96a11b7@gmail.com> <4c80c74c-16f3-26d5-0a31-2cdeef0216fa@lucidity.plus.com> <58C2778A.60400@stoneleaf.us> <58c3316d$0$1588$c3e8da3$5496439d@news.astraweb.com> <4sucpd-g59.ln1@esprimo.zbmc.eu> Message-ID: In Michael Torrie writes: > The order of the displayed fields is usually something set by the GUI > API when you create the table widget. At least in most toolkits I'm > familiar with. As well, when you add the row to the widget, you > normally specify the fields (the data) individually, so I would think > the order of the dict's fields does not matter since you'd manually > specify each field's data. The original example used a loop to get all of the dict fields and add them to the GUI, instead of adding each field individually. -- John Gordon A is for Amy, who fell down the stairs gordon at panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" From padawanwebdev at gmail.com Mon Mar 13 16:37:26 2017 From: padawanwebdev at gmail.com (padawanwebdev at gmail.com) Date: Mon, 13 Mar 2017 13:37:26 -0700 (PDT) Subject: Issues with in try except and excel spreadsheet In-Reply-To: References: Message-ID: <84f6caea-1d09-466c-abf7-f5f066cfb3fb@googlegroups.com> On Monday, March 13, 2017 at 11:10:36 AM UTC-7, Rhodri James wrote: > On 13/03/17 17:40, padawanwebdev at gmail.com wrote: > > Hello, I'm having a problem with a try except inside a while loop. The problem I see occuring has to do with an excel file the script tries to write to while the excel file is open. The exception captures and gives an error: > > > > OError: [Errno 13] Permission denied:'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' > > > > This is expected and is not the problem. However, the issue occurs when I close the excel file. As an example, if I run the script and the excel file is open thru 3 iterations, meaning that the script can't write to the excel file until the excel file is closed, then after the excel file is closed the script prints to the excel file 3 times. I don't need it to write to the excel file 3 times. I only need it to write just once. If the excel file is closed before I run the script than it works like its suppose too. > > I hope I made my case clear. I look forward to some feedback. Any would be greatly appreciated! > > When you say "...the excel file is open thru 3 iterations", what do you > mean? Three iterations of what? You haven't shown us a loop, so it's > not obvious. > > How do you know it prints (writes?) to the excel file three times? > Again, there's nothing in the code snippet that would tell you. > > > here is part of the code: > > > > connectionResults = None > > returnResults = InternetQualityTest.connectionTest(connectionResults) > > if returnResults == True: > > try: > > execfile('assetMapping.py') > > time.sleep(4) > > sys.exit() > > except Exception as e: > > print "error",e > > time.sleep(20) > > This looks plausible, though honestly the execfile makes me feel icky > for unrelated reasons. I repeat, though; this isn't a loop, and my > crystal ball isn't up to telling me how it gets invoked. > > > FYI: The assetMapping.py runs another module from inside, and it's this module running from assetMapping that writes to the excel file. > > > > > -- > Rhodri James *-* Kynesim Ltd I apologize if I short-changed you with the code. It's a bigger piece of code and I thought maybe with my explanation and the piece I showed it would be enough. I was wrong. Here is the rest. I apologize in advance if there are any more confusions. I do appreciate your help! Thanks in advance :-) THIS IS: Main.py import InternetQualityTest import assetMapping import time import sys if __name__ == '__main__': while True: connectionResults = None returnResults = InternetQualityTest.connectionTest(connectionResults) if returnResults == True: try: execfile('assetMapping.py') time.sleep(4) sys.exit() except Exception as e: print "error",e time.sleep(20) THIS IS: constants.py import urllib import socket from openpyxl.reader.excel import load_workbook hostname = socket.gethostname() getip = urllib.urlopen('https://api.ipify.org').read() errorReportWB = load_workbook(r'C:\Users\Administrator\Desktop\Version5.0\DeviceTrackerReport45.xlsx') masterListWB = load_workbook(r'C:\Users\Administrator\Desktop\Version5.0\masterListWB.xlsx') yardWB = load_workbook(r'C:\Users\Administrator\Desktop\Version5.0\yardWB.xlsx') errorReportSheet = errorReportWB.get_sheet_names() masterListSheet = masterListWB.get_sheet_names() yardSheet = yardWB.get_sheet_names() import constants import DataRedundancyCheck import assetMappingFunctions ipCoordinate = [] deviceCoordinate = [] #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# #************************************************************************************************************************************# THIS IS: assetMapping.py ## Initital Test: checks if IP is in master list initialCheck = assetMappingFunctions.functions() #Creat object Initial_Test of Asset_Mapping_Module Class from the Asset_Mapping.py file masterInventorySheet = initialCheck.yard(constants.masterListSheet,0,constants.masterListWB) #Get Master list sheet name ipMasterInventoryCount = initialCheck.inventoryCount(masterInventorySheet,"B") #Get number count of IP addresses in the Master list ipMasterInventory = initialCheck.ipDeviceList(ipMasterInventoryCount,"B",masterInventorySheet) #Get the list of IPs in the Masterlist ipMasterValidation = initialCheck.ipValidationCheck(ipMasterInventory,masterInventorySheet) #Test if external IP address is in the Master List if ipMasterValidation==False: print "IP INVALID" elif ipMasterValidation == True: #if ipMasterValidation from initial test returns something than program continues ## print "IP VALIDATED" matchTrack = assetMappingFunctions.functions() #Create object Track_Map for the class Asset_Mapping_Module found in the Asset_Mapping.py file for x in range(0,len(constants.yardSheet)): #loop range dependent on number of sheets in yardWB.xlsx yardNameUnfil = constants.yardSheet[x] #Get from yardWB.xlsx list of all sheet names... #....Formated to print to excel spreadsheet ## print "unfiltered yard",yardNameUnfil yardName = matchTrack.yard(constants.yardSheet,x,constants.yardWB) #Get from yardWB.xlsx list of all sheet names... #....Unformated and used for testing. ## print yardName,yardNameUnfil ipListCount = matchTrack.inventoryCount(yardName,"B") #Get the number of IP addresses in each yards list deviceListCount = matchTrack.inventoryCount(yardName,"C") #Get the number Devices in each yards list ## print ipListCount ## print deviceListCount ## print "\n" #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# #************************************************************************************************************************************# ipList = matchTrack.ipDeviceList(ipListCount,"B",yardName) #Get list of IP Addresses from each yard deviceList = matchTrack.ipDeviceList(deviceListCount,"C",yardName) #Get list of Devices from each yard ## print "IP list ",ipList ## print "Device list ",deviceList ## print "\n" #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# #************************************************************************************************************************************# ipValidation = matchTrack.ipValidationCheck(ipList,yardName) #IP COORDINATE: Track IP address to yard deviceValidation = matchTrack.deviceValidationCheck(deviceList,yardName) #DEVICE COORDINATE: Track Device hostname to yard ## print "Test IP match to yard: ", ipValidation,yardName ## print "Test Device match to yard: ",deviceValidation, yardName ## print "\n" #### When ipValidation makes a match of IP to a yard, the yard gets appended into a list called ipCoordinate if ipValidation == True: #Test condition to isolate and append yard into a list ipConfirmed = ipValidation ipCoordinate.append(yardNameUnfil) ## print "Filter list of yards that contains the external IP address: ",ipCoordinate,ipValidation #### When deviceValidation makes a match of Device to a yard, the yard gets appended into a list called deviceCoordinate if deviceValidation == True: #Test condition to isolate and append yard into a list deviceConfirmed = deviceValidation deviceCoordinate.append(yardNameUnfil) ## print "Filter list of yards that contains the Device Host Name: ",deviceCoordinate,deviceConfirmed ## print "02. device validation =",constants.device_yard_coordinate #xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx# #************************************************************************************************************************************# ## print "testing",deviceConfirmed,deviceCoordinate ## if ipConfirmed and deviceConfirmed == True: ## print None ## print "03. Device validation =",deviceConfirmed,"; IP traced to yard: ",deviceCoordinate if ipCoordinate == deviceCoordinate: #Test if yards ipCoordinate = deviceCoordinate print None else: errorReport = matchTrack.yard(constants.errorReportSheet,0,constants.errorReportWB) inventoryCount = matchTrack.inventoryCount(errorReport,"B") temp = DataRedundancyCheck.redundancy() ipRedundancy = (", ".join(ipCoordinate)) deviceRedundancy = (", ".join(deviceCoordinate)) redundancyTest = temp.dataRedundancyCheck(ipRedundancy,deviceRedundancy) print "Test =",redundancyTest if redundancyTest == True: print "" ## print str(((", ".join(ipCoordinate)),(", ".join(deviceCoordinate)),errorReport,inventoryCount)) matchTrack.entryReport((", ".join(ipCoordinate)),(", ".join(deviceCoordinate)),errorReport,inventoryCount) # THIS IS: DataRedundancyCheck.py import datetime import constants import assetMappingFunctions from openpyxl import load_workbook ##errorReportWB = load_workbook(r'C:\Users\Administrator\Desktop\Version5.0\DeviceTrackerReport.xlsx', data_only=True) temp = assetMappingFunctions.functions() errorReportWB = constants.errorReportWB cellData = errorReportWB["IP_TrackMap_Report"] wb = temp.yard(constants.errorReportSheet,0,constants.errorReportWB) count = temp.inventoryCount(wb,"B") class redundancy(): def dataRedundancyCheck(self,ipAssigned,deviceFound): celllist=[] cmpValue = 0 for i in range (0,4): cellAdd = chr(ord("C")+i) cell = cellAdd + str((count+1)) celllist.append(str(cellData[cell].value)) data =[constants.getip,ipAssigned,deviceFound,'{:%m-%d-%Y}'.format(datetime.date.today())] ## print celllist[i],"<=>",data[i] cmpValue = cmp (celllist,data) if cmpValue == 0: print "" else: print cmpValue return True THIS IS: assetMappingFunctions.py import constants import datetime class functions(): def yard(self,sheet,sheetNumber,workBook): ## sheetNumber = len(sheet)-1 return workBook[sheet[sheetNumber]] def inventoryCount(self,yard,column): count = 0 while True: count += 1 append = column + str(count) yard[append].value if yard[append].value == None: break return count-2 def ipDeviceList(self, count, column, yard): x=2 list=[] #temp = "" for a in range (0,count): append1 = column + str(x) x +=1 list.append(str(yard[append1].value)) ## print str(yard[append1].value) ## #temp= ", ".join(list1) return list def ipValidationCheck(self, inventory_list,yard): temp = constants.getip if temp in inventory_list: ## print temp return True else: return False def deviceValidationCheck(self, inventory_list,yard): temp = constants.hostname if temp in inventory_list: return True else: return False def ipReport(self, yard): if get_field == 1: set_field = constants.wb.get_sheet_by_name('IP_Report') return set_field def entryReport(self,ipCoordinate,deviceCoordinate,yard,row_count): dataInput = [str(constants.hostname),str(constants.getip),str(ipCoordinate),str(deviceCoordinate),'{:%m-%d-%Y}'.format(datetime.date.today()),'{:%H:%M:%S}'.format(datetime.datetime.now())] for i in range(0,6): temp= chr(ord("B")+i) ## print "temp",temp column = temp + str((row_count+2)) ## print "column",column,dataInput[i] yard[column]=dataInput[i] ## print dataInput[i] constants.errorReportWB.save(r'C:\Users\Administrator\Desktop\Version5.0\DeviceTrackerReport45.xlsx') print "Report Updated" From tjreedy at udel.edu Mon Mar 13 18:20:18 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Mar 2017 18:20:18 -0400 Subject: [External] Unsubscribe to Python email list In-Reply-To: <93285AC0FA20BA47BE43FA54FCA5B321EDDBD84A@ASHBDAG2M3.resource.ds.bah.com> References: <6DD74957-1E1E-4EB3-A1C0-EF7F26392411@hotmail.com> <93285AC0FA20BA47BE43FA54FCA5B321EDDBD84A@ASHBDAG2M3.resource.ds.bah.com> Message-ID: On 3/13/2017 9:24 AM, Falter, Donald [USA] wrote: > Yeah, I think I'm going to bail on this list too. Thanks Then follow MRAB's explaination of how. ---- You'll have to do it yourself. Read this: https://mail.python.org/mailman/listinfo/python-list The relevant bit is in the section titled "Python-list Subscribers". -- Terry Jan Reedy From m at funkyhat.org Mon Mar 13 18:36:06 2017 From: m at funkyhat.org (Matt Wheeler) Date: Mon, 13 Mar 2017 22:36:06 +0000 Subject: Substitute a mock object for the metaclass of a class In-Reply-To: <857f3ugfr1.fsf@benfinney.id.au> References: <857f3ugfr1.fsf@benfinney.id.au> Message-ID: On Mon, 13 Mar 2017 at 00:52 Ben Finney wrote: > How can I override the metaclass of a Python class, with a > `unittest.mock.MagicMock` instance instead? > At first I misunderstood what you were looking for, and was about to reply to the effect of "you're too late, the metaclass has already been called so this doesn't make sense", but I see that you're actually asking for something that's a bit interesting... > I have a function whose job involves working with the metaclass of an > argument:: > > # lorem.py > > class Foo(object): > pass > > def quux(existing_class): > ? > metaclass = type(existing_class) > new_class = metaclass(?) > > The unit tests for this function will need to assert that the calls to > the metaclass go as expected, *without* actually calling a real class > object. > > To write a unit test for this function, I want to temporarily override > the metaclass of some classes in the system with a mock object instead. > This will allow, for example, making assertions about how the metaclass > was called, and ensuring no unwanted side effects. > The simple, lazy option would be to patch `type` to return your mocked metaclass. i.e. ``` from unittest.mock import patch import lorem @patch('lorem.type') def test_things(mocktype): lorem.quux(metameta.Foo()) lorem.return_value.assert_called_with() ``` Don't try and patch `type` from `builtins`. I did, and things go bad because, unsurprisingly, `mock` calls `type` quite a lot internally :). > # test_lorem.py > > import unittest > import unittest.mock > > import lorem > > class stub_metaclass(type): > def __new__(metaclass, name, bases, namespace): > return super().__new__(metaclass, name, bases, namespace) > > class quux_TestCase(unittest.TestCase): > > @unittest.mock.patch.object( > lorem.Foo, '__class__', side_effect=stub_metaclass) > def test_calls_expected_metaclass_with_class_name( > self, > mock_foo_metaclass, > ): > lorem.quux(lorem.Foo) > mock_foo_metaclass.assert_called_with( > 'Foo', unittest.mock.ANY, unittest.mock.ANY) > When I try to add the stub_metaclass side_effect in to my code I get `TypeError: __new__() missing 2 required positional arguments: 'bases' and 'namespace'` ... which seems quite reasonable, and I expect you're in a better position to figure out how to handle that (the side effect may actually need to be a wrapper around stub_metaclass which injects something suitable). -- -- Matt Wheeler http://funkyh.at From m at funkyhat.org Mon Mar 13 19:01:44 2017 From: m at funkyhat.org (Matt Wheeler) Date: Mon, 13 Mar 2017 23:01:44 +0000 Subject: Substitute a mock object for the metaclass of a class In-Reply-To: References: <857f3ugfr1.fsf@benfinney.id.au> Message-ID: A small correction... On Mon, 13 Mar 2017 at 22:36 Matt Wheeler wrote: > ``` > from unittest.mock import patch > > import lorem > > > @patch('lorem.type') > def test_things(mocktype): > lorem.quux(metameta.Foo()) > > lorem.return_value.assert_called_with() > this line should of course read `mocktype.return_value.assert_called_with()` > ``` > -- -- Matt Wheeler http://funkyh.at From hpj at urpla.net Mon Mar 13 19:33:34 2017 From: hpj at urpla.net (Hans-Peter Jansen) Date: Tue, 14 Mar 2017 00:33:34 +0100 Subject: keyrings.cryptfile released on github In-Reply-To: <87tw70rf7m.fsf@nightsong.com> References: <2356566.kSNyJECJKv@xrated> <87tw70rf7m.fsf@nightsong.com> Message-ID: <13668788.UAFrYTDxEq@xrated> On Freitag, 10. M?rz 2017 13:31:41 Paul Rubin wrote: > Hans-Peter Jansen writes: > > [1] http://web.cs.ucdavis.edu/~rogaway/ocb/license.htm > > Oh that's interesting, he's expanded the free licenses. Still though, > while OCB is very clever and it was important as the first satisfactory > AEAD mode, I don't think it's that important these days. GCM is > standardized, does similar things, and while it's potentially slower, > some CPUs even have hardware support for it now. If you library doesn't > support GCM (I haven't checked yet) then it probably should. It does support GCM now, it's even the new default(!). I've added support for all AEAD modes, that PyCryptodome supports, and supplied a small encryption mode conversion tool as well. I plan to add authenticated service and username support via associated data as well (that protects against tampering with these values). It might be a good idea to record and secure the number of entries as well. Cheers, Pete From hpj at urpla.net Mon Mar 13 20:41:59 2017 From: hpj at urpla.net (Hans-Peter Jansen) Date: Tue, 14 Mar 2017 01:41:59 +0100 Subject: keyrings.cryptfile released on github In-Reply-To: <13668788.UAFrYTDxEq@xrated> References: <2356566.kSNyJECJKv@xrated> <87tw70rf7m.fsf@nightsong.com> <13668788.UAFrYTDxEq@xrated> Message-ID: <10347545.VtY6WNlyOl@xrated> On Dienstag, 14. M?rz 2017 00:33:34 Hans-Peter Jansen wrote: > > I plan to add authenticated service and username support via associated data > as well (that protects against tampering with these values). Done. > Cheers, > Pete From zljubisic at gmail.com Tue Mar 14 03:34:19 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Tue, 14 Mar 2017 00:34:19 -0700 (PDT) Subject: Extraction of model and date created tag from own picture/video recordings Message-ID: <7fbbfdff-d7ab-4825-9721-2024fd4369bf@googlegroups.com> I am looking for the way to extract two simple information from pictures/videos that I have recorded with different devices that I own: model (of the device that has recorded) and recordings (local) creation time. So far, I tried different approaches. I tried to use pymediainfo (https://pypi.python.org/pypi/pymediainfo/), which is kind of good for iPhone videos, but doesn't recognize model of the android videos and it is bed for pictures, but at the moment, I don't have anything better. I also tried ExifRead (https://pypi.python.org/pypi/ExifRead), that is good for some pictures, but not for all. For such a simple requirement (model and creation date) is there a library that can: 1. Cover both pictures and videos 2. Work with android and iPhone Does someone have an experience with such task in order to suggest a library to me? From zljubisic at gmail.com Tue Mar 14 03:43:07 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Tue, 14 Mar 2017 00:43:07 -0700 (PDT) Subject: Extraction of model and date created tag from own picture/video recordings Message-ID: <473ec4d0-9eb1-4359-afb1-367546e5a198@googlegroups.com> I am looking for the way to extract two simple information from pictures/videos that I have recorded with different devices that I own: model (of the device that has recorded) and recordings (local) creation time. So far, I tried different approaches. I tried to use pymediainfo (https://pypi.python.org/pypi/pymediainfo/), which is kind of good for iPhone videos, but doesn't recognize model of the android videos and it is bed for pictures, but at the moment, I don't have anything better. I also tried ExifRead (https://pypi.python.org/pypi/ExifRead), that is good for some pictures, but not for all. For such a simple requirement (model and creation date) is there a library that can: 1. Cover both pictures and videos 2. Work with android and iPhone Does someone have an experience with such task in order to suggest a library to me? From steve+python at pearwood.info Tue Mar 14 07:32:49 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 14 Mar 2017 22:32:49 +1100 Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Mar 2017 08:47 pm, eryk sun wrote: > On Sun, Mar 12, 2017 at 5:48 PM, Steve D'Aprano > wrote: >> >> Does os.remove work like this under Windows too? > > os.remove calls DeleteFile on Windows. [...] Thanks for the unexpectedly detailed explanation! A few follow-up questions: > One hurdle to getting delete access is the sharing mode. If there are > existing File objects that reference the file, they all have to share > delete access. Otherwise the open fails with a sharing violation. This > is often the show stopper because the C runtime (and thus CPython, > usually) opens files with read and write sharing but not delete > sharing. This is the famous "can't delete a file which is open under Windows" problem, am I right? I take it that you *can* delete open files, but only if the process that opens them takes special care to use "delete sharing". Is that correct? I don't have a machine to test this on, but I'd like to deal with this situation in my (cross-platform) code. If I have one Python script do this: with open("My Documents/foo") as f: time.sleep(100000) and while it is sleeping another script does this: os.remove("My Documents/foo") what exception will I get? Is that unique to this situation, or is a generic exception that could mean anything? My aim is to do: try: os.remove(thefile) except SomeError: # Could be a virus checker or other transient process. time.sleep(0.2) os.remove(thefile) # try again Does that seem reasonable to you, as a Windows user? [...] > OK, that covers the basics. The basics, he says :-) > In user mode, a kernel object such as a File instance is referenced as > a handle. Out of curiosity, I only know the term "handle" from classic Macintosh (pre-OS X) where a handle was a managed pointer to a pointer to a chunk of memory. Being managed, the OS could move the memory around without the handles ending up pointing to garbage. Is that the same meaning in Windows land? [...] > When the delete disposition is set, no new File references can be > instantiated (i.e. any level of access is denied, even just to read > the file attributes), but the file isn't immediately unlinked. It's > still listed in the parent directory. Any existing File reference that > has delete access can unset the delete disposition. > > When all handle and pointer references to a File object are closed, > the file system decrements the reference count on the FCB. When the > FCB reference count drops to 0, if the delete disposition is currently > set, then finally the file is unlinked from the parent directory. So technically file deletions aren't atomic in Windows? In principle, I could say: delete file X which then returns immediately, and if I try to open(X) it will fail. But I can still see it if I do a dir() on the parent directory? Eventually the last reference to X will go away, and then it is unlinked. What happens if I pull the plug in the meantime? Will the file magically come back on rebooting? [...] > Finally, I'm sure most people are familiar with the read-only file > attribute. If this attribute is set you can still open a file with > delete access to rename it, but setting the delete disposition will > fail with access denied. That was actually the situation I was thinking about when I started on this question. From Python code, I was considering writing something like this: def delete_readonly(thefile): try: os.remove(thefile) except ReadOnlyFileError: # what is this really? try: # change the user permissions to unset Read-Only old_perms = ... ? set_perms(...) except OSError: pass else: # We changed Read-Only. Try deleting again. If it fails, # revert the flags and fail. try: os.remove(thefile) except OSError: # Restore permissions ... else: # Success on the second attempt! return raise That's intended to emulate the behaviour on Unix where deleting a file that you own will succeed even if you don't have write access to the file. (The bash rm command will ask you before deleting, but Python's os.remove just removes it.) Does this seem reasonable? Or overly complicated for not enough benefit? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rhodri at kynesim.co.uk Tue Mar 14 07:42:14 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 14 Mar 2017 11:42:14 +0000 Subject: Issues with in try except and excel spreadsheet In-Reply-To: <84f6caea-1d09-466c-abf7-f5f066cfb3fb@googlegroups.com> References: <84f6caea-1d09-466c-abf7-f5f066cfb3fb@googlegroups.com> Message-ID: On 13/03/17 20:37, padawanwebdev at gmail.com wrote: > On Monday, March 13, 2017 at 11:10:36 AM UTC-7, Rhodri James wrote: >> On 13/03/17 17:40, padawanwebdev at gmail.com wrote: >>> Hello, I'm having a problem with a try except inside a while loop. The problem I see occuring has to do with an excel file the script tries to write to while the excel file is open. The exception captures and gives an error: >>> >>> OError: [Errno 13] Permission denied:'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' >>> >>> This is expected and is not the problem. However, the issue occurs when I close the excel file. As an example, if I run the script and the excel file is open thru 3 iterations, meaning that the script can't write to the excel file until the excel file is closed, then after the excel file is closed the script prints to the excel file 3 times. I don't need it to write to the excel file 3 times. I only need it to write just once. If the excel file is closed before I run the script than it works like its suppose too. >>> I hope I made my case clear. I look forward to some feedback. Any would be greatly appreciated! >> >> When you say "...the excel file is open thru 3 iterations", what do you >> mean? Three iterations of what? You haven't shown us a loop, so it's >> not obvious. >> >> How do you know it prints (writes?) to the excel file three times? >> Again, there's nothing in the code snippet that would tell you. >> >>> here is part of the code: >>> >>> connectionResults = None >>> returnResults = InternetQualityTest.connectionTest(connectionResults) >>> if returnResults == True: >>> try: >>> execfile('assetMapping.py') >>> time.sleep(4) >>> sys.exit() >>> except Exception as e: >>> print "error",e >>> time.sleep(20) >> >> This looks plausible, though honestly the execfile makes me feel icky >> for unrelated reasons. I repeat, though; this isn't a loop, and my >> crystal ball isn't up to telling me how it gets invoked. >> >>> FYI: The assetMapping.py runs another module from inside, and it's this module running from assetMapping that writes to the excel file. >>> >> >> >> -- >> Rhodri James *-* Kynesim Ltd > > I apologize if I short-changed you with the code. It's a bigger piece of code and I thought maybe with my explanation and the piece I showed it would be enough. I was wrong. Here is the rest. I apologize in advance if there are any more confusions. > > I do appreciate your help! Thanks in advance :-) > > > THIS IS: Main.py > > import InternetQualityTest > import assetMapping > import time > import sys > > > > if __name__ == '__main__': > > while True: > > connectionResults = None > returnResults = InternetQualityTest.connectionTest(connectionResults) > if returnResults == True: > try: > execfile('assetMapping.py') > time.sleep(4) > sys.exit() > except Exception as e: > print "error",e > time.sleep(20) [Large amount of code with no suspicious-looking loops snipped] Thanks for the extra code. It's hard to get the balance right between giving people enough information to help and giving us so much information we can't see the wood for the trees. Anyway, I'll go back to my questions. What output do you have that convinces you that assetMapping.py is invoked three (or however many) times while the excel file is open? What output do you have that convinces you that it then writes three (or however many) times? As far as I can tell, the loop above can only repeat the call to execfile() if it catches an exception: what were those exceptions? -- Rhodri James *-* Kynesim Ltd From rosuav at gmail.com Tue Mar 14 09:07:32 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Mar 2017 00:07:32 +1100 Subject: When will os.remove fail? In-Reply-To: <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 14, 2017 at 10:32 PM, Steve D'Aprano wrote: > On Mon, 13 Mar 2017 08:47 pm, eryk sun wrote: >> One hurdle to getting delete access is the sharing mode. If there are >> existing File objects that reference the file, they all have to share >> delete access. Otherwise the open fails with a sharing violation. This >> is often the show stopper because the C runtime (and thus CPython, >> usually) opens files with read and write sharing but not delete >> sharing. > > This is the famous "can't delete a file which is open under Windows" > problem, am I right? > > I take it that you *can* delete open files, but only if the process that > opens them takes special care to use "delete sharing". Is that correct? Yes, but you can't always control the process that opens them. For example, it's annoyingly difficult to update a running executable. >> In user mode, a kernel object such as a File instance is referenced as >> a handle. > > Out of curiosity, I only know the term "handle" from classic Macintosh > (pre-OS X) where a handle was a managed pointer to a pointer to a chunk of > memory. Being managed, the OS could move the memory around without the > handles ending up pointing to garbage. Is that the same meaning in Windows > land? The old Mac meaning was very concrete and specific: it's a pointer to a pointer. Since all *you* ever see is the first pointer, the OS is free to (atomically) move the destination. More generally, a handle is just an opaque cookie that represents a thing. If you do cross-platform socket programming, you'll find that on Unix, creating a socket returns a "file descriptor"; but on Windows, it returns a "socket handle". Aside from the fact that socket handles can only be used with socket functions (making them harder to pass to other processes etc), the two concepts work broadly the same way: you have a small integer value that represents a large resource. >> When the delete disposition is set, no new File references can be >> instantiated (i.e. any level of access is denied, even just to read >> the file attributes), but the file isn't immediately unlinked. It's >> still listed in the parent directory. Any existing File reference that >> has delete access can unset the delete disposition. >> >> When all handle and pointer references to a File object are closed, >> the file system decrements the reference count on the FCB. When the >> FCB reference count drops to 0, if the delete disposition is currently >> set, then finally the file is unlinked from the parent directory. > > So technically file deletions aren't atomic in Windows? In principle, I > could say: > > delete file X > > which then returns immediately, and if I try to open(X) it will fail. But I > can still see it if I do a dir() on the parent directory? > > Eventually the last reference to X will go away, and then it is unlinked. > What happens if I pull the plug in the meantime? Will the file magically > come back on rebooting? Without actually testing it, my answers (based on experience of using Windows) would be that the file doesn't disappear at all until it's actually deleted. The "no new File refs can be instantiated" would mean that it kicks back an error, not that it looks like the file doesn't exist. If you pull the plug, it won't "magically come back" - it'll have never gone. > That's intended to emulate the behaviour on Unix where deleting a file that > you own will succeed even if you don't have write access to the file. > > (The bash rm command will ask you before deleting, but Python's os.remove > just removes it.) (And the rm command won't ask if you say "-f".) > Does this seem reasonable? Or overly complicated for not enough benefit? I'm terrified to think what the interactions would be between this and the Ubuntu subsystem in Win 10. What're the semantics of unlinkat()? What about the common practice of creating a file and then unlinking it so it doesn't show up in the directory? (And is that different on a file system that supports hard links?) Or are heaps of POSIX features simply not available? ChrisA From jon+usenet at unequivocal.eu Tue Mar 14 09:30:36 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 14 Mar 2017 13:30:36 -0000 (UTC) Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-03-14, Chris Angelico wrote: >> (The bash rm command will ask you before deleting, but Python's os.remove >> just removes it.) > > (And the rm command won't ask if you say "-f".) rm does not ask before deleting. However some Linux distributions take it upon themselves to put "alias rm='rm -i'" in /etc/profile. From a24061 at ducksburg.com Tue Mar 14 09:50:12 2017 From: a24061 at ducksburg.com (Adam Funk) Date: Tue, 14 Mar 2017 13:50:12 +0000 Subject: managing the RDFLib NamespaceManager Message-ID: I'm using RDFLib 4.2.2 (installed with pip3) in Python 3.5.2, and the automatic behaviour of the NamespaceManager is giving me conniptions, because the automatically generated namespaces go too far to the right in the URIs and make the right-hand parts of the QNames meaningless. For example, I have this code: nsMgr = NamespaceManager(rdflib.Graph()) nsMgr.bind('dbpedia', Namespace('http://dbpedia.org/resource/')) # plus some others but in the serialized RDF I get these (and some other ns-numbered ones): @prefix dbpedia: . @prefix ns3: . @prefix ns5: . and obviously the QName outputs are wrong. Is there any way to make an RDFLib NamespaceManager *not* generate any namespaces automatically? Thanks, Adam From rosuav at gmail.com Tue Mar 14 09:56:19 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Mar 2017 00:56:19 +1100 Subject: When will os.remove fail? In-Reply-To: References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens wrote: > On 2017-03-14, Chris Angelico wrote: >>> (The bash rm command will ask you before deleting, but Python's os.remove >>> just removes it.) >> >> (And the rm command won't ask if you say "-f".) > > rm does not ask before deleting. However some Linux distributions > take it upon themselves to put "alias rm='rm -i'" in /etc/profile. I have no such alias, but it still prompts. 'man rm': If the -I or --interactive=once option is given, and there are more than three files or the -r, -R, or --recursive are given, then rm prompts the user for whether to proceed with the entire operation. If the response is not affirmative, the entire command is aborted. Otherwise, if a file is unwritable, standard input is a terminal, and the -f or --force option is not given, or the -i or --interac? tive=always option is given, rm prompts the user for whether to remove the file. If the response is not affirmative, the file is skipped. This is the GNU coreutils rm command. Obviously behaviour may be different with non-GNU rm's. ChrisA From frank at chagford.com Tue Mar 14 10:22:12 2017 From: frank at chagford.com (Frank Millman) Date: Tue, 14 Mar 2017 16:22:12 +0200 Subject: When will os.remove fail? In-Reply-To: References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmrim9TJHfOLgynUJATx_HkVXXQ_D8YJPkX8Y32qHCzzFw at mail.gmail.com... On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens wrote: >>> >>> (And the rm command won't ask if you say "-f".) >> >> rm does not ask before deleting. However some Linux distributions >> take it upon themselves to put "alias rm='rm -i'" in /etc/profile. > > I have no such alias, but it still prompts. > On Fedora 22 (and for many previous versions) I have noticed that, if I log in as 'root', it does prompt, but if I log in as an ordinary user, it does not. If I type 'alias' at the console, it lists current aliases. 'root' shows exactly what Jon quoted above. 'frank' shows no alias for 'rm'. I had a quick look to see what was setting it, but there is nothing in /etc/profile or in /etc/bashrc. I don't know where else to check. Frank Millman From padawanwebdev at gmail.com Tue Mar 14 10:26:00 2017 From: padawanwebdev at gmail.com (padawanwebdev at gmail.com) Date: Tue, 14 Mar 2017 07:26:00 -0700 (PDT) Subject: Issues with in try except and excel spreadsheet In-Reply-To: References: <84f6caea-1d09-466c-abf7-f5f066cfb3fb@googlegroups.com> Message-ID: <9df59029-9b34-4f6a-b2a6-74093186c13c@googlegroups.com> On Tuesday, March 14, 2017 at 4:42:39 AM UTC-7, Rhodri James wrote: > On 13/03/17 20:37, padawanwebdev at gmail.com wrote: > > On Monday, March 13, 2017 at 11:10:36 AM UTC-7, Rhodri James wrote: > >> On 13/03/17 17:40, padawanwebdev at gmail.com wrote: > >>> Hello, I'm having a problem with a try except inside a while loop. The problem I see occuring has to do with an excel file the script tries to write to while the excel file is open. The exception captures and gives an error: > >>> > >>> OError: [Errno 13] Permission denied:'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' > >>> > >>> This is expected and is not the problem. However, the issue occurs when I close the excel file. As an example, if I run the script and the excel file is open thru 3 iterations, meaning that the script can't write to the excel file until the excel file is closed, then after the excel file is closed the script prints to the excel file 3 times. I don't need it to write to the excel file 3 times. I only need it to write just once. If the excel file is closed before I run the script than it works like its suppose too. > >>> I hope I made my case clear. I look forward to some feedback. Any would be greatly appreciated! > >> > >> When you say "...the excel file is open thru 3 iterations", what do you > >> mean? Three iterations of what? You haven't shown us a loop, so it's > >> not obvious. > >> > >> How do you know it prints (writes?) to the excel file three times? > >> Again, there's nothing in the code snippet that would tell you. > >> > >>> here is part of the code: > >>> > >>> connectionResults = None > >>> returnResults = InternetQualityTest.connectionTest(connectionResults) > >>> if returnResults == True: > >>> try: > >>> execfile('assetMapping.py') > >>> time.sleep(4) > >>> sys.exit() > >>> except Exception as e: > >>> print "error",e > >>> time.sleep(20) > >> > >> This looks plausible, though honestly the execfile makes me feel icky > >> for unrelated reasons. I repeat, though; this isn't a loop, and my > >> crystal ball isn't up to telling me how it gets invoked. > >> > >>> FYI: The assetMapping.py runs another module from inside, and it's this module running from assetMapping that writes to the excel file. > >>> > >> > >> > >> -- > >> Rhodri James *-* Kynesim Ltd > > > > I apologize if I short-changed you with the code. It's a bigger piece of code and I thought maybe with my explanation and the piece I showed it would be enough. I was wrong. Here is the rest. I apologize in advance if there are any more confusions. > > > > I do appreciate your help! Thanks in advance :-) > > > > > > THIS IS: Main.py > > > > import InternetQualityTest > > import assetMapping > > import time > > import sys > > > > > > > > if __name__ == '__main__': > > > > while True: > > > > connectionResults = None > > returnResults = InternetQualityTest.connectionTest(connectionResults) > > if returnResults == True: > > try: > > execfile('assetMapping.py') > > time.sleep(4) > > sys.exit() > > except Exception as e: > > print "error",e > > time.sleep(20) > > [Large amount of code with no suspicious-looking loops snipped] > > Thanks for the extra code. It's hard to get the balance right between > giving people enough information to help and giving us so much > information we can't see the wood for the trees. > > Anyway, I'll go back to my questions. What output do you have that > convinces you that assetMapping.py is invoked three (or however many) > times while the excel file is open? What output do you have that > convinces you that it then writes three (or however many) times? As far > as I can tell, the loop above can only repeat the call to execfile() if > it catches an exception: what were those exceptions? > > -- > Rhodri James *-* Kynesim Ltd As an example, If I have the excel file open and there is data that needs to be written to the excel file than the exception will catch this error: IOError: [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' essentially, because the excel file is open during the process of writing to the excel file the "try" will keep attempting to write to the excel until its closed. So, if there were 5 attempts to write the data to the excel file, then after the excel file is closed that data will be written to the excel file n+1 times (6 times). When this happens it shows 6 rows of the newly written data, however, it's the same data. To illustrate this here is the output from the shell line while the excel file is open and when it's closed. Note, When I close it it will say Report Updated. Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> -1 Test = True error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' -1 Test = True error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' -1 Test = True error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' -1 Test = True error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' -1 Test = True error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' -1 Test = True Report Updated >>> This is what's written to the excel file: 3 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:03:46 4 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:04:07 5 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:04:27 6 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:04:47 7 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:05:07 8 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:05:28 As you can see from the shell line the number of attempts made, and from the excel file the number of rows taken, that there is a correlation between the attempts and what gets written to the excel file. Also, if the excel file is closed during the writing process than the execfile() executes once because there is no exception, and the data only gets written once to the excel file. because the execfile() is inside the try except it catches this error: error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' which is just telling you that the data can't be written to the excel file because its open. Thanks again Mr. James. I hope with my explanation I may have cleared up any confusion of the problem I'm facing. From rosuav at gmail.com Tue Mar 14 10:26:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Mar 2017 01:26:48 +1100 Subject: When will os.remove fail? In-Reply-To: References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 15, 2017 at 1:22 AM, Frank Millman wrote: > "Chris Angelico" wrote in message > news:CAPTjJmrim9TJHfOLgynUJATx_HkVXXQ_D8YJPkX8Y32qHCzzFw at mail.gmail.com... > > On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens > wrote: >>>> >>>> >>>> (And the rm command won't ask if you say "-f".) >>> >>> >>> rm does not ask before deleting. However some Linux distributions >>> take it upon themselves to put "alias rm='rm -i'" in /etc/profile. >> >> >> I have no such alias, but it still prompts. >> > > On Fedora 22 (and for many previous versions) I have noticed that, if I log > in as 'root', it does prompt, but if I log in as an ordinary user, it does > not. > > If I type 'alias' at the console, it lists current aliases. 'root' shows > exactly what Jon quoted above. 'frank' shows no alias for 'rm'. > > I had a quick look to see what was setting it, but there is nothing in > /etc/profile or in /etc/bashrc. I don't know where else to check. Since root has the prompt, check /root/.profile and /root/.bashrc. There may also be other files sourced from either of those, eg /root/.bash_aliases. ChrisA From frank at chagford.com Tue Mar 14 10:29:02 2017 From: frank at chagford.com (Frank Millman) Date: Tue, 14 Mar 2017 16:29:02 +0200 Subject: When will os.remove fail? In-Reply-To: References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Frank Millman" wrote in message news:oa8uaf$k9e$1 at blaine.gmane.org... > On Fedora 22 (and for many previous versions) I have noticed that, if I > log in as 'root', it does prompt, but if I log in as an ordinary user, it does not. > If I type 'alias' at the console, it lists current aliases. 'root' shows exactly what Jon quoted above. 'frank' shows no alias for 'rm'. > I had a quick look to see what was setting it, but there is nothing in /etc/profile or in /etc/bashrc. I don't know where else to check. I should have looked a bit harder. It is in /root/.bashrc - alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' Frank From jon+usenet at unequivocal.eu Tue Mar 14 10:30:16 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 14 Mar 2017 14:30:16 -0000 (UTC) Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-03-14, Chris Angelico wrote: > On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens wrote: >> rm does not ask before deleting. However some Linux distributions >> take it upon themselves to put "alias rm='rm -i'" in /etc/profile. > > I have no such alias, but it still prompts. I'm think you must be mistaken. What do you see if you type 'alias rm' and 'which rm'? Are you perhaps trying to delete files to which you do not have write permission? > 'man rm': > > If the -I or --interactive=once option is given, and there are more > than three files or the -r, -R, or --recursive are given, then rm > prompts the user for whether to proceed with the entire operation. If > the response is not affirmative, the entire command is aborted. > > Otherwise, if a file is unwritable, standard input is a terminal, and > the -f or --force option is not given, or the -i or --interac? > tive=always option is given, rm prompts the user for whether to remove > the file. If the response is not affirmative, the file is skipped. Yes, this describes the behaviour if you specify -I or -i, as I mentioned - not if you don't specify either of those options. > This is the GNU coreutils rm command. I am talking about the GNU coreutils rm command (and POSIX for that matter, since the behaviour of GNU rm appears to be POSIX compliant as far as what we are talking about goes). From jon+usenet at unequivocal.eu Tue Mar 14 10:32:35 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 14 Mar 2017 14:32:35 -0000 (UTC) Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-03-14, Frank Millman wrote: > If I type 'alias' at the console, it lists current aliases. 'root' shows > exactly what Jon quoted above. 'frank' shows no alias for 'rm'. > > I had a quick look to see what was setting it, but there is nothing in > /etc/profile or in /etc/bashrc. I don't know where else to check. Perhaps one or more of: /root/.profile /root/.bash_profile /root/.bashrc /etc/profile.d/* From rosuav at gmail.com Tue Mar 14 10:40:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Mar 2017 01:40:16 +1100 Subject: When will os.remove fail? In-Reply-To: References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 15, 2017 at 1:30 AM, Jon Ribbens wrote: > On 2017-03-14, Chris Angelico wrote: >> On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens wrote: >>> rm does not ask before deleting. However some Linux distributions >>> take it upon themselves to put "alias rm='rm -i'" in /etc/profile. >> >> I have no such alias, but it still prompts. > > I'm think you must be mistaken. What do you see if you type > 'alias rm' and 'which rm'? Are you perhaps trying to delete > files to which you do not have write permission? This conversation was specifically about files for which one does not have write permission. So yes. (It's pretty common; .git/objects is mostly or entirely made up of such files.) ChrisA From lele at metapensiero.it Tue Mar 14 10:57:13 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Tue, 14 Mar 2017 15:57:13 +0100 Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <871stzewja.fsf@metapensiero.it> Jon Ribbens writes: >> Otherwise, if a file is unwritable, standard input is a terminal, and >> the -f or --force option is not given, or the -i or --interac? >> tive=always option is given, rm prompts the user for whether to remove >> the file. If the response is not affirmative, the file is skipped. > > Yes, this describes the behaviour if you specify -I or -i, > as I mentioned - not if you don't specify either of those options. English is not my native language, but that's not how I understand that paragraph: if -i is given, it always ask, regardless the writable bit, otherwise it does when f is readonly and no -f is given. I think Chris is right, consider: $ rm --version rm (GNU coreutils) 8.26 $ which rm /bin/rm $ alias | grep rm | wc -l 0 $ ls -l *file* -rw-rw-r-- 1 lele lele 0 Mar 14 15:52 myfile -r-------- 1 lele lele 0 Mar 14 15:52 myfile2 -rw-r--r-- 1 root root 0 Mar 14 15:52 othersfile $ rm myfile $ rm myfile2 rm: remove write-protected regular empty file 'myfile2'? y $ rm othersfile rm: remove write-protected regular empty file 'othersfile'? y $ ls -l *file* ls: cannot access '*file*': No such file or directory my 0.02? ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From jon+usenet at unequivocal.eu Tue Mar 14 11:27:37 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 14 Mar 2017 15:27:37 -0000 (UTC) Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> <871stzewja.fsf@metapensiero.it> Message-ID: On 2017-03-14, Lele Gaifax wrote: > Jon Ribbens writes: >>> Otherwise, if a file is unwritable, standard input is a terminal, and >>> the -f or --force option is not given, or the -i or --interac? >>> tive=always option is given, rm prompts the user for whether to remove >>> the file. If the response is not affirmative, the file is skipped. >> >> Yes, this describes the behaviour if you specify -I or -i, >> as I mentioned - not if you don't specify either of those options. > > English is not my native language, but that's not how I understand that > paragraph: if -i is given, it always ask, regardless the writable bit, > otherwise it does when f is readonly and no -f is given. You're understanding that paragraph correctly, but are misunderstanding what I wrote - I didn't disagree with what you're saying. From rhodri at kynesim.co.uk Tue Mar 14 11:59:19 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 14 Mar 2017 15:59:19 +0000 Subject: Issues with in try except and excel spreadsheet In-Reply-To: <9df59029-9b34-4f6a-b2a6-74093186c13c@googlegroups.com> References: <84f6caea-1d09-466c-abf7-f5f066cfb3fb@googlegroups.com> <9df59029-9b34-4f6a-b2a6-74093186c13c@googlegroups.com> Message-ID: On 14/03/17 14:26, padawanwebdev at gmail.com wrote: > As an example, If I have the excel file open and there is data that needs to be written to the excel file than the exception will catch this error: > > IOError: [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' Ah yes, you did say that, sorry I missed it. > essentially, because the excel file is open during the process of writing to the excel file the "try" will keep attempting to write to the excel until its closed. So, if there were 5 attempts to write the data to the excel file, then after the excel file is closed that data will be written to the excel file n+1 times (6 times). When this happens it shows 6 rows of the newly written data, however, it's the same data. To illustrate this here is the output from the shell line while the excel file is open and when it's closed. Note, When I close it it will say Report Updated. Ah, no. According to your code, successfully writing to the file is what causes "Report Updated" to be printed, not the closing of the file. It's important to be accurate about things like that, otherwise you spend hours looking for a connection in entirely the wrong place. > > Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. >>>> ================================ RESTART ================================ >>>> > -1 > Test = True > > error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' > -1 > Test = True > > error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' > -1 > Test = True > > error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' > -1 > Test = True > > error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' > -1 > Test = True > > error [Errno 13] Permission denied: 'C:\\Users\\Administrator\\Desktop\\Version5.0\\DeviceTrackerReport45.xlsx' > -1 > Test = True > > Report Updated > > This is what's written to the excel file: > > 3 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:03:46 > 4 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:04:07 > 5 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:04:27 > 6 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:04:47 > 7 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:05:07 > 8 NB19097 24.221.51.225 376_SouthYard 373_Reseda 03-14-2017 07:05:28 > > As you can see from the shell line the number of attempts made, and from the excel file the number of rows taken, that there is a correlation between the attempts and what gets written to the excel file. The interesting thing is that there is only one write. This suggests that the information is being appended to another file somewhere, or held in some other way that persists between invocations of assetMapping.py. Now I'm not going to hunt through your code for the answer, because there's too much of it and frankly the overly long lines don't survive email well on my machine. However, you should look for the tidying up in your code that doesn't get done because the attempted write throws an exception. -- Rhodri James *-* Kynesim Ltd From eryksun at gmail.com Tue Mar 14 13:12:38 2017 From: eryksun at gmail.com (eryk sun) Date: Tue, 14 Mar 2017 17:12:38 +0000 Subject: When will os.remove fail? In-Reply-To: <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 14, 2017 at 11:32 AM, Steve D'Aprano wrote: > On Mon, 13 Mar 2017 08:47 pm, eryk sun wrote: > >> One hurdle to getting delete access is the sharing mode. If there are >> existing File objects that reference the file, they all have to share >> delete access. Otherwise the open fails with a sharing violation. This >> is often the show stopper because the C runtime (and thus CPython, >> usually) opens files with read and write sharing but not delete >> sharing. > > This is the famous "can't delete a file which is open under Windows" > problem, am I right? If you aren't allowed shared delete access, the error you'll get is a sharing violation (32). If the file security doesn't allow delete access, then the error is access denied (5). In Python both of these raise a PermissionError, so telling the difference requires checking the winerror attribute. Two more cases are (1) a read-only file and (2) a file that's memory-mapped as code or data. In these two cases you can open the file with delete access, which allows you to rename it, but setting the delete disposition fails with access denied. If you have the right to set the file's attributes, then you can at least work around the read-only problem via os.chmod(filename, stat.S_IWRITE). For the mapped file case the best you can do is rename the file to another directory. At least it gets it out of the way if you're doing an upgrade to a running program. This workaround is rarely used -- I think mostly due to people not knowing that it's possible. > I take it that you *can* delete open files, but only if the process that > opens them takes special care to use "delete sharing". Is that correct? Unix programmers can't simply use delete sharing as a way to get familiar semantics on Windows. A file pending delete is in limbo on Windows. It can't be opened again, and as long as there are File objects that reference the common file control block (FCB), it can't be unlinked. One of those File objects may even be used to restore the file (i.e. unset the delete disposition) if it has delete access. Notably, this limbo file prevents the containing directory from being deleted. > I don't have a machine to test this on, but I'd like to deal with this > situation in my (cross-platform) code. If I have one Python script do this: > > with open("My Documents/foo") as f: > time.sleep(100000) > > and while it is sleeping another script does this: > > os.remove("My Documents/foo") > > what exception will I get? Is that unique to this situation, or is a generic > exception that could mean anything? This will fail with a sharing violation, i.e. winerror == 32. > My aim is to do: > > try: > os.remove(thefile) > except SomeError: > # Could be a virus checker or other transient process. > time.sleep(0.2) > os.remove(thefile) # try again > > Does that seem reasonable to you, as a Windows user? If you get an access-denied error, then you can try to remove the read-only attribute if it's set. Otherwise you can try to rename the file to get it out of the way. But if you're locked out by a sharing violation, there isn't anything you can do short of terminating the offending program. Virus scanners and other filter drivers generally aren't an immediate problem with deleting. They share all access. But they might keep a file from being immediately unlinked, which could cause problems in functions like shutil.rmtree. Removing the parent directory can fail if the file hasn't been unlinked yet. >> In user mode, a kernel object such as a File instance is referenced as >> a handle. > > Out of curiosity, I only know the term "handle" from classic Macintosh > (pre-OS X) where a handle was a managed pointer to a pointer to a chunk of > memory. Being managed, the OS could move the memory around without the > handles ending up pointing to garbage. Is that the same meaning in Windows > land? That sounds similar to an HGLOBAL handle used with GlobalAlloc/GlobalLock. This was a feature from 16-bit Windows, and it's kept around for compatibility with older APIs that still use it. I was talking about handles for kernel objects. Every process has a table of handle entries that's used to refer to kernel objects. These objects are allocated in the shared kernel space (the upper range of virtual memory), so user-mode code can't refer to them directly. Instead a program passes a handle to a system call, and kernel code and drivers use the object manager to look up the pointer reference. A kernel object has an associated type object (e.g. the "File" type), and there's a "Type" metatype like in Python. The list of supported methods is pretty basic: DumpProcedure, OpenProcedure, ParseProcedure, SecurityProcedure, QueryNameProcedure, OkayToCloseProcedure, CloseProcedure, DeleteProcedure The close method is called when a process closes a handle to the object. It gets passed a reference to the Process that's closing the handle and also the object's handle count, both in the process and across all processes, to allow for whatever cleanup is required when the last handle is closed both in the process and in the system. The delete method is called when the object is no longer referenced, which is for pointer references, but that implicitly includes handle references as well. For the File type, these methods reference the associated Device and call into the device stack with an I/O request packet (IRP). For closing a handle the major function is IRP_MJ_CLEANUP. For deleting the object the major function is IRP_MJ_CLOSE. The Driver object [1] has a MajorFunction table of function pointers for dispatching IRPs by major function code. If a File object [2] refers to a file-system file/directory (as opposed to a device), then the file-system context is the shared file control block (FCB) and usually a private context control block (CCB), which are respectively the object members FsContext and FsContext2. If the FCB is flagged as delete-on-close, then when the last reference is cleaned up, the file system does the work of unlinking and whatever else it has to do to really delete a file. If the CCB is flagged as delete-on-close (e.g. CreateFile was called with FILE_FLAG_DELETE_ON_CLOSE), then when the File object is cleaned up it transfers this flag to the shared FCB. If you want to see this in practice, look at the published cleanup code for the fastfat driver [3]. [1]: https://msdn.microsoft.com/en-us/library/ff544174 [2]: https://msdn.microsoft.com/en-us/library/ff545834 [3]: https://github.com/Microsoft/Windows-driver-samples/blob/master/filesys/fastfat/cleanup.c > In principle, I could say: > > delete file X > > which then returns immediately, and if I try to open(X) it will fail. But I > can still see it if I do a dir() on the parent directory? Yes. > Eventually the last reference to X will go away, and then it is unlinked. > What happens if I pull the plug in the meantime? Will the file magically > come back on rebooting? Setting the delete disposition is just a flag in the in-memory FCB structure, so if you pull the plug the file hasn't actually been unlinked. It's still there. Bear in mind that sharing delete access is rare on Windows. Normally when a file is deleted there's only a single File object referencing it, such as from DeleteFile calling NtOpenFile. Then it immediately calls NtSetInformationFile to set the delete disposition. When it closes the handle, this triggers the CloseProcedure => IRP_MJ_CLEANUP, DeleteProcedure => IRP_MJ_CLOSE sequence that actually unlinks the file. >> Finally, I'm sure most people are familiar with the read-only file >> attribute. If this attribute is set you can still open a file with >> delete access to rename it, but setting the delete disposition will >> fail with access denied. > > That was actually the situation I was thinking about when I started on this > question. From Python code, I was considering writing something like this: > > def delete_readonly(thefile): > try: > os.remove(thefile) > except ReadOnlyFileError: # what is this really? It's a PermissionError with winerror == 5, i.e. access denied. As mentioned above, you can use os.chmod to remove the read-only file attribute. From eryksun at gmail.com Tue Mar 14 13:40:04 2017 From: eryksun at gmail.com (eryk sun) Date: Tue, 14 Mar 2017 17:40:04 +0000 Subject: When will os.remove fail? In-Reply-To: References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 14, 2017 at 1:07 PM, Chris Angelico wrote: > On Tue, Mar 14, 2017 at 10:32 PM, Steve D'Aprano > wrote: > >> I take it that you *can* delete open files, but only if the process that >> opens them takes special care to use "delete sharing". Is that correct? > > Yes, but you can't always control the process that opens them. For > example, it's annoyingly difficult to update a running executable. One option is to move it out of the way. For example: src = Path(sys.executable) dst = Path('C:/Temp/python.exe') >>> src.exists(), dst.exists() (True, False) >>> src.rename(dst) >>> src.exists(), dst.exists() (False, True) >>> dst.rename(src) >>> src.exists(), dst.exists() (True, False) > More generally, a handle is just an opaque cookie that represents a > thing. If you do cross-platform socket programming, you'll find that > on Unix, creating a socket returns a "file descriptor"; but on > Windows, it returns a "socket handle". Aside from the fact that socket > handles can only be used with socket functions (making them harder to > pass to other processes etc), the two concepts work broadly the same > way: you have a small integer value that represents a large resource. Usually a socket is a handle for a File object, from opening the AFD (ancillary function) device. You can use it with [Nt]ReadFile and [Nt]WriteFile [1]. It's just better to use it with Winsock APIs like WSARecv and WSASend, which make NtDeviceIoControlFile calls. But there's also the headache of the deprecated layered service providers, for which a socket isn't really a File object and using File functions is inefficient. [1]: https://msdn.microsoft.com/en-us/library/ms740522 Similarly for a console File handle you can use [Nt]ReadFile and [Nt]WriteFile, which encode and decode byte streams using the console input and output codepages. But it's generally better to use ReadConsole and WriteConsole, which allow using the UTF-16 API via NtDeviceIoControlFile. ReadConsole also allows defining a custom control mask, if, for example, you want Ctrl+D to signal EOF. > I'm terrified to think what the interactions would be between this and > the Ubuntu subsystem in Win 10. What're the semantics of unlinkat()? > What about the common practice of creating a file and then unlinking > it so it doesn't show up in the directory? (And is that different on a > file system that supports hard links?) Or are heaps of POSIX features > simply not available? WSL uses the VolFs file system for the Linux VFS. This should implement native Linux file-system behavior. The interesting interaction is for Windows drives that are made available under /mnt. In the following example, in Windows Python I set the delete disposition on a file named "spam". Then in WSL python3 I checked the directory listing and whether I could stat, remove, or open the file: >>> os.listdir() ['spam'] >>> os.stat('spam') Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: 'spam' >>> os.remove('spam') Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: 'spam' >>> open('spam') Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: 'spam' >>> open('spam', 'w') Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: 'spam' Back in Windows I called SetFileInformationByHandle to unset the delete disposition. Then regular access was restored in WSL: >>> s = os.stat('spam') >>> s.st_ino, s.st_size (35184372088857305, 10) From michael at felt.demon.nl Tue Mar 14 14:28:53 2017 From: michael at felt.demon.nl (Michael Felt) Date: Tue, 14 Mar 2017 19:28:53 +0100 Subject: When will os.remove fail? In-Reply-To: <58c5fb06$0$1612$c3e8da3$5496439d@news.astraweb.com> References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <87inne1ggt.fsf@universite-de-strasbourg.fr.invalid> <58c5fb06$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 13/03/2017 02:51, Steve D'Aprano wrote: > On Mon, 13 Mar 2017 05:45 am, Alain Ketterlin wrote: > >> Steve D'Aprano writes: > [...] >>> It seems that os.remove on Linux will force the delete even if the file >>> is read-only or unreadable, provided you own the file. >> Your permissions on the file do not really matters. It's all about your >> permissions on the parent directory (removing a file is really modifying >> the parent dir). Actually, it is even slightly more complicated. Here is >> an excerpt of the unlink(2) call (which does the job) listing common >> error cases: Granted, I am a bit behind in the discussion - and I know nothing about how Windows manages this since DOS 3.3 - there it also called unlink(). rm is the command we run. The system call it uses to remove a file is unlink(). unlink() removes the "link" of the name in the directory to the inode and lowers the count of the number of links to the file (a hard link is an additional directory link to the inode). To modify the inode (link counter) you need to own the file or have (super user) elevated privelidges. To remove the directory link you need to have write privilidge on the (special file type) directory. On UNIX/Linux when the link count is zero the inode and the filesystem blocks it provides access to are cleared if no process is holding the file open. This means it is easy to unlink() (not remove!) an open file. The inode is active and can be used "normally". FYI, the classic mktemp() library routine on UNIX would create a file, open (better create) the file, unlink the file, and then return file descriptor. Regardless of how the program ended (crash or normal) the temp file would be cleaned up on exit. I would be guessing - but FAT and/or NTFS may not be written to clean up on a file with no "links" - and this is why Windows behavior seems to be more restrictive than POSIX/LINUX. > Thanks for the detailed explanation, and to everyone else who corrected my > misunderstanding. > > > From python at mrabarnett.plus.com Tue Mar 14 14:53:52 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Mar 2017 18:53:52 +0000 Subject: Extraction of model and date created tag from own picture/video recordings In-Reply-To: <7fbbfdff-d7ab-4825-9721-2024fd4369bf@googlegroups.com> References: <7fbbfdff-d7ab-4825-9721-2024fd4369bf@googlegroups.com> Message-ID: On 2017-03-14 07:34, zljubisic at gmail.com wrote: > I am looking for the way to extract two simple information from pictures/videos that I have recorded with different devices that I own: model (of the device that has recorded) and recordings (local) creation time. > > So far, I tried different approaches. > > I tried to use pymediainfo (https://pypi.python.org/pypi/pymediainfo/), which is kind of good for iPhone videos, but doesn't recognize model of the android videos and it is bed for pictures, but at the moment, I don't have anything better. > > I also tried ExifRead (https://pypi.python.org/pypi/ExifRead), that is good for some pictures, but not for all. > > For such a simple requirement (model and creation date) is there a library that can: > 1. Cover both pictures and videos > 2. Work with android and iPhone > > Does someone have an experience with such task in order to suggest a library to me? > It might be worth trying "ImageMagick". From grant.b.edwards at gmail.com Tue Mar 14 15:01:46 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 14 Mar 2017 19:01:46 +0000 (UTC) Subject: When will os.remove fail? References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-03-13, eryk sun wrote: [An impressive 150-line explanation of file removal on Windows.] Wow. I have two comments: 1. I think I can see the VMS heritage of Windows shining through. 2. You have my condolences regarding whatever it was that required you to know all that... VMS: for when just one overly complex solution to a simple problem isn't enough. -- Grant Edwards grant.b.edwards Yow! Finally, Zippy at drives his 1958 RAMBLER gmail.com METROPOLITAN into the faculty dining room. From rosuav at gmail.com Tue Mar 14 15:19:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Mar 2017 06:19:48 +1100 Subject: When will os.remove fail? In-Reply-To: References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <87inne1ggt.fsf@universite-de-strasbourg.fr.invalid> <58c5fb06$0$1612$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 15, 2017 at 5:28 AM, Michael Felt wrote: > Granted, I am a bit behind in the discussion - and I know nothing about how > Windows manages this since DOS 3.3 - there it also called unlink(). > > rm is the command we run. The system call it uses to remove a file is > unlink(). unlink() removes the "link" of the name in the directory to the > inode and lowers the count of the number of links to the file (a hard link > is an additional directory link to the inode). To modify the inode (link > counter) you need to own the file or have (super user) elevated privelidges. > To remove the directory link you need to have write privilidge on the > (special file type) directory. > > On UNIX/Linux when the link count is zero the inode and the filesystem > blocks it provides access to are cleared if no process is holding the file > open. This means it is easy to unlink() (not remove!) an open file. The > inode is active and can be used "normally". FYI, the classic mktemp() > library routine on UNIX would create a file, open (better create) the file, > unlink the file, and then return file descriptor. Regardless of how the > program ended (crash or normal) the temp file would be cleaned up on exit. You've fairly accurately summed up the POSIX model. The rm command uses the unlink syscall, and the semantics are broadly as you describe; the permissions question is handled by the standard permission bits "rwxrwxrwx", but otherwise you're about right. And yes, removing a file means removing one name from it, which is why a log file growing to infinity can't simply be deleted when you run out of disk space. If the program ends while the OS is still alive, then yes, the temp file will be cleaned up on exit. If the power is pulled, AIUI a fsck will notice that there's a file with no directory entries, and clean it up, although it may end up dropping it into lost+found rather than just deleting it. > I would be guessing - but FAT and/or NTFS may not be written to clean up on > a file with no "links" - and this is why Windows behavior seems to be more > restrictive than POSIX/LINUX. The Windows semantics are very different. Firstly, FAT doesn't even _have_ the concept of hardlinks (aka files with multiple directory entries), so there's no way that it'll ever be able to do this kind of thing. (And before you say "oh but FAT is dead these days", it's still frequently used on removable media.) NTFS does have hardlinks, so in theory it would be capable of POSIX semantics, but Windows semantics are baked into a lot of programs' expectations, so I doubt that that's going to change. ChrisA From saxri89 at gmail.com Tue Mar 14 15:56:13 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Tue, 14 Mar 2017 12:56:13 -0700 (PDT) Subject: python and pyqt4 Message-ID: <02c730ac-9fb0-40d1-be2e-de86769e1106@googlegroups.com> i will want to create a simple python script with pyqt4 and Q designer where the user put a number (line_edit) and if that number is something the user take back three new codes(lineEdit_2,lineEdit_3,lineEdit_4) and if user press ok(buttonBox) then plugin do something else in the some GUI. for that i create a new additional pushButton in Qdesigner and i create additional def function(run1) for execute code for pushButton. first i add new pushbutton in __init__ : def __init__(self, iface): self.dlg = pluginDialog() self.dlg.pushButton.clicked.connect(self.run1) plugin work without error but dont show me the codes (lineEdit_2,lineEdit_3,lineEdit_4) in the plugin window if i press pushbutton any idea ? my python code : def run1(self): distance = str(self.dlg.lineEdit.text()) if distance==0: area1='some' area2='hello' area3='world' self.dlg.lineEdit_2.setText(str(area1)) self.dlg.lineEdit_3.setText(str(area2)) self.dlg.lineEdit_4.setText(str(area3)) def run(self): self.dlg.show() result = self.dlg.exec_() if result: pass and i try to replace run1 with : def run1(self): self.dlg.show() result = self.dlg.exec_() if result: distance = str(self.dlg.lineEdit.text()) if distance==0: area1='some' area2='hello' area3='world' self.dlg.lineEdit_2.setText(str(area1)) self.dlg.lineEdit_3.setText(str(area2)) self.dlg.lineEdit_4.setText(str(area3)) pass but no change. From saxri89 at gmail.com Tue Mar 14 15:59:32 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Tue, 14 Mar 2017 12:59:32 -0700 (PDT) Subject: python and databases Message-ID: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> I have a database in microsoft ACCESS with about 150 records.. if I want to get some data from this database using a query in python and i want to store in some variables in python that will do this ? to avoid the 150 if ...: Using the standard library the python? know easily put it an SQL query but i canot use additional library python. From irving.duran at gmail.com Tue Mar 14 16:44:24 2017 From: irving.duran at gmail.com (Irving Duran) Date: Tue, 14 Mar 2017 15:44:24 -0500 Subject: python and databases In-Reply-To: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> References: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> Message-ID: I don't know that there is a native library in python for you to call an MS Access db. Would you be able to extract the content into a CSV and read it that way? Also, is there a particular reason why you couldn't use an additional python lib? Thank You, Irving Duran On Tue, Mar 14, 2017 at 2:59 PM, Xristos Xristoou wrote: > I have a database in microsoft ACCESS with about 150 records.. if I want > to get some data from this database using a query in python and i want to > store in some variables in python that will do this ? to avoid the 150 if > ...: Using the standard library the python? know easily put it an SQL query > but i canot use additional library python. > -- > https://mail.python.org/mailman/listinfo/python-list > From ian.g.kelly at gmail.com Tue Mar 14 16:58:08 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Tue, 14 Mar 2017 14:58:08 -0600 Subject: Python3.6 a little conundrum In-Reply-To: References: Message-ID: On Tue, Mar 14, 2017 at 2:25 PM, Gilmeh Serda wrote: > Thanks. I guess I could get a new(-er) copy when that day comes and redo > all this. I trust 3.6.0 won't be the last one. :) As it says in the Book of Armaments, Chapter 2, verses 9?21: """ Three shall be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, neither count thou two, excepting that thou then proceed to three. Five is right out. """ We should thus infer that Python 3.9 will be the final release as Guido does not want a 3.10 and proceeding to 4.0 would be unholy. From vincent.vande.vyvre at telenet.be Tue Mar 14 17:03:37 2017 From: vincent.vande.vyvre at telenet.be (Vincent Vande Vyvre) Date: Tue, 14 Mar 2017 22:03:37 +0100 Subject: python and pyqt4 In-Reply-To: <02c730ac-9fb0-40d1-be2e-de86769e1106@googlegroups.com> References: <02c730ac-9fb0-40d1-be2e-de86769e1106@googlegroups.com> Message-ID: Le 14/03/17 ? 20:56, Xristos Xristoou a ?crit : > i will want to create a simple python script with pyqt4 and Q designer where the user put a number (line_edit) and if that number is something the user take back three new codes(lineEdit_2,lineEdit_3,lineEdit_4) and if user press ok(buttonBox) then plugin do something else in the some GUI. > for that i create a new additional pushButton in Qdesigner and i create additional def function(run1) for execute code for pushButton. > > > first i add new pushbutton in __init__ : > def __init__(self, iface): > self.dlg = pluginDialog() > self.dlg.pushButton.clicked.connect(self.run1) > > plugin work without error but dont show me the codes (lineEdit_2,lineEdit_3,lineEdit_4) in the plugin window if i press > pushbutton > any idea ? my python code : > > def run1(self): > distance = str(self.dlg.lineEdit.text()) > if distance==0: > area1='some' > area2='hello' > area3='world' > self.dlg.lineEdit_2.setText(str(area1)) > self.dlg.lineEdit_3.setText(str(area2)) > self.dlg.lineEdit_4.setText(str(area3)) > > > > def run(self): > self.dlg.show() > result = self.dlg.exec_() > > if result: > pass > > and i try to replace run1 with : > > def run1(self): > self.dlg.show() > result = self.dlg.exec_() > if result: > distance = str(self.dlg.lineEdit.text()) > if distance==0: > area1='some' > area2='hello' > area3='world' > self.dlg.lineEdit_2.setText(str(area1)) > self.dlg.lineEdit_3.setText(str(area2)) > self.dlg.lineEdit_4.setText(str(area3)) > pass > > but no change. distance is a string, then you have to compare it with the string "0" not the integer Vincent From python at lucidity.plus.com Tue Mar 14 17:14:53 2017 From: python at lucidity.plus.com (Erik) Date: Tue, 14 Mar 2017 21:14:53 +0000 Subject: When will os.remove fail? In-Reply-To: References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4ef9b333-a1b2-14dd-0da3-ef06a16f2dfc@lucidity.plus.com> On 14/03/17 13:56, Chris Angelico wrote: > On Wed, Mar 15, 2017 at 12:30 AM, Jon Ribbens wrote: >> rm does not ask before deleting. However some Linux distributions >> take it upon themselves to put "alias rm='rm -i'" in /etc/profile. > > I have no such alias, but it still prompts. [snip] > This is the GNU coreutils rm command. Obviously behaviour may be > different with non-GNU rm's. Yes, I believe this is something extra that particular versions of 'rm' may do (over and above the POSIX/unlink() semantics discussed already). Although one has permission at the OS/filesystem level to unlink the file, unless '-f' is specified they may still ask ('-i' behaviour) if that file is otherwise not modifiable by the user running the command, as a safety net. E. From python at mrabarnett.plus.com Tue Mar 14 17:27:41 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Mar 2017 21:27:41 +0000 Subject: python and pyqt4 In-Reply-To: References: <02c730ac-9fb0-40d1-be2e-de86769e1106@googlegroups.com> Message-ID: <633eebe7-ea88-3330-6d8a-b02925146031@mrabarnett.plus.com> On 2017-03-14 21:03, Vincent Vande Vyvre wrote: > Le 14/03/17 ? 20:56, Xristos Xristoou a ?crit : >> i will want to create a simple python script with pyqt4 and Q designer where the user put a number (line_edit) and if that number is something the user take back three new codes(lineEdit_2,lineEdit_3,lineEdit_4) and if user press ok(buttonBox) then plugin do something else in the some GUI. >> for that i create a new additional pushButton in Qdesigner and i create additional def function(run1) for execute code for pushButton. >> >> >> first i add new pushbutton in __init__ : >> def __init__(self, iface): >> self.dlg = pluginDialog() >> self.dlg.pushButton.clicked.connect(self.run1) >> >> plugin work without error but dont show me the codes (lineEdit_2,lineEdit_3,lineEdit_4) in the plugin window if i press >> pushbutton >> any idea ? my python code : >> >> def run1(self): >> distance = str(self.dlg.lineEdit.text()) >> if distance==0: >> area1='some' >> area2='hello' >> area3='world' >> self.dlg.lineEdit_2.setText(str(area1)) >> self.dlg.lineEdit_3.setText(str(area2)) >> self.dlg.lineEdit_4.setText(str(area3)) >> >> >> >> def run(self): >> self.dlg.show() >> result = self.dlg.exec_() >> >> if result: >> pass >> >> and i try to replace run1 with : >> >> def run1(self): >> self.dlg.show() >> result = self.dlg.exec_() >> if result: >> distance = str(self.dlg.lineEdit.text()) >> if distance==0: >> area1='some' >> area2='hello' >> area3='world' >> self.dlg.lineEdit_2.setText(str(area1)) >> self.dlg.lineEdit_3.setText(str(area2)) >> self.dlg.lineEdit_4.setText(str(area3)) >> pass >> >> but no change. > > distance is a string, then you have to compare it with the string "0" > not the integer > In addition, if the condition is false, then area1, area2 and area3 won't exist, and you'll get a NameError (although the GUI might be hiding that from you!). From rosuav at gmail.com Tue Mar 14 17:30:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Mar 2017 08:30:31 +1100 Subject: python and databases In-Reply-To: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> References: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> Message-ID: On Wed, Mar 15, 2017 at 6:59 AM, Xristos Xristoou wrote: > I have a database in microsoft ACCESS with about 150 records.. if I want to get some data from this database using a query in python and i want to store in some variables in python that will do this ? to avoid the 150 if ...: Using the standard library the python? know easily put it an SQL query but i canot use additional library python. > If you can't use third-party libraries, then basically your only option is to export it as text, eg CSV. ChrisA From brjohan at gmail.com Tue Mar 14 17:43:52 2017 From: brjohan at gmail.com (BrJohan) Date: Tue, 14 Mar 2017 22:43:52 +0100 Subject: python and databases In-Reply-To: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> References: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> Message-ID: On 2017-03-14 20:59, Xristos Xristoou wrote: > I have a database in microsoft ACCESS with about 150 records.. if I want to get some data from this database using a query in python and i want to store in some variables in python that will do this ? to avoid the 150 if ...: Using the standard library the python? know easily put it an SQL query but i canot use additional library python. > Some years ago I did some experiments using pyodbc and MS Access. Some success. From irmen.NOSPAM at xs4all.nl Tue Mar 14 17:55:40 2017 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Tue, 14 Mar 2017 22:55:40 +0100 Subject: python and databases In-Reply-To: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> References: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> Message-ID: <58c866dc$0$703$e4fe514c@news.xs4all.nl> On 14-3-2017 20:59, Xristos Xristoou wrote: > I have a database in microsoft ACCESS with about 150 records.. if I want to get some > data from this database using a query in python and i want to store in some > variables in python that will do this ? to avoid the 150 if ...: Using the standard > library the python? know easily put it an SQL query but i canot use additional > library python. > Is the data in the Access database static? 150 records is not much data. You might be able to extract it ONCE, and store it directly in Python data structures instead. Or extract it and store it in a sqlite database instead, which you can use from Python using the standard library's sqlite3 module. If the data is dynamic however because it is being changed by other sources, you'll have to use a third party library to get to it I think.... Irmen From eryksun at gmail.com Tue Mar 14 20:09:34 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 15 Mar 2017 00:09:34 +0000 Subject: When will os.remove fail? In-Reply-To: References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 14, 2017 at 7:01 PM, Grant Edwards wrote: > > 1. I think I can see the VMS heritage of Windows shining through. That's not surprising considering that VMS and NT have the same architect -- Dave Cutler -- and that I/O system and file systems were design by former DEC programmers that he brought with him, such as Darryl Havens and Gary Kimura. The old joke is that WNT = VMS + 1. From torriem at gmail.com Tue Mar 14 20:23:21 2017 From: torriem at gmail.com (Michael Torrie) Date: Tue, 14 Mar 2017 18:23:21 -0600 Subject: python and databases In-Reply-To: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> References: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> Message-ID: On 03/14/2017 01:59 PM, Xristos Xristoou wrote: > I have a database in microsoft ACCESS with about 150 records.. if I > want to get some data from this database using a query in python and > i want to store in some variables in python that will do this ? to > avoid the 150 if ...: Using the standard library the python? know > easily put it an SQL query but i canot use additional library > python. If you simply want to move data to an sql server, your best bet is to use mdbtools to dump the database schema and records out to an .sql file that you can then massage and import into whatever sql server you are using. https://github.com/brianb/mdbtools If you're looking for a way to use the access file directly, and continue using it in MS Access, you might be able to get the odbc bridge working (on windows of course), and communicate with it with pyodbc. From christina at codepop.com Tue Mar 14 20:45:50 2017 From: christina at codepop.com (Christina Lugo) Date: Tue, 14 Mar 2017 20:45:50 -0400 Subject: Open SourceCraft Interview w/Python Instructor Trey Hunner Message-ID: <1613fb8b-6ad5-551d-3c45-0756e6236d62@codepop.com> Hello, *I wanted to let you know about an interview I just published on Open SourceCraft with Trey Hunner, who worked his way from a freelance Python dev to a Python instructor. He also runs weekly free Python chat where he discusses Python, teaching, open source, and more. Here is the link to his interview:* *http://codepop.com/open-sourcecraft/episodes/trey-hunner/* *Thanks so much! * *Christina Lugo* From eryksun at gmail.com Tue Mar 14 21:21:12 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 15 Mar 2017 01:21:12 +0000 Subject: When will os.remove fail? In-Reply-To: References: <58c58a0c$0$1606$c3e8da3$5496439d@news.astraweb.com> <58c7d4e3$0$22140$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 14, 2017 at 10:05 PM, Dennis Lee Bieber wrote: > On Wed, 15 Mar 2017 00:07:32 +1100, Chris Angelico > >>Yes, but you can't always control the process that opens them. For >>example, it's annoyingly difficult to update a running executable. >> > I wouldn't be surprised if Windows mmap()'s running executables into > swap space, rather than actually swapping in-core image to the normal swap > file. Executables are memory mapped, and this also applies to memory-mapped data files (i.e. CreateFileMapping / MapViewOfFile) like with Python's mmap module. Notice how the fastfat driver's function that sets the delete disposition, FatSetDispositionInfo [1], has to check for this by calling the kernel memory-manager function MmFlushImageSection [2] (note that a flush type of MmFlushForDelete also checks the number of views of the data section). If the mapped view prevents deleting the file it returns STATUS_CANNOT_DELETE. This status code gets translated to the Windows error code ERROR_ACCESS_DENIED, for which Python raises a PermissionError. This is misleading because you were probably granted delete access. The file just can't be deleted. Typically you can still open such files with delete access to allow renaming (relinking) them to another directory on the volume. You're just not allowed to unlink them. [1]: https://github.com/Microsoft/Windows-driver-samples/blob/master/filesys/fastfat/fileinfo.c#L2417 [2]: https://msdn.microsoft.com/en-us/library/ff549808 It's also interesting that the sharing mode is special cased. Normally if write access isn't shared you're denied the right to open the file with either write or append access. But with executables mapped by the loader, you can still open them for append access. The C runtime's POSIX (low) I/O layer has its own implementation of append mode that requires opening the file with both write and append access (O_WRONLY | O_APPEND), which is what Python's "a" mode uses. So you have to call CreateFile directly to get append-only access. For example, using a virtual environment copy of python.exe: append = 4 h = _winapi.CreateFile(sys.executable, append, 7, 0, 3, 0, 0) _winapi.WriteFile(h, b'spam') f = open(sys.executable, 'rb') f.seek(-4, os.SEEK_END) >>> f.read() b'spam' From steve+python at pearwood.info Wed Mar 15 04:02:00 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 15 Mar 2017 19:02:00 +1100 Subject: Extract items from string in db References: Message-ID: <58c8f4fa$0$1587$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Mar 2017 09:26 am, DFS wrote: > I have a SQLite database with TEXT columns containing strings of the > format: > > ['Item1: Value1 has,comma','Item2: has'apostrophe','Item3: Value3'] > > The brackets are part of the string. So in Python format, you have something like this: s = "['Item1: Value1 has,comma','Item2: has'apostrophe','Item3: Value3']" assert type(s) is str assert s[0] == "[" assert s[-1] == "]" Correct? I can't help you in getting s out of the SQLite database. Below, you tell us that you're extracting the string, but it isn't actually a string, it is a tuple. You need to fix that. > How can I unpack and access each item? > Item1: Value1 has,comma > Item2: has'apostrophe > Item3: Value3 Is the string format documented anywhere? > I tried this: > db.execute("SELECT COLUMN FROM TABLE WHERE ID = ?;",(123,)) > vals = [db.fetchone()] > for val in list(vals): > print val There's no point wrapping the output of db.fetchone() in a list. And no point converting vals to a list. db.execute("SELECT COLUMN FROM TABLE WHERE ID = ?;", (123,)) vals = db.fetchone() for val in vals: print type(val), val What does it output now? > but it just prints the string as is. > > split(",") returns "tuple object has no attribute split" If it is a tuple object, it isn't a string. It isn't both at once. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From zljubisic at gmail.com Wed Mar 15 04:31:18 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 15 Mar 2017 01:31:18 -0700 (PDT) Subject: Extraction of model and date created tag from own picture/video recordings In-Reply-To: References: <7fbbfdff-d7ab-4825-9721-2024fd4369bf@googlegroups.com> Message-ID: On Tuesday, 14 March 2017 19:54:18 UTC+1, MRAB wrote: > It might be worth trying "ImageMagick". ImageMagick is only for pictures. :( Do you have a suggestion for videos? From rosuav at gmail.com Wed Mar 15 05:04:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Mar 2017 20:04:29 +1100 Subject: Extraction of model and date created tag from own picture/video recordings In-Reply-To: References: <7fbbfdff-d7ab-4825-9721-2024fd4369bf@googlegroups.com> Message-ID: On Wed, Mar 15, 2017 at 7:31 PM, wrote: > On Tuesday, 14 March 2017 19:54:18 UTC+1, MRAB wrote: >> It might be worth trying "ImageMagick". > > ImageMagick is only for pictures. :( > Do you have a suggestion for videos? What format are they in? Search the web for "read media info" and see what you find. Optionally add "python" to look specifically for libraries for Python. ChrisA From zljubisic at gmail.com Wed Mar 15 05:22:53 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Wed, 15 Mar 2017 02:22:53 -0700 (PDT) Subject: Extraction of model and date created tag from own picture/video recordings In-Reply-To: References: <7fbbfdff-d7ab-4825-9721-2024fd4369bf@googlegroups.com> Message-ID: <91b42555-2aaf-4382-932e-82433212bb21@googlegroups.com> I have done that. The best article I have found is: https://getpocket.com/a/read/1651596570 So far I have tried exifread, exiftool, mediainfo, but looks like I will have to combine several tools in order to get the information that I need. Major problem is with the model. Looks like every manufacturer has its tags. :( From nulla.epistola at web.de Wed Mar 15 05:53:33 2017 From: nulla.epistola at web.de (Sibylle Koczian) Date: Wed, 15 Mar 2017 10:53:33 +0100 Subject: python and databases In-Reply-To: References: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> Message-ID: <37595e05-ea8d-50ad-b553-e0aae514e289@web.de> Am 15.03.2017 um 01:23 schrieb Michael Torrie: > On 03/14/2017 01:59 PM, Xristos Xristoou wrote: >> I have a database in microsoft ACCESS with about 150 records.. if I >> want to get some data from this database using a query in python and >> i want to store in some variables in python that will do this ? to >> avoid the 150 if ...: Using the standard library the python? know >> easily put it an SQL query but i canot use additional library >> python. > > If you simply want to move data to an sql server, your best bet is to > use mdbtools to dump the database schema and records out to an .sql file > that you can then massage and import into whatever sql server you are > using. > > https://github.com/brianb/mdbtools > > If you're looking for a way to use the access file directly, and > continue using it in MS Access, you might be able to get the odbc bridge > working (on windows of course), and communicate with it with pyodbc. > Or you could use adodbapi. Depending on your Python installation you might have the Python for Windows extensions already installed (are they still part of ActivePython?), so that might not count as a third party library. From nulla.epistola at web.de Wed Mar 15 05:53:33 2017 From: nulla.epistola at web.de (Sibylle Koczian) Date: Wed, 15 Mar 2017 10:53:33 +0100 Subject: python and databases In-Reply-To: References: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> Message-ID: <37595e05-ea8d-50ad-b553-e0aae514e289@web.de> Am 15.03.2017 um 01:23 schrieb Michael Torrie: > On 03/14/2017 01:59 PM, Xristos Xristoou wrote: >> I have a database in microsoft ACCESS with about 150 records.. if I >> want to get some data from this database using a query in python and >> i want to store in some variables in python that will do this ? to >> avoid the 150 if ...: Using the standard library the python? know >> easily put it an SQL query but i canot use additional library >> python. > > If you simply want to move data to an sql server, your best bet is to > use mdbtools to dump the database schema and records out to an .sql file > that you can then massage and import into whatever sql server you are > using. > > https://github.com/brianb/mdbtools > > If you're looking for a way to use the access file directly, and > continue using it in MS Access, you might be able to get the odbc bridge > working (on windows of course), and communicate with it with pyodbc. > Or you could use adodbapi. Depending on your Python installation you might have the Python for Windows extensions already installed (are they still part of ActivePython?), so that might not count as a third party library. From marco.nawijn at colosso.nl Wed Mar 15 05:54:49 2017 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Wed, 15 Mar 2017 02:54:49 -0700 (PDT) Subject: Dynamically replacing an objects __class__; is it safe? Message-ID: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> Dear All, Summary of the question: Is it generally safe to dynamically change an objects class; if not under which conditions can it be considered safe. Context: Given the code below, I have no direct control over Base and M1. M1 is a instantiated by 'calling' the read-only property of Base. I would like to transparently switch behaviour from M1 to M2. I have tried several things, but finally settled on the code below. Although it works really well, I am not sure whether I am about to shoot myself in the foot. In short, what I do is derive from Base, shadow the read-only property 'my_prop' so it returns M2 and finally replace an objects __class__ attribute with my derived class. Any thoughts or comments? (code below is Python 3) class M1(object): def __init__(self): print('Initializing M1') class M2(object): def __init__(self): print('Initializing M2') class Base(object): @property def my_prop(self): return M1() class ShadowBase(Base): @property def my_prop(self): return M2() if __name__ == '__main__': o = Base() o.my_prop # Prints 'Initializing M1' o = Base() o.__class__ = ShadowBase o.my_prop # Prints 'Initializing M2' From __peter__ at web.de Wed Mar 15 06:33:26 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Mar 2017 11:33:26 +0100 Subject: Dynamically replacing an objects __class__; is it safe? References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> Message-ID: marco.nawijn at colosso.nl wrote: > Dear All, > > Summary of the question: > Is it generally safe to dynamically change an objects class; if not > under which conditions can it be considered safe. > > Context: > Given the code below, I have no direct control over Base and M1. M1 > is a instantiated by 'calling' the read-only property of Base. > I would like to transparently switch behaviour from M1 to M2. I have > tried several things, but finally settled on the code below. Although > it works really well, I am not sure whether I am about to shoot myself > in the foot. In short, what I do is derive from Base, shadow the read-only > property 'my_prop' so it returns M2 and finally replace an objects > __class__ attribute with my derived class. > > Any thoughts or comments? Saying that something is "safe" is always problematic. I'd rather look for ways to break the code and then decide if you can live with these potential problems. I'll start with - If Base is reimplemented in C __class__ may become read-only - my_prop may be accessed by Base methods and expect an M1 instance > (code below is Python 3) > > class M1(object): > > def __init__(self): > print('Initializing M1') > > > class M2(object): > > def __init__(self): > print('Initializing M2') > > > class Base(object): > > @property > def my_prop(self): > return M1() > > > class ShadowBase(Base): > > @property > def my_prop(self): > return M2() > > if __name__ == '__main__': > > o = Base() > o.my_prop > # Prints 'Initializing M1' > > o = Base() > o.__class__ = ShadowBase > o.my_prop > # Prints 'Initializing M2' From marco.nawijn at colosso.nl Wed Mar 15 06:55:47 2017 From: marco.nawijn at colosso.nl (marco.nawijn at colosso.nl) Date: Wed, 15 Mar 2017 03:55:47 -0700 (PDT) Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> Message-ID: <290ca112-02a2-426a-bdc5-43689bd869e5@googlegroups.com> On Wednesday, March 15, 2017 at 11:33:56 AM UTC+1, Peter Otten wrote: > marco.nawijn at colosso.nl wrote: > > > Dear All, > > > > Summary of the question: > > Is it generally safe to dynamically change an objects class; if not > > under which conditions can it be considered safe. > > > > Context: > > Given the code below, I have no direct control over Base and M1. M1 > > is a instantiated by 'calling' the read-only property of Base. > > I would like to transparently switch behaviour from M1 to M2. I have > > tried several things, but finally settled on the code below. Although > > it works really well, I am not sure whether I am about to shoot myself > > in the foot. In short, what I do is derive from Base, shadow the read-only > > property 'my_prop' so it returns M2 and finally replace an objects > > __class__ attribute with my derived class. > > > > Any thoughts or comments? > > Saying that something is "safe" is always problematic. I'd rather look for > ways to break the code and then decide if you can live with these potential > problems. I'll start with > > - If Base is reimplemented in C __class__ may become read-only > - my_prop may be accessed by Base methods and expect an M1 instance Ok. These are valid points. The first is not a real concern to me at the moment. The whole purpose of Base is to provide a higher level interface to the underlying C/C++ code. The second is more interesting. I was aware of this and checked the source code of the library. I know an M1 instance is not directly used by Base. In addition, I expose the exact same interface in M2. Thanks for the feedback. Much appreciated! Marco From cl at isbd.net Wed Mar 15 08:04:59 2017 From: cl at isbd.net (Chris Green) Date: Wed, 15 Mar 2017 12:04:59 +0000 Subject: How to make selected row visible in GTK TreeView? Message-ID: I have a GTK TreeView with scrollbars which enables me to scroll through the values OK. Clicking on a row selects it and highlights it. However if one uses 'down arrow' to move the selection/highlight down the list then the selected row disappears from the visibble window. How can I scroll the window so that the selected row remains visible? I would also like a 'go to row x' function to scroll to a specific row in the list and highlight it. I guess this would need very similar code to the first requirement. -- Chris Green ? From g.starck at gmail.com Wed Mar 15 09:49:32 2017 From: g.starck at gmail.com (gst) Date: Wed, 15 Mar 2017 06:49:32 -0700 (PDT) Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: <290ca112-02a2-426a-bdc5-43689bd869e5@googlegroups.com> References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <290ca112-02a2-426a-bdc5-43689bd869e5@googlegroups.com> Message-ID: <791c33da-e4dc-47c0-b74c-2df3609d2037@googlegroups.com> Hi, You can subclass M2 from M1 and override only what you need. Regards, From steve+python at pearwood.info Wed Mar 15 09:53:04 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 16 Mar 2017 00:53:04 +1100 Subject: Dynamically replacing an objects __class__; is it safe? References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> Message-ID: <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Mar 2017 08:54 pm, marco.nawijn at colosso.nl wrote: > Dear All, > > Summary of the question: > Is it generally safe to dynamically change an objects class; if not > under which conditions can it be considered safe. *Generally* safe? No. You cannot expect to take an arbitrary object and change its class: animal = Whale() animal.__class__ = Bird animal.fly() You probably can't make a whale fly just by changing the class to bird. It will need wings, and feathers, at the very least. For pure-Python classes, it is "safe" in the sense that the worst that will happen is an exception, not a seg fault or core dump. But it is not safe in the sense that the instance will work correctly: methods may fail, or do he wrong thing. (Actually, *silently doing the wrong thing* is usually much worse than raising an exception or crashing. At least when the program crashes, you know it is broken!) For *cooperative* classes, where you design the Before and After classes to operate correctly when you change the __class__, that's perfectly safe. > Context: > Given the code below, I have no direct control over Base and M1. M1 > is a instantiated by 'calling' the read-only property of Base. > I would like to transparently switch behaviour from M1 to M2. I have > tried several things, but finally settled on the code below. Although > it works really well, I am not sure whether I am about to shoot myself > in the foot. In short, what I do is derive from Base, shadow the read-only > property 'my_prop' so it returns M2 and finally replace an objects > __class__ attribute with my derived class. Sounds scarily confusing, and I say that as somebody who LOVES the "swap the __class__" trick when it is appropriate. If I wouldn't risk swapping out the __class__ if I didn't control the classes. You have this: o = Base() o.my_prop # Prints 'Initializing M1' o = Base() o.__class__ = ShadowBase o.my_prop # Prints 'Initializing M2' But why not just do this? o = ShadowBase() # inherits from Base, overrides my_prop o.my_prop # Prints 'Initializing M2' This sounds like an ordinary example of class inheritance to me, no need to add complications with swapping out the __class__ for something different. The only reason I would consider using the __class__ trick here is if you don't control the instantiation of the object: you don't create your own instance, you receive it pre-instantiated from elsewhere. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From odt at dtrx.de Wed Mar 15 10:19:46 2017 From: odt at dtrx.de (Olaf Dietrich) Date: Wed, 15 Mar 2017 14:19:46 +0000 (UTC) Subject: numpy indexing performance Message-ID: This is a simplified example of a Monte Carlo simulation where random vectors (here 2D vectors, which are all zero) are summed (the result is in r1 and r2 or r, respectively): def case1(): import numpy as np M = 100000 N = 10000 r1 = np.zeros(M) r2 = np.zeros(M) s1 = np.zeros(N) s2 = np.zeros(N) for n in range(1000): ind = np.random.random_integers(N, size=M) - 1 r1 += s1[ind] r2 += s2[ind] def case2(): import numpy as np M = 100000 N = 10000 r = np.zeros((M, 2)) s = np.zeros((N, 2)) for n in range(1000): ind = np.random.random_integers(N, size=M) - 1 r += s[ind] import timeit print("case1:", timeit.timeit( "case1()", setup="from __main__ import case1", number=1)) print("case2:", timeit.timeit( "case2()", setup="from __main__ import case2", number=1)) Resulting in: case1: 2.6224704339983873 case2: 4.374910838028882 Why is case2 significantly slower (almost by a factor of 2) than case1? There should be the same number of operations (additions) in both cases; the main difference is the indexing. Is there another (faster) way to avoid the separate component arrays r1 and r2? (I also tried r = np.zeros(M, dtype='2d'), which was comparable to case2.) Olaf From toby at tobiah.org Wed Mar 15 10:23:19 2017 From: toby at tobiah.org (Tobiah) Date: Wed, 15 Mar 2017 07:23:19 -0700 Subject: Extract items from string in db References: Message-ID: On 03/14/2017 03:26 PM, DFS wrote: > I have a SQLite database with TEXT columns containing strings of the format: > > ['Item1: Value1 has,comma','Item2: has'apostrophe','Item3: Value3'] > > The brackets are part of the string. > > How can I unpack and access each item? > Item1: Value1 has,comma > Item2: has'apostrophe > Item3: Value3 > This problem is probably unsolvable for all cases because the data is apparently allowed to freely contain the characters that provide the string with its structure. Still, there are clues that enable the parsing of most normal cases you are likely to encounter. This hinges on the fact that "','" is unlikely to occur in the actual data: s = "['Item1: Value1 has,comma','Item2: has'apostrophe','Item3: Value3']" items = s[2:-2].split("','") # Toss brackets, first and last quotes for thing in items: key, val = thing.split(": ") print "%s: %s" % (key, val) Output: ------- Item1: Value1 has,comma Item2: has'apostrophe Item3: Value3 From saxri89 at gmail.com Wed Mar 15 10:45:14 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Wed, 15 Mar 2017 07:45:14 -0700 (PDT) Subject: python and databases In-Reply-To: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> References: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> Message-ID: <4369f5e2-831b-4c87-b4d3-ddb177a81fe5@googlegroups.com> ?? ?????, 14 ??????? 2017 - 9:59:42 ?.?. UTC+2, ? ??????? Xristos Xristoou ??????: first thx for response second i cant use additional packate because i build tool for other python program and that use standar python only, sqlite is in standar python 2.7 @Irmen de Jong ? can use quyries in CSV @ Irving Duran @Chris Angelico ? From torriem at gmail.com Wed Mar 15 11:19:00 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 15 Mar 2017 09:19:00 -0600 Subject: python and databases In-Reply-To: <4369f5e2-831b-4c87-b4d3-ddb177a81fe5@googlegroups.com> References: <53e87a35-9911-4e87-9470-a09437b06e14@googlegroups.com> <4369f5e2-831b-4c87-b4d3-ddb177a81fe5@googlegroups.com> Message-ID: <256d4dcf-f423-a232-ba69-fee5fa13e714@gmail.com> On 03/15/2017 08:45 AM, Xristos Xristoou wrote: > first thx for response second i cant use additional packate because i > build tool for other python program and that use standar python > only, I don't see how you can retrieve data from MS Access without a tool that is not part of the standard Python distribution. > sqlite is in standar python 2.7 @Irmen de Jong ? Yes. Sqlite3 is built into Python 2.7. However I don't see how it will help you with an access database. You'd have to convert the data from MS Access to sql and insert it into the sqlite database. > can use quyries in CSV @ Irving Duran @Chris Angelico ? No. CSV is just a data interchange format. It's not a database. However you could export the entire table from MS Access to CSV and then with a Python script create an SQLite table and insert records into it from the CSV file that you load and parse with Python. From bolchisb at gmail.com Wed Mar 15 14:18:19 2017 From: bolchisb at gmail.com (Bogdan Radu Bolchis) Date: Wed, 15 Mar 2017 11:18:19 -0700 (PDT) Subject: crc method for a serial driver for fiscal cash register Message-ID: <16c6144f-923a-4dd1-89af-83b8c33028d2@googlegroups.com> hi, i'm developing a Point Of Sale app in python for my company, and we need to integrate the fiscal cash register driver in python. The original driver is only for windows and no longer supported, we want to switch to Linux. We managed to find the serial protocol, but the sent data is followed by a CRC. Can someone help me building a CRC function according to the manufacturer data? Here is what i have: ALGORITHM FOR CRC CALCULATION The two CRC bytes are calculated according to the formula x^15 + 1. In the calculation are included all data bytes plus the byte for block end. Every byte passes through the calculation register from teh MSB to LSB. Three working bytes are used - S1, S0 and TR S1 - Most significant byte from the CRC ( it is transmitted immediatelly after END) S0 - Least significant byte from the CRC ( It is transmitted after S1) TR - the current transmitted byte in the block. The CRC is calculated as follows: 1. S1 and S0 are zeroed 2. TR is loaded with the current transmitted byte. The byte is transmitted. 3. Points 3.1 and 3.2 are executed 8 times: 3.1. S1, S0 and TR are shifted one bit to the left. 3.2. If the carry bit from S1 is 1, the MSB of S1 and LSB of S0 are inverted. Points 2 and 3 are executed for all bytes, included in the calculation of the CRC - from the first byte after BEG up to and including byte END. 4. TR is loaded with 0 and point 3 is executed 5. TR is loaded with 0 and point 3 is executed 6. Byte S1 is transmitted 7. Byte S0 is transmitted ALGORITHM FOR CRC CHECK ON RECEIVING Three working bytes are used S1, S0 and RC S1 - Most significant byte from the CRC ( it is received immediately after END) S0 - Least significant byte from the CRC ( transmitted after S1) RC - the current received byte in the block ( beginning from the first byte after BEG and ending 2 bytes after END). The CRC is obtained as follows: 1. S1 and S0 are zeroed 2. RC is loaded with the current received byte 3. Points 3.1 and 3.2 are executed 8 times: 3.1. S1, S0 and RC are shifted 8 times to the left 3.2. if the MSB of S1 is 1 then MSB of S1 and LSB of S0 are inverted. Points 2 and 3 are executed for all bytes, included in the calculation of the CRC - from the first byte after BEG up to and including 2 bytes after END. S1 and S0 must be 0. thank you From greg.ewing at canterbury.ac.nz Wed Mar 15 18:03:56 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 16 Mar 2017 11:03:56 +1300 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > You probably can't make a whale fly just by changing the class to bird. It > will need wings, and feathers, at the very least. Some things succeed in flying with neither wings nor feathers. Helicopters, for example. -- Greg From rosuav at gmail.com Wed Mar 15 18:13:19 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Mar 2017 09:13:19 +1100 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 16, 2017 at 9:03 AM, Gregory Ewing wrote: > Steve D'Aprano wrote: >> >> You probably can't make a whale fly just by changing the class to bird. It >> will need wings, and feathers, at the very least. > > > Some things succeed in flying with neither wings nor feathers. > Helicopters, for example. Yeah but they do it by being so ugly that the earth repels them. I'm not sure that whale.ugliness is valid or high enough. ChrisA From python at mrabarnett.plus.com Wed Mar 15 18:19:04 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Mar 2017 22:19:04 +0000 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017-03-15 22:03, Gregory Ewing wrote: > Steve D'Aprano wrote: >> You probably can't make a whale fly just by changing the class to bird. It >> will need wings, and feathers, at the very least. > > Some things succeed in flying with neither wings nor feathers. > Helicopters, for example. > Could you argue that the blades were a kind of wing? After all, they rely on the same principle of moving through the air to produce lift. Balloons, on the other hand, ... :-) From rosuav at gmail.com Wed Mar 15 18:28:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Mar 2017 09:28:48 +1100 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 16, 2017 at 9:19 AM, MRAB wrote: > On 2017-03-15 22:03, Gregory Ewing wrote: >> >> Steve D'Aprano wrote: >>> >>> You probably can't make a whale fly just by changing the class to bird. >>> It >>> will need wings, and feathers, at the very least. >> >> >> Some things succeed in flying with neither wings nor feathers. >> Helicopters, for example. >> > Could you argue that the blades were a kind of wing? After all, they rely on > the same principle of moving through the air to produce lift. > > Balloons, on the other hand, ... :-) Certainly not. If they were, you'd move (or spin) them faster to go up, and slower to go down. But you don't. So it's all about the ugliness. You twist the blades up a bit to make the helicopter uglier. ChrisA From python at mrabarnett.plus.com Wed Mar 15 18:31:05 2017 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Mar 2017 22:31:05 +0000 Subject: crc method for a serial driver for fiscal cash register In-Reply-To: <16c6144f-923a-4dd1-89af-83b8c33028d2@googlegroups.com> References: <16c6144f-923a-4dd1-89af-83b8c33028d2@googlegroups.com> Message-ID: <5fc7c1ce-120b-1748-04ee-e7220ffe6b5e@mrabarnett.plus.com> On 2017-03-15 18:18, Bogdan Radu Bolchis wrote: > hi, > i'm developing a Point Of Sale app in python for my company, and we need to integrate the fiscal cash register driver in python. The original driver is only for windows and no longer supported, we want to switch to Linux. We managed to find the serial protocol, but the sent data is followed by a CRC. > > Can someone help me building a CRC function according to the manufacturer data? > > Here is what i have: > > ALGORITHM FOR CRC CALCULATION > > The two CRC bytes are calculated according to the formula x^15 + 1. In the calculation are included all data bytes plus the byte for block end. Every byte passes through the calculation register from teh MSB to LSB. > Three working bytes are used - S1, S0 and TR > S1 - Most significant byte from the CRC ( it is transmitted immediatelly after END) > S0 - Least significant byte from the CRC ( It is transmitted after S1) > TR - the current transmitted byte in the block. > > The CRC is calculated as follows: > 1. S1 and S0 are zeroed > 2. TR is loaded with the current transmitted byte. The byte is transmitted. > 3. Points 3.1 and 3.2 are executed 8 times: > 3.1. S1, S0 and TR are shifted one bit to the left. > 3.2. If the carry bit from S1 is 1, the MSB of S1 and LSB of S0 are inverted. > Points 2 and 3 are executed for all bytes, included in the calculation of the CRC - from the first byte after BEG up to and including byte END. > 4. TR is loaded with 0 and point 3 is executed > 5. TR is loaded with 0 and point 3 is executed > 6. Byte S1 is transmitted > 7. Byte S0 is transmitted > [snip] Step 3 is a little unclear. Step 3.1 says to shift TR, but step 3.2 says to check the carry bit after shifting S1, which is zero initially, therefore the carry bit will be clear, therefore S1 and S0 won't have any bits inverted and will stay zero. In summary, the CRC won't be affected by the data _at all_. And how about a few examples for checking the algorithm? From rosuav at gmail.com Wed Mar 15 20:08:16 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Mar 2017 11:08:16 +1100 Subject: crc method for a serial driver for fiscal cash register In-Reply-To: <5fc7c1ce-120b-1748-04ee-e7220ffe6b5e@mrabarnett.plus.com> References: <16c6144f-923a-4dd1-89af-83b8c33028d2@googlegroups.com> <5fc7c1ce-120b-1748-04ee-e7220ffe6b5e@mrabarnett.plus.com> Message-ID: On Thu, Mar 16, 2017 at 9:31 AM, MRAB wrote: >> 3.2. If the carry bit from S1 is 1, the MSB of S1 and LSB of S0 are >> inverted. >> Points 2 and 3 are executed for all bytes, included in the calculation of >> the CRC - from the first byte after BEG up to and including byte END. >> 4. TR is loaded with 0 and point 3 is executed >> 5. TR is loaded with 0 and point 3 is executed >> 6. Byte S1 is transmitted >> 7. Byte S0 is transmitted >> > [snip] > Step 3 is a little unclear. > > Step 3.1 says to shift TR, but step 3.2 says to check the carry bit after > shifting S1, which is zero initially, therefore the carry bit will be clear, > therefore S1 and S0 won't have any bits inverted and will stay zero. > I think probably "if the carry bit from TR is 1" would make this all make sense. Otherwise TR, which is the data payload, is completely ignored. ChrisA From no.email at nospam.invalid Wed Mar 15 20:49:18 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Wed, 15 Mar 2017 17:49:18 -0700 Subject: SimpleHTTPServer and CgiHTTPServer in practice Message-ID: <87bmt2nj01.fsf@nightsong.com> Sometimes I have a short term requirement to serve some data by http, so I've been using those modules rather than setting up a full featured web server. Some Python users have told me that isn't a good idea, but without any specifics. Are there any known problems with them such as security bugs, or in the py3 equivalents (server module)? I haven't had issues so far because it's just been ad hoc stuff for known clients, but they are much simpler to set up than something like Apache, so I don't see why not to make more use of them for low-traffic pages. Any thoughts/stories/cautions would be appreciated. Thanks From python at mrabarnett.plus.com Wed Mar 15 21:36:38 2017 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 16 Mar 2017 01:36:38 +0000 Subject: crc method for a serial driver for fiscal cash register In-Reply-To: References: <16c6144f-923a-4dd1-89af-83b8c33028d2@googlegroups.com> <5fc7c1ce-120b-1748-04ee-e7220ffe6b5e@mrabarnett.plus.com> Message-ID: <94036eed-e8b5-d9ab-3ae2-1e5b7b5728c0@mrabarnett.plus.com> On 2017-03-16 00:08, Chris Angelico wrote: > On Thu, Mar 16, 2017 at 9:31 AM, MRAB wrote: >>> 3.2. If the carry bit from S1 is 1, the MSB of S1 and LSB of S0 are >>> inverted. >>> Points 2 and 3 are executed for all bytes, included in the calculation of >>> the CRC - from the first byte after BEG up to and including byte END. >>> 4. TR is loaded with 0 and point 3 is executed >>> 5. TR is loaded with 0 and point 3 is executed >>> 6. Byte S1 is transmitted >>> 7. Byte S0 is transmitted >>> >> [snip] >> Step 3 is a little unclear. >> >> Step 3.1 says to shift TR, but step 3.2 says to check the carry bit after >> shifting S1, which is zero initially, therefore the carry bit will be clear, >> therefore S1 and S0 won't have any bits inverted and will stay zero. >> > > I think probably "if the carry bit from TR is 1" would make this all > make sense. Otherwise TR, which is the data payload, is completely > ignored. > Hence the need for examples. From python at deborahswanson.net Wed Mar 15 22:10:17 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Wed, 15 Mar 2017 19:10:17 -0700 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: Message-ID: <011801d29dfa$755d4f80$27b23dae@sambora> MRAB wrote, on Wednesday, March 15, 2017 3:19 PM > > On 2017-03-15 22:03, Gregory Ewing wrote: > > Steve D'Aprano wrote: > >> You probably can't make a whale fly just by changing the class to > >> bird. It will need wings, and feathers, at the very least. > > > > Some things succeed in flying with neither wings nor feathers. > > Helicopters, for example. > > > Could you argue that the blades were a kind of wing? After all, they > rely on the same principle of moving through the air to produce lift. > > Balloons, on the other hand, ... :-) or kites... ;) From jobmattcon at gmail.com Thu Mar 16 00:40:03 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Wed, 15 Mar 2017 21:40:03 -0700 (PDT) Subject: how to embed non-tkinter VLC player into grid of tkinter with python? Message-ID: we have many TV that would like to be monitored, how to embed non-tkinter VLC player into grid of tkinter with python? below code can embeded xterm but not for VLC player import vlc from Tkinter import * import os root = Tk() for r in range(2): for c in range(1): termf = Frame(root, height=100, width=200) termf.pack(fill=BOTH, expand=YES) wid = termf.winfo_id() termf.grid(row=r,column=c) p=vlc.MediaPlayer('file:///home/martin/Downloads/autoweb.mp4') p.get_tk_widget().grid(row=r,column=c) p.play() #os.system('xterm -into %d -geometry 40x20 -sb &' % wid) os.system('vlc --no-fullscreen "file:///home/martin/Downloads/autoweb.mp4" -into %d -geometry 100x200 -sb &' % wid) root.mainloop() From jobmattcon at gmail.com Thu Mar 16 01:16:28 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Wed, 15 Mar 2017 22:16:28 -0700 (PDT) Subject: how to embed non-tkinter VLC player into grid of tkinter with python? In-Reply-To: References: Message-ID: martin at ubuntu:~/Downloads/python-vlc/examples$ xdg-screensaver: Window 0x09000000 does not exist error when run after inherit a frame which put in a grid import vlc from Tkinter import * import os import Tkinter as tk class SampleApp(tk.Frame): def __init__(self, parent, title=None): #def __init__(self, *args, **kwargs): #tk.Tk.__init__(self, *args, **kwargs) tk.Frame.__init__(self, parent) self.parent = parent self.parent.title("video") p=vlc.MediaPlayer('file:///home/martin/Downloads/autoweb.mp4') p.play() self.register() #self.grid(row=1,column=1) root = Tk() for r in range(5): for c in range(5): termf = Frame(root, height=200, width=300) termf.pack(fill=BOTH, expand=YES) wid = termf.winfo_id() #player = Player() SampleApp(root, title="tkinter vlc").grid(row=r,column=c) #os.system('xterm -into %d -geometry 40x20 -sb &' % wid) #os.system('vlc --no-fullscreen "file:///home/martin/Downloads/autoweb.mp4" -into %d -geometry 100x200 -sb &' % wid) root.mainloop() On Thursday, March 16, 2017 at 12:40:16 PM UTC+8, Ho Yeung Lee wrote: > we have many TV that would like to be monitored, > > how to embed non-tkinter VLC player into grid of tkinter with python? > > below code can embeded xterm but not for VLC player > > > import vlc > from Tkinter import * > import os > > root = Tk() > for r in range(2): > for c in range(1): > termf = Frame(root, height=100, width=200) > termf.pack(fill=BOTH, expand=YES) > wid = termf.winfo_id() > termf.grid(row=r,column=c) > p=vlc.MediaPlayer('file:///home/martin/Downloads/autoweb.mp4') > p.get_tk_widget().grid(row=r,column=c) > p.play() > #os.system('xterm -into %d -geometry 40x20 -sb &' % wid) > os.system('vlc --no-fullscreen "file:///home/martin/Downloads/autoweb.mp4" -into %d -geometry 100x200 -sb &' % wid) > > root.mainloop() From jobmattcon at gmail.com Thu Mar 16 01:40:17 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Wed, 15 Mar 2017 22:40:17 -0700 (PDT) Subject: how to embed non-tkinter VLC player into grid of tkinter with python? In-Reply-To: References: Message-ID: <0d2806dc-78bb-4855-bdf1-b26993985210@googlegroups.com> after several trial, still can not put the player into grid import vlc from Tkinter import * import os import sys import ttk import Tkinter as tk class SampleApp(tk.Frame): def __init__(self, parent, title=None): #def __init__(self, *args, **kwargs): #tk.Tk.__init__(self, *args, **kwargs) tk.Frame.__init__(self, parent) self.parent = parent self.parent.title("video") self.player = None self.Instance = vlc.Instance('--no-audio') self.player = self.Instance.media_player_new() #self.player.set_xwindow(ttk.Frame(self.parent).winfo_id()) p=self.Instance.media_player_new() m=self.Instance.media_new('file:///home/martin/Downloads/autoweb.mp4') p.set_media(m) p.play() #self.videopanel = #p=vlc.MediaPlayer('file:///home/martin/Downloads/autoweb.mp4') #p.play() self.register(self, parent) #self.player.grid(row=1,column=1) #def GetHandle(self): #return self.videopanel.winfo_id() root = Tk() for r in range(2): for c in range(1): termf = Frame(root, height=200, width=300) termf.pack(fill=BOTH, expand=YES) wid = termf.winfo_id() #player = Player() SampleApp(root, title="tkinter vlc").grid(row=r,column=c) #os.system('xterm -into %d -geometry 40x20 -sb &' % wid) #os.system('vlc --no-fullscreen "file:///home/martin/Downloads/autoweb.mp4" -into %d -geometry 100x200 -sb &' % wid) root.mainloop() On Thursday, March 16, 2017 at 1:16:41 PM UTC+8, Ho Yeung Lee wrote: > martin at ubuntu:~/Downloads/python-vlc/examples$ xdg-screensaver: Window 0x09000000 does not exist > > error when run after inherit a frame which put in a grid > > import vlc > from Tkinter import * > import os > > import Tkinter as tk > > class SampleApp(tk.Frame): > def __init__(self, parent, title=None): > #def __init__(self, *args, **kwargs): > #tk.Tk.__init__(self, *args, **kwargs) > tk.Frame.__init__(self, parent) > self.parent = parent > self.parent.title("video") > p=vlc.MediaPlayer('file:///home/martin/Downloads/autoweb.mp4') > p.play() > self.register() > #self.grid(row=1,column=1) > > root = Tk() > for r in range(5): > for c in range(5): > termf = Frame(root, height=200, width=300) > termf.pack(fill=BOTH, expand=YES) > wid = termf.winfo_id() > #player = Player() > SampleApp(root, title="tkinter vlc").grid(row=r,column=c) > #os.system('xterm -into %d -geometry 40x20 -sb &' % wid) > #os.system('vlc --no-fullscreen "file:///home/martin/Downloads/autoweb.mp4" -into %d -geometry 100x200 -sb &' % wid) > > root.mainloop() > > > On Thursday, March 16, 2017 at 12:40:16 PM UTC+8, Ho Yeung Lee wrote: > > we have many TV that would like to be monitored, > > > > how to embed non-tkinter VLC player into grid of tkinter with python? > > > > below code can embeded xterm but not for VLC player > > > > > > import vlc > > from Tkinter import * > > import os > > > > root = Tk() > > for r in range(2): > > for c in range(1): > > termf = Frame(root, height=100, width=200) > > termf.pack(fill=BOTH, expand=YES) > > wid = termf.winfo_id() > > termf.grid(row=r,column=c) > > p=vlc.MediaPlayer('file:///home/martin/Downloads/autoweb.mp4') > > p.get_tk_widget().grid(row=r,column=c) > > p.play() > > #os.system('xterm -into %d -geometry 40x20 -sb &' % wid) > > os.system('vlc --no-fullscreen "file:///home/martin/Downloads/autoweb.mp4" -into %d -geometry 100x200 -sb &' % wid) > > > > root.mainloop() From auriocus at gmx.de Thu Mar 16 03:56:25 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 16 Mar 2017 08:56:25 +0100 Subject: how to embed non-tkinter VLC player into grid of tkinter with python? In-Reply-To: References: Message-ID: Am 16.03.17 um 05:40 schrieb Ho Yeung Lee: > we have many TV that would like to be monitored, > > how to embed non-tkinter VLC player into grid of tkinter with python? > > below code can embeded xterm but not for VLC player > > > import vlc > from Tkinter import * > import os > > root = Tk() > for r in range(2): > for c in range(1): > termf = Frame(root, height=100, width=200) > termf.pack(fill=BOTH, expand=YES) > wid = termf.winfo_id() > termf.grid(row=r,column=c) > p=vlc.MediaPlayer('file:///home/martin/Downloads/autoweb.mp4') > p.get_tk_widget().grid(row=r,column=c) > p.play() > #os.system('xterm -into %d -geometry 40x20 -sb &' % wid) > os.system('vlc --no-fullscreen "file:///home/martin/Downloads/autoweb.mp4" -into %d -geometry 100x200 -sb &' % wid) Two questions: 1) Does VLC support the -into option? I know that mplayer has such an option, but it is called -wid, for instance 2) Maybe the window needs to be mapped before? If so, insert a root.update() after the grid and before you try to embed. 3) It seems you try to instantiate VLC through two different mechanisms, via the python package vlc and via an external call to os.system. Christian From greg.ewing at canterbury.ac.nz Thu Mar 16 04:01:55 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 16 Mar 2017 21:01:55 +1300 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: MRAB wrote: > Could you argue that the blades were a kind of wing? After all, they > rely on the same principle of moving through the air to produce lift. > > Balloons, on the other hand, ... :-) Also rockets. -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 16 04:12:16 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 16 Mar 2017 21:12:16 +1300 Subject: The ternaery operator In-Reply-To: References: Message-ID: Stefan Ram wrote: > a if c else b > > Guido has invented something totally new. Why? It's arguably closer to the way you would say such a thing in English. Consider the following sentences: "I wear my red shirt if it's Tuesday, else my green one." "I wear if it's Tuesday my red shirt, else my green one." Which one sounds more natural? -- Greg From auriocus at gmx.de Thu Mar 16 04:12:18 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 16 Mar 2017 09:12:18 +0100 Subject: The ternaery operator In-Reply-To: References: Message-ID: Am 16.03.17 um 04:12 schrieb Stefan Ram: > The syntax > > a if c else b > > looks as if Guido made it intentionally ugly so that it will > not be used? > [...] > . But now Guido has invented something totally new. Why? The rationale can be read in PEP 308: https://www.python.org/dev/peps/pep-0308/ This should be the first place to go if you want to learn about Python language decisions. Asking here will just start the flame fire again. Christian From alister.ware at ntlworld.com Thu Mar 16 05:15:25 2017 From: alister.ware at ntlworld.com (alister) Date: Thu, 16 Mar 2017 09:15:25 GMT Subject: Dynamically replacing an objects __class__; is it safe? References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 16 Mar 2017 11:03:56 +1300, Gregory Ewing wrote: > Steve D'Aprano wrote: >> You probably can't make a whale fly just by changing the class to bird. >> It will need wings, and feathers, at the very least. > > Some things succeed in flying with neither wings nor feathers. > Helicopters, for example. helicopters DO have wings. that is why they are technical referred to as ROTARY WING Aircraft ;-) -- Boy, that crayon sure did hurt! From alister.ware at ntlworld.com Thu Mar 16 05:17:20 2017 From: alister.ware at ntlworld.com (alister) Date: Thu, 16 Mar 2017 09:17:20 GMT Subject: Dynamically replacing an objects __class__; is it safe? References: <011801d29dfa$755d4f80$27b23dae@sambora> Message-ID: On Wed, 15 Mar 2017 19:10:17 -0700, Deborah Swanson wrote: > MRAB wrote, on Wednesday, March 15, 2017 3:19 PM >> >> On 2017-03-15 22:03, Gregory Ewing wrote: >> > Steve D'Aprano wrote: >> >> You probably can't make a whale fly just by changing the class to >> >> bird. It will need wings, and feathers, at the very least. >> > >> > Some things succeed in flying with neither wings nor feathers. >> > Helicopters, for example. >> > >> Could you argue that the blades were a kind of wing? After all, they >> rely on the same principle of moving through the air to produce lift. >> >> Balloons, on the other hand, ... :-) > > or kites... ;) no kites are a wing, although they are dependant on the string to hold them up. -- Too many people are thinking of security instead of opportunity. They seem more afraid of life than death. -- James F. Byrnes From lutz.horn at posteo.de Thu Mar 16 07:09:16 2017 From: lutz.horn at posteo.de (Lutz Horn) Date: Thu, 16 Mar 2017 12:09:16 +0100 Subject: SimpleHTTPServer and CgiHTTPServer in practice In-Reply-To: <87bmt2nj01.fsf@nightsong.com> References: <87bmt2nj01.fsf@nightsong.com> Message-ID: <3944b2b755d208e1e1e396bf221fada7@posteo.de> > Some Python users have told me that isn't a good idea, but > without any specifics. We don't know *why* those people told you not to use these modules. We also don't know your use case. So it is very hard to advise you. Lutz From steve+python at pearwood.info Thu Mar 16 08:06:48 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 16 Mar 2017 23:06:48 +1100 Subject: Dynamically replacing an objects __class__; is it safe? References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58ca7fdb$0$1588$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Mar 2017 09:03 am, Gregory Ewing wrote: > Steve D'Aprano wrote: >> You probably can't make a whale fly just by changing the class to bird. >> It will need wings, and feathers, at the very least. > > Some things succeed in flying with neither wings nor feathers. > Helicopters, for example. For some definition of "no wings". But regardless of rockets, balloons, helicopters, Boeing 747s and Dr Strange's mystical Cloak Of Levitation, *birds* require wings and feathers to fly. If you just paint "BIRD" on the side of a whale, it won't get off the ground, and if you do manage to get it airborne (via a catapult, perhaps) it will just come down with a rather large splat. The point is that dynamically swapping the class of an existing instance at runtime is *not* just a way of doing duck-typing. It really does matter if your duck flies by flapping feathered wings or by blasting an exhaust of hot gasses out of its rear end at high speed. With duck-typing, you don't care whether you have a duck or a goose, so long as they both can fly: you don't care *how* it flies, so long as it does, and even a rocket-propelled balloon will be fine. But when you dynamically swap out __class__ (I think Objective-C "swizzling" is conceptually equivalent, so I'll call it by that word) you have to care about the implementation. The whole point of swizzling is that it allows you to swap out one implementation ("run forward and flap your wings") with another implementation ("light the blue touch paper"). But if you do that, you have to care about implementation details. There's no point in setting your swizzled fly() method to that of Rocket if your instance doesn't have blue touch paper to light. With duck-typing, making the methods work isn't your responsibility. But when you swizzle, you are responsible for making sure that the instance provides whatever the methods need to work. A very old but good example of Python swizzling is here: http://code.activestate.com/recipes/68429-ring-buffer/ -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From robin at reportlab.com Thu Mar 16 09:45:58 2017 From: robin at reportlab.com (Robin Becker) Date: Thu, 16 Mar 2017 13:45:58 +0000 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> Message-ID: <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> On 15/03/2017 13:53, Steve D'Aprano wrote: > You probably can't make a whale fly just by changing the class to bird. It > will need wings, and feathers, at the very least. the whale in the Hitchhiker's Guide found itself flying without feathers or wings -- Robin Becker From tony at vanderhoff.org Thu Mar 16 09:52:56 2017 From: tony at vanderhoff.org (Tony van der Hoff) Date: Thu, 16 Mar 2017 13:52:56 +0000 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> Message-ID: <9f3711e7-80de-3990-1307-e654a0fa6849@vanderhoff.org> On 16/03/17 13:45, Robin Becker wrote: > On 15/03/2017 13:53, Steve D'Aprano wrote: >> You probably can't make a whale fly just by changing the class to >> bird. It >> will need wings, and feathers, at the very least. > > the whale in the Hitchhiker's Guide found itself flying without feathers > or wings > It didn't so much fly, as plummet. -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From darcy at VybeNetworks.com Thu Mar 16 10:03:17 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Thu, 16 Mar 2017 10:03:17 -0400 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> Message-ID: <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> On 2017-03-16 09:45 AM, Robin Becker wrote: > On 15/03/2017 13:53, Steve D'Aprano wrote: >> You probably can't make a whale fly just by changing the class to >> bird. It >> will need wings, and feathers, at the very least. > > the whale in the Hitchhiker's Guide found itself flying without feathers > or wings Falling is not the same as flying unless you accidentally miss the ground. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From jon+usenet at unequivocal.eu Thu Mar 16 10:04:19 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Thu, 16 Mar 2017 14:04:19 -0000 (UTC) Subject: Dynamically replacing an objects __class__; is it safe? References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> Message-ID: On 2017-03-16, Robin Becker wrote: > On 15/03/2017 13:53, Steve D'Aprano wrote: >> You probably can't make a whale fly just by changing the class to bird. It >> will need wings, and feathers, at the very least. > > the whale in the Hitchhiker's Guide found itself flying without > feathers or wings Well, only if you redefine "flying" to include "accelerating to terminal velocity straight downwards under the force of gravity"... From robin at reportlab.com Thu Mar 16 10:21:53 2017 From: robin at reportlab.com (Robin Becker) Date: Thu, 16 Mar 2017 14:21:53 +0000 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> Message-ID: <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> On 16/03/2017 14:03, D'Arcy Cain wrote: > On 2017-03-16 09:45 AM, Robin Becker wrote: >> On 15/03/2017 13:53, Steve D'Aprano wrote: >>> You probably can't make a whale fly just by changing the class to >>> bird. It >>> will need wings, and feathers, at the very least. >> >> the whale in the Hitchhiker's Guide found itself flying without feathers >> or wings > > Falling is not the same as flying unless you accidentally miss the ground. > well in English an arrow flies as well as time, the whale was very interested in the approaching ground and perhaps forgot to conjure up virtual wings or rockets. In any case satellites miss the ground, but even their motion cannot be classed as flying with wings so I think this discussion has become irrelevant. -- Robin Becker From rosuav at gmail.com Thu Mar 16 10:31:22 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Mar 2017 01:31:22 +1100 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> Message-ID: On Fri, Mar 17, 2017 at 1:21 AM, Robin Becker wrote: >> Falling is not the same as flying unless you accidentally miss the ground. >> > well in English an arrow flies as well as time, the whale was very > interested in the approaching ground and perhaps forgot to conjure up > virtual wings or rockets. In any case satellites miss the ground, but even > their motion cannot be classed as flying with wings so I think this > discussion has become irrelevant. I just asked my father, and he believes that a satellite DOES fly, on the basis that it is perpetually falling and forever missing the ground. ChrisA From toby at tobiah.org Thu Mar 16 10:55:05 2017 From: toby at tobiah.org (Tobiah) Date: Thu, 16 Mar 2017 07:55:05 -0700 Subject: The ternaery operator References: Message-ID: On 03/16/2017 01:12 AM, Gregory Ewing wrote: > Stefan Ram wrote: > >> a if c else b >> >> Guido has invented something totally new. Why? > > It's arguably closer to the way you would say such a > thing in English. > > Consider the following sentences: > > "I wear my red shirt if it's Tuesday, else my green one." > > "I wear if it's Tuesday my red shirt, else my green one." > > Which one sounds more natural? > To be fair, the proper comparison would be: If it's Tuesday, I wear my red shirt, else my green one. I think it would be nice to have a way of getting the 'true' value as the return with an optional value if false. The desire comes about when the thing I'm comparing is an element of a collection: drugs['choice'] if drugs['choice'] else 'pot' Then I'm tempted to do: chosen = drugs['choice'] chosen if chosen else 'pot' I sometimes feel like doing: drugs['choice'] else 'pot' Tobiah From toby at tobiah.org Thu Mar 16 11:07:19 2017 From: toby at tobiah.org (Tobiah) Date: Thu, 16 Mar 2017 08:07:19 -0700 Subject: The ternaery operator References: Message-ID: On 03/16/2017 01:12 AM, Gregory Ewing wrote: > Stefan Ram wrote: > >> a if c else b >> >> Guido has invented something totally new. Why? > > It's arguably closer to the way you would say such a > thing in English. > > Consider the following sentences: > > "I wear my red shirt if it's Tuesday, else my green one." > > "I wear if it's Tuesday my red shirt, else my green one." > > Which one sounds more natural? > Actually, I see where now you are coming from: I wear (if a then b else c) as opposed to I wear (b if a else c) From mail at williammayor.co.uk Thu Mar 16 11:11:49 2017 From: mail at williammayor.co.uk (William Mayor) Date: Thu, 16 Mar 2017 15:11:49 +0000 Subject: The ternaery operator In-Reply-To: References: Message-ID: > > I think it would be nice to have a way of getting the 'true' > value as the return with an optional value if false. The desire > comes about when the thing I'm comparing is an element of a collection: > > drugs['choice'] if drugs['choice'] else 'pot' > > Then I'm tempted to do: > > chosen = drugs['choice'] > chosen if chosen else 'pot' > > I sometimes feel like doing: > > drugs['choice'] else 'pot' > For the case where the element in the collection exists, but might be falsey you could do: drugs[?choice?] or ?pot' The ternary operator would be useful for something like: drugs[?choice?] if is_good_for_you(drugs[?choice?]) else ?nice cup of tea? Most of the time I avoid the ternary stuff though, I don?t think it?s easy to read, no matter what language you?re writing in. From cl at isbd.net Thu Mar 16 11:21:36 2017 From: cl at isbd.net (Chris Green) Date: Thu, 16 Mar 2017 15:21:36 +0000 Subject: Dynamically replacing an objects __class__; is it safe? References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> Message-ID: <05nqpd-iua.ln1@esprimo.zbmc.eu> Robin Becker wrote: > On 16/03/2017 14:03, D'Arcy Cain wrote: > > On 2017-03-16 09:45 AM, Robin Becker wrote: > >> On 15/03/2017 13:53, Steve D'Aprano wrote: > >>> You probably can't make a whale fly just by changing the class to > >>> bird. It > >>> will need wings, and feathers, at the very least. > >> > >> the whale in the Hitchhiker's Guide found itself flying without feathers > >> or wings > > > > Falling is not the same as flying unless you accidentally miss the ground. > > > well in English an arrow flies as well as time, the whale was very interested in > the approaching ground and perhaps forgot to conjure up virtual wings or > rockets. In any case satellites miss the ground, but even their motion cannot be > classed as flying with wings so I think this discussion has become irrelevant. Time flies like an arrow Fruit flies like a banana -- Chris Green ? From alister.ware at ntlworld.com Thu Mar 16 11:50:28 2017 From: alister.ware at ntlworld.com (alister) Date: Thu, 16 Mar 2017 15:50:28 GMT Subject: The ternaery operator References: Message-ID: <8vyyA.225100$nT1.37099@fx44.am4> On Thu, 16 Mar 2017 03:12:32 +0000, Stefan Ram wrote: > The syntax > > a if c else b > > looks as if Guido made it intentionally ugly so that it will not be > used? > > Being able to detect patterns that are in widespread use among > programming languages enhances readability. > > IIRC, in Algol, there was an expression > > if c then a else b > > . IIRC, most popular languages today use > > c ? a : b > > . But now Guido has invented something totally new. Why? > > Perl has something like it, the "expression modifier". > Did Guido like /this/ so much, that he wanted to imitate it? >>>import this i think you will find at least 1 line that explains everything. -- We were so poor that we thought new clothes meant someone had died. From alister.ware at ntlworld.com Thu Mar 16 11:51:25 2017 From: alister.ware at ntlworld.com (alister) Date: Thu, 16 Mar 2017 15:51:25 GMT Subject: Dynamically replacing an objects __class__; is it safe? References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> Message-ID: <1wyyA.225138$nT1.79388@fx44.am4> On Thu, 16 Mar 2017 14:04:19 +0000, Jon Ribbens wrote: > On 2017-03-16, Robin Becker wrote: >> On 15/03/2017 13:53, Steve D'Aprano wrote: >>> You probably can't make a whale fly just by changing the class to >>> bird. It will need wings, and feathers, at the very least. >> >> the whale in the Hitchhiker's Guide found itself flying without >> feathers or wings > > Well, only if you redefine "flying" to include "accelerating to terminal > velocity straight downwards under the force of gravity"... Arthur himself was a regular flyer. -- genius, n.: Person clever enough to be born in the right place at the right time of the right sex and to follow up this advantage by saying all the right things to all the right people. From jussi.piitulainen at helsinki.fi Thu Mar 16 11:55:56 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Thu, 16 Mar 2017 17:55:56 +0200 Subject: The ternaery operator References: Message-ID: William Mayor writes: >> I think it would be nice to have a way of getting the 'true' value as >> the return with an optional value if false. The desire comes about >> when the thing I'm comparing is an element of a collection: >> >> drugs['choice'] if drugs['choice'] else 'pot' >> >> Then I'm tempted to do: >> >> chosen = drugs['choice'] >> chosen if chosen else 'pot' >> >> I sometimes feel like doing: >> >> drugs['choice'] else 'pot' >> > > For the case where the element in the collection exists, but might be > falsey you could do: > > drugs[?choice?] or ?pot' drugs.get('choice') or 'pot' drugs.get('choice', 'pot') [snip] From sjmsoft at gmail.com Thu Mar 16 14:22:27 2017 From: sjmsoft at gmail.com (sjmsoft at gmail.com) Date: Thu, 16 Mar 2017 11:22:27 -0700 (PDT) Subject: SimpleHTTPServer and CgiHTTPServer in practice In-Reply-To: <87bmt2nj01.fsf@nightsong.com> References: <87bmt2nj01.fsf@nightsong.com> Message-ID: <6a4428ea-a3bf-4f3a-bcb6-12eb7e24c167@googlegroups.com> For a couple of years we've used SimpleHTTPServer to serve pages to internal users at low volumes, and we find it to be reliable and trivial to set up. We have not subjected it to a rigorous security assessment. HTH, Steve J. Martin From chloe.anna.talbot at gmail.com Thu Mar 16 14:33:28 2017 From: chloe.anna.talbot at gmail.com (chloe.anna.talbot at gmail.com) Date: Thu, 16 Mar 2017 11:33:28 -0700 (PDT) Subject: Doing it Wrong: python-ldap and delete operations using ldifWriter Message-ID: I want to do (what I thought) would be quite a simple thing. I have an LDAP entry that looks like this(in LDIF format): dn: cn=myorg,ou=teams,ou=groups,o=company,c=us cn: myorg objectClass: top objectClass: CompanyTeams objectClass: groupOfUniqueNames owner: cn=john,ou=people,o=company,c=us uniqueMember: cn=bob,ou=people,o=company,c=us uniqueMember: cn=bill,ou=people,o=company,c=us uniqueMember: cn=carol,ou=people,o=company,c=us uniqueMember: cn=frank,ou=people,o=company,c=us uniqueMember: cn=alice,ou=people,o=company,c=us In my code, I have all these entries represented as dicts. I'm using Python's LDIF writer to write these entries out to proper LDIF. Exporting the whole thing is easy: def dump_ldif(self): writer = LDIFWriter(open('entrybackup.ldif', 'wb')) writer.unparse(cn=myorg, self.all_the_teams.get_teamstr_by_name('{'objectClass': ['top', 'CompanyTeams', 'groupOfUniqueNames']'owner': ['cn=john,ou=people,o=company,c=us'], 'uniqueMember': ['uniqueMember: cn=bob,ou=people,o=company,c=us','uniqueMember: cn=bill,ou=people,o=company,c=us','uniqueMember: cn=carol,ou=people,o=company,c=us','uniqueMember: cn=frank,ou=people,o=company,c=us','uniqueMember: cn=alice,ou=people,o=company,c=us'], 'cn': ['myorg']}') But how do you have LDIF output that uses delete/modify operators? I have a list of uniqueMember that I want to go away: ['cn=bob,ou=people,o=company,c=us', 'cn=bill,ou=people,o=company,c=us'] And (I believe) this is the end goal in LDIF format, pulling from my list: dn: cn=myorg,ou=teams,ou=groups,o=company,c=us changetype: modify delete: uniqueMember uniqueMember: cn=bob,ou=people,o=company,c=us uniqueMember: cn=bill,ou=people,o=company,c=us Is there not some simple way to do this with Python(2.7)? Starting to feel crazy. Note: I could just do the text output/manipulation, but I want to stick with LDIFWriter to write this output. I just want find the syntax to output 'delete' LDIF directives. From greg.ewing at canterbury.ac.nz Thu Mar 16 17:03:04 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 17 Mar 2017 10:03:04 +1300 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> Message-ID: Chris Angelico wrote: > I just asked my father, and he believes that a satellite DOES fly, on > the basis that it is perpetually falling and forever missing the > ground. Also, NASA people talk about "flying" the ISS, so it seems your father is in good company. -- Greg From greg.ewing at canterbury.ac.nz Thu Mar 16 17:13:41 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 17 Mar 2017 10:13:41 +1300 Subject: The ternaery operator In-Reply-To: References: Message-ID: Tobiah wrote: > To be fair, the proper comparison would be: > > If it's Tuesday, I wear my red shirt, else my green one. The Python analog of that would be if it_is_tuesday: wear(red_shirt) else: wear(green_shirt) i.e. a statement rather than an expression. We're looking for an English analog of a conditional expression: wear(red_shirt if it_is_tuesday else green_shirt) For that, we need a conditional noun phrase, and the only way to get one of those in English without sounding like a non-native speaker is to put the condition in the middle. -- Greg From no.email at nospam.invalid Thu Mar 16 20:28:28 2017 From: no.email at nospam.invalid (Paul Rubin) Date: Thu, 16 Mar 2017 17:28:28 -0700 Subject: SimpleHTTPServer and CgiHTTPServer in practice References: <87bmt2nj01.fsf@nightsong.com> <3944b2b755d208e1e1e396bf221fada7@posteo.de> Message-ID: <87inn8eogj.fsf@nightsong.com> Lutz Horn writes: > We don't know *why* those people told you not to use these modules. We > also don't know your use case. So it is very hard to advise you. The use case is to have a very easily set up way to serve basic pages and files, without a lot of configuration files and other infrastructure. The main reason not to use it would be security holes if there are some. I haven't examined the code carefully but didn't see obvious issues at a quick glanace. I frankly worry more about large C programs than Python programs. From rosuav at gmail.com Thu Mar 16 20:29:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Mar 2017 11:29:29 +1100 Subject: The ternaery operator In-Reply-To: References: Message-ID: On Fri, Mar 17, 2017 at 10:45 AM, Stefan Ram wrote: > Gregory Ewing writes: >>wear(red_shirt if it_is_tuesday else green_shirt) > > Operators in Python usually are written with special > symbols, not with words, so a word usually indicates, > "This is not an operator.". > Non-operators like "is [not]", "[not] in", "and", "or", and so on? ChrisA From python at deborahswanson.net Thu Mar 16 22:07:03 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Thu, 16 Mar 2017 19:07:03 -0700 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: <58ca7fdb$0$1588$c3e8da3$5496439d@news.astraweb.com> Message-ID: <012d01d29ec3$2c3a5f40$27b23dae@sambora> Steve D'Aprano wrote,on March 16, 2017 5:07 AM > > On Thu, 16 Mar 2017 09:03 am, Gregory Ewing wrote: > > > Steve D'Aprano wrote: > >> You probably can't make a whale fly just by changing the class to > >> bird. It will need wings, and feathers, at the very least. > > > > Some things succeed in flying with neither wings nor feathers. > > Helicopters, for example. > > For some definition of "no wings". > > But regardless of rockets, balloons, helicopters, Boeing 747s > and Dr Strange's mystical Cloak Of Levitation, *birds* > require wings and feathers to fly. If you just paint "BIRD" > on the side of a whale, it won't get off the ground, and if > you do manage to get it airborne (via a catapult, > perhaps) it will just come down with a rather large splat. > > The point is that dynamically swapping the class of an > existing instance at runtime is *not* just a way of doing > duck-typing. It really does matter if your duck flies by > flapping feathered wings or by blasting an exhaust of hot > gasses out of its rear end at high speed. > > With duck-typing, you don't care whether you have a duck or a > goose, so long as they both can fly: you don't care *how* it > flies, so long as it does, and even a rocket-propelled > balloon will be fine. > > But when you dynamically swap out __class__ (I think > Objective-C "swizzling" is conceptually equivalent, so I'll > call it by that word) you have to care about the > implementation. The whole point of swizzling is that it > allows you to swap out one implementation ("run forward and > flap your wings") with another implementation ("light the > blue touch paper"). But if you do that, you have to care > about implementation details. There's no point in setting > your swizzled fly() method to that of Rocket if your instance > doesn't have blue touch paper to light. > > With duck-typing, making the methods work isn't your > responsibility. But when you swizzle, you are responsible for > making sure that the instance provides whatever the methods > need to work. > > A very old but good example of Python swizzling is here: > http://code.activestate.com/recipes/68429-ring-buffer/ -- Steve "Cheer up," they said, "things could be worse." So I cheered up, and sure enough, things got worse. Condolences, Steve. Nobody on this thread wants to plumb the depths of Python swizzling. Or anything else Python, so it appears. From ian.g.kelly at gmail.com Thu Mar 16 22:52:44 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 16 Mar 2017 20:52:44 -0600 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> Message-ID: On Thu, Mar 16, 2017 at 7:56 PM, Dennis Lee Bieber wrote: > On Fri, 17 Mar 2017 10:03:04 +1300, Gregory Ewing > declaimed the following: > >>Chris Angelico wrote: >>> I just asked my father, and he believes that a satellite DOES fly, on >>> the basis that it is perpetually falling and forever missing the >>> ground. >> >>Also, NASA people talk about "flying" the ISS, so it seems your >>father is in good company. > > Most likely they are referring to using gyroscopes (reaction wheels), > and maneuvering thrusters to maintain orientation relative to the sun, so > the solar panels stay fully lit. The ISS orbit is low enough that they also have to do regular (approximately monthly) boosts to counteract the gradual decay. From rosuav at gmail.com Thu Mar 16 22:58:32 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Mar 2017 13:58:32 +1100 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> Message-ID: On Fri, Mar 17, 2017 at 1:52 PM, Ian Kelly wrote: > On Thu, Mar 16, 2017 at 7:56 PM, Dennis Lee Bieber > wrote: >> On Fri, 17 Mar 2017 10:03:04 +1300, Gregory Ewing >> declaimed the following: >> >>>Chris Angelico wrote: >>>> I just asked my father, and he believes that a satellite DOES fly, on >>>> the basis that it is perpetually falling and forever missing the >>>> ground. >>> >>>Also, NASA people talk about "flying" the ISS, so it seems your >>>father is in good company. >> >> Most likely they are referring to using gyroscopes (reaction wheels), >> and maneuvering thrusters to maintain orientation relative to the sun, so >> the solar panels stay fully lit. > > The ISS orbit is low enough that they also have to do regular > (approximately monthly) boosts to counteract the gradual decay. Maybe what the ISS does isn't flying - it's falling with style? ChrisA From chenchao at inhand.com.cn Fri Mar 17 00:08:34 2017 From: chenchao at inhand.com.cn (chenchao) Date: Fri, 17 Mar 2017 00:08:34 -0400 Subject: How to add a built-in library in pyhton Message-ID: <33a418df-514a-2ebc-3afd-87deaf5d7b34@inhand.com.cn> Hello, everybody: I use python2.7.10 and want to add a c language library in python. So how can i built it as a built-in module in python? From greg.ewing at canterbury.ac.nz Fri Mar 17 00:18:26 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 17 Mar 2017 17:18:26 +1300 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> Message-ID: Dennis Lee Bieber wrote: > I'd say satellites do "not" fly, as they have no force/action opposing > the fall caused by the pull of gravity. Arrows, bullets, thrown stones, etc. are often said to be flying. Seems to me the word gets applied to anything that is moving while not contacting the ground. -- Greg From greg.ewing at canterbury.ac.nz Fri Mar 17 00:21:42 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 17 Mar 2017 17:21:42 +1300 Subject: The ternaery operator In-Reply-To: References: Message-ID: Stefan Ram wrote: > A postponed ?if? can be found (x if a, otherwise y), but a > preceding ?if? (if a, x, otherwise y) also is found often. Yes, both forms occur in English. The point is that Guido didn't just make the idea up, it was inspired by natural language. -- Greg From greg.ewing at canterbury.ac.nz Fri Mar 17 00:27:43 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 17 Mar 2017 17:27:43 +1300 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> Message-ID: Chris Angelico wrote: > Maybe what the ISS does isn't flying - it's falling with style? Yep. They didn't really launch it into orbit with rockets, that was all faked. They actually hauled it up there with a crane, let it go and pulled the earth away at the last moment. -- Greg From lutz.horn at posteo.de Fri Mar 17 04:27:39 2017 From: lutz.horn at posteo.de (Lutz Horn) Date: Fri, 17 Mar 2017 09:27:39 +0100 Subject: How to add a built-in library in pyhton In-Reply-To: <33a418df-514a-2ebc-3afd-87deaf5d7b34@inhand.com.cn> References: <33a418df-514a-2ebc-3afd-87deaf5d7b34@inhand.com.cn> Message-ID: Am 17.03.2017 05:08 schrieb chenchao: > I use python2.7.10 and want to add a c language library in python. > So how can i built it as a built-in module in python? Why do you want to build it as a built-in module? Why not a simple module as described on https://docs.python.org/2/extending/index.html ? Lutz From tony at vanderhoff.org Fri Mar 17 05:58:45 2017 From: tony at vanderhoff.org (Tony van der Hoff) Date: Fri, 17 Mar 2017 09:58:45 +0000 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> Message-ID: On 17/03/17 04:18, Gregory Ewing wrote: > Dennis Lee Bieber wrote: >> I'd say satellites do "not" fly, as they have no force/action >> opposing >> the fall caused by the pull of gravity. > > Arrows, bullets, thrown stones, etc. are often said to be > flying. > > Seems to me the word gets applied to anything that is > moving while not contacting the ground. > Yep, like a Ferrari on a motorway -- Tony van der Hoff | mailto:tony at vanderhoff.org Buckinghamshire, England | From oleg at redhat.com Fri Mar 17 10:54:59 2017 From: oleg at redhat.com (Oleg Nesterov) Date: Fri, 17 Mar 2017 15:54:59 +0100 Subject: __del__ is not called after creating a new reference Message-ID: <20170317145459.GA3628@redhat.com> I started to learn python a few days ago and I am trying to understand what __del__() actually does. https://docs.python.org/3/reference/datamodel.html says: object.__del__(self) ... Note that it is possible (though not recommended!) for the __del__() method to postpone destruction of the instance by creating a new reference to it. It may then be called at a later time when this new reference is deleted. However, this trivial test-case class C: def __del__(self): print("DEL") global X X = self C() print(X) X = 0 print(X) shows that __del__ is called only once, it is not called again after "X = 0": DEL <__main__.C object at 0x7f067695f4a8> 0 (Just in case, I verified later that this object actually goes away and its memory is freed, so the problem is not that it still has a reference). I've cloned https://github.com/python/cpython.git and everything looks clear at first glance (but let me repeat that I am very new to python): PyObject_CallFinalizerFromDealloc() calls PyObject_CallFinalizer() which finally calls "__del__" method in slot_tp_finalize(), then it notices that "X = self" creates the new reference and does: /* tp_finalize resurrected it! Make it look like the original Py_DECREF * never happened. */ refcnt = self->ob_refcnt; _Py_NewReference(self); self->ob_refcnt = refcnt; However, PyObject_CallFinalizer() also does _PyGC_SET_FINALIZED(self, 1) and that is why __del__ is not called again after "X = 0": /* tp_finalize should only be called once. */ if (PyType_IS_GC(tp) && _PyGC_FINALIZED(self)) return; The comment and the code are very explicit, so this does nt look like a bug in cpython. Probably the docs should be fixed? Or this code is actually wrong? The test-case works as documented if I remove _PyGC_SET_FINALIZED() in PyObject_CallFinalizer() or add another _PyGC_SET_FINALIZED(self, 0) into PyObject_CallFinalizerFromDealloc() after _Py_NewReference(self), but yes, yes, I understand that this is not correct and won't really help. Oleg. From tjreedy at udel.edu Fri Mar 17 11:11:54 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 17 Mar 2017 11:11:54 -0400 Subject: __del__ is not called after creating a new reference In-Reply-To: <20170317145459.GA3628@redhat.com> References: <20170317145459.GA3628@redhat.com> Message-ID: On 3/17/2017 10:54 AM, Oleg Nesterov wrote: > I started to learn python a few days ago and I am trying to understand what > __del__() actually does. https://docs.python.org/3/reference/datamodel.html > says: > > object.__del__(self) > ... > Note that it is possible (though not recommended!) for the __del__() > method to postpone destruction of the instance by creating a new > reference to it. If I understand the below, 'that persists after the function call' should be added. Note that the function call itself 'creates a new reference' by binding 'self' to the obj. It may then be called at a later time when this new > reference is deleted. > > However, this trivial test-case > > class C: > def __del__(self): > print("DEL") > global X > X = self > C() > print(X) > X = 0 > print(X) > > shows that __del__ is called only once, it is not called again after "X = 0": > > DEL > <__main__.C object at 0x7f067695f4a8> > 0 > > (Just in case, I verified later that this object actually goes away and its > memory is freed, so the problem is not that it still has a reference). > > I've cloned https://github.com/python/cpython.git and everything looks clear > at first glance (but let me repeat that I am very new to python): > > PyObject_CallFinalizerFromDealloc() calls PyObject_CallFinalizer() > which finally calls "__del__" method in slot_tp_finalize(), then it > notices that "X = self" creates the new reference and does: > > /* tp_finalize resurrected it! Make it look like the original Py_DECREF > * never happened. > */ > refcnt = self->ob_refcnt; > _Py_NewReference(self); > self->ob_refcnt = refcnt; > > However, PyObject_CallFinalizer() also does _PyGC_SET_FINALIZED(self, 1) > and that is why __del__ is not called again after "X = 0": > > /* tp_finalize should only be called once. */ > if (PyType_IS_GC(tp) && _PyGC_FINALIZED(self)) > return; I suspect that this was added after the doc. If git has an annotate function, you could check. > The comment and the code are very explicit, so this does nt look like a > bug in cpython. > > Probably the docs should be fixed? > > Or this code is actually wrong? The test-case works as documented if I > remove _PyGC_SET_FINALIZED() in PyObject_CallFinalizer() or add another > _PyGC_SET_FINALIZED(self, 0) into PyObject_CallFinalizerFromDealloc() > after _Py_NewReference(self), but yes, yes, I understand that this is > not correct and won't really help. > > Oleg. > -- Terry Jan Reedy From oleg at redhat.com Fri Mar 17 11:35:53 2017 From: oleg at redhat.com (Oleg Nesterov) Date: Fri, 17 Mar 2017 16:35:53 +0100 Subject: __del__ is not called after creating a new reference In-Reply-To: References: <20170317145459.GA3628@redhat.com> Message-ID: <20170317153553.GA4739@redhat.com> On 03/17, Terry Reedy wrote: > > On 3/17/2017 10:54 AM, Oleg Nesterov wrote: >> I started to learn python a few days ago and I am trying to understand what >> __del__() actually does. https://docs.python.org/3/reference/datamodel.html >> says: >> >> object.__del__(self) >> ... >> Note that it is possible (though not recommended!) for the __del__() >> method to postpone destruction of the instance by creating a new >> reference to it. > > If I understand the below, 'that persists after the function call' > should be added. Yes, > Note that the function call itself 'creates a new > reference' by binding 'self' to the obj. Well, not really if I have read this code correctly (quite possibly not), PyObject_CallFinalizer() is called with the "artificial" ob_refcnt == 1 after it was already zero, and I am not sure call_unbound_noarg() binds "self", but this doesn't mattter at all afaics. > I suspect that this was added after the doc. If git has an annotate > function, you could check. I did. And it is not clear to me if this behavioural change was intentional or not. I don't have the sources right now so I can't tell you the commit id, I can do this later when I return home. I have python2.5 on my working laptop, the test-case works as documented. Oleg. From jladasky at itu.edu Fri Mar 17 17:24:12 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Fri, 17 Mar 2017 14:24:12 -0700 (PDT) Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> Message-ID: <8ee1a5bc-e858-42e1-96a9-3bf12eb71787@googlegroups.com> On Thursday, March 16, 2017 at 9:27:56 PM UTC-7, Gregory Ewing wrote: > Chris Angelico wrote: > > Maybe what the ISS does isn't flying - it's falling with style? > > Yep. They didn't really launch it into orbit with rockets, > that was all faked. They actually hauled it up there with > a crane, let it go and pulled the earth away at the last > moment. > > -- > Greg Chris, this is evidence you need to stick to Flying Circus references when attempting to construct a joke in this newsgroup. Buzz Lightyear won't cut it. From rosuav at gmail.com Fri Mar 17 17:29:01 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Mar 2017 08:29:01 +1100 Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: <8ee1a5bc-e858-42e1-96a9-3bf12eb71787@googlegroups.com> References: <201aac84-4014-487b-9e24-e5ed8360eda8@googlegroups.com> <58c94740$0$1604$c3e8da3$5496439d@news.astraweb.com> <1d1d62dc-773b-a8b2-2719-6c12671244c1@chamonix.reportlab.co.uk> <29e0195f-eb12-24b8-80db-ed1cf03231db@VybeNetworks.com> <03b84ea9-9b35-232f-1021-a347f705394e@chamonix.reportlab.co.uk> <8ee1a5bc-e858-42e1-96a9-3bf12eb71787@googlegroups.com> Message-ID: On Sat, Mar 18, 2017 at 8:24 AM, wrote: > On Thursday, March 16, 2017 at 9:27:56 PM UTC-7, Gregory Ewing wrote: >> Chris Angelico wrote: >> > Maybe what the ISS does isn't flying - it's falling with style? >> >> Yep. They didn't really launch it into orbit with rockets, >> that was all faked. They actually hauled it up there with >> a crane, let it go and pulled the earth away at the last >> moment. >> >> -- >> Greg > > Chris, this is evidence you need to stick to Flying Circus references when attempting to construct a joke in this newsgroup. Buzz Lightyear won't cut it. And cue the discussion of whether Joke.__init__() is the constructor or not. ChrisA From jladasky at itu.edu Fri Mar 17 17:44:23 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Fri, 17 Mar 2017 14:44:23 -0700 (PDT) Subject: Dynamically replacing an objects __class__; is it safe? In-Reply-To: References: <58ca7fdb$0$1588$c3e8da3$5496439d@news.astraweb.com> <012d01d29ec3$2c3a5f40$27b23dae@sambora> Message-ID: On Thursday, March 16, 2017 at 7:07:17 PM UTC-7, Deborah Swanson wrote: > Steve D'Aprano wrote,on March 16, 2017 5:07 AM > > > > On Thu, 16 Mar 2017 09:03 am, Gregory Ewing wrote: > > > > > Steve D'Aprano wrote: > > >> You probably can't make a whale fly just by changing the class to > > >> bird. It will need wings, and feathers, at the very least. > > > > > > Some things succeed in flying with neither wings nor feathers. > > > Helicopters, for example. > > > > For some definition of "no wings". > > > > But regardless of rockets, balloons, helicopters, Boeing 747s > > and Dr Strange's mystical Cloak Of Levitation, *birds* > > require wings and feathers to fly. If you just paint "BIRD" > > on the side of a whale, it won't get off the ground, and if > > you do manage to get it airborne (via a catapult, > > perhaps) it will just come down with a rather large splat. > > > > The point is that dynamically swapping the class of an > > existing instance at runtime is *not* just a way of doing > > duck-typing. It really does matter if your duck flies by > > flapping feathered wings or by blasting an exhaust of hot > > gasses out of its rear end at high speed. > > > > With duck-typing, you don't care whether you have a duck or a > > goose, so long as they both can fly: you don't care *how* it > > flies, so long as it does, and even a rocket-propelled > > balloon will be fine. > > > > But when you dynamically swap out __class__ (I think > > Objective-C "swizzling" is conceptually equivalent, so I'll > > call it by that word) you have to care about the > > implementation. The whole point of swizzling is that it > > allows you to swap out one implementation ("run forward and > > flap your wings") with another implementation ("light the > > blue touch paper"). But if you do that, you have to care > > about implementation details. There's no point in setting > > your swizzled fly() method to that of Rocket if your instance > > doesn't have blue touch paper to light. > > > > With duck-typing, making the methods work isn't your > > responsibility. But when you swizzle, you are responsible for > > making sure that the instance provides whatever the methods > > need to work. > > > > A very old but good example of Python swizzling is here: > > http://code.activestate.com/recipes/68429-ring-buffer/ > > -- > Steve > "Cheer up," they said, "things could be worse." So I cheered up, and > sure enough, things got worse. > > Condolences, Steve. Nobody on this thread wants to plumb the depths of > Python swizzling. Or anything else Python, so it appears. Hey Deborah, If you're getting discouraged by a certain spammer who posts to this newsgroup in ALL CAPS and ITALIAN, don't let him beat you. Go find newsreader software that allows you to define filters and killfiles. It will help. If you read further into that article about the RingBuffer class and "swizzling", Steve Alexander suggests a method that I have used myself, and which I consider to be generally superior: conditionally rebinding the names of methods you want to change within a class, rather than overriding __class__ itself. I suppose that each approach has its merits. If you want the object's type to advertise that a condition has changed, rebinding __class__ is good. If you have many methods to change, and you don't like long lists of similarly-named functions in one class, rebinding __class__ could also be good. I don't encounter those conditions much myself. In the RingBufferFull case, only two methods need to change, .append() and .get(). Both methods are short. Both methods' eventual replacements, which we might name ._full_append() and ._get(), are also short. I would do it Steve Alexander's way. From mikhailwas at gmail.com Fri Mar 17 20:52:49 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sat, 18 Mar 2017 01:52:49 +0100 Subject: Who are the "spacists"? Message-ID: So Python supports both spaces and tabs for indentation. I just wonder, why not forbid spaces in the beginning of lines? How would one come to the idea to use spaces for indentation at all? Space is not even a control/format character, but a word separator. And when editors will be proportional font based, indenting with spaces will not make *any* sense so they are just annoyance. Neither makes it sense in general case of text editing. I think it would be a salvation to forbid spaces for indentation, did such attemps take place? From joel.goldstick at gmail.com Fri Mar 17 22:09:10 2017 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Fri, 17 Mar 2017 22:09:10 -0400 Subject: Who are the "spacists"? In-Reply-To: References: Message-ID: On Fri, Mar 17, 2017 at 8:52 PM, Mikhail V wrote: > So Python supports both spaces and tabs for indentation. > > I just wonder, why not forbid spaces in the beginning of lines? > How would one come to the idea to use spaces for indentation at all? > > Space is not even a control/format character, but a word separator. > And when editors will be proportional font based, indenting with > spaces will not make *any* sense so they are just annoyance. > Neither makes it sense in general case of text editing. > I think it would be a salvation to forbid spaces for indentation, > did such attemps take place? > -- > https://mail.python.org/mailman/listinfo/python-list This is not a useful conversation. It has been had over and over in the past. Some people like tabs, some like spaces. In python you can use either, but you must stick to one or the other -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From darcy at VybeNetworks.com Fri Mar 17 23:50:52 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Fri, 17 Mar 2017 23:50:52 -0400 Subject: Who are the "spacists"? In-Reply-To: References: Message-ID: <3d91c973-6ad1-532d-7bc7-34f7dbde31d4@VybeNetworks.com> On 2017-03-17 10:09 PM, Joel Goldstick wrote: > This is not a useful conversation. It has been had over and over in > the past. Some people like tabs, some like spaces. In python you can > use either, but you must stick to one or the other s/must/should/ Technically you can use both if you are careful but life is so much easier if you pick one or the other. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From ben+python at benfinney.id.au Sat Mar 18 00:02:31 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 18 Mar 2017 15:02:31 +1100 Subject: Who are the "spacists"? References: Message-ID: <85shmbfd0o.fsf@benfinney.id.au> Mikhail V writes: > I just wonder, why not forbid spaces in the beginning of lines? > How would one come to the idea to use spaces for indentation at all? Those are two very different questions. I think you may be under the false impression that the decision you refer to was made in a vacuum. The truth is that there was an impressive culture of programming convention before Python ever existed; and, now that Python does exist, there is an enormous amount of Python code to continue supporting. For the first: > I just wonder, why not forbid spaces in the beginning of lines? Because that would make countless lines of existing Python code illegal. For the second: > How would one come to the idea to use spaces for indentation at all? Because, whether in the context of programming or not, the space character is the most obvious way to make invisible horizontal separation when typing at a keyboard. Therefore, it's the most obvious way for people to type what they see in programming examples. Therefore, it would be astonishing to reject it for indentation. Astonishment is a property to be minimised in a programming language. > I think it would be a salvation to forbid spaces for indentation, did > such attemps take place? Feel free to start your own discussion forum for your new programming language that forbids spaces for indentation. That language will never be Python, so please don't ask us to discuss it here. -- \ ?We are stuck with technology when what we really want is just | `\ stuff that works.? ?Douglas Adams | _o__) | Ben Finney From wrw at mac.com Sat Mar 18 00:36:00 2017 From: wrw at mac.com (William Ray Wing) Date: Sat, 18 Mar 2017 00:36:00 -0400 Subject: Who are the "spacists"? In-Reply-To: References: Message-ID: > On Mar 17, 2017, at 8:52 PM, Mikhail V wrote: > > So Python supports both spaces and tabs for indentation. > > I just wonder, why not forbid spaces in the beginning of lines? > How would one come to the idea to use spaces for indentation at all? > That convention dates all the way back to the IBM 026 and 029 card punches and FORTRAN. > Space is not even a control/format character, but a word separator. > And when editors will be proportional font based, indenting with > spaces will not make *any* sense so they are just annoyance. > Neither makes it sense in general case of text editing. > I think it would be a salvation to forbid spaces for indentation, > did such attemps take place? > -- > https://mail.python.org/mailman/listinfo/python-list From auriocus at gmx.de Sat Mar 18 04:05:39 2017 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 18 Mar 2017 09:05:39 +0100 Subject: Who are the "spacists"? In-Reply-To: References: Message-ID: Am 18.03.17 um 01:52 schrieb Mikhail V: > So Python supports both spaces and tabs for indentation. > > I just wonder, why not forbid spaces in the beginning of lines? > How would one come to the idea to use spaces for indentation at all? In the Python world it is the opposite - spaces are preferred and tabs are merely "allowed" - see PEP8 https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces Both have advantages and disadvantages for indentation. Some ideas how to get both have never gained widespread adoption: http://nickgravgaard.com/elastic-tabstops/ Christian From kwpolska at gmail.com Sat Mar 18 04:35:40 2017 From: kwpolska at gmail.com (Chris Warrick) Date: Sat, 18 Mar 2017 09:35:40 +0100 Subject: SimpleHTTPServer and CgiHTTPServer in practice In-Reply-To: <87inn8eogj.fsf@nightsong.com> References: <87bmt2nj01.fsf@nightsong.com> <3944b2b755d208e1e1e396bf221fada7@posteo.de> <87inn8eogj.fsf@nightsong.com> Message-ID: On 17 March 2017 at 01:28, Paul Rubin wrote: > Lutz Horn writes: >> We don't know *why* those people told you not to use these modules. We >> also don't know your use case. So it is very hard to advise you. > > The use case is to have a very easily set up way to serve basic pages > and files, without a lot of configuration files and other > infrastructure. The main reason not to use it would be security holes > if there are some. I haven't examined the code carefully but didn't see > obvious issues at a quick glanace. I frankly worry more about large C > programs than Python programs. > -- > https://mail.python.org/mailman/listinfo/python-list Security isn?t the main problem. SimpleHTTPServer is fine for small, local, one-off servers. However, for anything large, there are two problems: (a) its ephemeral nature, and (b) slow performance (no caching). nginx (or apache if you must) takes only a few minutes to set up, and does not have those problems. CgiHTTPServer? It?s 2017 and CGI should be long dead. CGI means firing up a Python/Perl/$cgi_language interpreter on every single HTTP request, already a waste of time. And then, CGI scripts take input via random environment variables (not very dependable) and output to stdout, which is a completely broken architecture. Give up and run a real web framework (Django) using uWSGI and nginx. -- Chris Warrick PGP: 5EAAEA16 From mikhailwas at gmail.com Sat Mar 18 09:46:16 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sat, 18 Mar 2017 14:46:16 +0100 Subject: Who are the "spacists"? In-Reply-To: References: Message-ID: On 18 March 2017 at 03:09, Joel Goldstick wrote: > On Fri, Mar 17, 2017 at 8:52 PM, Mikhail V wrote: >> So Python supports both spaces and tabs for indentation. >> >> I just wonder, why not forbid spaces in the beginning of lines? >> How would one come to the idea to use spaces for indentation at all? >> >> Space is not even a control/format character, but a word separator. >> And when editors will be proportional font based, indenting with >> spaces will not make *any* sense so they are just annoyance. >> Neither makes it sense in general case of text editing. >> I think it would be a salvation to forbid spaces for indentation, >> did such attemps take place? > > This is not a useful conversation. It has been had over and over in > the past. Some people like tabs, some like spaces. In python you can > use either, but you must stick to one or the other > Not to judge, but usually such opinions come from determined spasists. And "stick to one or the other" is exactly what would make life easier, but in literal sense of global preference. On 18 March 2017 at 05:02, Ben Finney wrote: > Mikhail V writes: > >> I just wonder, why not forbid spaces in the beginning of lines? > > Because that would make countless lines of existing Python code illegal. Yes, yes. And it is of course so hard to clean up spaces in existing code. From darcy at VybeNetworks.com Sat Mar 18 10:08:38 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Sat, 18 Mar 2017 10:08:38 -0400 Subject: Who are the "spacists"? In-Reply-To: References: Message-ID: <051a032b-10ce-80ae-bdef-a8b652156346@VybeNetworks.com> On 2017-03-18 09:46 AM, Mikhail V wrote: > Not to judge, but usually such opinions come from determined And he probably wasn't being facetious. Butyouareprobablyright.Spaceisawasteofspace. -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From mal at europython.eu Sat Mar 18 11:00:46 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Sat, 18 Mar 2017 16:00:46 +0100 Subject: EuroPython 2017: Welcome our new Logo Message-ID: <6ea7f4f2-51de-1dd5-07b9-10e5ddbb51f6@europython.eu> Blue sea. Yellow sand. EuroPython goes to Rimini 2017 with a brand new logo. Colorful waves play with beach umbrellas to shape the foundation symbol with different patterns that visually immerse us in our new location, one of the most popular sea places in Italy. New place, new dates, new style and colors. Same spirit as before. EuroPython 2017 website, now with our new logo: *** http://ep2017.europython.eu/ *** Training sessions, an enthusiastic line-up of keynote speakers from around the world, opportunities for sponsors and much more. While waiting for the new website launch, save the dates and join us in Rimini, Italy, from 9th to 16th July for a new edition of EuroPython. Please subscribe to our various EuroPython channels for updates on the conference: http://ep2017.europython.eu/social-media/ Enjoy, ? EuroPython 2017 Team http://ep2017.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/843024186461380608 Thanks. From mikhailwas at gmail.com Sat Mar 18 11:18:22 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sat, 18 Mar 2017 16:18:22 +0100 Subject: Who are the "spacists"? In-Reply-To: <85shmbfd0o.fsf@benfinney.id.au> References: <85shmbfd0o.fsf@benfinney.id.au> Message-ID: On 18 March 2017 at 05:02, Ben Finney wrote: > Mikhail V writes: > >> I think it would be a salvation to forbid spaces for indentation, did >> such attemps take place? > > Feel free to start your own discussion forum for your new programming > language that forbids spaces for indentation. That language will never > be Python, so please don't ask us to discuss it here. Slight note of aggression in you words makes me think you are a ... spacist? So you are the opinion it would be more productive to invent a new language instead of just cleaning up spaces? Interesting idea indeed, but that is ok. I think it still helps to realize that in the future this will become more noticable problem than it seems now, so at least making up a strategy for converting to tabs could be way more productive on a long term basis, than replacing tabs and spaces back and forth, like pouring water from one glass to another. From lutz.horn at posteo.de Sat Mar 18 11:54:32 2017 From: lutz.horn at posteo.de (Lutz Horn) Date: Sat, 18 Mar 2017 16:54:32 +0100 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> Message-ID: <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Am 18.03.17 um 16:18 schrieb Mikhail V: > On 18 March 2017 at 05:02, Ben Finney > wrote: >> Mikhail V writes: >> >>> I think it would be a salvation to forbid spaces for indentation, >>> did such attemps take place? >> >> Feel free to start your own discussion forum for your new >> programming language that forbids spaces for indentation. That >> language will never be Python, so please don't ask us to discuss it >> here. > So you are the opinion it would be more productive to invent a new > language instead of just cleaning up spaces? Productive in solving what problem exactly? Why do you think a cleaning of spaces is necessary? > I think it still helps to realize that in the future this will become > more noticable problem than it seems now Why? What could be the problem? I fail to see how the Python policy of preferring spaces over tabs while allowing both if used consistent is causing any problem. Lutz -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 907 bytes Desc: OpenPGP digital signature URL: From torriem at gmail.com Sat Mar 18 12:04:51 2017 From: torriem at gmail.com (Michael Torrie) Date: Sat, 18 Mar 2017 10:04:51 -0600 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> Message-ID: On 03/18/2017 09:18 AM, Mikhail V wrote: > Slight note of aggression in you words makes me think you > are a ... spacist? Please stop trolling. You obviously have an opinion and you are pursuing it aggressively, apparently attempting to bait people into an argument. Please stop. Your argument is not constructive. From darcy at VybeNetworks.com Sat Mar 18 12:07:56 2017 From: darcy at VybeNetworks.com (D'Arcy Cain) Date: Sat, 18 Mar 2017 12:07:56 -0400 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> Message-ID: On 2017-03-18 11:18 AM, Mikhail V wrote: > On 18 March 2017 at 05:02, Ben Finney wrote: >> Feel free to start your own discussion forum for your new programming >> language that forbids spaces for indentation. That language will never >> be Python, so please don't ask us to discuss it here. > > Slight note of aggression in you words makes me think you > are a ... spacist? As are just about everyone on this list except you. > So you are the opinion it would be more productive to > invent a new language instead of just cleaning up spaces? No, he thinks it would be more productive for us if you went away and invented your own language. > Interesting idea indeed, but that is ok. > I think it still helps to realize that in the future this will > become more noticable problem than it seems now, so > at least making up a strategy for converting to tabs > could be way more productive on a long term basis, > than replacing tabs and spaces back and forth, like pouring > water from one glass to another. At one point I couldn't decide if you were just a troll or not. Thanks for clearing it up. *plonk* -- D'Arcy J.M. Cain Vybe Networks Inc. http://www.VybeNetworks.com/ IM:darcy at Vex.Net VoIP: sip:darcy at VybeNetworks.com From grant.b.edwards at gmail.com Sat Mar 18 12:30:12 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 18 Mar 2017 16:30:12 +0000 (UTC) Subject: Who are the "spacists"? References: Message-ID: On 2017-03-18, Mikhail V wrote: > So Python supports both spaces and tabs for indentation. Indeed. > I just wonder, why not forbid spaces in the beginning of lines? Because spaces are pure, clean, and secure. > How would one come to the idea to use spaces for indentation at all? Because tabs are a major security vulnerability and should be outlawed in all source code. -- Grant From jon+usenet at unequivocal.eu Sat Mar 18 13:13:30 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sat, 18 Mar 2017 17:13:30 -0000 (UTC) Subject: Who are the "spacists"? References: Message-ID: On 2017-03-18, Grant Edwards wrote: > On 2017-03-18, Mikhail V wrote: >> How would one come to the idea to use spaces for indentation at all? > > Because tabs are a major security vulnerability and should be outlawed > in all source code. You forgot to mention that tabs are carcinogenic, can be addictive, and hate our freedoms. If we use them, the terrorists win. Tabs can settle during transit, and may contain traces of nuts. Tabs should not be folded, spindled or mutilated. Tabs are vicious if wounded. Remember, kids: Just Say No to the Invisible Menace. From gherron at digipen.edu Sat Mar 18 13:30:39 2017 From: gherron at digipen.edu (Gary Herron) Date: Sat, 18 Mar 2017 10:30:39 -0700 Subject: Who are the "spacists"? In-Reply-To: References: Message-ID: On 03/18/2017 06:46 AM, Mikhail V wrote: > On 18 March 2017 at 03:09, Joel Goldstick wrote: >> On Fri, Mar 17, 2017 at 8:52 PM, Mikhail V wrote: >>> So Python supports both spaces and tabs for indentation. >>> >>> I just wonder, why not forbid spaces in the beginning of lines? >>> How would one come to the idea to use spaces for indentation at all? >>> >>> Space is not even a control/format character, but a word separator. >>> And when editors will be proportional font based, indenting with >>> spaces will not make *any* sense so they are just annoyance. >>> Neither makes it sense in general case of text editing. >>> I think it would be a salvation to forbid spaces for indentation, >>> did such attemps take place? >> This is not a useful conversation. It has been had over and over in >> the past. Some people like tabs, some like spaces. In python you can >> use either, but you must stick to one or the other >> > Not to judge, but usually such opinions come from determined > spasists. And "stick to one or the other" is exactly what would make > life easier, but in literal sense of global preference. > > On 18 March 2017 at 05:02, Ben Finney wrote: >> Mikhail V writes: >> >>> I just wonder, why not forbid spaces in the beginning of lines? >> Because that would make countless lines of existing Python code illegal. > Yes, yes. And it is of course so hard to clean up spaces in existing code. As a mater of fact, and despite the snark, that is true. A quick count finds 46,209 .py files on my computer, spread across the OS, installed packages, and my own work. I would strongly resist anything that needs that much re-installation and personal attention. -- Dr. Gary Herron Professor of Computer Science DigiPen Institute of Technology (425) 895-4418 From grant.b.edwards at gmail.com Sat Mar 18 14:11:09 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sat, 18 Mar 2017 18:11:09 +0000 (UTC) Subject: Who are the "spacists"? References: Message-ID: On 2017-03-18, Jon Ribbens wrote: > On 2017-03-18, Grant Edwards wrote: >> On 2017-03-18, Mikhail V wrote: >>> How would one come to the idea to use spaces for indentation at all? >> >> Because tabs are a major security vulnerability and should be outlawed >> in all source code. > > You forgot to mention that tabs are carcinogenic, can be addictive, > and hate our freedoms. And they contribute to global warming. > If we use them, the terrorists win. Tabs can settle during transit, > and may contain traces of nuts. Tabs should not be folded, spindled > or mutilated. Tabs are vicious if wounded. Remember, kids: Just Say > No to the Invisible Menace. And remember, kids... Do Not Taunt Tabs. -- Grant Edwards grant.b.edwards Yow! I want EARS! I want at two ROUND BLACK EARS gmail.com to make me feel warm 'n secure!! From bgailer at gmail.com Sat Mar 18 16:19:55 2017 From: bgailer at gmail.com (Bob Gailer) Date: Sat, 18 Mar 2017 16:19:55 -0400 Subject: Who are the "spacists"? In-Reply-To: References: Message-ID: On Mar 17, 2017 9:23 PM, "Mikhail V" wrote: > > So Python supports both spaces and tabs for indentation. > > I just wonder, why not forbid spaces in the beginning of lines? > How would one come to the idea to use spaces for indentation at all? One problem for me with tabs: there is no standard visual representation (1 tab = ? Spaces) > > Space is not even a control/format character, but a word separator. Huh? The character sets I'm familiar with don't have "word separators". Space is just another no -control character. > And when editors will be proportional font based Editors allow your choice of font. Some are proportional, some monospaced. I fail to see any benefit from making a proportional-only font based editor. , indenting with > spaces will not make *any* sense so they are just annoyance. Only in the eye of the beholder. > Neither makes it sense in general case of text editing. > I think it would be a salvation to forbid spaces for indentation, > did such attemps take place? > -- > https://mail.python.org/mailman/listinfo/python-list From mikhailwas at gmail.com Sat Mar 18 17:24:18 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sat, 18 Mar 2017 22:24:18 +0100 Subject: Who are the "spacists"? In-Reply-To: <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: On 18 March 2017 at 16:54, Lutz Horn wrote: > Am 18.03.17 um 16:18 schrieb Mikhail V: >> On 18 March 2017 at 05:02, Ben Finney >> wrote: >>> Mikhail V writes: >>> >>>> I think it would be a salvation to forbid spaces for indentation, >>>> did such attemps take place? >>> >>> Feel free to start your own discussion forum for your new >>> programming language that forbids spaces for indentation. That >>> language will never be Python, so please don't ask us to discuss it >>> here. > >> So you are the opinion it would be more productive to invent a new >> language instead of just cleaning up spaces? > > Productive in solving what problem exactly? Why do you think a cleaning > of spaces is necessary? Ehm, why is it necessary? I won't mix them and I use tabs, so if I become a source with spaces and edit it, I must replace them, then if a spacist becomes tabulated code he replaces tabs with spaces again. Not a big deal, but seems strange. > >> I think it still helps to realize that in the future this will become >> more noticable problem than it seems now > > Why? What could be the problem? I fail to see how the Python policy of > preferring spaces over tabs while allowing both if used consistent is > causing any problem. There can be some problems, say in one class a teacher says: never use tabs, in other class a teacher says: don't use spaces. Who is right? This is not a major problem, but technically seen using tabs is more logical way, but de-facto spaces are recommended. I've noticed a tendency that more and more users choose tabs. Indeed if you think about it, using several spaces for one level of indentation is ridiculous and it is not only my opinion. So tabs are quite natural choice, but with spaces being a 'recommended' style, there are two 'camps' within one language. New users will be always frustrated, and ask why is it bad to use tabs. But can all teachers explain exactly the difference? So it starts as a problem of choice. From dvl at psu.edu Sat Mar 18 17:44:05 2017 From: dvl at psu.edu (ROGER GRAYDON CHRISTMAN) Date: Sat, 18 Mar 2017 17:44:05 -0400 Subject: Who are the "spacists"? Message-ID: <1489873444l.9830606l.0l@psu.edu> Just a couple minor notes from my experience: 1) Some of the course management software I use doesn't like me typing tab characters. When I want to post sample code into a course page using this software, tabs are either ignored or does something really broken (like post an incomplete file). So, I must necessarily type spaces when posting that code -- and of course, downloading that sample from the page has spaces in it instead of tabs. Point in favor of using spaces. 2) Tabs are one byte; spaces are one byte; so unless all of your indents are only one space at a time, a source file with tabs takes less memory than a source file with tabs. It's not a significant difference. Very minor point in favor of using tabs. I'm still a spacer myself. From nathan.ernst at gmail.com Sat Mar 18 17:50:06 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Sat, 18 Mar 2017 16:50:06 -0500 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: My issue with using spaces instead of tabs, is that, as mentioned earlier in the thread, everyone has their own preferences on indentation. I've worked on teams where different developers used 2, 3 & 4 spaces as indentation. Obviously, if you're using spaces, several of the members will be unhappy. Tabs have the benefit that most editors used by developers allow the adjustment of the width of a tab. If you use tabs, everyone can be happy with the visual presentation of their code. My rule of thumb: tabs for indentation, spaces for alignment (i.e. trying to line up anything after a non-whitespace character on a single line). Regards, Nathan On Sat, Mar 18, 2017 at 4:24 PM, Mikhail V wrote: > On 18 March 2017 at 16:54, Lutz Horn wrote: > > Am 18.03.17 um 16:18 schrieb Mikhail V: > >> On 18 March 2017 at 05:02, Ben Finney > >> wrote: > >>> Mikhail V writes: > >>> > >>>> I think it would be a salvation to forbid spaces for indentation, > >>>> did such attemps take place? > >>> > >>> Feel free to start your own discussion forum for your new > >>> programming language that forbids spaces for indentation. That > >>> language will never be Python, so please don't ask us to discuss it > >>> here. > > > >> So you are the opinion it would be more productive to invent a new > >> language instead of just cleaning up spaces? > > > > Productive in solving what problem exactly? Why do you think a cleaning > > of spaces is necessary? > > Ehm, why is it necessary? I won't mix them and I use tabs, so if I become a > source with spaces and edit it, I must replace them, then if a spacist > becomes > tabulated code he replaces tabs with spaces again. Not a big > deal, but seems strange. > > > > >> I think it still helps to realize that in the future this will become > >> more noticable problem than it seems now > > > > Why? What could be the problem? I fail to see how the Python policy of > > preferring spaces over tabs while allowing both if used consistent is > > causing any problem. > > There can be some problems, say in one class a teacher says: never > use tabs, in other class a teacher says: don't use spaces. > Who is right? > This is not a major problem, but technically seen using tabs > is more logical way, but de-facto spaces are recommended. > I've noticed a tendency that more and more users > choose tabs. Indeed if you think about it, using several spaces for > one level of indentation is ridiculous and it is not only my opinion. > So tabs are quite natural choice, but with spaces being a 'recommended' > style, there are two 'camps' within one language. > New users will be always frustrated, and ask why is it bad to use tabs. > But can all teachers explain exactly the difference? So it starts as a > problem of choice. > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sat Mar 18 17:55:17 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Mar 2017 08:55:17 +1100 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: On Sun, Mar 19, 2017 at 8:50 AM, Nathan Ernst wrote: > My rule of thumb: tabs for indentation, spaces for alignment (i.e. trying > to line up anything after a non-whitespace character on a single line). My rule of thumb: tabs for indentation, and don't align stuff after non-whitespace :) ChrisA From arequipeno at gmail.com Sat Mar 18 17:58:53 2017 From: arequipeno at gmail.com (Ian Pilcher) Date: Sat, 18 Mar 2017 16:58:53 -0500 Subject: cryptography default_backend is "hazmat"? Message-ID: Yet another newbie question/observation ... So every example I can find of using python-cryptography includes a call to cryptography.hazmat.backends.default_backend(). Of course, the documentation at https://cryptography.io/en/latest/hazmat/backends/ says: ! Danger This is a ?Hazardous Materials? module. You should ONLY use it if you?re 100% absolutely sure that you know what you?re doing because this module is full of land mines, dragons, and dinosaurs with laser guns. Anyone else see a conflict here? -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From nathan.ernst at gmail.com Sat Mar 18 17:59:16 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Sat, 18 Mar 2017 16:59:16 -0500 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: I don't generally align stuff, either, but if you're going to, use spaces. On Sat, Mar 18, 2017 at 4:55 PM, Chris Angelico wrote: > On Sun, Mar 19, 2017 at 8:50 AM, Nathan Ernst > wrote: > > My rule of thumb: tabs for indentation, spaces for alignment (i.e. trying > > to line up anything after a non-whitespace character on a single line). > > My rule of thumb: tabs for indentation, and don't align stuff after > non-whitespace :) > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sat Mar 18 18:01:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Mar 2017 09:01:31 +1100 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: On Sun, Mar 19, 2017 at 8:59 AM, Nathan Ernst wrote: > I don't generally align stuff, either, but if you're going to, use spaces. The most interesting coder in the world. https://imgflip.com/i/1lo0wl ChrisA From rosuav at gmail.com Sat Mar 18 18:15:29 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Mar 2017 09:15:29 +1100 Subject: cryptography default_backend is "hazmat"? In-Reply-To: References: Message-ID: On Sun, Mar 19, 2017 at 8:58 AM, Ian Pilcher wrote: > Yet another newbie question/observation ... > > So every example I can find of using python-cryptography includes a > call to cryptography.hazmat.backends.default_backend(). Of course, the > documentation at https://cryptography.io/en/latest/hazmat/backends/ > says: > > ! Danger > > This is a ?Hazardous Materials? module. You should ONLY use it if > you?re 100% absolutely sure that you know what you?re doing because > this module is full of land mines, dragons, and dinosaurs with laser > guns. > > Anyone else see a conflict here? Not necessarily. I don't know about that exact example, but let me give you a couple of others. 1) exec and eval. Very dangerous. Do not use them in production code unless you know what you're doing. Where do you find exec used? In namedtuple. Yep. Every time you create a namedtuple, it exec's a big block of code with interpolated bits to make your stuff happen. Is namedtuple dangerous because it uses exec? No, because namedtuple has been well-written and is maintained with care. 2) cffi, ctypes, extension libraries, etc - untrusted access to C code. Incredibly dangerous, because you can mess up refcounts in CPython, your code can't be ported to other Pythons without a lot of care, and you can break things in ways you wouldn't even have thought possible (try redefining the value of the integer 1 - Python gets confused in a very short space of time). Where are they used? All over the place. All over the place. Poke around on PyPI and you'll find a ton of great modules that are written in C (and not using Cython), and the Python community hasn't collapsed under their collective fragility yet. Are they dangerous? Well, yes, in the sense that certain types of bugs can segfault the interpreter rather than raising an exception - but your code isn't more dangerous because you type "import psycopg2". So the question is: How well do you trust the examples? Are they likely to be instructing you in a safe way to use this potentially-dangerous module? ChrisA From arequipeno at gmail.com Sat Mar 18 18:27:39 2017 From: arequipeno at gmail.com (Ian Pilcher) Date: Sat, 18 Mar 2017 17:27:39 -0500 Subject: cryptography default_backend is "hazmat"? In-Reply-To: References: Message-ID: On 03/18/2017 05:15 PM, Chris Angelico wrote: > So the question is: How well do you trust the examples? Are they > likely to be instructing you in a safe way to use this > potentially-dangerous module? But as far as I can tell, there's no way to use many of the non-hazmat functions (e.g. parsing a certificate) without a backend, and all of the backends are "hazmat". So what's the point of marking something as hazmat, if a large portion of the rest of the module can't be used without it? -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From mikhailwas at gmail.com Sat Mar 18 18:32:14 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sat, 18 Mar 2017 23:32:14 +0100 Subject: Who are the "spacists"? In-Reply-To: References: Message-ID: On 18 March 2017 at 21:19, Bob Gailer wrote: > On Mar 17, 2017 9:23 PM, "Mikhail V" wrote: >> >> So Python supports both spaces and tabs for indentation. >> >> I just wonder, why not forbid spaces in the beginning of lines? >> How would one come to the idea to use spaces for indentation at all? > > One problem for me with tabs: there is no standard visual representation (1 > tab = ? Spaces) Hi Bob, The rendering of each character, including tab character is up to the renderer, i.e. editor or IDE. This means, if the editor supports customisations, then you can define the width of the tabs. With more advanced rendering, editor can 'know' if it is a preceding (indent) tab or some other indentation, e.g. multiline list definition (e.g. 'elastic tabs', but that is more about future). In VIM I set the tab width = 4 spaces and VIM is a monospaced-only editor. >> >> Space is not even a control/format character, but a word separator. > > Huh? The character sets I'm familiar with don't have "word separators". > Space is just another no -control character. Yes that is what I mean. So it is quite logical to use a tab, i.e. different character than space for this specific case, 1 char for 1 level. > >> And when editors will be proportional font based > > Editors allow your choice of font. Some are proportional, some monospaced. I > fail to see any benefit from making a proportional-only font based editor. Well, if there will be a decent IDE/editor with realistic font rendering and good tabs mangement, I will not ever want to switch back to a monospaced font. So put another way, there will be no need to use a monospaced font. And if one uses spaces to indent e.g. multiline list with proportional font, then it is not possible to achieve exact alignment. Anyway, why use space? space is space, a character for specific usage. Also if I increase the font size I don;t necesserily want to increase the tab width. I treat monospaced editors more as an anachronism, I mean of course only the 'visual' component. So VIM, despite its monospaced nature, is for me high above all products I've tested so far, if speak about input, editing. From arthur.darcet+list at m4x.org Sat Mar 18 18:42:49 2017 From: arthur.darcet+list at m4x.org (Arthur Darcet) Date: Sat, 18 Mar 2017 22:42:49 +0000 Subject: cryptography default_backend is "hazmat"? In-Reply-To: References: Message-ID: On Sat, 18 Mar 2017 at 23:29, Ian Pilcher wrote: > On 03/18/2017 05:15 PM, Chris Angelico wrote: > > So the question is: How well do you trust the examples? Are they > > likely to be instructing you in a safe way to use this > > potentially-dangerous module? > > But as far as I can tell, there's no way to use many of the non-hazmat > functions (e.g. parsing a certificate) without a backend, and all of the > backends are "hazmat". > > So what's the point of marking something as hazmat, if a large portion > of the rest of the module can't be used without it? > If I'm not mistaken, the hazmat module contains functions that are easy to misuse, which is why they are hazardous. Using those same functions through the "safe" part of the library isn't dangerous > -- > ======================================================================== > Ian Pilcher arequipeno at gmail.com > -------- "I grew up before Mark Zuckerberg invented friendship" -------- > ======================================================================== > > -- > https://mail.python.org/mailman/listinfo/python-list > From nathan.ernst at gmail.com Sat Mar 18 19:16:31 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Sat, 18 Mar 2017 18:16:31 -0500 Subject: Who are the "spacists"? In-Reply-To: <1489873444l.9830606l.0l@psu.edu> References: <1489873444l.9830606l.0l@psu.edu> Message-ID: On Sat, Mar 18, 2017 at 4:44 PM, ROGER GRAYDON CHRISTMAN wrote: > Just a couple minor notes from my experience: > > 1) > Some of the course management software I use doesn't like me typing tab > characters. > When I want to post sample code into a course page using this software, > tabs > are either > ignored or does something really broken (like post an incomplete file). > So, I > must necessarily > type spaces when posting that code -- and of course, downloading that > sample > from the page > has spaces in it instead of tabs. > > Point in favor of using spaces. > Then your course management software is broken, and should be fixed. This is not a valid argument against tabs, although it may make it more convenient to use spaces for you. > 2) > Tabs are one byte; spaces are one byte; so unless all of your indents are > only > one space at a time, > a source file with tabs takes less memory than a source file with tabs. > It's not a significant difference. > > Very minor point in favor of using tabs. > > I'm still a spacer myself. > > > -- > https://mail.python.org/mailman/listinfo/python-list The size of tab vs space is a novel argument, but generally specious. Yes, it may matter in certain circumstances, but it's not generally valid (and I say this with a tab preferrence). As I said earlier, where tabs are superior in that most code focused editors (at least those worth using) allow you to adjust the width of the tab. I'm not aware of a single editor that allows you to adjust the indentation of multiple spaces, let alone in the face of sources with mixed space indentations in the same codebase. Again, I've seen 2, 3 and 4 spaced identations. Really f***ing annoying to see that in a single codebase. It's even worse when you get files edited by two different people with different styles and their white space changes happen to work because the entire block is within their preferred style. (yes, I've seen 3-spaced indents mixed with 2-spaced idents and 4-spaced indents all within a single file!) Tabs rectify this issue as you can configure them to appear how you like to see your code without affecting or impacting any other contributors to a code base. Personally, I used to be a 4-spacer. Now, I prefer 2 spaces. Guess what? When I changed my preference, zero lines of source were changed, no commits were necessary, and I was happy. From marko at pacujo.net Sat Mar 18 19:20:03 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 19 Mar 2017 01:20:03 +0200 Subject: Who are the "spacists"? References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: <87d1dejhp8.fsf@elektro.pacujo.net> Chris Angelico : > My rule of thumb: tabs for indentation, and don't align stuff after > non-whitespace :) I always use the "Tab" key to indent, but I don't allow the file to contain any ASCII HT characters. The only control character in my files is the LF. The only exception would be plain text files that I paginate using the FF before sending them to the printer. Marko From robertoshea2k11 at gmail.com Sat Mar 18 19:20:28 2017 From: robertoshea2k11 at gmail.com (Robert O'Shea) Date: Sat, 18 Mar 2017 23:20:28 +0000 Subject: Where to start in the field of AI with Python Message-ID: Hi all, I've been given a good bit of free time at the moment and I really want to get into the field of AI with my time. I just want to get into the basics for the moment, eventually getting into stuff like machine learning and NLP (Natural Language Processing). I was wondering if any of you fine people know some good resources of where to start as I'm finding it hard to procure decent content. If any of you know of any resources in the field please send them my way. Regards, Robert From marko at pacujo.net Sat Mar 18 19:38:01 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 19 Mar 2017 01:38:01 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> Message-ID: <8760j6jgva.fsf@elektro.pacujo.net> Nathan Ernst : > Tabs rectify this issue as you can configure them to appear how you > like to see your code without affecting or impacting any other > contributors to a code base. > > Personally, I used to be a 4-spacer. Now, I prefer 2 spaces. Guess > what? When I changed my preference, zero lines of source were changed, > no commits were necessary, and I was happy. Your scheme is thrown into disarray by the default emacs setup, which defines C source code indendation levels as follows: Level 1: SPC SPC Level 2: SPC SPC SPC SPC Level 3: SPC SPC SPC SPC SPC SPC Level 4: HT Level 5: HT SPC SPC etc. (You see, in emacs pressing the Tab key is a command to indent the current line by the "appropriate amount;" it doesn't cause an HT to be inserted.) Point is, something's going to have to give, no matter what you do. You are going to have to issue a binding executive order that is not an automatic default for everybody. Where I work, the executive order is: no HT's in files, and use 4-space indentation. Marko From nathan.ernst at gmail.com Sat Mar 18 20:01:42 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Sat, 18 Mar 2017 19:01:42 -0500 Subject: Who are the "spacists"? In-Reply-To: <8760j6jgva.fsf@elektro.pacujo.net> References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> Message-ID: emacs, like Vim is very configurable. I'm sure there's an appropriate setting. Because 1 editor does it one way, doesn't mean the rest of the numerous editors should follow suit. Personally, I dislike any editor that, by default, changes my input to something else. If I hit tab, I want a tab to be inserted, by default. If I want something else, I'll change the configuration. On Sat, Mar 18, 2017 at 6:38 PM, Marko Rauhamaa wrote: > Nathan Ernst : > > > Tabs rectify this issue as you can configure them to appear how you > > like to see your code without affecting or impacting any other > > contributors to a code base. > > > > Personally, I used to be a 4-spacer. Now, I prefer 2 spaces. Guess > > what? When I changed my preference, zero lines of source were changed, > > no commits were necessary, and I was happy. > > Your scheme is thrown into disarray by the default emacs setup, which > defines C source code indendation levels as follows: > > Level 1: SPC SPC > Level 2: SPC SPC SPC SPC > Level 3: SPC SPC SPC SPC SPC SPC > Level 4: HT > Level 5: HT SPC SPC > > etc. > > (You see, in emacs pressing the Tab key is a command to indent the > current line by the "appropriate amount;" it doesn't cause an HT to be > inserted.) > > Point is, something's going to have to give, no matter what you do. You > are going to have to issue a binding executive order that is not an > automatic default for everybody. > > Where I work, the executive order is: no HT's in files, and use 4-space > indentation. > > > Marko > -- > https://mail.python.org/mailman/listinfo/python-list > From steve+python at pearwood.info Sat Mar 18 20:32:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 19 Mar 2017 11:32:22 +1100 Subject: Tabs are a security vulnerabilty [was Re: Who are the "spacists"?] References: Message-ID: <58cdd198$0$1596$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Mar 2017 03:30 am, Grant Edwards wrote: > tabs are a major security vulnerability and should be outlawed > in all source code. I've heard many arguments both in favour of and against tabs, but I've never heard them described as a security vulnerability before. Let alone a major one. Got a citation or some more information? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Sat Mar 18 20:39:43 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 19 Mar 2017 11:39:43 +1100 Subject: Who are the "spacists"? References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: <58cdd351$0$1586$c3e8da3$5496439d@news.astraweb.com> On Sun, 19 Mar 2017 08:24 am, Mikhail V wrote: > There can be some problems, say in one class a teacher says: never > use tabs, in other class a teacher says: don't use spaces. > Who is right? Neither is right, both are wrong, and the students have just learned a valuable lesson: authority figures can be mistaken, they can be ignorant, and they can spread superstition. > This is not a major problem, but technically seen using tabs > is more logical way, but de-facto spaces are recommended. Yes, I agree 100% with that. > I've noticed a tendency that more and more users > choose tabs. Have you really? I've noticed the opposite. > Indeed if you think about it, using several spaces for > one level of indentation is ridiculous Is it? Is it also ridiculous to use several newlines to space paragraphs vertically? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From marko at pacujo.net Sat Mar 18 20:52:54 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 19 Mar 2017 02:52:54 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> Message-ID: <871stujdeh.fsf@elektro.pacujo.net> Nathan Ernst : > emacs, like Vim is very configurable. I'm sure there's an appropriate > setting. > > Because 1 editor does it one way, doesn't mean the rest of the > numerous editors should follow suit. Correct. There's no universal standard so we have to declare a local one. I have defined: (custom-set-variables '(indent-tabs-mode nil)) meaning: don't indent using ASCII HT characters. > Personally, I dislike any editor that, by default, changes my input to > something else. If I hit tab, I want a tab to be inserted, by default. > If I want something else, I'll change the configuration. Well, I have yet to find an editor that gives no interpretation to the keys. For example, typing the "Esc" key in vi's insert mode will not place an ESC character in the file. And even vi puts an LF in your file if you should press the "Enter" key. Of course, you are free to like or dislike any editor you want. Marko From rosuav at gmail.com Sat Mar 18 20:56:10 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Mar 2017 11:56:10 +1100 Subject: Who are the "spacists"? In-Reply-To: <58cdd351$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> <58cdd351$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Mar 19, 2017 at 11:39 AM, Steve D'Aprano wrote: >> Indeed if you think about it, using several spaces for >> one level of indentation is ridiculous > > Is it? > > Is it also ridiculous to use several newlines to space paragraphs > vertically? At least with paragraphs, we don't have eternal debates between people who think they should have four newlines, three newlines, or.... oh wait, there is debate between two and one.... ChrisA From marko at pacujo.net Sat Mar 18 21:05:53 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Sun, 19 Mar 2017 03:05:53 +0200 Subject: Who are the "spacists"? References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> <58cdd351$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87tw6qhy8e.fsf@elektro.pacujo.net> Chris Angelico : > On Sun, Mar 19, 2017 at 11:39 AM, Steve D'Aprano > wrote: >> Is it also ridiculous to use several newlines to space paragraphs >> vertically? > > At least with paragraphs, we don't have eternal debates between people > who think they should have four newlines, three newlines, or.... oh > wait, there is debate between two and one.... Some people like fluffy source code: def f(): "doc" # Code follows x = calculate_some() return x + 1 Me, I like it compact: def f(): "doc" # Code follows x = calculate_some() return x + 1 Not to worry! Just use VT characters to indicate vertical space and configure your editor to display it with your favorite number of empty pixels. Thankfully, the use of VT characters in source code has experienced a 200% increase in recent years. Marko From mikhailwas at gmail.com Sat Mar 18 23:12:34 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 19 Mar 2017 04:12:34 +0100 Subject: Who are the "spacists"? In-Reply-To: <58cdd351$0$1586$c3e8da3$5496439d@news.astraweb.com> References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> <58cdd351$0$1586$c3e8da3$5496439d@news.astraweb.com> Message-ID: > On 19 March 2017 at 01:39, Steve D'Aprano wrote: >> On Sun, 19 Mar 2017 08:24 am, Mikhail V wrote: >> >> I've noticed a tendency that more and more users >> choose tabs. >Have you really? I've noticed the opposite. Not *really*, but on stackoverflow more and more answers recommending tabs are upvoted. Few years ago IIRC I noticed merely upvoted PEP citations. Of my friends, I know those who use Sublime editor on Macs, use tabs, probably spaces cause issues there, IDK. Younger people today have more and more previous experience with digital documents and already familiar with the concept of tabulation. Also after one tries to move the cursor around line beginnings and try to delete or add indentation, with spaces it is not so easy. On the other hand I've noticed that spacists are for some reason quite active in the web and at times even agressive, writing that tabs are 'cancer' and so on. >> Indeed if you think about it, using several spaces for >> one level of indentation is ridiculous >Is it? Yes it is. In the times of DOS it felt totally ok to indent e.g. 2 spaces, but those were text mode apps on small resolution screens. Now one wants more than 2 spaces for sure, and for Python specifically, the intuitive wish is to use one tab for one indentation level, since one already knows that indentation is important and despite spaces work, those are not control characters. The point is that spaces are not supposed for indentation regardless if it is code or MS Word document, at least in the modern world. This reminds me of Lexicon: https://en.wikipedia.org/wiki/Lexicon_(program) It is a DOS text-mode word processor, to make full line justify it inserts additional spaces between words. All those space alignments is more about ASCII art. From steve+python at pearwood.info Sun Mar 19 01:48:07 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 19 Mar 2017 16:48:07 +1100 Subject: Redmonk language rankings Message-ID: <58ce1b99$0$1611$c3e8da3$5496439d@news.astraweb.com> Redmonk have announced their language rankings for January 2017, and Python has moved up to third most popular language: http://redmonk.com/sogrady/2017/03/17/language-rankings-1-17/ Note that the way Redmonk calculate the rankings have changed, so you cannot directly compare the previous ranking with these. Other languages of note: - Rust, Typescript and Powershell are three languages showing high levels of growth in popularity; - Despite entering the "Trough Of Disillusionment" phase of the hype cycle, Swift's popularity continues to grow. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From pavol.lisy at gmail.com Sun Mar 19 01:53:28 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Sun, 19 Mar 2017 06:53:28 +0100 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: On 3/18/17, Nathan Ernst wrote: > My issue with using spaces instead of tabs, is that, as mentioned earlier > in the thread, everyone has their own preferences on indentation. I've > worked on teams where different developers used 2, 3 & 4 spaces as > indentation. Obviously, if you're using spaces, several of the members will > be unhappy. > > Tabs have the benefit that most editors used by developers allow the > adjustment of the width of a tab. If you use tabs, everyone can be happy > with the visual presentation of their code. > > My rule of thumb: tabs for indentation, spaces for alignment (i.e. trying > to line up anything after a non-whitespace character on a single line). > > Regards, > Nathan Everyone has their own preferences how to display tabs (2, 3, 4 spaces?). How could alignment look in case of mixed tabs and spaces? Everybody will be happy? In case of spaces there is not discrepancy. pep8 and similar linters could work fine without incompatible configurations. PL. PS. I am "spacist" :P but I feel this a little more aggressive than is necessary too: > Feel free to start your own discussion forum for your new programming > language that forbids spaces for indentation. That language will never > be Python, so please don't ask us to discuss it here. I think there could be enough time to deprecate now and forbid tabs (or spaces) as indentation in python4. That doesn't mean I propose that! I only think that this transition could be technically possible so discussion is not necessary useless. From rosuav at gmail.com Sun Mar 19 02:32:06 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Mar 2017 17:32:06 +1100 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: On Sun, Mar 19, 2017 at 4:53 PM, Pavol Lisy wrote: > Everyone has their own preferences how to display tabs (2, 3, 4 spaces?). Exactly, and they're welcome to them. > How could alignment look in case of mixed tabs and spaces? Everybody > will be happy? Don't do that. Ever. In any language. > In case of spaces there is not discrepancy. pep8 and similar linters > could work fine without incompatible configurations. I don't like the pep8 tool; its name implies far more authority than it actually has. But if you look at the rules Python 3 applies, or Python 2 with "-tt", you should easily be able to comply. ChrisA From pavol.lisy at gmail.com Sun Mar 19 04:00:01 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Sun, 19 Mar 2017 09:00:01 +0100 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: On 3/19/17, Pavol Lisy wrote: > On 3/18/17, Nathan Ernst wrote: > PS. I am "spacist" :P but I feel this a little more aggressive than is > necessary too: > >> Feel free to start your own discussion forum for your new programming >> language that forbids spaces for indentation. That language will never >> be Python, so please don't ask us to discuss it here. > > I think there could be enough time to deprecate now and forbid tabs > (or spaces) as indentation in python4. > > That doesn't mean I propose that! I only think that this transition > could be technically possible so discussion is not necessary useless. Sorry here I forgot to mention that citation above is from Ben Finney's mail and not from Nathan's! Anyway. I just made a simple and primitive analyze: re.findall('^ '...) and re.findall('^\t'...) for more than 100k py-files discoverable by find / -name "*.py" on my (ubuntu 16.04) computer. Anybody could see that it incorrectly finds lines in multiline strings (and has maybe much more flaws) but it could be probably still interesting. there are: 127 837 files where at least one line starts with space 2 273 files where at least one line starts with tab 1 192 files where are lines which starts with space and lines which starts with tab and there are: 35 144 893 lines which starts with space 428 160 lines which starts with tab PL. From pavol.lisy at gmail.com Sun Mar 19 04:24:52 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Sun, 19 Mar 2017 09:24:52 +0100 Subject: About linters and PEP-8 Message-ID: On 3/19/17, Chris Angelico wrote: > On Sun, Mar 19, 2017 at 4:53 PM, Pavol Lisy wrote: >> In case of spaces there is not discrepancy. pep8 and similar linters >> could work fine without incompatible configurations. > I don't like the pep8 tool; its name implies far more authority than > it actually has. But if you look at the rules Python 3 applies, or > Python 2 with "-tt", you should easily be able to comply. There was discussion on python-idea about duplicity in dict definition. {"a": "foo", "a": "bar"} Conclusion was that it is not an error and anybody could use linters for finding it. For example pylint could do it. Modern editors could do linting parallel to editing and many people use it. I think - I couldn't like everything what pep8 or pylint or any others do. But it is some kind of responsibility to write codes, which do not produce plenty of warnings. (because they could hide warning like duplicity in dict) And I think that significance of linters could grow as machine learning will evolve. So if there is something wrong about PEP-8 maybe there is some work for us to improve it. PL. From list at qtrac.plus.com Sun Mar 19 05:22:00 2017 From: list at qtrac.plus.com (Mark Summerfield) Date: Sun, 19 Mar 2017 02:22:00 -0700 (PDT) Subject: Error installing python on Windows In-Reply-To: References: <58b0779b$0$740$e4fe514c@news.xs4all.nl> Message-ID: <6003cf2d-c49f-48e7-9648-62b030ce41cc@googlegroups.com> Windows users (quite reasonably IMO) expect installs to "just work". If Python needs extra bits it should ask the user if it can go get them and if they say Yes it should do just that. (And this should actually work -- unlike maybe, the Python 3.5 Windows installer.) And as for searching Google for error messages, sure, experienced programmers do this, but many people come to Python as first-time programmers and don't realise. The fact that Michelle asked on this list shows that she made an effort that I suspect many people wouldn't bother making -- I can't help wondering how many new people have been lost to Python since the new installer. My experience has been that the new Python windows installer is less convenient than the old one. For example, with Python 3.6.0 64-bit on Windows the registry has to be fixed to be able to install popular packages like pywin32 (as well as less popular but excellent ones like apsw). Furthermore, the old and new installers offer the choice of "install just for you" or "install for everyone on the machine" but give no explanation of what difference this makes. If you install for everyone, you'll find that pip won't work. (OK, sure it'll work, providing you use the --user option, but how many people will realise that --user means "install for me"?) From rosuav at gmail.com Sun Mar 19 07:20:07 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Mar 2017 22:20:07 +1100 Subject: About linters and PEP-8 In-Reply-To: References: Message-ID: On Sun, Mar 19, 2017 at 7:24 PM, Pavol Lisy wrote: > On 3/19/17, Chris Angelico wrote: >> On Sun, Mar 19, 2017 at 4:53 PM, Pavol Lisy wrote: > >>> In case of spaces there is not discrepancy. pep8 and similar linters >>> could work fine without incompatible configurations. > >> I don't like the pep8 tool; its name implies far more authority than >> it actually has. But if you look at the rules Python 3 applies, or >> Python 2 with "-tt", you should easily be able to comply. > > There was discussion on python-idea about duplicity in dict definition. > > {"a": "foo", "a": "bar"} > > Conclusion was that it is not an error and anybody could use linters > for finding it. For example pylint could do it. Modern editors could > do linting parallel to editing and many people use it. > > I think - I couldn't like everything what pep8 or pylint or any others > do. But it is some kind of responsibility to write codes, which do not > produce plenty of warnings. (because they could hide warning like > duplicity in dict) > > And I think that significance of linters could grow as machine > learning will evolve. So if there is something wrong about PEP-8 maybe > there is some work for us to improve it. I'm not sure what your point is, or why you're responding to my post to make it, so I'll clarify what I was saying: The tool "pep8" is inappropriately named. No linter should use this name. It implies a level of authority by linking with a very specific document. Now, the tool itself may well be a brilliant linter. That's fine, and linters are excellent. But saying "a linter should be able to catch this error" should not have people immediately turn around and say "then PEP 8 should have a rule about this". And that's what seems to happen when the tool and the document are too tightly linked. http://rosuav.blogspot.com/2016/04/falsehoods-programmers-believe-about.html PEP 8 is a very specific-purpose document: it is a set of rules which govern the Python standard library. It so happens that, like many other style guides, it can be adopted for other projects (just as the airbnb style guide is adopted by a lot of JavaScript projects, and the GNU style guide can be used for non-GNU projects), but it's still a document aimed at humans. Here is its most important section: https://www.python.org/dev/peps/pep-0008/#a-foolish-consistency-is-the-hobgoblin-of-little-minds Start by disconnecting the style guide from the linter. A piece of code may fulfil every rule in your guide, but still be flagged by the linter; or it can pass the linter's check, but still fail code review because it violates a rule of style. (Example of the latter: inconsistent naming of similar concepts. No linter can understand that X.foo and Y.bar mean the same thing.) Enhancements to the style guide and enhancements to the linter are thus completely independent, and serve different (though related) purposes. ChrisA From grant.b.edwards at gmail.com Sun Mar 19 10:23:55 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 19 Mar 2017 14:23:55 +0000 (UTC) Subject: Who are the "spacists"? References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: On 2017-03-18, Chris Angelico wrote: > On Sun, Mar 19, 2017 at 8:50 AM, Nathan Ernst wrote: >> My rule of thumb: tabs for indentation, spaces for alignment (i.e. trying >> to line up anything after a non-whitespace character on a single line). > > My rule of thumb: tabs for indentation, and don't align stuff after > non-whitespace :) Aligning columns in tables of data make it far easier to read/edit. -- Grant From grant.b.edwards at gmail.com Sun Mar 19 10:27:42 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Sun, 19 Mar 2017 14:27:42 +0000 (UTC) Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> Message-ID: On 2017-03-18, Nathan Ernst wrote: > As I said earlier, where tabs are superior in that most code focused > editors (at least those worth using) allow you to adjust the width of the > tab. What about all other other text tools that _aren't_ 'code focused editors'? (e.g. grep, less, cat, awk, sed, a2ps, asciidoc, etc.) > I'm not aware of a single editor that allows you to adjust the > indentation of multiple spaces, let alone in the face of sources with mixed > space indentations in the same codebase. So the only thing that ever touches your code is that one editor? -- Grant From mikhailwas at gmail.com Sun Mar 19 12:02:05 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 19 Mar 2017 17:02:05 +0100 Subject: Who are the "spacists"? In-Reply-To: <87tw6qhy8e.fsf@elektro.pacujo.net> References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> <58cdd351$0$1586$c3e8da3$5496439d@news.astraweb.com> <87tw6qhy8e.fsf@elektro.pacujo.net> Message-ID: On 19 March 2017 at 02:05, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sun, Mar 19, 2017 at 11:39 AM, Steve D'Aprano >> wrote: >>> Is it also ridiculous to use several newlines to space paragraphs >>> vertically? >> >> At least with paragraphs, we don't have eternal debates between people >> who think they should have four newlines, three newlines, or.... oh >> wait, there is debate between two and one.... > > Some people like fluffy source code: > > def f(): > > "doc" > > # Code follows > > x = calculate_some() > > return x + 1 > BTW, this was a good option, if one worked in such text modes where lines are so close to each other, that it was too hard to read anything. So it would be not 'fluffy' but actually normal spacing. Thankfully modern tools allow configuring the line spacing. From garabik-news-2005-05 at kassiopeia.juls.savba.sk Sun Mar 19 12:14:56 2017 From: garabik-news-2005-05 at kassiopeia.juls.savba.sk (garabik-news-2005-05 at kassiopeia.juls.savba.sk) Date: Sun, 19 Mar 2017 16:14:56 +0000 (UTC) Subject: Where to start in the field of AI with Python References: Message-ID: Robert O'Shea wrote: > I just want to get into the basics for the moment, eventually getting into > stuff like machine learning and NLP (Natural Language Processing). You cannot do wrong by starting with NLTK (https://www.nltk.org/) and scikit (http://scikit-learn.org/) -- ----------------------------------------------------------- | Radovan Garab?k http://kassiopeia.juls.savba.sk/~garabik/ | | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk | ----------------------------------------------------------- Antivirus alert: file .signature infected by signature virus. Hi! I'm a signature virus! Copy me into your signature file to help me spread! From mikhailwas at gmail.com Sun Mar 19 12:52:20 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 19 Mar 2017 17:52:20 +0100 Subject: Tabs are a security vulnerabilty [was Re: Who are the "spacists"?] In-Reply-To: <58cdd198$0$1596$c3e8da3$5496439d@news.astraweb.com> References: <58cdd198$0$1596$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 19 March 2017 at 01:32, Steve D'Aprano wrote: > On Sun, 19 Mar 2017 03:30 am, Grant Edwards wrote: > >> tabs are a major security vulnerability and should be outlawed >> in all source code. > > > I've heard many arguments both in favour of and against tabs, but I've never > heard them described as a security vulnerability before. Let alone a major > one. > > Got a citation or some more information? Double that, I've googled and did not find anything. Also it is not clear, since vulnerability can be only for a particular executable that does something with a file, not the file itslef. I've heard some arguments aginst tabs also, but it turned out that most of them are even not real. From steve+python at pearwood.info Sun Mar 19 13:29:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 20 Mar 2017 04:29:22 +1100 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> Message-ID: <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Mar 2017 01:27 am, Grant Edwards wrote: > On 2017-03-18, Nathan Ernst wrote: > >> As I said earlier, where tabs are superior in that most code focused >> editors (at least those worth using) allow you to adjust the width of the >> tab. > > What about all other other text tools that _aren't_ 'code focused > editors'? (e.g. grep, less, cat, awk, sed, a2ps, asciidoc, etc.) I wonder whether the tabs versus spaces divide is closely aligned to the Windows versus Unix/Linux divide? It seems to me that Unix users are typically going to be using Unix tools which often assume spaces are used for indentation, and consequently cope badly with tabs. I maintain that makes them "broken" tools, but broken or not, that's the status quo and Unix users will simply deal with it by using spaces for indents. On the other hand, the typical Windows developer probably has little or no access to grep, less, sed, etc, and consequently doesn't fear using tabs in source code. Since nothing is going to touch it apart from either Notepad or the IDE, there's no problem with using tabs. Back when dinosaurs ruled the earth, and I had a Macintosh (classic OS, not OS X) it was normal to use tabs for indents. Likewise when I had a Windows machine. It was only when I moved to Linux that I had "tabs are bad, m'kay?" beaten into me, with the main justification being "tabs will break your tools". I'm not even sure that it is true that tabs will break the Unix toolset. But Unix users mostly *believe* it is true. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From alain at universite-de-strasbourg.fr.invalid Sun Mar 19 13:34:54 2017 From: alain at universite-de-strasbourg.fr.invalid (Alain Ketterlin) Date: Sun, 19 Mar 2017 18:34:54 +0100 Subject: Who are the "spacists"? References: Message-ID: <87efxt1875.fsf@universite-de-strasbourg.fr.invalid> Jon Ribbens writes: > On 2017-03-18, Grant Edwards wrote: >> On 2017-03-18, Mikhail V wrote: >>> How would one come to the idea to use spaces for indentation at all? >> >> Because tabs are a major security vulnerability and should be outlawed >> in all source code. > > You forgot to mention that tabs are carcinogenic, can be addictive, > and hate our freedoms. If we use them, the terrorists win. Tabs can > settle during transit, and may contain traces of nuts. Tabs should > not be folded, spindled or mutilated. Tabs are vicious if wounded. > Remember, kids: Just Say No to the Invisible Menace. And US government officials call them "alternative spaces". Enough said. -- Alain. P/S: just in case: https://www.jwz.org/doc/tabs-vs-spaces.html From saxri89 at gmail.com Sun Mar 19 13:38:09 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sun, 19 Mar 2017 10:38:09 -0700 (PDT) Subject: python script Non-ASCII character Message-ID: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> hello i have create a python script when read some files using paths and do something with that files. if that paths for files is in english likes this "c:/my_path/english " then python script working but if that paths is in my main language or the path have some blank character then not working and i take that error : SyntaxError: Non-ASCII character '\xce' in file Untitled_.py on line 15, but no encoding declared; can i fix that in python 2.7.13 ? can i find some solution to python read paths in my main language or paths with blanks? From rosuav at gmail.com Sun Mar 19 15:00:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 06:00:33 +1100 Subject: Who are the "spacists"? In-Reply-To: <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 20, 2017 at 4:29 AM, Steve D'Aprano wrote: > I wonder whether the tabs versus spaces divide is closely aligned to the > Windows versus Unix/Linux divide? > > It seems to me that Unix users are typically going to be using Unix tools > which often assume spaces are used for indentation, and consequently cope > badly with tabs. I maintain that makes them "broken" tools, but broken or > not, that's the status quo and Unix users will simply deal with it by using > spaces for indents. Nope. I'm on Linux and I love my tabs. They play fine with grep, diff, etc. None of my tools has a problem with them. ChrisA From rosuav at gmail.com Sun Mar 19 15:07:09 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 06:07:09 +1100 Subject: python script Non-ASCII character In-Reply-To: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> References: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> Message-ID: On Mon, Mar 20, 2017 at 4:38 AM, Xristos Xristoou wrote: > hello i have create a python script when read some files using paths and do something with that files. > if that paths for files is in english likes this "c:/my_path/english " then python script working but if that paths is in my main language or the path have some blank character then not working and i take that error : > > SyntaxError: Non-ASCII character '\xce' in file Untitled_.py on line 15, but no encoding declared; > > can i fix that in python 2.7.13 ? can i find some solution to python read paths in my main language or paths with blanks? Based on your name, I'm guessing your main language is Greek. You might be using a character encoding of ISO-8859-7. Or you might be using UTF-8, which is a universal standard. Either way, the solution is to declare the encoding (as the error hints). The first thing I would recommend is switching to Python 3. This has a number of benefits relating to non-ASCII source code, including that UTF-8 is accepted automatically. That might fix your problem (\xce mentioned in the message is the beginning of the UTF-8 encoding for certain Greek letters), and if it doesn't, you can still declare the encoding to be ISO-8859-7. But go with UTF-8 if you possibly can. ChrisA From saxri89 at gmail.com Sun Mar 19 15:48:04 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sun, 19 Mar 2017 12:48:04 -0700 (PDT) Subject: python script Non-ASCII character In-Reply-To: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> References: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> Message-ID: <5a032175-8e51-407a-aa28-5c1d9fd60918@googlegroups.com> ?? ???????, 19 ??????? 2017 - 7:38:19 ?.?. UTC+2, ? ??????? Xristos Xristoou ??????: how to define my script with encoding of ISO-8859-7 or UTF-8?and for the blanks ? From tjreedy at udel.edu Sun Mar 19 15:50:42 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Mar 2017 15:50:42 -0400 Subject: About linters and PEP-8 In-Reply-To: References: Message-ID: On 3/19/2017 7:20 AM, Chris Angelico wrote: > The tool "pep8" is inappropriately named. No linter should use this > name. It implies a level of authority by linking with a very specific > document. At Guido's request, the name was changed to 'pycodestyle'. See the note at the top of https://pep8.readthedocs.io/en/release-1.7.x/ This really should be noted also at the top of https://pypi.python.org/pypi/pep8/1.7.0 -- Terry Jan Reedy From rosuav at gmail.com Sun Mar 19 15:56:10 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 06:56:10 +1100 Subject: python script Non-ASCII character In-Reply-To: <5a032175-8e51-407a-aa28-5c1d9fd60918@googlegroups.com> References: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> <5a032175-8e51-407a-aa28-5c1d9fd60918@googlegroups.com> Message-ID: On Mon, Mar 20, 2017 at 6:48 AM, Xristos Xristoou wrote: > ?? ???????, 19 ??????? 2017 - 7:38:19 ?.?. UTC+2, ? ??????? Xristos Xristoou ??????: > > how to define my script with encoding of ISO-8859-7 or UTF-8?and for the blanks ? First, try using Python 3. Most of the time, that will be the best solution. I won't explain PEP 263 coding cookies until you've tried that :) ChrisA From rosuav at gmail.com Sun Mar 19 15:57:46 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 06:57:46 +1100 Subject: About linters and PEP-8 In-Reply-To: References: Message-ID: On Mon, Mar 20, 2017 at 6:50 AM, Terry Reedy wrote: > On 3/19/2017 7:20 AM, Chris Angelico wrote: > >> The tool "pep8" is inappropriately named. No linter should use this >> name. It implies a level of authority by linking with a very specific >> document. > > > At Guido's request, the name was changed to 'pycodestyle'. See the note at > the top of > https://pep8.readthedocs.io/en/release-1.7.x/ > > This really should be noted also at the top of > https://pypi.python.org/pypi/pep8/1.7.0 Oh, good. I heard that he requested it, but the place I looked was the PyPI landing page, so it looked like they were still using that name. Sadly, it's still going to be "pip install pep8", isn't it :( ChrisA From tjreedy at udel.edu Sun Mar 19 16:01:54 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Mar 2017 16:01:54 -0400 Subject: python script Non-ASCII character In-Reply-To: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> References: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> Message-ID: On 3/19/2017 1:38 PM, Xristos Xristoou wrote: > hello i have create a python script when read some files using paths and do something with that files. > if that paths for files is in english likes this "c:/my_path/english " then python script working but if that paths is in my main language Non-ascii in a pathname and non-ascii within a file are different issues. On Windows, non-ascii in pathnames did not work consistently until 3.2 or maybe 3.3. > or the path have some blank character then not working This should not be a problem. With 2.7.13: >>> f = open('c:/program files/7-zip/readme.txt') >>> print(f.read()) 7-Zip 9.20 ---------- ... > SyntaxError: Non-ASCII character '\xce' in file Untitled_.py on line 15, but no encoding declared; This is non-ascii within a file. > can i fix that in python 2.7.13 ? can i find some solution to python read paths in my main language or paths with blanks? Chris gave the answer for within-file non-ascii: provide the encoding. -- Terry Jan Reedy From saxri89 at gmail.com Sun Mar 19 16:05:06 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sun, 19 Mar 2017 13:05:06 -0700 (PDT) Subject: python script Non-ASCII character In-Reply-To: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> References: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> Message-ID: <7be219d8-bde7-4f91-8426-810b5ca3d8fc@googlegroups.com> ?? ???????, 19 ??????? 2017 - 7:38:19 ?.?. UTC+2, ? ??????? Xristos Xristoou ??????: yes that i know but i need python 2.7 for my task From saxri89 at gmail.com Sun Mar 19 16:10:20 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Sun, 19 Mar 2017 13:10:20 -0700 (PDT) Subject: python script Non-ASCII character In-Reply-To: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> References: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> Message-ID: ?? ???????, 19 ??????? 2017 - 7:38:19 ?.?. UTC+2, ? ??????? Xristos Xristoou ??????: @Terry non-ascii in pathnames i need for ex :var1="C:\Users\username\Desktop\my language\mylanguage\myfile" and for the blank ? From mikhailwas at gmail.com Sun Mar 19 16:11:31 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 19 Mar 2017 21:11:31 +0100 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: On 18 March 2017 at 22:50, Nathan Ernst wrote: > My issue with using spaces instead of tabs, is that, as mentioned earlier in > the thread, everyone has their own preferences on indentation. I've worked > on teams where different developers used 2, 3 & 4 spaces as indentation. > Obviously, if you're using spaces, several of the members will be unhappy. > > Tabs have the benefit that most editors used by developers allow the > adjustment of the width of a tab. If you use tabs, everyone can be happy > with the visual presentation of their code. > > My rule of thumb: tabs for indentation, spaces for alignment (i.e. trying to > line up anything after a non-whitespace character on a single line). > > Regards, > Nathan > Trying to line up things after a non-whitespace character, e.g. like this? myList = [ ["a", "b", "c"], ["mess up your alignment", "b", "c"], ["a", "b", "c"] ] Well there is no easy solution possible, especially if you want it to look exactly the same on all computers and editors. Before something like elastic tabstops will be a standard, it will continue to confuse people. Spaces are still one of the worst solutions, although it will give same results on monospaced editors. Changing a long string in above example means again ASCII art exercises, and it is not funny. I'd just leave it as is or use tabs, despite they can look different on other editor. Most importang thing, one should just stop thinking 'monospaced'. Monospaced text rendering is an artifact, which exist on a very short time period in history. At best, one should just imagine it should not exist, and is just a temporary inconvinience. Actually it lasts already much longer than I would expect. So for column alignment technically correct IMO are single tabs which are rendered depending on the context, i.e. this is like elastic tabstobs work, IIUC. On the other hand one should not edit spreadsheets in a text editor. If one does a lot of work on tables, then use appropriate softwre, e.g. Excell. Mikhail ine up anything after a non-whitespace character From greg.ewing at canterbury.ac.nz Sun Mar 19 17:47:50 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 20 Mar 2017 10:47:50 +1300 Subject: Who are the "spacists"? In-Reply-To: <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > Unix tools > which often assume spaces are used for indentation, and consequently cope > badly with tabs. I maintain that makes them "broken" tools, They're not broken in the context of Unix, where there is a long-standing convention of assuming tab stops every 8 columns. From that point of view, tabs are not formatting instructions, but are just a way of compressing consecutive spaces. If tabs are used according to that convention, Unix tools cope with them just fine. > I'm not even sure that it is true that tabs will break the Unix toolset. But > Unix users mostly *believe* it is true. Tabs used according to non-Unix conventions will break Unix tools. But that doesn't mean the tools themselves are broken, any more than the fact that putting diesel fuel in a petrol car damages it means that petrol engines are broken. Python is in the awkward position of being expected to run on either petrol or diesel. It copes by requiring a particularly refined form of fuel, i.e. not mixing tabs and spaces. -- Greg From greg.ewing at canterbury.ac.nz Sun Mar 19 17:54:10 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 20 Mar 2017 10:54:10 +1300 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: Mikhail V wrote: > Monospaced text rendering is an artifact, > which exist on a very short time period in history. > At best, one should just imagine it should not exist, and is > just a temporary inconvinience. Actually it lasts already much > longer than I would expect. The fact that it *has* lasted so long might be telling us something. It has some advantages when machine processing text such as source code, where the semantic content is much more important than making it look pretty. -- Greg From orgnut at yahoo.com Sun Mar 19 17:54:37 2017 From: orgnut at yahoo.com (Larry Hudson) Date: Sun, 19 Mar 2017 14:54:37 -0700 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> Message-ID: On 03/18/2017 05:01 PM, Nathan Ernst wrote: [...] > Personally, I dislike any editor that, by default, changes my input to > something else. If I hit tab, I want a tab to be inserted, by default. If I > want something else, I'll change the configuration. > A trivial point (and irrelevant)... The thing I find annoying about an editor set to expand tabs to spaces is that it takes one keypress to indent but four (or whatever) to unindent. -- -=- Larry -=- From jon+usenet at unequivocal.eu Sun Mar 19 18:29:18 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 19 Mar 2017 22:29:18 -0000 (UTC) Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> Message-ID: On 2017-03-19, breamoreboy at gmail.com wrote: > On Sunday, March 19, 2017 at 9:54:52 PM UTC, Larry Hudson wrote: >> A trivial point (and irrelevant)... The thing I find annoying >> about an editor set to expand tabs to spaces is that it takes one >> keypress to indent but four (or whatever) to unindent. > > No, just about every editor that I've ever used has SHIFT-TAB set to > undo whatever TAB does. Not to mention plenty of editors (e.g. vim) will unindent when you press backspace. From p.f.moore at gmail.com Sun Mar 19 18:46:09 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Sun, 19 Mar 2017 15:46:09 -0700 (PDT) Subject: cryptography default_backend is "hazmat"? In-Reply-To: References: Message-ID: <8e450ce8-ea01-4668-99a3-391ddbcdf9ea@googlegroups.com> On Sunday, 19 March 2017 03:16:17 UTC, Arthur Darcet wrote: > On Sat, 18 Mar 2017 at 23:29, Ian Pilcher wrote: > > > On 03/18/2017 05:15 PM, Chris Angelico wrote: > > > So the question is: How well do you trust the examples? Are they > > > likely to be instructing you in a safe way to use this > > > potentially-dangerous module? > > > > But as far as I can tell, there's no way to use many of the non-hazmat > > functions (e.g. parsing a certificate) without a backend, and all of the > > backends are "hazmat". > > > > So what's the point of marking something as hazmat, if a large portion > > of the rest of the module can't be used without it? > > > > If I'm not mistaken, the hazmat module contains functions that are easy to > misuse, which is why they are hazardous. > Using those same functions through the "safe" part of the library isn't > dangerous I do tend to agree with the OP. As someone who *definitely* doesn't claim to be a security expert, I'd prefer to stick solely to the "for non-expert users only" part of the module. As far as I can see, that part includes only: 1. Fernet symmetric encryption, which is fine, but needs me to manage the key safely (and offers no help in doing that) 2. X509, whose docs are a reference (that you need to understand X509 to follow) and a couple of tutorials on generating/requesting keys. Nothing on using X509 for encryption. Some of the "obvious" things I'd like to be able to do (e.g., create a message digest, public key cryptography, hashing passwords for storage) are all in the "hazmat" part of the documentation. So I'm left with the choice of using cryptography and explicitly using parts documented as not suitable for me, or using something else that claims to be robust (but which may not be, depending on whether I trust the author, or prefer to trust the PyCA, who seem to be implying that the subject is too complex for them to be able to provide a non-expert-friendly version, so how come other authors can?) FWIW, for the 3 examples I gave above, quick Google searches found: * message digest - the stdlib hashlib module * public key - pycrypto * password hashes - passlib I have no idea whether these are "acceptable" solutions, but I'd tend to use them in preference to the cryptography library, simply because they don't claim that the functions needed are "dangerous to use". Paul From mikhailwas at gmail.com Sun Mar 19 18:48:40 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 19 Mar 2017 23:48:40 +0100 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: On 19 March 2017 at 22:54, Gregory Ewing wrote: > Mikhail V wrote: >> >> Monospaced text rendering is an artifact, >> which exist on a very short time period in history. >> At best, one should just imagine it should not exist, and is >> just a temporary inconvinience. Actually it lasts already much >> longer than I would expect. > > > The fact that it *has* lasted so long might be telling us > something. It has some advantages when machine processing > text such as source code, where the semantic content is much > more important than making it look pretty. > > -- > Greg If we speak about information reading, e.g. text or Python code, then I don't know of any helpful feature, except that characters are vertically aligned. And the feature is helpful only in this sense that I can align table columns with integer amount of spaces. The readability is however very poor and cannot be remedied with any tricks. Also if one *needs* monospaced for some reason, then one can always render units at equal distances, e.g. to compare two encrypted strings visually, but those are rare specific tasks. Obviously there are some technical advantages, e.g. the algorithms for tiled rendering are much simpler and respectively hardware can be much simpler / more performant. (E.g. tabloid in airport) Or, for example collision detection, which is part of mouse text selection algorithm is much simpler, etc. These are IMO main reasons why it still often used. Sadly, many people believe that a code editor should be monospaced, but generally that does not have any sense. Mikhail From marko at pacujo.net Sun Mar 19 18:50:45 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 20 Mar 2017 00:50:45 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87wpbkhoe2.fsf@elektro.pacujo.net> Gregory Ewing : > Steve D'Aprano wrote: >> Unix tools which often assume spaces are used for indentation, and >> consequently cope badly with tabs. I maintain that makes them >> "broken" tools, > > They're not broken in the context of Unix, where there is a > long-standing convention of assuming tab stops every 8 columns. From > that point of view, tabs are not formatting instructions, but are just > a way of compressing consecutive spaces. If tabs are used according to > that convention, Unix tools cope with them just fine. Correct, the 8-column interpretation is the only defensible use for tabs. However, since that use is completely redundant, better not use them at all. Marko From python at lucidity.plus.com Sun Mar 19 19:01:22 2017 From: python at lucidity.plus.com (Erik) Date: Sun, 19 Mar 2017 23:01:22 +0000 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> Message-ID: <921339c5-a64f-d4b5-c64a-947b47e3afe5@lucidity.plus.com> On 19/03/17 22:29, Jon Ribbens wrote: > On 2017-03-19, breamoreboy at gmail.com wrote: >> On Sunday, March 19, 2017 at 9:54:52 PM UTC, Larry Hudson wrote: >>> A trivial point (and irrelevant)... The thing I find annoying >>> about an editor set to expand tabs to spaces is that it takes one >>> keypress to indent but four (or whatever) to unindent. >> >> No, just about every editor that I've ever used has SHIFT-TAB set to >> undo whatever TAB does. > > Not to mention plenty of editors (e.g. vim) will unindent when you > press backspace. I don't think that's strictly true. If you have just indented with a tab character, then backspace will delete that tab character. But, if you indent with either 4 spaces or use the Tab key with "expandtab" enabled, then it will just delete the right-most space character. The closest I've come to an "unindent" in vim so far is Ctrl-D, which backs up one "shift width's" worth. For sanity, in 'vim', I always use (for my own Python code, at least): :set sw=4 ts=4 expandtabs That way, all tab keypresses insert 4 spaces instead of a tab and the shift operations ('<' and '>') will do the same. This also means the "back up one shift-width" command (Ctrl-D) is the same as a "dedent". If you also use the autoindent setting (:set ai), then writing code is as easy as pressing enter and Tab to start a new suite, enter only to continue a suite, and enter and Ctrl-D to drop back to the outer suite. E. From tjreedy at udel.edu Sun Mar 19 19:01:25 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Mar 2017 19:01:25 -0400 Subject: About linters and PEP-8 In-Reply-To: References: Message-ID: On 3/19/2017 3:57 PM, Chris Angelico wrote: > On Mon, Mar 20, 2017 at 6:50 AM, Terry Reedy wrote: >> On 3/19/2017 7:20 AM, Chris Angelico wrote: >> >>> The tool "pep8" is inappropriately named. No linter should use this >>> name. It implies a level of authority by linking with a very specific >>> document. >> >> >> At Guido's request, the name was changed to 'pycodestyle'. See the note at >> the top of >> https://pep8.readthedocs.io/en/release-1.7.x/ >> >> This really should be noted also at the top of >> https://pypi.python.org/pypi/pep8/1.7.0 > > Oh, good. I heard that he requested it, but the place I looked was the > PyPI landing page, so it looked like they were still using that name. > > Sadly, it's still going to be "pip install pep8", isn't it :( That should get the last pep8 from early 2016. I presume the current pycodestyle needs C:\Users\Terry>py -m pip install pycodestyle Collecting pycodestyle Downloading pycodestyle-2.3.1-py2.py3-none-any.whl (45kB) 100% |????????????????????????????????| 51kB 501kB/s Installing collected packages: pycodestyle Successfully installed pycodestyle-2.3.1 -- Terry Jan Reedy From rosuav at gmail.com Sun Mar 19 19:02:05 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 10:02:05 +1100 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: On Mon, Mar 20, 2017 at 9:48 AM, Mikhail V wrote: > [regarding monospaced text] > Or, for example collision detection, which is part > of mouse text selection algorithm is much simpler, etc. > These are IMO main reasons why it still often used. I work extensively with MUDs, where traditionally ASCII text is monospaced. It's normal to create alignment with spaces, and for tabs to represent eight-space positions (so "abc\td" will take up nine slots of width). But in the world of Unicode, it's not that simple. Some text runs right-to-left, some characters have different widths assigned, some have no width at all. My program has to cope with all of these, including when you use the mouse to select text. Monospacing is not about making it easier for the program; it's about keeping things the way the human expects. I do not ever want my MUDs or my shells to run with classic "proportionally-spaced" fonts, but I do want them to be able to cope with RTL text etc. And they can. ChrisA From marko at pacujo.net Sun Mar 19 19:04:42 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 20 Mar 2017 01:04:42 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> Message-ID: <87shm8hnqt.fsf@elektro.pacujo.net> Larry Hudson : > A trivial point (and irrelevant)... The thing I find annoying about an > editor set to expand tabs to spaces is that it takes one keypress to > indent but four (or whatever) to unindent. In emacs' Python mode, if I have entered: ======================================================================== env.SharedLibrary('custom', [ 'a.c', ? ======================================================================== and press Tab, the cursor moves to the right position: ======================================================================== env.SharedLibrary('custom', [ 'a.c', ? ======================================================================== Now, pressing Backspace once (or Tab once more), I get: ======================================================================== env.SharedLibrary('custom', [ 'a.c', ? ======================================================================== After a second Backspace (or a third Tab): ======================================================================== env.SharedLibrary('custom', [ 'a.c', ? ======================================================================== and so on, 4 columns at a time. I have told emacs not to use HT characters. Marko From python at mrabarnett.plus.com Sun Mar 19 19:06:37 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 19 Mar 2017 23:06:37 +0000 Subject: python script Non-ASCII character In-Reply-To: References: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> Message-ID: <83546177-5fa0-93e5-dc8c-6ad7b214808d@mrabarnett.plus.com> On 2017-03-19 20:10, Xristos Xristoou wrote: > ?? ???????, 19 ??????? 2017 - 7:38:19 ?.?. UTC+2, ? ??????? Xristos Xristoou ??????: > @Terry non-ascii in pathnames i need for ex :var1="C:\Users\username\Desktop\my language\mylanguage\myfile" and for the blank ? > Your choices are: 1. Raw string literals: var1 = r"C:\Users\username\Desktop\my language\mylanguage\myfile" However, the literal shouldn't end with a backslash, so, for example, r"C:\" _won't_ work. 2. Slashes: var1 = "C:/Users/username/Desktop/my language/mylanguage/myfile" 3. Doubled backslashes: var1 = "C:\\Users\\username\\Desktop\\my language\\mylanguage\\myfile" If the path contains non-ASCII characters (for example, Greek letters), it's much better to use Unicode instead. If you're using Unicode string literals, your choices are: 1. Raw string literals: var1 = ur"C:\Users\username\Desktop\? ?????? ???\mylanguage\myfile" However, the literal shouldn't end with a backslash, so, for example, ur"C:\" _won't_ work. 2. Slashes: var1 = u"C:/Users/username/Desktop/? ?????? ???/mylanguage/myfile" 3. Doubled backslashes: var1 = u"C:\\Users\\username\\Desktop\\? ?????? ???\\mylanguage\\myfile" Just remember to specify the encoding as the first or second line: # -*- coding: utf-8 -*- and save the file in that encoding (UTF-8, in this case). From steve+python at pearwood.info Sun Mar 19 19:20:11 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 20 Mar 2017 10:20:11 +1100 Subject: python script Non-ASCII character References: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> <5a032175-8e51-407a-aa28-5c1d9fd60918@googlegroups.com> Message-ID: <58cf122d$0$22142$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Mar 2017 06:48 am, Xristos Xristoou wrote: > ?? ???????, 19 ??????? 2017 - 7:38:19 ?.?. UTC+2, ? ??????? Xristos > Xristoou ??????: > > how to define my script with encoding of ISO-8859-7 or UTF-8?and for the > blanks ? First you need to know whether your editor is saving the file using UTF-8 or ISO-8859-7. What editor are you using? Set your editor to use UTF-8. That is the best option. In your script, put: # -*- coding: utf-8 -*- as the **very first or second** line of the script. It must be at the beginning. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jon+usenet at unequivocal.eu Sun Mar 19 19:23:09 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Sun, 19 Mar 2017 23:23:09 -0000 (UTC) Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> <921339c5-a64f-d4b5-c64a-947b47e3afe5@lucidity.plus.com> Message-ID: On 2017-03-19, Erik wrote: > On 19/03/17 22:29, Jon Ribbens wrote: >> Not to mention plenty of editors (e.g. vim) will unindent when you >> press backspace. > > I don't think that's strictly true. If you have just indented with a tab > character, then backspace will delete that tab character. But, if you > indent with either 4 spaces or use the Tab key with "expandtab" enabled, > then it will just delete the right-most space character. The option you want is "smarttab", then it will behave as I describe. (Or install the "vim-sensible" settings, which I highly recommend.) From rosuav at gmail.com Sun Mar 19 19:26:28 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 10:26:28 +1100 Subject: About linters and PEP-8 In-Reply-To: References: Message-ID: On Mon, Mar 20, 2017 at 10:01 AM, Terry Reedy wrote: >>> At Guido's request, the name was changed to 'pycodestyle'. See the note >>> at >>> the top of >>> https://pep8.readthedocs.io/en/release-1.7.x/ >>> >>> This really should be noted also at the top of >>> https://pypi.python.org/pypi/pep8/1.7.0 >> >> >> Oh, good. I heard that he requested it, but the place I looked was the >> PyPI landing page, so it looked like they were still using that name. >> >> Sadly, it's still going to be "pip install pep8", isn't it :( > > > That should get the last pep8 from early 2016. I presume the current > pycodestyle needs > > C:\Users\Terry>py -m pip install pycodestyle In the docs link you posted, scroll down a bit: https://pep8.readthedocs.io/en/release-1.7.x/intro.html#installation Or maybe that's outdated and also needs to be fixed? ChrisA From steve+python at pearwood.info Sun Mar 19 19:55:07 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 20 Mar 2017 10:55:07 +1100 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> Message-ID: <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Mar 2017 09:50 am, Marko Rauhamaa wrote: > the 8-column interpretation is the only defensible use for > tabs. Oh, that's a law of physics is it? "8 columns per tab" is one of the fundamental mathematical or physical constants baked into the nature of reality, like ? ? 3.14159... e ? 2.71828... Feigenbaum constant ? ? 4.66920... gravitational constant G ? 6.673e-11 N m**2 kg**-2 fine structure constant ? ? 7.297351e-3 etc. And here I was, in my ignorance, thinking that it was a mere convention, something that could trivially be made a config option for those tools which actually needed it: --tabwidth=4 But I guess that's just as silly as redefining ? as 3 exactly. -- Steve 299792.458 km/s ? not just a good idea, it?s the law! From rosuav at gmail.com Sun Mar 19 20:12:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 11:12:58 +1100 Subject: Who are the "spacists"? In-Reply-To: <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 20, 2017 at 10:55 AM, Steve D'Aprano wrote: > Oh, that's a law of physics is it? "8 columns per tab" is one of the > fundamental mathematical or physical constants baked into the nature of > reality, like > > ? ? 3.14159... > e ? 2.71828... > Feigenbaum constant ? ? 4.66920... > gravitational constant G ? 6.673e-11 N m**2 kg**-2 > fine structure constant ? ? 7.297351e-3 > > etc. And here I was, in my ignorance, thinking that it was a mere > convention, something that could trivially be made a config option for > those tools which actually needed it: > > --tabwidth=4 > > But I guess that's just as silly as redefining ? as 3 exactly. Yes. Actually, all of those constants are themselves defined in terms of the width of a tab; if you change a tab to be seven spaces, e would become 2.3785. That's just how the world works. Actually, when I first met tabs, they were defined in centimeters. Aside from the fact that they really should have been defined in millimeters, I fully support that broad concept. (And they weren't defined as "every 2.5 cm" necessarily; the default was for them to repeat, but if you wanted, you could have them at 2.5, then 5.0, then 6.0, then 9.0, etc, etc, etc.) ChrisA From steve+python at pearwood.info Sun Mar 19 20:42:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 20 Mar 2017 11:42:22 +1100 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58cf2571$0$1584$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Mar 2017 06:00 am, Chris Angelico wrote: > On Mon, Mar 20, 2017 at 4:29 AM, Steve D'Aprano > wrote: >> I wonder whether the tabs versus spaces divide is closely aligned to the >> Windows versus Unix/Linux divide? >> >> It seems to me that Unix users are typically going to be using Unix tools >> which often assume spaces are used for indentation, and consequently cope >> badly with tabs. I maintain that makes them "broken" tools, but broken or >> not, that's the status quo and Unix users will simply deal with it by >> using spaces for indents. > > Nope. I'm on Linux and I love my tabs. They play fine with grep, diff, > etc. None of my tools has a problem with them. Hence my comment: "I'm not even sure that it is true that tabs will break the Unix toolset. But Unix users mostly believe it is true." Perhaps I should have specified, *many* Unix users believe. Or "some" Unix users. Or "the guys I work with". Or perhaps "just that one guy": here is JMZ, who says it is "impossible" to do anything with a text file unless you know what a TAB character represents: I just care that two people editing the same file use the same interpretations, and that it's possible to look at a file and know what interpretation of the TAB character was used, because otherwise it's just impossible to read. https://www.jwz.org/doc/tabs-vs-spaces.html Jamie Zawinski is a clever man, but I've read that document probably a dozen times over the years, and I still don't understand it. If I indent something using tab characters: indent 1 indent 2 indent 1 again why does JMZ need to know how many columns *I* choose to use to display this? I could use 4 columns per tab, or 64, and not only is the source text identical but the interpretation in terms of *indent levels* is the same. And that's the only interpretation that really matters: whether something is indented once, or twice, not the physical number of columns that takes up on *my* screen. JMZ's "solution" is to ban TAB characters from source files. I don't understand why he thinks that solves *anything*. If anything, it makes it worse: for example, in the above quoted paragraph, I deliberately indented the quote by *two* indents, not one, but using a spaces. How can JMZ distinguish between "one 8-column indent" and "two 4-column indent" when spaces are used instead of tabs? I don't think you can. I think he is working on the unstated assumption that indentation will never increase by more than one level. If so, then he can easily read: indented text more indented text as a single 8-column indent. And he'll usually be right, until he keeps reading and find: still more indented text outdented by half a level text? I find myself using spaces because it is the path of least resistance, and the tools I use make it tolerable. But for the life of me I still cannot understand the *logical argument* against tabs. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Mar 19 21:01:48 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 12:01:48 +1100 Subject: Who are the "spacists"? In-Reply-To: <58cf2571$0$1584$c3e8da3$5496439d@news.astraweb.com> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58cf2571$0$1584$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 20, 2017 at 11:42 AM, Steve D'Aprano wrote: > Or perhaps "just that one guy": here is JMZ, who says it is "impossible" to > do anything with a text file unless you know what a TAB character > represents: > > I just care that two people editing the same file use the same > interpretations, and that it's possible to look at a file and > know what interpretation of the TAB character was used, because > otherwise it's just impossible to read. > > https://www.jwz.org/doc/tabs-vs-spaces.html > > > Jamie Zawinski is a clever man, but I've read that document probably a dozen > times over the years, and I still don't understand it. If I indent > something using tab characters: > > indent 1 > indent 2 > indent 1 again > > why does JMZ need to know how many columns *I* choose to use to display > this? It's the same problem that you get when you put byte value 97 into a file and it's impossible to know whether you meant for it to be displayed in Courier or Times Roman. When you care about that level of detail, *you're doing it wrong*. Text files are not intended to convey exact pixel arrangements - they're for carrying linguistic information. In a text file, horizontal tab means "move horizontally". It doesn't mean "move eight times the width of one standard character" (which is less standard than a standard drink), and it doesn't mean "move 30mm", and it certainly doesn't mean "move into debate mode against people who use spaces". ChrisA From python at lucidity.plus.com Sun Mar 19 21:18:17 2017 From: python at lucidity.plus.com (Erik) Date: Mon, 20 Mar 2017 01:18:17 +0000 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> <921339c5-a64f-d4b5-c64a-947b47e3afe5@lucidity.plus.com> Message-ID: On 19/03/17 23:23, Jon Ribbens wrote: > On 2017-03-19, Erik wrote: >> On 19/03/17 22:29, Jon Ribbens wrote: >>> Not to mention plenty of editors (e.g. vim) will unindent when you >>> press backspace. >> >> I don't think that's strictly true. If you have just indented with a tab >> character, then backspace will delete that tab character. But, if you >> indent with either 4 spaces or use the Tab key with "expandtab" enabled, >> then it will just delete the right-most space character. > > The option you want is "smarttab", then it will behave as I describe. You're quite right (as was I because you didn't mention it wasn't out-of-the-box functionality ;)). I may well add that setting to my .vimrc, but FWIW, the Ctrl-D thing harks back to the original "vi" which I grew up on, so although I may add that setting, my muscle memory will probably still have me pressing Ctrl-D forever ;) > (Or install the "vim-sensible" settings, which I highly recommend.) I have no interest in making my settings "sensible", thank you very much :D Thanks though - it's always nice to learn another way to hone things just as one likes them ... E. From chenchao at inhand.com.cn Sun Mar 19 22:42:38 2017 From: chenchao at inhand.com.cn (chenchao) Date: Sun, 19 Mar 2017 22:42:38 -0400 Subject: how to corss-compile azure-iot-sdk-python Message-ID: <4008972c-4f71-7102-c0e4-580ed6b3cd5a@inhand.com.cn> Hi: I want to port the 'azure-iot-sdk-python' to my router(arm platform). How can i achieve this? From eryksun at gmail.com Sun Mar 19 22:50:43 2017 From: eryksun at gmail.com (eryk sun) Date: Mon, 20 Mar 2017 02:50:43 +0000 Subject: python script Non-ASCII character In-Reply-To: <83546177-5fa0-93e5-dc8c-6ad7b214808d@mrabarnett.plus.com> References: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> <83546177-5fa0-93e5-dc8c-6ad7b214808d@mrabarnett.plus.com> Message-ID: On Sun, Mar 19, 2017 at 11:06 PM, MRAB wrote: > > If you're using Unicode string literals, your choices are: > > 1. Raw string literals: > > var1 = ur"C:\Users\username\Desktop\? ?????? ???\mylanguage\myfile" Raw unicode literals are practically useless in Python 2. They're not actually raw because \u and \U are still parsed as Unicode escapes, e.g. ur"C:\Users" and ur"C:\users" are syntax errors. > 2. Slashes: > > var1 = u"C:/Users/username/Desktop/? ?????? ???/mylanguage/myfile" I prefer to normalize a path with os.path.normpath, or pathlib.Path in Python 3. This converts slashes to backslashes to get a canonical Windows path. IMO, it's also visually better in a text representation or error messages. Otherwise at runtime joined paths often end up with mixed slashes, which to me is ugly. From tjreedy at udel.edu Sun Mar 19 22:52:49 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Mar 2017 22:52:49 -0400 Subject: About linters and PEP-8 In-Reply-To: References: Message-ID: On 3/19/2017 7:26 PM, Chris Angelico wrote: > In the docs link you posted, scroll down a bit: > > https://pep8.readthedocs.io/en/release-1.7.x/intro.html#installation > > Or maybe that's outdated and also needs to be fixed? It is up to date for the latest outdated 'pep8'. It is needed for someone replicating setups that have not upgraded. There are still occasional downloads for PIL even though essentially superceded by pillow years ago. https://pycodestyle.readthedocs.io/en/latest/ tells how to install the renamed and currently maintained module. -- Terry Jan Reedy From rosuav at gmail.com Sun Mar 19 23:18:45 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 14:18:45 +1100 Subject: About linters and PEP-8 In-Reply-To: References: Message-ID: On Mon, Mar 20, 2017 at 1:52 PM, Terry Reedy wrote: > On 3/19/2017 7:26 PM, Chris Angelico wrote: > >> In the docs link you posted, scroll down a bit: >> >> https://pep8.readthedocs.io/en/release-1.7.x/intro.html#installation >> >> Or maybe that's outdated and also needs to be fixed? > > > It is up to date for the latest outdated 'pep8'. It is needed for someone > replicating setups that have not upgraded. There are still occasional > downloads for PIL even though essentially superceded by pillow years ago. > > https://pycodestyle.readthedocs.io/en/latest/ > tells how to install the renamed and currently maintained module. Gotcha. Maybe the note in the old docs needs to be clearer in saying "this module is now unmaintained - see the new module, install that, yada yada". ChrisA From python at mrabarnett.plus.com Sun Mar 19 23:36:45 2017 From: python at mrabarnett.plus.com (MRAB) Date: Mon, 20 Mar 2017 03:36:45 +0000 Subject: python script Non-ASCII character In-Reply-To: References: <2d71de91-6299-459d-b477-60d8b4cbc0f1@googlegroups.com> <83546177-5fa0-93e5-dc8c-6ad7b214808d@mrabarnett.plus.com> Message-ID: <586f79c3-e0d3-86d6-9321-664c64b6f1b3@mrabarnett.plus.com> On 2017-03-20 02:50, eryk sun wrote: > On Sun, Mar 19, 2017 at 11:06 PM, MRAB wrote: >> >> If you're using Unicode string literals, your choices are: >> >> 1. Raw string literals: >> >> var1 = ur"C:\Users\username\Desktop\? ?????? ???\mylanguage\myfile" > > Raw unicode literals are practically useless in Python 2. They're not > actually raw because \u and \U are still parsed as Unicode escapes, > e.g. ur"C:\Users" and ur"C:\users" are syntax errors. > Thanks for the correction. I haven't used Python 2 for a long time (apart from running the unit tests when I make a new release of the regex module)! >> 2. Slashes: >> >> var1 = u"C:/Users/username/Desktop/? ?????? ???/mylanguage/myfile" > > I prefer to normalize a path with os.path.normpath, or pathlib.Path in > Python 3. This converts slashes to backslashes to get a canonical > Windows path. IMO, it's also visually better in a text representation > or error messages. Otherwise at runtime joined paths often end up with > mixed slashes, which to me is ugly. > From marko at pacujo.net Mon Mar 20 03:01:35 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 20 Mar 2017 09:01:35 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> Message-ID: <878to0h1o0.fsf@elektro.pacujo.net> Steve D'Aprano : > On Mon, 20 Mar 2017 09:50 am, Marko Rauhamaa wrote: > >> the 8-column interpretation is the only defensible use for >> tabs. > > > Oh, that's a law of physics is it? Pretty much. Try printing out your program with lpr, or sending it to the terminal with cat, or opening it with with Firefox. Marko From rosuav at gmail.com Mon Mar 20 03:19:07 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 18:19:07 +1100 Subject: Who are the "spacists"? In-Reply-To: <878to0h1o0.fsf@elektro.pacujo.net> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 20, 2017 at 6:01 PM, Marko Rauhamaa wrote: > Steve D'Aprano : > >> On Mon, 20 Mar 2017 09:50 am, Marko Rauhamaa wrote: >> >>> the 8-column interpretation is the only defensible use for >>> tabs. >> >> >> Oh, that's a law of physics is it? > > Pretty much. Try printing out your program with lpr, or sending it to > the terminal with cat, or opening it with with Firefox. I don't use paper, but I tried cat and Firefox. In each case, the tab characters showed precisely as they should: as indentation. Was it the exact same amount of indentation that showed when I originally wrote the text in my editor? Was it displayed in the same font as my text editor uses? Was the window the same size as that of my text editor? Was the text colour the same everywhere? And do any of these questions even matter? Semantically, indentation is indentation. Obviously there are ridiculous extremes (a tab character probably shouldn't indent by just one pixel, nor should it normally indent by the entire width of a line), but even those should be under the control of the viewer, not the author. I prefer to use tabs in my code precisely *because* they are not defined in a concrete way. The only thing I demand of the display is that a sequence of N tabs be narrower than a sequence of N+1 tabs. ChrisA From arequipeno at gmail.com Mon Mar 20 03:28:12 2017 From: arequipeno at gmail.com (Ian Pilcher) Date: Mon, 20 Mar 2017 02:28:12 -0500 Subject: cryptography default_backend is "hazmat"? In-Reply-To: <8e450ce8-ea01-4668-99a3-391ddbcdf9ea@googlegroups.com> References: <8e450ce8-ea01-4668-99a3-391ddbcdf9ea@googlegroups.com> Message-ID: On 03/19/2017 05:46 PM, Paul Moore wrote: > 1. Fernet symmetric encryption, which is fine, but needs me to manage > the key safely (and offers no help in doing that) 2. X509, whose docs > are a reference (that you need to understand X509 to follow) and a > couple of tutorials on generating/requesting keys. Nothing on using > X509 for encryption. Actually, even loading an X.509 certificate from a PEM file requires a backend, which means delving into the "hazmat" area. I'm not saying that some crypto functions require careful handling; they obviously do. But is default_backend one of them? -- ======================================================================== Ian Pilcher arequipeno at gmail.com -------- "I grew up before Mark Zuckerberg invented friendship" -------- ======================================================================== From marko at pacujo.net Mon Mar 20 03:37:25 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 20 Mar 2017 09:37:25 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> Message-ID: <874lyoh00a.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Mar 20, 2017 at 6:01 PM, Marko Rauhamaa wrote: >> Pretty much. Try printing out your program with lpr, or sending it to >> the terminal with cat, or opening it with with Firefox. > > I don't use paper, but I tried cat and Firefox. In each case, the tab > characters showed precisely as they should: as indentation. Was it the > exact same amount of indentation that showed when I originally wrote > the text in my editor? Was it displayed in the same font as my text > editor uses? Was the window the same size as that of my text editor? > Was the text colour the same everywhere? And do any of these questions > even matter? Those questions do matter when you mix whitespace and tabs, as well as in cases like these: call_some_function(1, 2, 3) The tools I mentioned honor the traditional tab stop columns: 1, 9, 17, 25, 33, 41, 49, 57, 65, 73 > Semantically, indentation is indentation. The presence of a HT code point in a plain text file is not a semantic marker for indentation. It is a silly, traditional compression scheme for whitespace. > I prefer to use tabs in my code precisely *because* they are not > defined in a concrete way. If you ever had to review C source code pull requests where tabs and spaces alternate randomly... Marko From rosuav at gmail.com Mon Mar 20 04:15:14 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 19:15:14 +1100 Subject: Who are the "spacists"? In-Reply-To: <874lyoh00a.fsf@elektro.pacujo.net> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 20, 2017 at 6:37 PM, Marko Rauhamaa wrote: >> I don't use paper, but I tried cat and Firefox. In each case, the tab >> characters showed precisely as they should: as indentation. Was it the >> exact same amount of indentation that showed when I originally wrote >> the text in my editor? Was it displayed in the same font as my text >> editor uses? Was the window the same size as that of my text editor? >> Was the text colour the same everywhere? And do any of these questions >> even matter? > > Those questions do matter when you mix whitespace and tabs, as well as > in cases like these: > > call_some_function(1, > 2, > 3) > > The tools I mentioned honor the traditional tab stop columns: > > 1, 9, 17, 25, 33, 41, 49, 57, 65, 73 (Point of clarity: "whitespace" is a general term that covers U+0020 SPACE, U+0009 CHARACTER TABULATION, U+000A LINE FEED, U+2008 PUNCTUATION SPACE, and others. You're talking about mixing *spaces* and tabs.) That means that you were depending, in your source file, on something that isn't actually part of the character's definition. You're depending on "horizontal tab" meaning those exact tab stops. If you want those semantics, you should use spaces - or better still, *change your needs* and don't align things like that. In far too many fonts, this simply won't work. (It was only from context that I figured out that that's what you were even aiming for. It didn't work in my email.) >> Semantically, indentation is indentation. > > The presence of a HT code point in a plain text file is not a semantic > marker for indentation. It is a silly, traditional compression scheme > for whitespace. Only if you truly expect and assume that. Can you show me a standards document that says "the meaning of this byte/character value is this sequence of this other byte/character"? >> I prefer to use tabs in my code precisely *because* they are not >> defined in a concrete way. > > If you ever had to review C source code pull requests where tabs and > spaces alternate randomly... Yes, and if you've ever had to review source code pull requests where the letters "q" and "e" were used interchangeably, you'd also be appalled. The different kinds of whitespace have different semantic meanings, and while I'm sympathetic to the desire to stick to ASCII where possible (resulting in a pair of newlines often being used to represent a paragraph, where semantically U+2029 PARAGRAPH SEPARATOR would be more appropriate), I believe that the meanings of different characters should be respected. You wouldn't separate words in a sentence with form-feeds; nor should you mix tabulation and space characters to create indentation. ChrisA From Avon at f101.n1.z21.fsxnet Mon Mar 20 04:39:04 2017 From: Avon at f101.n1.z21.fsxnet (Avon) Date: Mon, 20 Mar 2017 20:39:04 +1200 Subject: Python BBS (and more) Message-ID: <20507560@f101.n1.z21.fsxnet> Hi all. Just a FYI that a new Wiki has been started at wiki.bbs.geek.nz which aims to provide helpful information to bulletin board system (BBS) developers and users. It's a work in progress with a growing number of contributors that include tutorials related to coding a BBS using Python and another using Crystal. There are also links to other open source and closed source BBS platforms under active development in 2017 The FTN style network that is sponsoring these efforts and being used as a place for online discussions (echoarea FSX_BBS) is called fsxNet. If you would like to know more visit bbs.geek.nz or grab an infopack at bbs.geek.nz/fsxnet.zip Best, Paul From marko at pacujo.net Mon Mar 20 05:56:13 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 20 Mar 2017 11:56:13 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> Message-ID: <87r31sz2yq.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Mar 20, 2017 at 6:37 PM, Marko Rauhamaa wrote: >> The tools I mentioned honor the traditional tab stop columns: >> >> 1, 9, 17, 25, 33, 41, 49, 57, 65, 73 > > (Point of clarity: "whitespace" is a general term that covers U+0020 > SPACE, U+0009 CHARACTER TABULATION, U+000A LINE FEED, U+2008 > PUNCTUATION SPACE, and others. You're talking about mixing *spaces* > and tabs.) > > That means that you were depending, in your source file, on something > that isn't actually part of the character's definition. Those tab stops are a 40-year-old de-facto UNIX standard. > You're depending on "horizontal tab" meaning those exact tab stops. Not me. All terminal emulators, editors, text utils etc honor the convention out of the box. No wonder then that C source code files have consecutive lines indented randomly: HT SPC HT SPC SPC SPC SPC HT etc. The tools show no visible difference between those variants, so you can't blame the developers for being inconsistent. > If you want those semantics, you should use spaces - That is precisely what we have done: HT is banished (except in Makefiles, but we have banished Makefiles as well...). > or better still, *change your needs* and don't align things like that. > In far too many fonts, this simply won't work. You must use fixed-width fonts even in the absense of HT's. Try RFC 793, for example: TCP Header Format 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Port | Destination Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Sequence Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Acknowledgment Number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Data | |U|A|P|R|S|F| | | Offset| Reserved |R|C|S|S|Y|I| Window | | | |G|K|H|T|N|N| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Checksum | Urgent Pointer | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | data | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Those kinds of ASCII graphics diagrams are commonplace in source code comments. > (It was only from context that I figured out that that's what you were > even aiming for. It didn't work in my email.) When participating in technical discussions, I strongly recommend using a fixed-width font. For example: ===== ===== ======= A B A and B ===== ===== ======= False False False True False False False True False True True True ===== ===== ======= >> The presence of a HT code point in a plain text file is not a >> semantic marker for indentation. It is a silly, traditional >> compression scheme for whitespace. > > Only if you truly expect and assume that. Can you show me a standards > document that says "the meaning of this byte/character value is this > sequence of this other byte/character"? I already mentioned three examples: lpr, cat on a terminal and Firefox. Ultimately, it's the terminals that dictate the de-facto standard. I bet some terminal emulators support ANSI escape sequences to set the tab stops to arbitrary columns, but nobody uses that type-writer-era mechanism. >> If you ever had to review C source code pull requests where tabs and >> spaces alternate randomly... > > Yes, and if you've ever had to review source code pull requests where > the letters "q" and "e" were used interchangeably, you'd also be > appalled. Huh? I'm talking about a real issue. I'm surprised you haven't run into it. > The different kinds of whitespace have different semantic meanings, Only in your head (and Makefiles). Marko From rosuav at gmail.com Mon Mar 20 06:15:21 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Mar 2017 21:15:21 +1100 Subject: Who are the "spacists"? In-Reply-To: <87r31sz2yq.fsf@elektro.pacujo.net> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> <87r31sz2yq.fsf@elektro.pacujo.net> Message-ID: On Mon, Mar 20, 2017 at 8:56 PM, Marko Rauhamaa wrote: > All terminal emulators, editors, text utils etc honor the > convention out of the box. No wonder then that C source code files have > consecutive lines indented randomly: > > HT > SPC HT > SPC SPC SPC SPC HT > > etc. The tools show no visible difference between those variants, so you > can't blame the developers for being inconsistent. Actually you can, for the same reason that you expect programmers to use ASCII Latin to write language keywords, not other symbols that happen to look identical. >> If you want those semantics, you should use spaces - > > That is precisely what we have done: HT is banished (except in > Makefiles, but we have banished Makefiles as well...). > >> or better still, *change your needs* and don't align things like that. >> In far too many fonts, this simply won't work. > > You must use fixed-width fonts even in the absense of HT's. > [chomp examples] Yes, there are good reasons for using monospaced fonts for certain types of documents. But if those documents have been created correctly, they won't be mixing tabs and spaces to achieve that alignment - they'll be using spaces exclusively. >>> The presence of a HT code point in a plain text file is not a >>> semantic marker for indentation. It is a silly, traditional >>> compression scheme for whitespace. >> >> Only if you truly expect and assume that. Can you show me a standards >> document that says "the meaning of this byte/character value is this >> sequence of this other byte/character"? > > I already mentioned three examples: lpr, cat on a terminal and Firefox. > Ultimately, it's the terminals that dictate the de-facto standard. Do they actually document that its meaning is strictly as you describe? On all of my terminals, a tab is *NOT* the same thing as X spaces - for example, highlighting with the mouse will grab the entire tab as a single character, and will copy it to the clipboard as a character. Also, check out 'man tabs'. It's trivially easy to tell the terminal to use a different set of tab stops, and catting a file will look different. Notice that I didn't say "reconfigure cat". It's not cat that does this - it's only the terminal, and I suspect that every modern terminal on every POSIX system supports it (since the 'tabs' command is itself part of POSIX). What 'lpr' does with tabs I don't know, because paper is an archaic data transmission format that I use only when absolutely necessary (such as when sending information off to the gummint). Firefox... what's the betting that it can be configured too, maybe with CSS? > I bet some terminal emulators support ANSI escape sequences to set the > tab stops to arbitrary columns, but nobody uses that type-writer-era > mechanism. Probably not. Most people would use the tabs(1) command instead. >>> If you ever had to review C source code pull requests where tabs and >>> spaces alternate randomly... >> >> Yes, and if you've ever had to review source code pull requests where >> the letters "q" and "e" were used interchangeably, you'd also be >> appalled. > > Huh? I'm talking about a real issue. I'm surprised you haven't run into > it. Maybe I have, and just rejected the PR out of hand. It certainly isn't something that I am forced to wrestle with. Every PR that I have accepted has been internally consistent (either all tabs or all spaces). >> The different kinds of whitespace have different semantic meanings, > > Only in your head (and Makefiles). And in the Unicode specifications, and in a lot of other people's heads. But you're welcome to reject all that too. ChrisA From mal at europython.eu Mon Mar 20 06:32:03 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 20 Mar 2017 11:32:03 +0100 Subject: EuroPython 2017: We have liftoff! Message-ID: <399ae331-030d-460d-58fc-3dfdd4955a09@europython.eu> We are excited to announce the launch of the EuroPython 2017 website: *** http://ep2017.europython.eu/ *** The EuroPython conference will take place in sunny Rimini, Italy, this year, from July 9 - 16. EuroPython 2017 - The European Python Conference ------------------------------------------------ Here?s an overview of what you can expect in Rimini: We will start with a Beginner?s Day workshop and a Django Girls workshop on Sunday, July 9. The main 5 conference days follow, packed with keynotes, talks, training sessions, help desks, interactive sessions, panels and poster sessions. A complete PyData EuroPython is included as well. The two weekend days after the conference, July 15 and 16, are reserved for sprints. Overall, we will again have 8 days worth of great Python content, arranged in over 200 sessions, waiting for you. In short: * Sunday, July 9: Beginners? Day Workshop and other workshops * Monday - Friday, July 10-14: Conference talks, keynotes, training * Saturday, Sunday, July 15-16: Sprints Meet our sponsors ----------------- All this would not be possible without the generous help of our launch sponsors: * Intel * CFM * Facebook * Microsoft * numberly * criteo labs * JetBrains * Kiwi.com * yelp * 2ndQuadrant * TrustYou * demonware * Riverbank * Plone Foundation In the coming days, we will announce the start of the Call for Proposals and Early Bird Ticket sales. Please watch our EuroPython blog for updates. https://ep2017.europython.eu/social-media/ Enjoy, ? EuroPython 2017 Team http://ep2017.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/843769909796655104 Thanks. From daiyueweng at gmail.com Mon Mar 20 07:36:17 2017 From: daiyueweng at gmail.com (Daiyue Weng) Date: Mon, 20 Mar 2017 11:36:17 +0000 Subject: How to package my project and make it ready to be installed by using pip Message-ID: Hi, I using Python 3.5.2 on Linux Mint 18.1, and I am wondering how to package my PyCharm Python project as a module so that it can installed by someone else by using pip. Like what tools and script I need to use or write in order to do that. cheers From zondo42 at gmail.com Mon Mar 20 07:50:44 2017 From: zondo42 at gmail.com (Glenn Hutchings) Date: Mon, 20 Mar 2017 04:50:44 -0700 (PDT) Subject: How to package my project and make it ready to be installed by using pip In-Reply-To: References: Message-ID: <73e47f28-7bcc-4319-bdee-0c6d176c041a@googlegroups.com> On Monday, 20 March 2017 11:36:34 UTC, Daiyue Weng wrote: > Hi, I using Python 3.5.2 on Linux Mint 18.1, and I am wondering how to > package my PyCharm Python project as a module so that it can installed by > someone else by using pip. Like what tools and script I need to use or > write in order to do that. A good place to start is https://packaging.python.org. From marko at pacujo.net Mon Mar 20 09:30:39 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 20 Mar 2017 15:30:39 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> <87r31sz2yq.fsf@elektro.pacujo.net> Message-ID: <87mvcgyt1c.fsf@elektro.pacujo.net> Chris Angelico : > On Mon, Mar 20, 2017 at 8:56 PM, Marko Rauhamaa wrote: >> I bet some terminal emulators support ANSI escape sequences to set >> the tab stops to arbitrary columns, but nobody uses that >> type-writer-era mechanism. > > Probably not. Most people would use the tabs(1) command instead. >From "man tabs": Use "-8" to set tabs to the standard interval. I'd argue most people never touch the standard interval. >>> The different kinds of whitespace have different semantic meanings, >> >> Only in your head (and Makefiles). > > And in the Unicode specifications, Unicode was 25 years late to the game, but please point me to the paragraph anyway. Marko From rosuav at gmail.com Mon Mar 20 09:49:49 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Mar 2017 00:49:49 +1100 Subject: Who are the "spacists"? In-Reply-To: <87mvcgyt1c.fsf@elektro.pacujo.net> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> <87r31sz2yq.fsf@elektro.pacujo.net> <87mvcgyt1c.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 21, 2017 at 12:30 AM, Marko Rauhamaa wrote: >> And in the Unicode specifications, > > Unicode was 25 years late to the game, but please point me to the > paragraph anyway. 3.3, D3 Character semantics: The semantics of a character are determined by its identity, normative properties, and behavior. That's the best I can find for you. The best statement that says "hey you idiot, a character's name indicates the intended semantics of that character". If U+0009's name were "SHORTER ENCODED FORM FOR SEQUENCE OF SPACES", then I might be prepared to believe you. But it isn't. It's "CHARACTER TABULATION". Does the specification really need to say "don't be a fool"? ChrisA From steve+python at pearwood.info Mon Mar 20 10:20:12 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 21 Mar 2017 01:20:12 +1100 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> <87r31sz2yq.fsf@elektro.pacujo.net> <87mvcgyt1c.fsf@elektro.pacujo.net> Message-ID: <58cfe51d$0$1622$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Mar 2017 12:30 am, Marko Rauhamaa wrote: > Unicode was 25 years late to the game I don't understand that comment. Are you suggesting that the oldest convention wins? The Unix 8-column convention is older than Unicode, so it wins? Well... in that case, there are tab conventions that pre-date Unix, e.g. those used by COBOL. The tabs command offers them as pre-defined standards. >From the man page: -c 1,8,12,16,20,55 COBOL, normal format. But wait... before there was COBOL, there were *typewriters*. Its been many years since I've had my hands on a manual typewriter, but if I remember correctly the standard default tab setting was 1 inch. So there you go. Unix was 50+ years late to the game. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From bc at freeuk.com Mon Mar 20 10:24:27 2017 From: bc at freeuk.com (BartC) Date: Mon, 20 Mar 2017 14:24:27 +0000 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> Message-ID: On 20/03/2017 08:15, Chris Angelico wrote: > On Mon, Mar 20, 2017 at 6:37 PM, Marko Rauhamaa wrote: >> The tools I mentioned honor the traditional tab stop columns: >> >> 1, 9, 17, 25, 33, 41, 49, 57, 65, 73 > That means that you were depending, in your source file, on something > that isn't actually part of the character's definition. You're > depending on "horizontal tab" meaning those exact tab stops. If you > want those semantics, you should use spaces There are effectively two versions of the text: the slightly higher level, or 'marked up' version containing these special controls, and the 'rendered' version you see displayed on the screen. You're suggesting doing away with the controls, working only with the rendered snapshot version. Which means instead of pressing Backspace once to delete a tab, you might need to press it 8 times, or 1 to 8 times if not at the start. This is little different to inserting hard newlines at the end of each visible line of a paragraph, to ensure that it is shown how you want it and isn't 'reflowed' depending on the width of someone's display. Which work great - until you have to edit the text with those newlines present, which can be a lot of work. So really you want to keep and work with the original version, not the rendered one. In the case of tabs, it might be possible to take the rendered text (I call it 'flat' text because the tabs have been flattened out) and reconstruct the tabs, but there are some problems (are those 8 spaces one tab, or two or four, or were they just 8 spaces?). It might be a little easier if the text represented, say, Python source code. But it would be better IMO if tabs were used, with some scheme for suggesting the tab width (or set of tab stops) that is recommended (eg. a comment at the top). -- bartc From rosuav at gmail.com Mon Mar 20 10:32:28 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Mar 2017 01:32:28 +1100 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 21, 2017 at 1:24 AM, BartC wrote: > But it would be better IMO if tabs were used, with some scheme for > suggesting the tab width (or set of tab stops) that is recommended (eg. a > comment at the top). If you absolutely have to, then sure, put a directive in some machine-readable way at the top or bottom of the file. It's like the coding cookie that Python follows - some editors also respect it. But I would prefer to just use tabs *without* suggesting a width, because each one represents *one indent*. Not a number of spaces. One indentation level. ChrisA From davidgshi at yahoo.co.uk Mon Mar 20 10:53:29 2017 From: davidgshi at yahoo.co.uk (David Shi) Date: Mon, 20 Mar 2017 14:53:29 +0000 (UTC) Subject: How to search out all Zip codes and replace with the first 2 digits, in a Pandas dataframe, with the use of regex? References: <403347784.6411726.1490021609515.ref@mail.yahoo.com> Message-ID: <403347784.6411726.1490021609515@mail.yahoo.com> Hi, there, Can anyone help? How to search out all Zip codes and replace with the first 2 digits, in a Pandas dataframe, with the use of regex? For instance, a ZIP code 33132 was found and replaced with 33. Looking forward to hearing from you. Regards. David From bc at freeuk.com Mon Mar 20 11:19:47 2017 From: bc at freeuk.com (BartC) Date: Mon, 20 Mar 2017 15:19:47 +0000 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> Message-ID: On 20/03/2017 14:32, Chris Angelico wrote: > On Tue, Mar 21, 2017 at 1:24 AM, BartC wrote: >> But it would be better IMO if tabs were used, with some scheme for >> suggesting the tab width (or set of tab stops) that is recommended (eg. a >> comment at the top). > > If you absolutely have to, then sure, put a directive in some > machine-readable way at the top or bottom of the file. It's like the > coding cookie that Python follows - some editors also respect it. But > I would prefer to just use tabs *without* suggesting a width, because > each one represents *one indent*. Not a number of spaces. One > indentation level. For leading tabs at the start of a new statement that wouldn't be a problem. Changing the tab width shown just spreads out statements more, or less, horizontally. It works - there is no jarring misalignment - because each tab corresponds to the same N spaces, whatever N happens to be. But tabs are also used after statements, before comments for example, or to line up elements in tables. Then it doesn't work, because tabs may represent 1 to N spaces: Using N=4, with 1 tab before each number: (one, 1), #comment 1 (two, 2), #comment 2 (three, 3), #comment 3 Displayed using N=3: (one, 1), #comment 1 (two, 2), #comment 2 (three, 3), #comment 3 Displayed using N=6: (one, 1), #comment 1 (two, 2), #comment 2 (three, 3), #comment 3 Even tabs at the start of a line are sometimes using to line things up with a previous line; here with N=4, and 5 tabs before B and C: longfunctionname ( A, #comment 1 B, #comment 2 C) #comment 3 With N=2: longfunctionname ( A, #comment 1 B, #comment 2 C) #comment 3 With N=8: longfunctionname ( A, #comment 1 B, #comment 2 C) #comment 3 -- bartc From rosuav at gmail.com Mon Mar 20 11:32:55 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Mar 2017 02:32:55 +1100 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> Message-ID: On Tue, Mar 21, 2017 at 2:19 AM, BartC wrote: > But tabs are also used after statements, before comments for example, or to > line up elements in tables. Then it doesn't work, because tabs may represent > 1 to N spaces: > > Using N=4, with 1 tab before each number: > > (one, 1), #comment 1 > (two, 2), #comment 2 > (three, 3), #comment 3 > > Displayed using N=3: > > (one, 1), #comment 1 > (two, 2), #comment 2 > (three, 3), #comment 3 > > Displayed using N=6: > > (one, 1), #comment 1 > (two, 2), #comment 2 > (three, 3), #comment 3 > > Even tabs at the start of a line are sometimes using to line things up with > a previous line; here with N=4, and 5 tabs before B and C: > > longfunctionname ( A, #comment 1 > B, #comment 2 > C) #comment 3 > > With N=2: > > longfunctionname ( A, #comment 1 > B, #comment 2 > C) #comment 3 > > With N=8: > > longfunctionname ( A, #comment 1 > B, #comment 2 > C) #comment 3 My points here are the same as for the other examples: 1) Preferably, don't do it at all. 2) If you absolutely have to do it, then by definition you're counting character slots, so use spaces, not tabs. Note that PEP 8 specifically forbids one of these kinds of usages: """ More than one space around an assignment (or other) operator to align it with another. Yes: x = 1 y = 2 long_variable = 3 No: x = 1 y = 2 long_variable = 3 """ The reasoning behind this also applies to most of the other forms: you're fiddling with formatting in ways that have to be forever fiddled with as you make edits. Here's a suggestion: Use a single tab after a statement and before the hash. Exactly one tab. Then configure your editor to right-align that. If someone else's editor doesn't right-align, no big deal, and you'll get some measure of alignment anyway (eg if tabs are every eight spaces, it rounds the alignment off to the next eight-mark); it won't hurt anything, as those of us who don't care about the alignment won't be bothered anyway. ChrisA From toby at tobiah.org Mon Mar 20 11:40:34 2017 From: toby at tobiah.org (Tobiah) Date: Mon, 20 Mar 2017 08:40:34 -0700 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: > I wonder whether the tabs versus spaces divide is closely aligned to the > Windows versus Unix/Linux divide? > > It seems to me that Unix users are typically going to be using Unix tools > which often assume spaces are used for indentation, and consequently cope > badly with tabs. I can't think of any classic Unix tool that behaves in a way that would support this point of view. From random832 at fastmail.com Mon Mar 20 11:54:45 2017 From: random832 at fastmail.com (Random832) Date: Mon, 20 Mar 2017 11:54:45 -0400 Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: <1490025285.1155445.917284336.67A94C1E@webmail.messagingengine.com> On Sun, Mar 19, 2017, at 18:48, Mikhail V wrote: > Sadly, many people believe that a code editor > should be monospaced, but generally that does not > have any sense. It's also a bit self-reinforcing because there aren't many good coding fonts that are proportional. And in fact there are issues for coding usability in proportional fonts that aren't even present for monospaced fonts. Confusables like lI1| O0 are only the beginning of the story. If , and ' are only one pixel wide each, it's hard to tell which order they are in. And in many proportional fonts it is difficult or impossible to distinguish '' from ". Other issues also exist, such as """ having more space between the ticks of a single character than between characters, looking more like '""'. @ and % and sometimes # are too wide and too short. Minus is too narrow, too thick, and too low owing to its design as a hyphen (U+2212 is usually nicer, but not used in programming languages). < and > are wide and low, which works great as relational operators but makes them visually unpleasant as brackets - and >= doesn't look nice either. {} are often too tall, too narrow, and a little bit too curly. So people try coding in the proportional fonts available on their systems and rightly note how ugly it is. From robin at reportlab.com Mon Mar 20 12:32:05 2017 From: robin at reportlab.com (Robin Becker) Date: Mon, 20 Mar 2017 16:32:05 +0000 Subject: cross python version randomness Message-ID: <5e23aa27-a14f-0be6-d5f9-7d780b01a01b@chamonix.reportlab.co.uk> Is there a way to get the same sequences of random numbers in python 2.7 and python >= 3.3? I notice that this simple script produces different values in python 2.7 and >=3.3 C:\code\hg-repos\reportlab>cat s.py import sys, random print(sys.version) random.seed(103) for i in range(5): print(i, random.randint(10,25)) C:\code\hg-repos\reportlab>\python27\python s.py 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] 0 25 1 17 2 21 3 21 4 13 C:\code\hg-repos\reportlab>\python33\python s.py 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 64 bit (AMD64)] 0 24 1 16 2 12 3 13 4 22 However, when I use random.random() all seems to be the same so this script C:\code\hg-repos\reportlab>cat u.py import sys, random print(sys.version) random.seed(103) for i in range(5): print(i, random.random()) seems to be fine C:\code\hg-repos\reportlab>\python27\python u.py 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] (0, 0.9790501200727744) (1, 0.45629827629184827) (2, 0.7188470341002364) (3, 0.7348862425853395) (4, 0.21490166849706338) C:\code\hg-repos\reportlab>\python33\python u.py 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 64 bit (AMD64)] 0 0.9790501200727744 1 0.45629827629184827 2 0.7188470341002364 3 0.7348862425853395 4 0.21490166849706338 presumably randint is doing something different to get its values. -- Robin Becker From daiyueweng at gmail.com Mon Mar 20 12:37:37 2017 From: daiyueweng at gmail.com (Daiyue Weng) Date: Mon, 20 Mar 2017 16:37:37 +0000 Subject: How to package my project and make it ready to be installed by using pip In-Reply-To: References: <73e47f28-7bcc-4319-bdee-0c6d176c041a@googlegroups.com> Message-ID: I have been Python Packaging User Guide , and I created a setup.py in my PyCharm project root, from setuptools import setup, find_packages from os import path here = path.abspath(path.dirname(__file__)) packages = find_packages(exclude=['contrib', 'docs', 'tests*']) setup( name='lumar_stackdriver_logging', description='A sample Python project', author='project_dev', author_email='pypa-dev at googlegroups.com', # Choose your license license='GNU GPL', # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ # How mature is this project? Common values are # 3 - Alpha # 4 - Beta # 5 - Production/Stable 'Development Status :: 3 - Alpha', # Indicate who your project is intended for 'Intended Audience :: Project Developers', 'Topic :: System :: Logging', # Pick your license as you wish (should match "license" above) 'License :: OSI Approved :: GNU General Public License (GPL)', # Specify the Python versions you support here. In particular, ensure # that you indicate whether you support Python 2, Python 3 or both. # 'Programming Language :: Python :: 3', # 'Programming Language :: Python :: 3.2', # 'Programming Language :: Python :: 3.3', # 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', ], # What does your project relate to? keywords='sample setuptools development', # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). packages=packages, ) I uploaded/committed the project into a Git repo/BitBucket, what I want is anyone who can access the repo, can deploy the project from the repo to their machines using pip. I am wondering how to achieve that? Many thanks On 20 March 2017 at 11:57, Daiyue Weng wrote: > thanks, i am reading it. > > On 20 March 2017 at 11:50, Glenn Hutchings wrote: > >> On Monday, 20 March 2017 11:36:34 UTC, Daiyue Weng wrote: >> > Hi, I using Python 3.5.2 on Linux Mint 18.1, and I am wondering how to >> > package my PyCharm Python project as a module so that it can installed >> by >> > someone else by using pip. Like what tools and script I need to use or >> > write in order to do that. >> >> A good place to start is https://packaging.python.org. >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > From saxri89 at gmail.com Mon Mar 20 13:05:23 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Mon, 20 Mar 2017 10:05:23 -0700 (PDT) Subject: relative paths connect using python Message-ID: i have a little confused problem. i want to store some paths from images using python 2.7 in windows 10. i have some relative path like this var1='C:/my/store/path' and in the final folder where in my example is the name 'path' inside that folder i have some images like this : -path -myimage_1010_im.png -myimage_1010_im1.png -myimage_1010_im3.png -myimage_1020_im.png -myimage_1020_im1.png can i connect my relative path like var1 with the images using only the number of the mid name of images and finaly i take the full original path like this var1='C:/my/store/path/myimage_1010_im.png' ? i try something but not work import os cwd = os.getcwd() path = os.path.join(cwd, "my_file") From jladasky at itu.edu Mon Mar 20 13:05:54 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Mon, 20 Mar 2017 10:05:54 -0700 (PDT) Subject: Who are the "spacists"? In-Reply-To: References: <85shmbfd0o.fsf@benfinney.id.au> <0cbf3858-c162-dee4-1018-5007e32d80b3@posteo.de> Message-ID: <7890ea4c-1b57-4798-ad4c-3cfe48a98011@googlegroups.com> On Sunday, March 19, 2017 at 1:11:45 PM UTC-7, Mikhail V wrote: > Trying to line up things after a non-whitespace character, e.g. like this? > > myList = [ > ["a", "b", "c"], > ["mess up your alignment", "b", "c"], > ["a", "b", "c"] > ] > > Well there is no easy solution possible, especially if you want it > to look exactly the same on all computers and editors. > Before something like elastic tabstops will be a standard, > it will continue to confuse people. > Spaces are still one of the worst solutions, although it will > give same results on monospaced editors. This is a good example of exactly WHY I continue to write code using monospaced fonts, and spaces for indentation. The results are unambiguous. If I want vertical alignment between specific characters in different rows, I can have it. I am not only interested in the indentation of the first character in a line of code. Yes, sometimes I have to adjust the spacing manually, but I can live with that. Now, my word-processing documents make full use of styles, and in that context I've transcended tabs completely. For casual documents I might find myself falling back into the email-like habit of pushing "Enter" twice between paragraphs. But when it's time to get serious, I define an appropriate paragraph style. I have read about elastic tabstops. If they become a standard and address my needs (it looks like they should), I will be happy to switch. If you want to make your head spin, investigate how to represent polyphonic musical notation in a data structure that ensures it will be drawn accurately on staff paper, as well as played correctly by a synthesizer. Code is child's play by comparison. From daiyueweng at gmail.com Mon Mar 20 13:20:32 2017 From: daiyueweng at gmail.com (Daiyue Weng) Date: Mon, 20 Mar 2017 17:20:32 +0000 Subject: How to package my project and make it ready to be installed by using pip In-Reply-To: References: <73e47f28-7bcc-4319-bdee-0c6d176c041a@googlegroups.com> Message-ID: If I tried pip3 install git+https://user_name at bitbucket.org/user_name/project_name.git the package would get installed, but there are no python files that have been installed in /usr/local/lib/python3.5/dist-packages/project_name Hence I couldn't import any class in the package in python. I am wondering how to fix this. On 20 March 2017 at 16:37, Daiyue Weng wrote: > I have been Python Packaging User Guide , > and I created a setup.py in my PyCharm project root, > > from setuptools import setup, find_packages > from os import path > > here = path.abspath(path.dirname(__file__)) > > packages = find_packages(exclude=['contrib', 'docs', 'tests*']) > > setup( > name='lumar_stackdriver_logging', > > description='A sample Python project', > > > author='project_dev', > author_email='pypa-dev at googlegroups.com', > > > # Choose your license > license='GNU GPL', > > # See https://pypi.python.org/pypi?%3Aaction=list_classifiers > classifiers=[ > # How mature is this project? Common values are > # 3 - Alpha > # 4 - Beta > # 5 - Production/Stable > 'Development Status :: 3 - Alpha', > > # Indicate who your project is intended for > 'Intended Audience :: Project Developers', > 'Topic :: System :: Logging', > > # Pick your license as you wish (should match "license" above) > 'License :: OSI Approved :: GNU General Public License (GPL)', > > # Specify the Python versions you support here. In particular, ensure > # that you indicate whether you support Python 2, Python 3 or both. > # 'Programming Language :: Python :: 3', > # 'Programming Language :: Python :: 3.2', > # 'Programming Language :: Python :: 3.3', > # 'Programming Language :: Python :: 3.4', > 'Programming Language :: Python :: 3.5', > ], > > # What does your project relate to? > keywords='sample setuptools development', > > > # You can just specify the packages manually here if your project is > # simple. Or you can use find_packages(). > packages=packages, > ) > > > I uploaded/committed the project into a Git repo/BitBucket, what I want is anyone who can access the repo, can deploy the project from the repo to their machines using pip. > > I am wondering how to achieve that? > > > Many thanks > > > On 20 March 2017 at 11:57, Daiyue Weng wrote: > >> thanks, i am reading it. >> >> On 20 March 2017 at 11:50, Glenn Hutchings wrote: >> >>> On Monday, 20 March 2017 11:36:34 UTC, Daiyue Weng wrote: >>> > Hi, I using Python 3.5.2 on Linux Mint 18.1, and I am wondering how to >>> > package my PyCharm Python project as a module so that it can installed >>> by >>> > someone else by using pip. Like what tools and script I need to use or >>> > write in order to do that. >>> >>> A good place to start is https://packaging.python.org. >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> >> > From steve+python at pearwood.info Mon Mar 20 13:37:09 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 21 Mar 2017 04:37:09 +1100 Subject: relative paths connect using python References: Message-ID: <58d01348$0$1598$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Mar 2017 04:05 am, Xristos Xristoou wrote: > i have a little confused problem. i want to store some paths from images > using python 2.7 in windows 10. i have some relative path like this > var1='C:/my/store/path' That's not a relative path, that's an absolute path. > and in the final folder where in my example is the > name 'path' inside that folder i have some images like this : -path > -myimage_1010_im.png > -myimage_1010_im1.png > -myimage_1010_im3.png > -myimage_1020_im.png > -myimage_1020_im1.png > can i connect my relative path like var1 var1 is not a relative path. It is an absolute path. Absolute paths start with a drive letter like C. Relative paths have no drive letter and start in the current working directory. > with the images using only the > number of the mid name of images and finaly i take the full original path > like this var1='C:/my/store/path/myimage_1010_im.png' ? I am afraid I have no idea what your code is doing. Instead of describing what your Python code isn't doing, can you show the code so we can see what it is doing? And please use variable names that mean something. # terrible variable names var, var1, var2 # good variable names directory_name, full_path, filename > i try something > but not work import os cwd = os.getcwd() > path = os.path.join(cwd, "my_file") That works perfectly for me: py> import os py> cwd = os.getcwd() py> path = os.path.join(cwd, "my_file") py> print path /home/steve/my_file What were you expecting it to do? Can you tell us what result you expected, and what result you got? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jladasky at itu.edu Mon Mar 20 13:38:59 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Mon, 20 Mar 2017 10:38:59 -0700 (PDT) Subject: relative paths connect using python In-Reply-To: References: Message-ID: On Monday, March 20, 2017 at 10:05:33 AM UTC-7, Xristos Xristoou wrote: > i have a little confused problem. i want to store some paths from images using python 2.7 in windows 10. > i have some relative path like this var1='C:/my/store/path' and in the final folder where in my example is the name 'path' inside that folder i have some images like this : > -path > -myimage_1010_im.png > -myimage_1010_im1.png > -myimage_1010_im3.png > -myimage_1020_im.png > -myimage_1020_im1.png > can i connect my relative path like var1 with the images using only the number of the mid name of images and finaly i take the full original path like this var1='C:/my/store/path/myimage_1010_im.png' ? > i try something but not work > import os > cwd = os.getcwd() > path = os.path.join(cwd, "my_file") I think you are new here. In order to get the best possible assistance, you always need to share as much information as you can. You posted your code. That's a good start. You did not post the error message you received. "i try something but not work" is never enough information. Post your actual error messages as well. What do they say? Are you new to programming or just to Python? Reading the error messages is sometimes hard for new programmers. But once you can read them, you can fix your own problems. From steve+python at pearwood.info Mon Mar 20 13:39:13 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 21 Mar 2017 04:39:13 +1100 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Mar 2017 02:40 am, Tobiah wrote: >> I wonder whether the tabs versus spaces divide is closely aligned to the >> Windows versus Unix/Linux divide? >> >> It seems to me that Unix users are typically going to be using Unix tools >> which often assume spaces are used for indentation, and consequently cope >> badly with tabs. > > I can't think of any classic Unix tool that behaves in a way that would > support this point of view. And yet I'm forever being told by my Linux sys admin work mates "don't use tabs, because they break everything". For another example, see JMZ's essay (its already been linked to twice in this thread, look it up). We've had a similar attitude right here from Marko, who insists that anything except 8-column tabs is the Devil's Work. (Or something like that -- to be perfectly honest, I'm not really sure I understand *what* Marko's objection is.) So okay, if tabs work fine with Unix tools, why do so many Unix people avoid tabs as if they were radioactive plague? -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From saxri89 at gmail.com Mon Mar 20 13:49:39 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Mon, 20 Mar 2017 10:49:39 -0700 (PDT) Subject: relative paths connect using python In-Reply-To: References: Message-ID: <2d596678-1382-4135-8545-e599d17f8949@googlegroups.com> ?? ???????, 20 ??????? 2017 - 7:05:33 ?.?. UTC+2, ? ??????? Xristos Xristoou ??????: > i have a little confused problem. i want to store some paths from images using python 2.7 in windows 10. > i have some relative path like this var1='C:/my/store/path' and in the final folder where in my example is the name 'path' inside that folder i have some images like this : > -path > -myimage_1010_im.png > -myimage_1010_im1.png > -myimage_1010_im3.png > -myimage_1020_im.png > -myimage_1020_im1.png > can i connect my relative path like var1 with the images using only the number of the mid name of images and finaly i take the full original path like this var1='C:/my/store/path/myimage_1010_im.png' ? > i try something but not work > import os > cwd = os.getcwd() > path = os.path.join(cwd, "my_file") i want like this a=1010 path = os.path.join(cwd, a") print path and the path i need full absolute path like this : var1='C:/my/store/path/myimage_1010_im.png' in my first code i dont have error but i take wrong for me path not full From steve+python at pearwood.info Mon Mar 20 13:51:48 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 21 Mar 2017 04:51:48 +1100 Subject: __del__ is not called after creating a new reference References: <20170317145459.GA3628@redhat.com> Message-ID: <58d016b6$0$1611$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Mar 2017 01:54 am, Oleg Nesterov wrote: [...] > However, this trivial test-case > > class C: > def __del__(self): > print("DEL") > global X > X = self > C() > print(X) > X = 0 > print(X) > > shows that __del__ is called only once, it is not called again after "X = > 0": > > DEL > <__main__.C object at 0x7f067695f4a8> > 0 I cannot confirm that test case. When I try it, I get NameError: py> class C: ... def __del__(self): ... print("DEL") ... global X ... X = self ... py> C() <__main__.C object at 0xb785c48c> py> print(X) Traceback (most recent call last): File "", line 1, in NameError: name 'X' is not defined py> X = 0 py> print(X) 0 I've tried it in both Python 2.7 and 3.5 and get the same NameError. I suspect that you are not running the code you have shown us. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Mon Mar 20 13:57:38 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 21 Mar 2017 04:57:38 +1100 Subject: __del__ is not called after creating a new reference References: <20170317145459.GA3628@redhat.com> <58d016b6$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <58d01814$0$1587$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Mar 2017 04:51 am, Steve D'Aprano wrote: > On Sat, 18 Mar 2017 01:54 am, Oleg Nesterov wrote: > > [...] >> However, this trivial test-case [...] > I cannot confirm that test case. When I try it, I get NameError: Ah, never mind! I was running this in the interactive interpreter, and forgot that it saves a reference to the last result using _ so of course the __del__ method didn't run at all. I changed the code to run: c = C() del c and now I'm seeing the same thing as you: DEL is only printed once. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From alister.ware at ntlworld.com Mon Mar 20 14:35:30 2017 From: alister.ware at ntlworld.com (alister) Date: Mon, 20 Mar 2017 18:35:30 GMT Subject: relative paths connect using python References: <2d596678-1382-4135-8545-e599d17f8949@googlegroups.com> Message-ID: On Mon, 20 Mar 2017 10:49:39 -0700, Xristos Xristoou wrote: > ?? ???????, 20 ??????? 2017 - 7:05:33 ?.?. UTC+2, ? ??????? Xristos > Xristoou ??????: >> i have a little confused problem. i want to store some paths from >> images using python 2.7 in windows 10. >> i have some relative path like this var1='C:/my/store/path' and in the >> final folder where in my example is the name 'path' inside that folder >> i have some images like this : >> -path >> -myimage_1010_im.png -myimage_1010_im1.png -myimage_1010_im3.png >> -myimage_1020_im.png -myimage_1020_im1.png >> can i connect my relative path like var1 with the images using only the >> number of the mid name of images and finaly i take the full original >> path like this var1='C:/my/store/path/myimage_1010_im.png' ? >> i try something but not work import os cwd = os.getcwd() >> path = os.path.join(cwd, "my_file") > > i want like this a=1010 path = os.path.join(cwd, a") > print path > > and the path i need full absolute path like this : > var1='C:/my/store/path/myimage_1010_im.png' > > in my first code i dont have error but i take wrong for me path not full without specifying what you expect to see & what you are actually seeing it is difficult for anyone to understand your problem let alon provide the solution. that said it looks like you need to develop your debugging skills so that you can hep yourself, try adding print statements at critical points in your program to check that your variables contain what you think they should ate each stage, this will help you pinpoint the point in your code you need to investigate. example: cwd=os.getcwd() print (cwd) // is cwd what you expect? if not why not path = os.path.join(cwd,'myfile') print (path) // is path what you expect ?if not why not? when you identify the part that is wrong post back with what you expect & what you get. I was making donuts and now I'm on a bus! From torriem at gmail.com Mon Mar 20 14:37:24 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 20 Mar 2017 12:37:24 -0600 Subject: relative paths connect using python In-Reply-To: <2d596678-1382-4135-8545-e599d17f8949@googlegroups.com> References: <2d596678-1382-4135-8545-e599d17f8949@googlegroups.com> Message-ID: On 03/20/2017 11:49 AM, Xristos Xristoou wrote: > and the path i need full absolute path like this : var1='C:/my/store/path/myimage_1010_im.png' > > in my first code i dont have error but i take wrong for me path not full Since you have not provided any sample output from your program, there's no way we can replicate the problem you are having. Please provide the output from your program (cut and paste it from the cmd.exe window). You may also want to print out the other variables, such as cwd, so you can tell exactly what it's doing. Hopefully through this process you can learn how to debug programs. From joel.goldstick at gmail.com Mon Mar 20 14:56:10 2017 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 20 Mar 2017 14:56:10 -0400 Subject: Who are the "spacists"? In-Reply-To: <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 20, 2017 at 1:39 PM, Steve D'Aprano wrote: > On Tue, 21 Mar 2017 02:40 am, Tobiah wrote: > >>> I wonder whether the tabs versus spaces divide is closely aligned to the >>> Windows versus Unix/Linux divide? >>> >>> It seems to me that Unix users are typically going to be using Unix tools >>> which often assume spaces are used for indentation, and consequently cope >>> badly with tabs. >> >> I can't think of any classic Unix tool that behaves in a way that would >> support this point of view. > > And yet I'm forever being told by my Linux sys admin work mates "don't use > tabs, because they break everything". For another example, see JMZ's essay > (its already been linked to twice in this thread, look it up). > > We've had a similar attitude right here from Marko, who insists that > anything except 8-column tabs is the Devil's Work. (Or something like > that -- to be perfectly honest, I'm not really sure I understand *what* > Marko's objection is.) > > So okay, if tabs work fine with Unix tools, why do so many Unix people avoid > tabs as if they were radioactive plague? > > > > > -- > Steve > ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure > enough, things got worse. > > -- > https://mail.python.org/mailman/listinfo/python-list I was the first to post that this topic would go nowhere. 77 posts later, for some reason the word 'spaceist' bothers me. Why do people debate spaces versus tabs? I don't think it has to do with spaces or tabs, but something more sociological or psychological. -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From alister.ware at ntlworld.com Mon Mar 20 14:57:51 2017 From: alister.ware at ntlworld.com (alister) Date: Mon, 20 Mar 2017 18:57:51 GMT Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> <921339c5-a64f-d4b5-c64a-947b47e3afe5@lucidity.plus.com> Message-ID: On Sun, 19 Mar 2017 23:01:22 +0000, Erik wrote: > On 19/03/17 22:29, Jon Ribbens wrote: >> On 2017-03-19, breamoreboy at gmail.com wrote: >>> On Sunday, March 19, 2017 at 9:54:52 PM UTC, Larry Hudson wrote: >>>> A trivial point (and irrelevant)... The thing I find annoying about >>>> an editor set to expand tabs to spaces is that it takes one keypress >>>> to indent but four (or whatever) to unindent. >>> >>> No, just about every editor that I've ever used has SHIFT-TAB set to >>> undo whatever TAB does. >> >> Not to mention plenty of editors (e.g. vim) will unindent when you >> press backspace. > > I don't think that's strictly true. If you have just indented with a tab > character, then backspace will delete that tab character. But, if you > indent with either 4 spaces or use the Tab key with "expandtab" enabled, > then it will just delete the right-most space character. > > The closest I've come to an "unindent" in vim so far is Ctrl-D, which > backs up one "shift width's" worth. > > > For sanity, in 'vim', I always use (for my own Python code, at least): > > :set sw=4 ts=4 expandtabs > > That way, all tab keypresses insert 4 spaces instead of a tab and the > shift operations ('<' and '>') will do the same. This also means the > "back up one shift-width" command (Ctrl-D) is the same as a "dedent". > > > If you also use the autoindent setting (:set ai), then writing code is > as easy as pressing enter and Tab to start a new suite, enter only to > continue a suite, and enter and Ctrl-D to drop back to the outer suite. > > E. I have just tested this with geany & it works a charm, personally I prefer tabs for setting my indent levels, it feels more logical & breaks nothing if the font or tab size is changed but votes have been counted & the jury has returned a verdict Spaces are the preferred option, but you are still able to make your own choice. -- It's a very *__UN*lucky week in which to be took dead. -- Churchy La Femme From marko at pacujo.net Mon Mar 20 14:58:03 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Mon, 20 Mar 2017 20:58:03 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> <87r31sz2yq.fsf@elektro.pacujo.net> <87mvcgyt1c.fsf@elektro.pacujo.net> <58cfe51d$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: <8760j3g4hw.fsf@elektro.pacujo.net> Steve D'Aprano : > On Tue, 21 Mar 2017 12:30 am, Marko Rauhamaa wrote: > >> Unicode was 25 years late to the game > > I don't understand that comment. Are you suggesting that the oldest > convention wins? The Unix 8-column convention is older than Unicode, so it > wins? The 8-column convention is older, alive and well on Unix so it wins on Unix. > Well... in that case, there are tab conventions that pre-date Unix, e.g. > those used by COBOL. COBOL is not highly relevant in the Unix world. > But wait... before there was COBOL, there were *typewriters*. Typewriters and teletypes are indeed behind the original intended (pre-Unix) semantics of things like BS, HT, CR and LF. However, they acquired modified meanings in Unix. For example, CR on input is converted to an LF, and LF on output is converted to a CRLF. > So there you go. Unix was 50+ years late to the game. Unix is normative for Unix. I seem to recall, though, that the same 8-column interpretation was there with CP/M and MS-DOS. The practice must be older: In practice, settable tab stops were rather quickly replaced with fixed tab stops, de facto standardized at every multiple of 8 characters horizontally, and every 6 lines vertically (typically one inch vertically). A printing program could easily send the necessary spaces or line feeds to move to any position wanted on a form, and this was far more reliable than the modal and non-standard methods of setting tab stops. Tab characters simply became a form of data compression. Marko From rosuav at gmail.com Mon Mar 20 15:01:26 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Mar 2017 06:01:26 +1100 Subject: Who are the "spacists"? In-Reply-To: <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Mar 21, 2017 at 4:39 AM, Steve D'Aprano wrote: > And yet I'm forever being told by my Linux sys admin work mates "don't use > tabs, because they break everything". For another example, see JMZ's essay > (its already been linked to twice in this thread, look it up). > > We've had a similar attitude right here from Marko, who insists that > anything except 8-column tabs is the Devil's Work. (Or something like > that -- to be perfectly honest, I'm not really sure I understand *what* > Marko's objection is.) > > So okay, if tabs work fine with Unix tools, why do so many Unix people avoid > tabs as if they were radioactive plague? Can you ask your workmates to elaborate? I'd love to hear. ChrisA From rosuav at gmail.com Mon Mar 20 15:04:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Mar 2017 06:04:12 +1100 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> <921339c5-a64f-d4b5-c64a-947b47e3afe5@lucidity.plus.com> Message-ID: On Tue, Mar 21, 2017 at 5:57 AM, alister wrote: > I have just tested this with geany & it works a charm, > > personally I prefer tabs for setting my indent levels, it feels more > logical & breaks nothing if the font or tab size is changed but votes > have been counted & the jury has returned a verdict > > Spaces are the preferred option, but you are still able to make your own > choice. I'm so glad the world isn't a democracy. "The votes have been counted" means nothing. :) ChrisA From alister.ware at ntlworld.com Mon Mar 20 17:19:02 2017 From: alister.ware at ntlworld.com (alister) Date: Mon, 20 Mar 2017 21:19:02 GMT Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> <921339c5-a64f-d4b5-c64a-947b47e3afe5@lucidity.plus.com> Message-ID: On Tue, 21 Mar 2017 06:04:12 +1100, Chris Angelico wrote: > On Tue, Mar 21, 2017 at 5:57 AM, alister > wrote: >> I have just tested this with geany & it works a charm, >> >> personally I prefer tabs for setting my indent levels, it feels more >> logical & breaks nothing if the font or tab size is changed but votes >> have been counted & the jury has returned a verdict >> >> Spaces are the preferred option, but you are still able to make your >> own choice. > > I'm so glad the world isn't a democracy. "The votes have been counted" > means nothing. :) > > ChrisA you know as well as Id that I meant this discussion was had many years ago & the decision was made. to be honest I don't know whether it was by a consensus of the community or simply Guido tossing a coin. either way does not matter it is not something that is going to change now. fortunately both tabs & spaces are still supported so individual programmes can still make their own decisions, the only time it makes any difference is when working on a collaboration with other programmers when style guides have to be agreed. if I was to say only a Nazi world try to enforce one or the other at this stage in the languages evolution can we call Godwin's on this un- Productive debate ;-) -- Remembering is for those who have forgotten. -- Chinese proverb From rosuav at gmail.com Mon Mar 20 17:32:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Mar 2017 08:32:12 +1100 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <8760j6jgva.fsf@elektro.pacujo.net> <921339c5-a64f-d4b5-c64a-947b47e3afe5@lucidity.plus.com> Message-ID: On Tue, Mar 21, 2017 at 8:19 AM, alister wrote: > On Tue, 21 Mar 2017 06:04:12 +1100, Chris Angelico wrote: > >> On Tue, Mar 21, 2017 at 5:57 AM, alister >> wrote: >>> I have just tested this with geany & it works a charm, >>> >>> personally I prefer tabs for setting my indent levels, it feels more >>> logical & breaks nothing if the font or tab size is changed but votes >>> have been counted & the jury has returned a verdict >>> >>> Spaces are the preferred option, but you are still able to make your >>> own choice. >> >> I'm so glad the world isn't a democracy. "The votes have been counted" >> means nothing. :) >> >> ChrisA > > you know as well as Id that I meant this discussion was had many years > ago & the decision was made. > > to be honest I don't know whether it was by a consensus of the community > or simply Guido tossing a coin. either way does not matter it is not > something that is going to change now. > > fortunately both tabs & spaces are still supported so individual > programmes can still make their own decisions, the only time it makes any > difference is when working on a collaboration with other programmers when > style guides have to be agreed. See, that's the thing. PEP 7 and PEP 8 govern the source code for the Python language itself, and there is no requirement to follow their recommendations in other projects. If you choose to adopt PEP 8 as the basis of your style guide, you should still make your own decisions on the points where the specific recommendations are less important than internal consistency - and tabs vs spaces is definitely one of them. The decision has NOT been made for the entire Python community. And even the decision governing the standard library was not on the basis of a vote. It was the basis of a considered decision by the person responsible. Like I said, the world - and Python - is not a democracy. :) ChrisA From greg.ewing at canterbury.ac.nz Mon Mar 20 18:08:24 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 21 Mar 2017 11:08:24 +1300 Subject: Who are the "spacists"? In-Reply-To: <58cfe51d$0$1622$c3e8da3$5496439d@news.astraweb.com> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> <87r31sz2yq.fsf@elektro.pacujo.net> <87mvcgyt1c.fsf@elektro.pacujo.net> <58cfe51d$0$1622$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steve D'Aprano wrote: > But wait... before there was COBOL, there were *typewriters*. Its been many > years since I've had my hands on a manual typewriter, but if I remember > correctly the standard default tab setting was 1 inch. I haven't used many manual typewriters, but on the ones I have used, there were no "standard" tab stops -- you configured them yourself, wherever you wanted. -- Greg From mikhailwas at gmail.com Mon Mar 20 22:18:42 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Tue, 21 Mar 2017 03:18:42 +0100 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <87wpbkhoe2.fsf@elektro.pacujo.net> <58cf1a5d$0$1618$c3e8da3$5496439d@news.astraweb.com> <878to0h1o0.fsf@elektro.pacujo.net> <874lyoh00a.fsf@elektro.pacujo.net> Message-ID: On 20 March 2017 at 16:19, BartC wrote: > On 20/03/2017 14:32, Chris Angelico wrote: >> >> On Tue, Mar 21, 2017 at 1:24 AM, BartC wrote: >>> >>> But it would be better IMO if tabs were used, with some scheme for >>> suggesting the tab width (or set of tab stops) that is recommended (eg. a >>> comment at the top). >> >> >> If you absolutely have to, then sure, put a directive in some >> machine-readable way at the top or bottom of the file. It's like the >> coding cookie that Python follows - some editors also respect it. But >> I would prefer to just use tabs *without* suggesting a width, because >> each one represents *one indent*. Not a number of spaces. One >> indentation level. > > > For leading tabs at the start of a new statement that wouldn't be a problem. > Changing the tab width shown just spreads out statements more, or less, > horizontally. > > It works - there is no jarring misalignment - because each tab corresponds > to the same N spaces, whatever N happens to be. > > But tabs are also used after statements, before comments for example, or to > line up elements in tables. Then it doesn't work, because tabs may represent > 1 to N spaces: > > Using N=4, with 1 tab before each number: > > (one, 1), #comment 1 > (two, 2), #comment 2 > (three, 3), #comment 3 > ... Well, the definition of tabwidth in file could help only in theory, As already said, one cannot define a tab as N charaters, since character size is not a constant. Don't assume that one uses monospaced editor. For screen, generally, the units are pixels. (warning: thinking too much about it can be brain-damaging) Reasonable solution is just to be patient and wait before IDEs can render tables inside a document depending on the context. This would mean exactly 1 tab as separator. Before that I'd say just don't worry much if your layout will look not so nice, and not be so fanatic with inserting multi-column content into the source code. Tab-separated tables is actually what I use on a daily basis, e.g copy-pasting from Excell to TXT file back and forth, and my scripts parse tables usually as tab-separated txt file. And I'd say again, don't spam multiple spaces anywhere, it will be harder to pluck them out for the collegues (and probably for the document creator in the future). My rule of thumb: if I see multiple spaces in any document, something is probably wrong (except ASCII art:))). So if one'd ask, this would be roughly my styleguide. Mikhail From kevin.p.dwyer at gmail.com Tue Mar 21 02:29:04 2017 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Tue, 21 Mar 2017 06:29:04 +0000 Subject: cross python version randomness References: <5e23aa27-a14f-0be6-d5f9-7d780b01a01b@chamonix.reportlab.co.uk> Message-ID: Robin Becker wrote: > Is there a way to get the same sequences of random numbers in python 2.7 > and python >= 3.3? > > I notice that this simple script produces different values in python 2.7 > and >=3.3 > > C:\code\hg-repos\reportlab>cat s.py > import sys, random > print(sys.version) > random.seed(103) > for i in range(5): > print(i, random.randint(10,25)) > > C:\code\hg-repos\reportlab>\python27\python s.py > 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit > (AMD64)] 0 25 > 1 17 > 2 21 > 3 21 > 4 13 > > C:\code\hg-repos\reportlab>\python33\python s.py > 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 64 bit > (AMD64)] 0 24 > 1 16 > 2 12 > 3 13 > 4 22 > > However, when I use random.random() all seems to be the same so this > script C:\code\hg-repos\reportlab>cat u.py > import sys, random > print(sys.version) > random.seed(103) > for i in range(5): > print(i, random.random()) > > seems to be fine > > > C:\code\hg-repos\reportlab>\python27\python u.py > 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit > (AMD64)] (0, 0.9790501200727744) > (1, 0.45629827629184827) > (2, 0.7188470341002364) > (3, 0.7348862425853395) > (4, 0.21490166849706338) > > C:\code\hg-repos\reportlab>\python33\python u.py > 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 64 bit > (AMD64)] 0 0.9790501200727744 > 1 0.45629827629184827 > 2 0.7188470341002364 > 3 0.7348862425853395 > 4 0.21490166849706338 > > presumably randint is doing something different to get its values. The docs [https://docs.python.org/3/library/random.html#random.randrange] for randrange have this note: Changed in version 3.2: randrange() is more sophisticated about producing equally distributed values. Formerly it used a style like int(random()*n) which could produce slightly uneven distributions. Maybe that's the explanation? Unfortunately I don't have an install of 3.0/1 to test against. From deavmi at disroot.org Tue Mar 21 03:27:51 2017 From: deavmi at disroot.org (Tristan B. Kildaire) Date: Tue, 21 Mar 2017 09:27:51 +0200 Subject: Python.NET question? Message-ID: Is Python.NET a version of Python that compiles Python source code to Microsoft's IR for running by a MS runtime? From deavmi at disroot.org Tue Mar 21 03:39:40 2017 From: deavmi at disroot.org (Tristan B. Kildaire) Date: Tue, 21 Mar 2017 09:39:40 +0200 Subject: Python.NET question? Message-ID: Is Python.NET a version of Python that compiles Python source code to Microsoft's IR for running by a MS runtime? From zondo42 at gmail.com Tue Mar 21 04:09:05 2017 From: zondo42 at gmail.com (Glenn Hutchings) Date: Tue, 21 Mar 2017 01:09:05 -0700 (PDT) Subject: How to package my project and make it ready to be installed by using pip In-Reply-To: References: <73e47f28-7bcc-4319-bdee-0c6d176c041a@googlegroups.com> Message-ID: <202dedd1-3673-47b1-a3d5-163484be1840@googlegroups.com> On Monday, 20 March 2017 17:21:04 UTC, Daiyue Weng wrote: > If I tried > > pip3 install git+https://user_name at bitbucket.org/user_name/project_name.git > > the package would get installed, but there are no python files that have > been installed in /usr/local/lib/python3.5/dist-packages/project_name > > Hence I couldn't import any class in the package in python. > > I am wondering how to fix this. Where are the files that did get installed? It's possible they were put somewhere you're not expecting. (Not, I hope, in a folder called 'project_name.git' -- that would be rather unhelpful!) From ivo.bellinsalarin at gmail.com Tue Mar 21 05:07:44 2017 From: ivo.bellinsalarin at gmail.com (Ivo Bellin Salarin) Date: Tue, 21 Mar 2017 09:07:44 +0000 Subject: Python.NET question? In-Reply-To: References: Message-ID: IronPython? Le mar. 21 mars 2017 08:52, Tristan B. Kildaire a ?crit : > Is Python.NET a version of Python that compiles Python source code to > Microsoft's IR for running by a MS runtime? > -- > https://mail.python.org/mailman/listinfo/python-list > From robin at reportlab.com Tue Mar 21 05:30:55 2017 From: robin at reportlab.com (Robin Becker) Date: Tue, 21 Mar 2017 09:30:55 +0000 Subject: cross python version randomness In-Reply-To: References: <5e23aa27-a14f-0be6-d5f9-7d780b01a01b@chamonix.reportlab.co.uk> Message-ID: <54913e52-f34e-fc81-8a29-e1918d0ba111@chamonix.reportlab.co.uk> .......... >> >> presumably randint is doing something different to get its values. > > > The docs [https://docs.python.org/3/library/random.html#random.randrange] > for randrange have this note: > > Changed in version 3.2: randrange() is more sophisticated about producing > equally distributed values. Formerly it used a style like int(random()*n) > which could produce slightly uneven distributions. > > Maybe that's the explanation? Unfortunately I don't have an install of > 3.0/1 to test against. > Looking in random.py it sesms to be true. Pity no backwards compatibility mode. I don't actually care about the quality of the ints produced, but I do care about reproducibility, luckily I think it's feasible to monkey patch the 2.7 method back in. -- Robin Becker From deavmi at disroot.org Tue Mar 21 05:39:40 2017 From: deavmi at disroot.org (Tristan B. Kildaire) Date: Tue, 21 Mar 2017 11:39:40 +0200 Subject: Python.NET question? In-Reply-To: References: Message-ID: On 2017/03/21 11:07 AM, Ivo Bellin Salarin wrote: > IronPython? > > Le mar. 21 mars 2017 08:52, Tristan B. Kildaire a > ?crit : > >> Is Python.NET a version of Python that compiles Python source code to >> Microsoft's IR for running by a MS runtime? >> -- >> https://mail.python.org/mailman/listinfo/python-list >> I heard of Python.NET. ANyway, what is IronPython (is that the one that runs on an MS runtime?). The name is something I remember. I know JPython compiles to Java's IR (Bytecode) and therefore runs on the JVM runtime. From pavol.lisy at gmail.com Tue Mar 21 05:43:46 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Tue, 21 Mar 2017 10:43:46 +0100 Subject: cross python version randomness In-Reply-To: References: <5e23aa27-a14f-0be6-d5f9-7d780b01a01b@chamonix.reportlab.co.uk> Message-ID: On 3/21/17, Kev Dwyer wrote: > Robin Becker wrote: > >> Is there a way to get the same sequences of random numbers in python 2.7 >> and python >= 3.3? >> >> I notice that this simple script produces different values in python 2.7 >> and >=3.3 >> >> C:\code\hg-repos\reportlab>cat s.py >> import sys, random >> print(sys.version) >> random.seed(103) >> for i in range(5): >> print(i, random.randint(10,25)) >> >> C:\code\hg-repos\reportlab>\python27\python s.py >> 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit >> (AMD64)] 0 25 >> 1 17 >> 2 21 >> 3 21 >> 4 13 >> >> C:\code\hg-repos\reportlab>\python33\python s.py >> 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 64 bit >> (AMD64)] 0 24 >> 1 16 >> 2 12 >> 3 13 >> 4 22 >> >> However, when I use random.random() all seems to be the same so this >> script C:\code\hg-repos\reportlab>cat u.py >> import sys, random >> print(sys.version) >> random.seed(103) >> for i in range(5): >> print(i, random.random()) >> >> seems to be fine >> >> >> C:\code\hg-repos\reportlab>\python27\python u.py >> 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit >> (AMD64)] (0, 0.9790501200727744) >> (1, 0.45629827629184827) >> (2, 0.7188470341002364) >> (3, 0.7348862425853395) >> (4, 0.21490166849706338) >> >> C:\code\hg-repos\reportlab>\python33\python u.py >> 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 64 bit >> (AMD64)] 0 0.9790501200727744 >> 1 0.45629827629184827 >> 2 0.7188470341002364 >> 3 0.7348862425853395 >> 4 0.21490166849706338 >> >> presumably randint is doing something different to get its values. > > > The docs [https://docs.python.org/3/library/random.html#random.randrange] > for randrange have this note: > > Changed in version 3.2: randrange() is more sophisticated about producing > equally distributed values. Formerly it used a style like int(random()*n) > which could produce slightly uneven distributions. > > Maybe that's the explanation? Unfortunately I don't have an install of > 3.0/1 to test against. > > -- > https://mail.python.org/mailman/listinfo/python-list > This is inspiring Robin! :) import sys, random print(sys.version) def randint(a, b): return int(random.random()*(b-a+1))+a random.seed(103) for i in range(5): print(i, randint(10,25)) 3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 12:22:00) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] 0 25 1 17 2 21 3 21 4 13 Output seems to be same as in your 2.7 version :) So if you are sure that sequences of random.random are same then you could use it. You could also save a sequence to file and use it repeatedly. (if it is not performance problem for you) PL. From odt at dtrx.de Tue Mar 21 05:46:17 2017 From: odt at dtrx.de (Olaf Dietrich) Date: Tue, 21 Mar 2017 09:46:17 +0000 (UTC) Subject: numpy indexing performance References: Message-ID: Olaf Dietrich : > This is a simplified example of a Monte Carlo > simulation where random vectors (here 2D vectors, > which are all zero) are summed (the result is in > r1 and r2 or r, respectively): > > def case1(): > import numpy as np > M = 100000 > N = 10000 > r1 = np.zeros(M) > r2 = np.zeros(M) > s1 = np.zeros(N) > s2 = np.zeros(N) > for n in range(1000): > ind = np.random.random_integers(N, size=M) - 1 > r1 += s1[ind] > r2 += s2[ind] > > def case2(): > import numpy as np > M = 100000 > N = 10000 > r = np.zeros((M, 2)) > s = np.zeros((N, 2)) > for n in range(1000): > ind = np.random.random_integers(N, size=M) - 1 > r += s[ind] > > import timeit > > print("case1:", timeit.timeit( > "case1()", setup="from __main__ import case1", number=1)) > print("case2:", timeit.timeit( > "case2()", setup="from __main__ import case2", number=1)) > > > Resulting in: > > case1: 2.6224704339983873 > case2: 4.374910838028882 I should add that I tried this with Python 3.4.2 and with Python 2.7.0 (on linux, x64), NumPy version 1.8.2; the performance differences were the same with both Python interpreters. > Why is case2 significantly slower (almost by a > factor of 2) than case1? There should be the same number > of operations (additions) in both cases; the main > difference is the indexing. > > Is there another (faster) way to avoid the separate > component arrays r1 and r2? (I also tried > r = np.zeros(M, dtype='2d'), which was comparable > to case2.) Olaf From steve+python at pearwood.info Tue Mar 21 07:46:50 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 21 Mar 2017 22:46:50 +1100 Subject: Python.NET question? References: Message-ID: <58d112ac$0$1620$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Mar 2017 08:39 pm, Tristan B. Kildaire wrote: > On 2017/03/21 11:07 AM, Ivo Bellin Salarin wrote: >> IronPython? >> >> Le mar. 21 mars 2017 08:52, Tristan B. Kildaire a >> ?crit : >> >>> Is Python.NET a version of Python that compiles Python source code to >>> Microsoft's IR for running by a MS runtime? >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> > I heard of Python.NET. ANyway, what is IronPython (is that the one that > runs on an MS runtime?). The name is something I remember. I'm not sure if Python.NET is a new name for "Python for .NET", or a completely different project. Do you have a URL for it? Python for .NET brings the regular CPython interpreter to the .NET and Mono environments. IronPython is a reimplementation of Python, written in C# as managed code for .Net, running on the CLR virtual machine. It doesn't use a GIL, and is sometimes considered a little faster than CPython. IronPython: http://ironpython.net/ Python for .Net: https://github.com/pythonnet/pythonnet http://pythonnet.github.io/ https://pypi.python.org/pypi/pythonnet -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Tue Mar 21 07:51:03 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Tue, 21 Mar 2017 22:51:03 +1100 Subject: cross python version randomness References: <5e23aa27-a14f-0be6-d5f9-7d780b01a01b@chamonix.reportlab.co.uk> <54913e52-f34e-fc81-8a29-e1918d0ba111@chamonix.reportlab.co.uk> Message-ID: <58d113a9$0$1621$c3e8da3$5496439d@news.astraweb.com> On Tue, 21 Mar 2017 08:30 pm, Robin Becker wrote: > Looking in random.py it sesms to be true. Pity no backwards compatibility > mode. I don't actually care about the quality of the ints produced, but I > do care about reproducibility, luckily I think it's feasible to monkey > patch the 2.7 method back in. A few years ago I came across that, and raised it on the bug tracker. The core devs decided that the backwards compatibility promise only applies to the output of random.random() itself, not the assorted other methods. If you care about the specific sequence of pseudo-random numbers generated by a particular method across versions, you have to use your own implementation. You can trust that random.random()'s output alone will be reproducible, anything more than that you have to manage yourself. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From robin at reportlab.com Tue Mar 21 08:03:18 2017 From: robin at reportlab.com (Robin Becker) Date: Tue, 21 Mar 2017 12:03:18 +0000 Subject: cross python version randomness In-Reply-To: References: <5e23aa27-a14f-0be6-d5f9-7d780b01a01b@chamonix.reportlab.co.uk> Message-ID: On 21/03/2017 09:43, Pavol Lisy wrote: > On 3/21/17, Kev Dwyer wrote: >> Robin Becker wrote: >> >>> Is there a way to get the same sequences of random numbers in python 2.7 >>> and python >= 3.3? >>> >>> I notice that this simple script produces different values in python 2.7 >>> and >=3.3 >>> >>> C:\code\hg-repos\reportlab>cat s.py >>> import sys, random >>> print(sys.version) >>> random.seed(103) >>> for i in range(5): >>> print(i, random.randint(10,25)) >>> >>> C:\code\hg-repos\reportlab>\python27\python s.py >>> 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit >>> (AMD64)] 0 25 >>> 1 17 >>> 2 21 >>> 3 21 >>> 4 13 >............ > > This is inspiring Robin! :) > > import sys, random > print(sys.version) > > def randint(a, b): > return int(random.random()*(b-a+1))+a > > random.seed(103) > for i in range(5): > print(i, randint(10,25)) > 3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 12:22:00) > [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] > 0 25 > 1 17 > 2 21 > 3 21 > 4 13 > > Output seems to be same as in your 2.7 version :) > > So if you are sure that sequences of random.random are same then you > could use it. > > You could also save a sequence to file and use it repeatedly. (if it > is not performance problem for you) > > PL. > I'm not as inspired as you; for the present I have chickened out and just modified the 2.7 randrange method to monkeypatch the 3.x random.Random class. It seems to be ok and allows all the test code to use random.randint, but for small widths I think your function is correct. -- Robin Becker From daiyueweng at gmail.com Tue Mar 21 08:34:25 2017 From: daiyueweng at gmail.com (Daiyue Weng) Date: Tue, 21 Mar 2017 12:34:25 +0000 Subject: How to package my project and make it ready to be installed by using pip In-Reply-To: <202dedd1-3673-47b1-a3d5-163484be1840@googlegroups.com> References: <73e47f28-7bcc-4319-bdee-0c6d176c041a@googlegroups.com> <202dedd1-3673-47b1-a3d5-163484be1840@googlegroups.com> Message-ID: the problem has been solved, as I forgot to define py_modules=[...] for a few python files needed to be installed. cheers On 21 March 2017 at 08:09, Glenn Hutchings wrote: > On Monday, 20 March 2017 17:21:04 UTC, Daiyue Weng wrote: > > If I tried > > > > pip3 install git+https://user_name at bitbucket.org/user_name/ > project_name.git > > > > the package would get installed, but there are no python files that have > > been installed in /usr/local/lib/python3.5/dist-packages/project_name > > > > Hence I couldn't import any class in the package in python. > > > > I am wondering how to fix this. > > Where are the files that did get installed? It's possible they were put > somewhere you're not expecting. (Not, I hope, in a folder called > 'project_name.git' -- that would be rather unhelpful!) > -- > https://mail.python.org/mailman/listinfo/python-list > From deavmi at disroot.org Tue Mar 21 08:57:41 2017 From: deavmi at disroot.org (Tristan B. Kildaire) Date: Tue, 21 Mar 2017 14:57:41 +0200 Subject: Python.NET question? In-Reply-To: <58d112ac$0$1620$c3e8da3$5496439d@news.astraweb.com> References: <58d112ac$0$1620$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2017/03/21 1:46 PM, Steve D'Aprano wrote: > On Tue, 21 Mar 2017 08:39 pm, Tristan B. Kildaire wrote: > >> On 2017/03/21 11:07 AM, Ivo Bellin Salarin wrote: >>> IronPython? >>> >>> Le mar. 21 mars 2017 08:52, Tristan B. Kildaire a >>> ?crit : >>> >>>> Is Python.NET a version of Python that compiles Python source code to >>>> Microsoft's IR for running by a MS runtime? >>>> -- >>>> https://mail.python.org/mailman/listinfo/python-list >>>> >> I heard of Python.NET. ANyway, what is IronPython (is that the one that >> runs on an MS runtime?). The name is something I remember. > > > I'm not sure if Python.NET is a new name for "Python for .NET", or a > completely different project. Do you have a URL for it? > > Python for .NET brings the regular CPython interpreter to the .NET and Mono > environments. > > IronPython is a reimplementation of Python, written in C# as managed code > for .Net, running on the CLR virtual machine. It doesn't use a GIL, and is > sometimes considered a little faster than CPython. > > IronPython: > http://ironpython.net/ > > Python for .Net: > https://github.com/pythonnet/pythonnet > http://pythonnet.github.io/ > https://pypi.python.org/pypi/pythonnet > > > > Ah. It was IronPython then. Thanks. From best_lay at yahoo.com Tue Mar 21 09:16:43 2017 From: best_lay at yahoo.com (Wildman) Date: Tue, 21 Mar 2017 08:16:43 -0500 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> On Tue, 21 Mar 2017 06:01:26 +1100, Chris Angelico wrote: > On Tue, Mar 21, 2017 at 4:39 AM, Steve D'Aprano > wrote: >> And yet I'm forever being told by my Linux sys admin work mates "don't use >> tabs, because they break everything". For another example, see JMZ's essay >> (its already been linked to twice in this thread, look it up). >> >> We've had a similar attitude right here from Marko, who insists that >> anything except 8-column tabs is the Devil's Work. (Or something like >> that -- to be perfectly honest, I'm not really sure I understand *what* >> Marko's objection is.) >> >> So okay, if tabs work fine with Unix tools, why do so many Unix people avoid >> tabs as if they were radioactive plague? > > Can you ask your workmates to elaborate? I'd love to hear. > > ChrisA I would love to hear also. I've been using Linux for about 10 years and I have never had anything "break" because of a tab. Sounds like a case of Chicken Little to me. -- GNU/Linux user #557453 The cow died so I don't need your bull! From zizwan93 at gmail.com Tue Mar 21 09:27:33 2017 From: zizwan93 at gmail.com (Zizwan) Date: Tue, 21 Mar 2017 06:27:33 -0700 (PDT) Subject: Exporting Tensorflow inceptionv3 graph for weight and bias extraction Message-ID: <9596de87-642f-4a9f-ac4f-9f7dbe5b60da@googlegroups.com> Anyone can help me with this? From marko at pacujo.net Tue Mar 21 09:42:01 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 21 Mar 2017 15:42:01 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> Message-ID: <871stqzqza.fsf@elektro.pacujo.net> Wildman : > On Tue, 21 Mar 2017 06:01:26 +1100, Chris Angelico wrote: >> Can you ask your workmates to elaborate? I'd love to hear. > > I would love to hear also. I've been using Linux for about 10 years > and I have never had anything "break" because of a tab. Sounds like a > case of Chicken Little to me. Example: - Start emacs with the default settings. - Edit buffer "abc": C-x C-b abc - Start drawing: M-x picture-mode - Draw this box starting from the top left corner and circling clockwise: +------------------+ | | | | +------------------+ - Move the cursor to the beginning of the first line of the box. Try to move the box to the left by three columns: C-SPC C-n C-n C-n C-f C-f C-f C-x r k What you get is: +------------------+ | | | | +------------------+ because only the first line was indented with spaces. Emacs uses when opening the other lines. If you disable tabs (or untabify), you get the intended result: +------------------+ | | | | +------------------+ This is only an example. Analogous annoyances crop up in all kinds of editing. Marko From mikhailwas at gmail.com Tue Mar 21 10:15:14 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Tue, 21 Mar 2017 15:15:14 +0100 Subject: Who are the "spacists"? In-Reply-To: <871stqzqza.fsf@elektro.pacujo.net> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> Message-ID: On 21 March 2017 at 14:42, Marko Rauhamaa wrote: > Wildman : > >> On Tue, 21 Mar 2017 06:01:26 +1100, Chris Angelico wrote: >>> Can you ask your workmates to elaborate? I'd love to hear. >> >> I would love to hear also. I've been using Linux for about 10 years >> and I have never had anything "break" because of a tab. Sounds like a >> case of Chicken Little to me. > > Example: > > - Start emacs with the default settings. > > - Edit buffer "abc": C-x C-b abc > > - Start drawing: M-x picture-mode > > - Draw this box starting from the top left corner and circling > clockwise: > > +------------------+ > | | > | | > +------------------+ > Didn't want to say this, but you know it was quite predictable from the beginning that the arguments will end up somewhere in "linux console is the center of the universe, e-macs is mother of all apps and monospaced text is peak of human evolution". I don't know how to help, probably if there is an important document which you want different people to read, just make plain txt, or HTML table, Office document, PNG image, etc. Or just use spaces if it is for ASCII-art purposes. And on linux console, by default one does not even have good possibilities for text-mode pseudographics, it was more relevant in DOS where one had rich possibilities and programmable binary fonts. Mikhail From marko at pacujo.net Tue Mar 21 10:38:32 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Tue, 21 Mar 2017 16:38:32 +0200 Subject: Who are the "spacists"? In-Reply-To: (Mikhail V.'s message of "Tue, 21 Mar 2017 15:15:14 +0100") References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> Message-ID: <87wpbiy9sn.fsf@elektro.pacujo.net> Mikhail V : > On 21 March 2017 at 14:42, Marko Rauhamaa wrote: >> - Draw this box starting from the top left corner and circling >> clockwise: >> >> +------------------+ >> | | >> | | >> +------------------+ >> > > Didn't want to say this, but you know it was quite predictable from > the beginning that the arguments will end up somewhere in "linux > console is the center of the universe, e-macs is mother of all apps > and monospaced text is peak of human evolution". > > I don't know how to help, probably if there is an important document > which you want different people to read, just make plain txt, or HTML > table, Office document, PNG image, etc. Or just use spaces if it is > for ASCII-art purposes. > > And on linux console, by default one does not even have good > possibilities for text-mode pseudographics, it was more relevant in > DOS where one had rich possibilities and programmable binary fonts. Here's what I have studied today (HTTP/2): +-----------------------------------------------+ | Length (24) | +---------------+---------------+---------------+ | Type (8) | Flags (8) | +-+-------------+---------------+-------------------------------+ |R| Stream Identifier (31) | +=+=============================================================+ | Frame Payload (0...) ... +---------------------------------------------------------------+ [...] +--------+ send PP | | recv PP ,--------| idle |--------. / | | \ v +--------+ v +----------+ | +----------+ | | | send H / | | ,------| reserved | | recv H | reserved |------. | | (local) | | | (remote) | | | +----------+ v +----------+ | | | +--------+ | | | | recv ES | | send ES | | | send H | ,-------| open |-------. | recv H | | | / | | \ | | | v v +--------+ v v | | +----------+ | +----------+ | | | half | | | half | | | | closed | | send R / | closed | | | | (remote) | | recv R | (local) | | | +----------+ | +----------+ | | | | | | | | send ES / | recv ES / | | | | send R / v send R / | | | | recv R +--------+ recv R | | | send R / `----------->| |<-----------' send R / | | recv R | closed | recv R | `----------------------->| |<----------------------' +--------+ State of the art. Thankfully, the editor of the RFC chose not to use tabs. Marko From grant.b.edwards at gmail.com Tue Mar 21 10:47:31 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 21 Mar 2017 14:47:31 +0000 (UTC) Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> Message-ID: On 2017-03-21, Wildman via Python-list wrote: > I would love to hear also. I've been using Linux for about > 10 years and I have never had anything "break" because of a > tab. Sounds like a case of Chicken Little to me. The main problem is that when you display/print a program that uses tabs on something that expands them to every 8-columns, you often end up with much of the code so far to the right you can't see much of it. Another problem is that people will use tabs to do things like line up comments to the right of code. That only works if the program displaying/printing the code has tab widths that match the authors. -- Grant Edwards grant.b.edwards Yow! I'm having a MID-WEEK at CRISIS! gmail.com From grant.b.edwards at gmail.com Tue Mar 21 10:49:13 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 21 Mar 2017 14:49:13 +0000 (UTC) Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> Message-ID: On 2017-03-21, Mikhail V wrote: > Didn't want to say this, but you know it was quite predictable from > the beginning that the arguments will end up somewhere in "linux > console is the center of the universe, e-macs is mother of all apps > and monospaced text is peak of human evolution". Well, I'm glad you've finally admitted it. :) > I don't know how to help, probably if there is an important document > which you want different people to read, just make plain txt, or > HTML table, Office document, PNG image, etc. Or just use spaces if > it is for ASCII-art purposes. Well written code _is_ ASCII-art. -- Grant Edwards grant.b.edwards Yow! Do I have a lifestyle at yet? gmail.com From jussi.piitulainen at helsinki.fi Tue Mar 21 11:01:20 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 21 Mar 2017 17:01:20 +0200 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> Message-ID: Grant Edwards writes: > Well written code _is_ ASCII-art. :) From mikhailwas at gmail.com Tue Mar 21 11:04:58 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Tue, 21 Mar 2017 16:04:58 +0100 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> Message-ID: On 21 March 2017 at 15:49, Grant Edwards wrote: > On 2017-03-21, Mikhail V wrote: > >> Didn't want to say this, but you know it was quite predictable from >> the beginning that the arguments will end up somewhere in "linux >> console is the center of the universe, e-macs is mother of all apps >> and monospaced text is peak of human evolution". > > Well, I'm glad you've finally admitted it. :) > >> I don't know how to help, probably if there is an important document >> which you want different people to read, just make plain txt, or >> HTML table, Office document, PNG image, etc. Or just use spaces if >> it is for ASCII-art purposes. > > Well written code _is_ ASCII-art. Written code is ASCII-art only if you live in the Monospaced Kingdom, and even there, only if you draw ASCII-art in multi-line comment blocks. But its true, that it will have a notable place in a museum. Mikhail From p.f.moore at gmail.com Tue Mar 21 11:22:29 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Tue, 21 Mar 2017 08:22:29 -0700 (PDT) Subject: Manager for project templates, that allows "incremental" feature addition Message-ID: <10cc3f5f-9345-4db7-846b-cd912a3771a9@googlegroups.com> I'm looking for a utility that is something like cookiecutter, in that it generates a "template" project for me. However, I would like the ability to have a template add content based on runtime questions, something like Do you want to include a C extension? [yes/no] ... adds Extension() to setup.py, adds a C source file, etc Do you want to include tests? [yes/no] ... add a test directory with a sample test Tests to run under tox? [yes/no] ... add tox support (this question shouldn't be asked if the previous answer was "no") As far as I know, this sort of feature isn't available in cookiecutter, nor is it planned. Does anyone know of any similar utility that has this feature? If not, how do people handle it themselves? The "obvious" solution is just to have a full-featured template and cut out what's not needed, but for simple tasks, I find that cutting out the unneeded stuff can be a bigger job than writing the actual code. Some examples of use cases I hit: 1. I need a trivial Python only, single-file project, to test some packaging issue. 2. Same, but I need a C module, that implements a single trivial function. 3. Added to either of the above, I need to include tests. Maybe with tox, maybe just standalone. 4. For a bigger project I might want Sphinx included as well. 5. Maybe add standard build scripts. At the moment I don't do this, but if I *had* a utility like I describe, this is one thing I'd like to do. For all of these cases, I only really want to maintain a single template, as I don't want to have to maintain all of the common boilerplate (author name/email, version handling, classifiers etc) multiple times. I don't use (or particularly want to switch to) an IDE. Generally I code using VS Code or Vim, on Windows, and run tests, builds etc from the command line. Is there any such utility that I'm not aware of? If not, then what do people use to manage this sort of thing? Paul From rosuav at gmail.com Tue Mar 21 11:37:56 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Mar 2017 02:37:56 +1100 Subject: Who are the "spacists"? In-Reply-To: <87wpbiy9sn.fsf@elektro.pacujo.net> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> <87wpbiy9sn.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 22, 2017 at 1:38 AM, Marko Rauhamaa wrote: > State of the art. Thankfully, the editor of the RFC chose not to use > tabs. Exactly. Because tabs are the wrong character to use for this kind of thing. So you see, this is not any fault of tabs - what you're pointing out is that misusing them causes problems. What a surprise. But using them appropriately has yet been shown to cause any problems. ChrisA From torriem at gmail.com Tue Mar 21 11:42:55 2017 From: torriem at gmail.com (Michael Torrie) Date: Tue, 21 Mar 2017 09:42:55 -0600 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> Message-ID: <509d90d6-d0b3-b430-9e94-437c23589c48@gmail.com> On 03/21/2017 08:15 AM, Mikhail V wrote: > Didn't want to say this, but you know it was quite predictable from > the beginning that > the arguments will end up somewhere in "linux console is the center of the > universe, e-macs is mother of all apps and monospaced text is peak of > human evolution". Knowing that, the honest question is: if you knew where this would all end up (in a heated argument), why did post your provocation in the first place? From rhodri at kynesim.co.uk Tue Mar 21 11:45:14 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Tue, 21 Mar 2017 15:45:14 +0000 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> Message-ID: On 21/03/17 15:04, Mikhail V wrote: > On 21 March 2017 at 15:49, Grant Edwards wrote: >> On 2017-03-21, Mikhail V wrote: >> >>> Didn't want to say this, but you know it was quite predictable from >>> the beginning that the arguments will end up somewhere in "linux >>> console is the center of the universe, e-macs is mother of all apps >>> and monospaced text is peak of human evolution". >> >> Well, I'm glad you've finally admitted it. :) >> >>> I don't know how to help, probably if there is an important document >>> which you want different people to read, just make plain txt, or >>> HTML table, Office document, PNG image, etc. Or just use spaces if >>> it is for ASCII-art purposes. >> >> Well written code _is_ ASCII-art. > > Written code is ASCII-art only if you live in the Monospaced Kingdom, > and even there, only if you draw ASCII-art in multi-line comment blocks. > But its true, that it will have a notable place in a museum. You misunderstand; well-written code has a pleasing shape all of its own, never mind any deliberate attempts at diagramming. You may be correct that it is only true in the Monospaced Kingdom; if so, that's a major plus point for fixed-width fonts. -- Rhodri James *-* Kynesim Ltd From jon+usenet at unequivocal.eu Tue Mar 21 12:08:35 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Tue, 21 Mar 2017 16:08:35 -0000 (UTC) Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> <509d90d6-d0b3-b430-9e94-437c23589c48@gmail.com> Message-ID: On 2017-03-21, Michael Torrie wrote: > On 03/21/2017 08:15 AM, Mikhail V wrote: >> Didn't want to say this, but you know it was quite predictable from >> the beginning that the arguments will end up somewhere in "linux >> console is the center of the universe, e-macs is mother of all apps >> and monospaced text is peak of human evolution". > > Knowing that, the honest question is: if you knew where this would all > end up (in a heated argument), why did post your provocation in the > first place? Seriously, could the trolling be any more obvious? Or successful? From grant.b.edwards at gmail.com Tue Mar 21 12:20:45 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Tue, 21 Mar 2017 16:20:45 +0000 (UTC) Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> <509d90d6-d0b3-b430-9e94-437c23589c48@gmail.com> Message-ID: On 2017-03-21, Jon Ribbens wrote: > On 2017-03-21, Michael Torrie wrote: >> On 03/21/2017 08:15 AM, Mikhail V wrote: >>> Didn't want to say this, but you know it was quite predictable from >>> the beginning that the arguments will end up somewhere in "linux >>> console is the center of the universe, e-macs is mother of all apps >>> and monospaced text is peak of human evolution". >> >> Knowing that, the honest question is: if you knew where this would all >> end up (in a heated argument), why did post your provocation in the >> first place? > > Seriously, could the trolling be any more obvious? Or successful? Question: is it still successfull trolling if we all knew that was the intent and are just playing along for the entertainment value? -- Grant Edwards grant.b.edwards Yow! Well, O.K. at I'll compromise with my gmail.com principles because of EXISTENTIAL DESPAIR! From gheskett at shentel.net Tue Mar 21 12:41:13 2017 From: gheskett at shentel.net (Gene Heskett) Date: Tue, 21 Mar 2017 12:41:13 -0400 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> Message-ID: <201703211241.13562.gheskett@shentel.net> On Tuesday 21 March 2017 11:04:58 Mikhail V wrote: > On 21 March 2017 at 15:49, Grant Edwards wrote: > > On 2017-03-21, Mikhail V wrote: > >> Didn't want to say this, but you know it was quite predictable from > >> the beginning that the arguments will end up somewhere in "linux > >> console is the center of the universe, e-macs is mother of all apps > >> and monospaced text is peak of human evolution". > > > > Well, I'm glad you've finally admitted it. :) > > > >> I don't know how to help, probably if there is an important > >> document which you want different people to read, just make plain > >> txt, or HTML table, Office document, PNG image, etc. Or just use > >> spaces if it is for ASCII-art purposes. > > > > Well written code _is_ ASCII-art. > > Written code is ASCII-art only if you live in the Monospaced Kingdom, Whats wrong with Monospace (caps yours)? In case you've not heard the news, we (linux users, other platform unk, don't use them) have a font, called "hack" (announced several years ago) that is not only Monospaced but quite civilized to look at. I use it for editing any executable codes source language, and here in kmail too. > and even there, only if you draw ASCII-art in multi-line comment > blocks. But its true, that it will have a notable place in a museum. > > Mikhail Cheers, Gene Heskett -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page From jladasky at itu.edu Tue Mar 21 13:59:30 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Tue, 21 Mar 2017 10:59:30 -0700 (PDT) Subject: Exporting Tensorflow inceptionv3 graph for weight and bias extraction In-Reply-To: <9596de87-642f-4a9f-ac4f-9f7dbe5b60da@googlegroups.com> References: <9596de87-642f-4a9f-ac4f-9f7dbe5b60da@googlegroups.com> Message-ID: <8ad755ce-801c-4f78-836f-520974d0dd7b@googlegroups.com> On Tuesday, March 21, 2017 at 6:27:43 AM UTC-7, Zizwan wrote: > Anyone can help me with this? TensorFlow has a Python wrapper, but it isn't Python. Do you require Python for what you are trying to do? You might try looking for more information in the TensorFlow tutorial newsgroup: https://groups.google.com/forum/#!forum/tensorflow I'm just getting started with TF myself, so I'm sorry that I can't answer your question. From oleg at redhat.com Tue Mar 21 14:33:20 2017 From: oleg at redhat.com (Oleg Nesterov) Date: Tue, 21 Mar 2017 19:33:20 +0100 Subject: __del__ is not called after creating a new reference In-Reply-To: <58d01814$0$1587$c3e8da3$5496439d@news.astraweb.com> References: <20170317145459.GA3628@redhat.com> <58d016b6$0$1611$c3e8da3$5496439d@news.astraweb.com> <58d01814$0$1587$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20170321183320.GC32729@redhat.com> On 03/21, Steve D'Aprano wrote: > > I changed the code to run: > > c = C() > del c > > and now I'm seeing the same thing as you: DEL is only printed once. Yes, I've forwared this question to python-dev, please see https://mail.python.org/pipermail/python-dev/2017-March/147631.html so the implementation is fine, the docs should be probably updated. Oleg. From breamoreboy at gmail.com Tue Mar 21 16:19:15 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Tue, 21 Mar 2017 13:19:15 -0700 (PDT) Subject: PyPy2.7 and PyPy3.5 v5.7 - two in one release Message-ID: Hopefully this https://morepypy.blogspot.co.uk/2017/03/pypy27-and-pypy35-v57-two-in-one-release.html is rather more interesting for some than blatant trolling about spaces vs tabs. Kindest regards. Mark Lawrence. From robertoshea2k11 at gmail.com Tue Mar 21 16:35:11 2017 From: robertoshea2k11 at gmail.com (Robert O'Shea) Date: Tue, 21 Mar 2017 20:35:11 +0000 Subject: PyPy2.7 and PyPy3.5 v5.7 - two in one release In-Reply-To: References: Message-ID: Been meaning to give Pypy a try for a while, tonight may be the time On Tue 21 Mar 2017, 20:32 , wrote: > Hopefully this > https://morepypy.blogspot.co.uk/2017/03/pypy27-and-pypy35-v57-two-in-one-release.html > is rather more interesting for some than blatant trolling about spaces vs > tabs. > > Kindest regards. > > Mark Lawrence. > -- > https://mail.python.org/mailman/listinfo/python-list > From python at mrabarnett.plus.com Tue Mar 21 16:59:51 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 21 Mar 2017 20:59:51 +0000 Subject: Python.NET question? In-Reply-To: References: Message-ID: On 2017-03-21 07:27, Tristan B. Kildaire wrote: > Is Python.NET a version of Python that compiles Python source code to > Microsoft's IR for running by a MS runtime? > Is this what you're talking about? https://github.com/pythonnet/pythonnet It says """Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers.""" From mikhailwas at gmail.com Tue Mar 21 17:27:59 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Tue, 21 Mar 2017 22:27:59 +0100 Subject: Who are the "spacists"? In-Reply-To: <201703211241.13562.gheskett@shentel.net> References: <1489873444l.9830606l.0l@psu.edu> <201703211241.13562.gheskett@shentel.net> Message-ID: On 21 March 2017 at 17:41, Gene Heskett wrote: > On Tuesday 21 March 2017 11:04:58 Mikhail V wrote: > >> On 21 March 2017 at 15:49, Grant Edwards > wrote: >> > On 2017-03-21, Mikhail V wrote: >> > >> >> I don't know how to help, probably if there is an important >> >> document which you want different people to read, just make plain >> >> txt, or HTML table, Office document, PNG image, etc. Or just use >> >> spaces if it is for ASCII-art purposes. >> > >> > Well written code _is_ ASCII-art. >> >> Written code is ASCII-art only if you live in the Monospaced Kingdom, > > Whats wrong with Monospace (caps yours)? In case you've not heard the > news, we (linux users, other platform unk, don't use them) have a font, > called "hack" (announced several years ago) that is not only Monospaced > but quite civilized to look at. I use it for editing any executable > codes source language, and here in kmail too. > This was already discussed here what is wrong with monospaced, but ok, since you question. Look, I know what is Hack font as well a lot of other thing about fonts, since I work on fonts and reading-related problems my whole life. I'd just tell one thing since I am a bit tired: if you wish, take an advice: avoid *any* monospaced fonts as plague if you are reading a lot of information, this includes coding. Avoid *any* sepia color schemes as plague. Avoid *any* sans-serif font. Get the most close to Garamond or Perpetua font. For cases, where you *absolutely must* use monospaced font, stick to Courier font (it is called "Courier 10 pitch" on Linux, if you don't have it in the system, try to find it, it must be in some true type font package). As for editing executables I don't know what *exactly* are you trying to do, what processes are involved, so I can't advice much. And don't worry if a zero does not look like a pusy, but looks like a big O, this is irrelevant in most cases. Now if you follow this, then probably in some time you will say: thanks, good man Mikhail. From rosuav at gmail.com Tue Mar 21 17:40:27 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Mar 2017 08:40:27 +1100 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <201703211241.13562.gheskett@shentel.net> Message-ID: On Wed, Mar 22, 2017 at 8:27 AM, Mikhail V wrote: > I'd just tell one thing since I am a bit tired: if you wish, > take an advice: avoid *any* monospaced fonts as plague if you are > reading a lot of information, this includes coding. > Avoid *any* sepia color schemes as plague. > Avoid *any* sans-serif font. Get the most close > to Garamond or Perpetua font. > > For cases, where you *absolutely must* use monospaced > font, stick to Courier font (it is called "Courier 10 pitch" on Linux, if > you don't have it in the system, try to find it, it must be > in some true type font package). > As for editing executables I don't know what *exactly* > are you trying to do, what processes are involved, > so I can't advice much. > And don't worry if a zero does not look like a pusy, > but looks like a big O, this is irrelevant in most cases. > > Now if you follow this, then probably in some time you > will say: thanks, good man Mikhail. Thanks, good troll Mikhail. You started a nice thread, but your advice is now crystal clear for what it is: duff. ChrisA From mikhailwas at gmail.com Tue Mar 21 18:32:07 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Tue, 21 Mar 2017 23:32:07 +0100 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <201703211241.13562.gheskett@shentel.net> Message-ID: On 21 March 2017 at 22:40, Chris Angelico wrote: > On Wed, Mar 22, 2017 at 8:27 AM, Mikhail V wrote: >> I'd just tell one thing since I am a bit tired: if you wish, >> take an advice: avoid *any* monospaced fonts as plague if you are >> reading a lot of information, this includes coding. >> Avoid *any* sepia color schemes as plague. >> Avoid *any* sans-serif font. Get the most close >> to Garamond or Perpetua font. >> >> For cases, where you *absolutely must* use monospaced >> font, stick to Courier font (it is called "Courier 10 pitch" on Linux, if >> you don't have it in the system, try to find it, it must be >> in some true type font package). >> As for editing executables I don't know what *exactly* >> are you trying to do, what processes are involved, >> so I can't advice much. >> And don't worry if a zero does not look like a pusy, >> but looks like a big O, this is irrelevant in most cases. >> >> Now if you follow this, then probably in some time you >> will say: thanks, good man Mikhail. > > Thanks, good troll Mikhail. You started a nice thread, but your advice > is now crystal clear for what it is: duff. > Youre welcome, good troll Chris :) And in this thread (apart this comment) you were reasonable, I am pleased. From mikhailwas at gmail.com Tue Mar 21 21:16:14 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Wed, 22 Mar 2017 02:16:14 +0100 Subject: Who are the "spacists"? In-Reply-To: <509d90d6-d0b3-b430-9e94-437c23589c48@gmail.com> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> <509d90d6-d0b3-b430-9e94-437c23589c48@gmail.com> Message-ID: On 21 March 2017 at 16:42, Michael Torrie wrote: > On 03/21/2017 08:15 AM, Mikhail V wrote: >> Didn't want to say this, but you know it was quite predictable from >> the beginning that >> the arguments will end up somewhere in "linux console is the center of the >> universe, e-macs is mother of all apps and monospaced text is peak of >> human evolution". > > Knowing that, the honest question is: if you knew where this would all > end up (in a heated argument), why did post your provocation in the > first place? That was a metaphor, it was predictable that arguments will touch some retro aspects, but it was quite unpredictable that till now I did not see good arguments for spaces, and I was interested of course to see some technical aspects. So one of mentioned points for spaces which I can count as more or less real argument, that many web forms keep converting tabs to spaces, when I paste code into them and when I copy back into the editor, I need again to convert them. This is not a good argument against tabs but this is at least a *real* issue. Unlike other, (not so logical or yet not supported) arguments. Does it sound reasonable? Why I ask? Well obviously because I and probably many people want to know why cannot one make sort of styleguide based on pros and cons. Mikhail From ben+python at benfinney.id.au Tue Mar 21 21:28:56 2017 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 22 Mar 2017 12:28:56 +1100 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> <509d90d6-d0b3-b430-9e94-437c23589c48@gmail.com> Message-ID: <85inn2f6av.fsf@benfinney.id.au> Grant Edwards writes: > Question: is it still successfull trolling if we all knew that was the > intent and are just playing along for the entertainment value? Yes, it creates more noise and drives away signal from people who don't want to be in a noisy environment. That is success for the troll. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but isn't that why they invented tube socks?? ?_Pinky | _o__) and The Brain_ | Ben Finney From nad at python.org Tue Mar 21 23:16:50 2017 From: nad at python.org (Ned Deily) Date: Tue, 21 Mar 2017 23:16:50 -0400 Subject: [RELEASE] Python 3.6.1 is now available Message-ID: <4AA9F522-CAC7-4ACC-991C-495F17E1045A@python.org> On behalf of the Python development community and the Python 3.6 release team, I would like to announce the availability of Python 3.6.1, the first maintenance release of Python 3.6. 3.6.0 was released on 2016-12-22 to great interest and now, three months later, we are providing the first set of bugfixes and documentation updates for it. Although it should be transparent to users of Python, 3.6.1 is the first release after some major changes to our development process so we ask users who build Python from source to be on the lookout for any unexpected differences. Please see "What?s New In Python 3.6" for more information: https://docs.python.org/3.6/whatsnew/3.6.html You can find Python 3.6.1 here: https://www.python.org/downloads/release/python-361/ and its change log here: https://docs.python.org/3.6/whatsnew/changelog.html#python-3-6-1 The next maintenance release of Python 3.6 is expected to follow in about 3 months by the end of 2017-06. More information about the 3.6 release schedule can be found here: https://www.python.org/dev/peps/pep-0494/ -- Ned Deily nad at python.org -- [] From lele at metapensiero.it Wed Mar 22 05:40:36 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Wed, 22 Mar 2017 10:40:36 +0100 Subject: Manager for project templates, that allows "incremental" feature addition References: <10cc3f5f-9345-4db7-846b-cd912a3771a9@googlegroups.com> Message-ID: <871stpzm23.fsf@metapensiero.it> Paul Moore writes: > I'm looking for a utility that is something like cookiecutter, in that it generates a "template" project for me. However, I would like the ability to have a template add content based on runtime questions, something like > > Do you want to include a C extension? [yes/no] > ... adds Extension() to setup.py, adds a C source file, etc > Do you want to include tests? [yes/no] > ... add a test directory with a sample test > Tests to run under tox? [yes/no] > ... add tox support (this question shouldn't be asked if the previous answer was "no") > > As far as I know, this sort of feature isn't available in cookiecutter, nor is it planned. > > Does anyone know of any similar utility that has this feature? This what I wrote and heavily use https://pypi.python.org/pypi/metapensiero.tool.tinject It seems to fit some, but not all, of your requested features. Hope this helps, ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From barry at barrys-emacs.org Wed Mar 22 06:40:47 2017 From: barry at barrys-emacs.org (Barry Scott) Date: Wed, 22 Mar 2017 10:40:47 +0000 Subject: Announcing SCM Workbench 0.8.5 GUI for Git, Mercurial (hg) and Subversion (svn) Message-ID: SCM Workbench features ? Support Subversion (svn), Mercurial (hg) and Git projects. ? Easy to learn and use ? Built in User Guide describes the operation and features of the application. ? Add project wizard can scan for all your existing projects. ? All subversion client operations in a GUI ? Many Git client operations in a GUI ? GUI git rebase ? Some mercurial (hg) client operations in a GUI ? Enhanced operations (subversion rename of modified files etc) ? Support software development workflow ? Built in GUI diff showing line and character diffs ? Ability to diff between commits in a files history ? Runs on Windows, Mac OS X and Unix platforms Kits are available for Windows, macOS and Fedora. Please visit http://scm-workbench.barrys-emacs.org/ for downloads and further information on SCM Workbench. SCM Workbench is implemented in Python3 using PyQt5, pysvn, GitPython and hglib-python. Barry From info at wingware.com Wed Mar 22 12:08:24 2017 From: info at wingware.com (Wingware) Date: Wed, 22 Mar 2017 12:08:24 -0400 Subject: ANN: Wing Python IDE 6.0.3 released Message-ID: <58D2A178.6050002@wingware.com> Hi, We've just released Wing 6.0.3 which implements auto-completion in strings and comments, supports syntax highlighting and error indicators for f-strings, adds a How-To for Jupyter notebooks, allows concurrent update of recent menus from multiple instances of Wing, fixes Django template debugging, and makes about 70 other improvements. For details, see http://wingware.com/pub/wingide/6.0.3/CHANGELOG.txt Wing 6 is the latest major release in Wingware's family of Python IDEs, including Wing Pro, Wing Personal, and Wing 101. Wing 6 adds many new features, introduces a new annual license option for Wing Pro, and makes Wing Personal free. New Features * Improved Multiple Selections: Quickly add selections and edit them all at once * Easy Remote Development: Work seamlessly on remote Linux, OS X, and Raspberry Pi systems * Debugging in the Python Shell: Reach breakpoints and exceptions in (and from) the Python Shell * Recursive Debugging: Debug code invoked in the context of stack frames that are already being debugged * PEP 484 and PEP 526 Type Hinting: Inform Wing's static analysis engine of types it cannot infer * Support for Python 3.6 and Stackless 3.4: Use async and other new language features * Optimized debugger: Run faster, particularly in multi-process and multi-threaded code * Support for OS X full screen mode: Zoom to a virtual screen, with auto-hiding menu bar * Added a new One Dark color palette: Enjoy the best dark display style yet * Updated French and German localizations: Thanks to Jean Sanchez, Laurent Fasnacht, and Christoph Heitkamp For a more detailed overview of new features see the release notice at http://wingware.com/news/2017-03-21 Annual Use License Option Wing 6 adds the option of purchasing a lower-cost expiring annual license for Wing Pro. An annual license includes access to all available Wing Pro versions while it is valid, and then ceases to function if it is now renewed. Pricing for annual licenses is US$ 179/user for Commercial Use and US$ 69/user for Non-Commercial Use. Perpetual licenses for Wing Pro will continue to be available at the same pricing. The cost of extending Support+Upgrades subscriptions on Non-Commercial Use perpetual licenses for Wing Pro has also been dropped from US$ 89 to US$ 39 per user. For details, see https://wingware.com/store/ Wing Personal is Free Wing Personal is now free and no longer requires a license to run. It now also includes the Source Browser, PyLint, and OS Commands tools, and supports the scripting API and Perspectives. However, Wing Personal does not include Wing Pro's advanced editing, debugging, testing and code management features, such as remote development, refactoring, find uses, version control, unit testing, interactive debug probe, multi-process and child process debugging, move program counter, conditional breakpoints, debug watch, framework-specific support (for Jupyter, Django, and others), find symbol in project, and other features. Links Release notice: http://wingware.com/news/2017-03-21 Download: http://wingware.com/downloads Buy: http://wingware.com/store/purchase Upgrade: https://wingware.com/store/upgrade Questions? Don't hesitate to email us at support at wingware.com. Thanks, -- Stephan Deibel Wingware | Python IDE The Intelligent Development Environment for Python Programmers wingware.com From k.d.jantzen at mailbox.org Wed Mar 22 12:42:08 2017 From: k.d.jantzen at mailbox.org (Klaus Jantzen) Date: Wed, 22 Mar 2017 17:42:08 +0100 Subject: Recompilation of Python3.6.x Message-ID: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> Hello, in order to have the Python-SQLite support available one has to recompile Python. For the recompiliation to succeed a number of 'modules/libs' have to be present. In the internet I found the following list build-essential libz-dev libreadline-dev libncursesw5-dev libssl-dev libgdbm-dev libsqlite3-dev libbz2-dev liblzma-dev tk-dev libdb-dev libc6-dev zlib After having installed these 'modules/libs' I recompiled Python3.6.1 and although the steps 'make', 'make test', and 'make install' produced some errors the sqlite3-support is available. My question: Is this list complete or are there superfluous items? My suggestion: Couldn't such a list be provided in the README file? -- K.D.J. From tomuxiong at gmx.com Wed Mar 22 13:34:52 2017 From: tomuxiong at gmx.com (Thomas Nyberg) Date: Wed, 22 Mar 2017 13:34:52 -0400 Subject: Recompilation of Python3.6.x In-Reply-To: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> Message-ID: On 03/22/2017 12:42 PM, Klaus Jantzen wrote: > Hello, > > in order to have the Python-SQLite support available one has to > recompile Python. For the recompiliation to succeed a number of > 'modules/libs' have to be present. > > In the internet I found the following list > > build-essential > libz-dev > libreadline-dev > libncursesw5-dev > libssl-dev > libgdbm-dev > libsqlite3-dev > libbz2-dev > liblzma-dev > tk-dev > libdb-dev > libc6-dev > > zlib > > After having installed these 'modules/libs' I recompiled Python3.6.1 and > although the steps > > 'make', 'make test', and 'make install' produced some errors the > sqlite3-support is available. > > My question: Is this list complete or are there superfluous items? > > My suggestion: Couldn't such a list be provided in the README file? If you're using Ubuntu/debian, you could use `sudo apt-get build-dep python3.5` (might need another version depending upon what you have in your package manager). What that does is install the packages required to build the debian packages. Unless any new libraries are needed for 3.6, you should be good. I can't speak for the maintainers, but I don't think that providing such a list is super reasonable considering that there are many different OSs which have sometimes have slightly different library package names (though of course one could argue that Ubuntu/debian helps a lot of people). Cheers, Thomas From irving.duran at gmail.com Wed Mar 22 14:37:55 2017 From: irving.duran at gmail.com (Irving Duran) Date: Wed, 22 Mar 2017 13:37:55 -0500 Subject: How to search out all Zip codes and replace with the first 2 digits, in a Pandas dataframe, with the use of regex? In-Reply-To: <403347784.6411726.1490021609515@mail.yahoo.com> References: <403347784.6411726.1490021609515.ref@mail.yahoo.com> <403347784.6411726.1490021609515@mail.yahoo.com> Message-ID: You can do the following df['field'] = df.replace(r'(? wrote: > Hi, there, > Can anyone help? > How to search out all Zip codes and replace with the first 2 digits, in a > Pandas dataframe, with the use of regex? > > For instance, a ZIP code 33132 was found and replaced with 33. > Looking forward to hearing from you. > Regards. > David > -- > https://mail.python.org/mailman/listinfo/python-list > From jon+usenet at unequivocal.eu Wed Mar 22 15:22:46 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 22 Mar 2017 19:22:46 -0000 (UTC) Subject: Recompilation of Python3.6.x References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> Message-ID: On 2017-03-22, Thomas Nyberg wrote: > I can't speak for the maintainers, but I don't think that providing such > a list is super reasonable considering that there are many different OSs > which have sometimes have slightly different library package names > (though of course one could argue that Ubuntu/debian helps a lot of people). A simple table with a list of the library names, the debian package names, and the rpm names would provide the information in a way that would be useful to everyone. From k.d.jantzen at mailbox.org Wed Mar 22 15:38:13 2017 From: k.d.jantzen at mailbox.org (Klaus Jantzen) Date: Wed, 22 Mar 2017 20:38:13 +0100 Subject: Recompilation of Python3.6.x In-Reply-To: References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> Message-ID: <4fb344fc-a31f-2807-10a9-f491b507e5d7@mailbox.org> On 03/22/2017 06:34 PM, Thomas Nyberg wrote: On 03/22/2017 12:42 PM, Klaus Jantzen wrote: Hello, in order to have the Python-SQLite support available one has to recompile Python. For the recompiliation to succeed a number of 'modules/libs' have to be present. In the internet I found the following list build-essential libz-dev libreadline-dev libncursesw5-dev libssl-dev libgdbm-dev libsqlite3-dev libbz2-dev liblzma-dev tk-dev libdb-dev libc6-dev zlib After having installed these 'modules/libs' I recompiled Python3.6.1 and although the steps 'make', 'make test', and 'make install' produced some errors the sqlite3-support is available. My question: Is this list complete or are there superfluous items? My suggestion: Couldn't such a list be provided in the README file? If you're using Ubuntu/debian, you could use `sudo apt-get build-dep python3.5` (might need another version depending upon what you have in your package manager). What that does is install the packages required to build the debian packages. Unless any new libraries are needed for 3.6, you should be good. I did not know somenthing like this exists. I can't speak for the maintainers, but I don't think that providing such a list is super reasonable considering that there are many different OSs which have sometimes have slightly different library package names (though of course one could argue that Ubuntu/debian helps a lot of people). Cheers, Thomas With the above my suggestion is superfluous. Thanks a lot for the information. -- K.D.J. From tomuxiong at gmx.com Wed Mar 22 16:34:15 2017 From: tomuxiong at gmx.com (Thomas Nyberg) Date: Wed, 22 Mar 2017 16:34:15 -0400 Subject: Recompilation of Python3.6.x In-Reply-To: References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> Message-ID: <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> On 03/22/2017 03:22 PM, Jon Ribbens wrote: > A simple table with a list of the library names, the debian package > names, and the rpm names would provide the information in a way that > would be useful to everyone. > I definitely agree, but it would be kind of difficult to maintain. I mean if you supported debian and redhat (should others be considered?), then who's responsibility is it to keep it up to date? And then for Macs would you use names from brew? For Windows what would be done there? Other systems? I might be over complicating things, but still it feels like this could quickly fall out of date (though I guess new libraries are introduced pretty rarely, so maybe this is an unfounded fear). It's a bit hypothetical anyway. I guess if someone started gathering all of this information it could maybe be added? If not directly into the actual repository then maybe somewhere on the main python website. Having this would definitely be great, but I know I personally don't feel like doing the legwork... Cheers, Thomas From grant.b.edwards at gmail.com Wed Mar 22 16:45:45 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Wed, 22 Mar 2017 20:45:45 +0000 (UTC) Subject: Recompilation of Python3.6.x References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> Message-ID: On 2017-03-22, Thomas Nyberg wrote: > On 03/22/2017 03:22 PM, Jon Ribbens wrote: >> A simple table with a list of the library names, the debian package >> names, and the rpm names would provide the information in a way that >> would be useful to everyone. A _simple_ table would be useful. However, a _simple_ table is not possible. > I definitely agree, but it would be kind of difficult to maintain. I > mean if you supported debian and redhat (should others be > considered?), And you would need table for each _version_ of each distribution (libraries sometimes get combined/renamed/split). And you would need tables showing which libraires are required for which Python features: tkinter is optional, crypto is optional (or at least used to be), etc. -- Grant Edwards grant.b.edwards Yow! FUN is never having to at say you're SUSHI!! gmail.com From rosuav at gmail.com Wed Mar 22 17:05:07 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Mar 2017 08:05:07 +1100 Subject: Recompilation of Python3.6.x In-Reply-To: <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> Message-ID: On Thu, Mar 23, 2017 at 7:34 AM, Thomas Nyberg wrote: > On 03/22/2017 03:22 PM, Jon Ribbens wrote: >> >> A simple table with a list of the library names, the debian package >> names, and the rpm names would provide the information in a way that >> would be useful to everyone. >> > > I definitely agree, but it would be kind of difficult to maintain. I mean if > you supported debian and redhat (should others be considered?), then who's > responsibility is it to keep it up to date? And then for Macs would you use > names from brew? For Windows what would be done there? Other systems? I > might be over complicating things, but still it feels like this could > quickly fall out of date (though I guess new libraries are introduced pretty > rarely, so maybe this is an unfounded fear). This is exactly what apt build-dep is. It's part of the package manager system, so it's tied to your own version of Debian/Ubuntu/etc, and it's usually pretty reliable. You ask for the build deps of a previous Python 3, and they'll generally be what you need for the latest. ChrisA From wintermute24x7 at icloud.com Wed Mar 22 17:57:43 2017 From: wintermute24x7 at icloud.com (M. R.P.) Date: Wed, 22 Mar 2017 14:57:43 -0700 Subject: python source code Message-ID: does anyone know were I can python source code programs? From tomuxiong at gmx.com Wed Mar 22 18:03:49 2017 From: tomuxiong at gmx.com (Thomas Nyberg) Date: Wed, 22 Mar 2017 18:03:49 -0400 Subject: python source code In-Reply-To: References: Message-ID: <5f8f4d0f-f114-41cd-57df-db8ba32d358c@gmx.com> On 03/22/2017 05:57 PM, M. R.P. wrote: > does anyone know were I can python source code programs? The source code for cpython (i.e. the most common interpreter) can be found here: https://www.python.org/downloads/source/ https://github.com/python/cpython Unless you mean the source of a specific python program...then it depends on the program and we'll need a bit more detail... Cheers, Thomas From python at lucidity.plus.com Wed Mar 22 18:08:07 2017 From: python at lucidity.plus.com (Erik) Date: Wed, 22 Mar 2017 22:08:07 +0000 Subject: python source code In-Reply-To: References: Message-ID: <0ac5a31c-086f-f68b-572d-ad8f56764b4a@lucidity.plus.com> On 22/03/17 21:57, M. R.P. wrote: > does anyone know were I can [find?] python source code programs? Are you looking for the source to a Python language implementation itself? If so, see this link: https://www.python.org/downloads/ If not, what are you looking for, exactly? What sort of Python programs? E. From jon+usenet at unequivocal.eu Wed Mar 22 19:23:51 2017 From: jon+usenet at unequivocal.eu (Jon Ribbens) Date: Wed, 22 Mar 2017 23:23:51 -0000 (UTC) Subject: Recompilation of Python3.6.x References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> Message-ID: On 2017-03-22, Grant Edwards wrote: > On 2017-03-22, Thomas Nyberg wrote: >> On 03/22/2017 03:22 PM, Jon Ribbens wrote: >>> A simple table with a list of the library names, the debian package >>> names, and the rpm names would provide the information in a way that >>> would be useful to everyone. > > A _simple_ table would be useful. However, a _simple_ table is not > possible. > >> I definitely agree, but it would be kind of difficult to maintain. I >> mean if you supported debian and redhat (should others be >> considered?), > > And you would need table for each _version_ of each distribution > (libraries sometimes get combined/renamed/split). Not really, that's why I suggested one of the fields in the table would be the standard library name - people should always be able to use that to find the appropriate package for their distribution (if there is one, otherwise they'll need to compile from source). > And you would need tables showing which libraires are required for > which Python features: tkinter is optional, crypto is optional (or at > least used to be), etc. That's a good idea - that would make the simple table have 4 columns: name, deb, rpm, python module (or "essential"). From nathan.ernst at gmail.com Wed Mar 22 19:50:00 2017 From: nathan.ernst at gmail.com (Nathan Ernst) Date: Wed, 22 Mar 2017 18:50:00 -0500 Subject: Recompilation of Python3.6.x In-Reply-To: References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> Message-ID: I would also add a link to the dependency's project page, in case building from source is necessary. You don't always have root, and you're not always building with the system supplied compiler. There are a lot of situations that may require building from source. Far too many to even bother to enumerate. On Wed, Mar 22, 2017 at 6:23 PM, Jon Ribbens wrote: > On 2017-03-22, Grant Edwards wrote: > > On 2017-03-22, Thomas Nyberg wrote: > >> On 03/22/2017 03:22 PM, Jon Ribbens wrote: > >>> A simple table with a list of the library names, the debian package > >>> names, and the rpm names would provide the information in a way that > >>> would be useful to everyone. > > > > A _simple_ table would be useful. However, a _simple_ table is not > > possible. > > > >> I definitely agree, but it would be kind of difficult to maintain. I > >> mean if you supported debian and redhat (should others be > >> considered?), > > > > And you would need table for each _version_ of each distribution > > (libraries sometimes get combined/renamed/split). > > Not really, that's why I suggested one of the fields in the table > would be the standard library name - people should always be able > to use that to find the appropriate package for their distribution > (if there is one, otherwise they'll need to compile from source). > > > And you would need tables showing which libraires are required for > > which Python features: tkinter is optional, crypto is optional (or at > > least used to be), etc. > > That's a good idea - that would make the simple table have 4 columns: > name, deb, rpm, python module (or "essential"). > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Wed Mar 22 21:39:26 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Mar 2017 12:39:26 +1100 Subject: Recompilation of Python3.6.x In-Reply-To: References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> Message-ID: On Thu, Mar 23, 2017 at 10:50 AM, Nathan Ernst wrote: > I would also add a link to the dependency's project page, in case building > from source is necessary. > > You don't always have root, and you're not always building with the system > supplied compiler. > > There are a lot of situations that may require building from source. Far > too many to even bother to enumerate. If you're building a large project from source and are not using a system-provided compiler, you should have enough experience with building stuff from source that you can track libraries down yourself. Conversely, if you don't have that experience, why in the world are you not using a provided compiler? You don't need admin access to install a compiler on Windows. On Linux, you can generally replicate the environment somewhere else (unless you're trying to build for some really unusual CPU, in which case, again, you should first have enough experience to do it manually), build using the normal methods, and then carry the binary up to the restricted system. ChrisA From k.d.jantzen at mailbox.org Thu Mar 23 03:45:35 2017 From: k.d.jantzen at mailbox.org (Klaus Jantzen) Date: Thu, 23 Mar 2017 08:45:35 +0100 Subject: Recompilation of Python3.6.x In-Reply-To: References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> Message-ID: <5d56bddc-cb65-e216-7a37-4e2d417dbb3e@mailbox.org> On 03/23/2017 12:23 AM, Jon Ribbens wrote: > On 2017-03-22, Grant Edwards wrote: >> On 2017-03-22, Thomas Nyberg wrote: >>> On 03/22/2017 03:22 PM, Jon Ribbens wrote: >>>> A simple table with a list of the library names, the debian package >>>> names, and the rpm names would provide the information in a way that >>>> would be useful to everyone. >> A _simple_ table would be useful. However, a _simple_ table is not >> possible. >> >>> I definitely agree, but it would be kind of difficult to maintain. I >>> mean if you supported debian and redhat (should others be >>> considered?), >> And you would need table for each _version_ of each distribution >> (libraries sometimes get combined/renamed/split). > Not really, that's why I suggested one of the fields in the table > would be the standard library name - people should always be able > to use that to find the appropriate package for their distribution > (if there is one, otherwise they'll need to compile from source). > >> And you would need tables showing which libraires are required for >> which Python features: tkinter is optional, crypto is optional (or at >> least used to be), etc. > That's a good idea - that would make the simple table have 4 columns: > name, deb, rpm, python module (or "essential"). The information must be somewhere because Python must have been compiled frequently and correctly for the various (important) OSs before making it available to the public. And I do not think that it is left up to "your luck" that the required packages and libraries are present. -- K.D.J. From fabiofz at gmail.com Thu Mar 23 08:00:15 2017 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Thu, 23 Mar 2017 09:00:15 -0300 Subject: PyDev 5.6.0 Released Message-ID: PyDev 5.6.0 Release Highlights - *Important* PyDev now requires Java 8 and Eclipse 4.6 (Neon) onwards. - PyDev 5.2.0 is the last release supporting Eclipse 4.5 (Mars). - *Debugger* - *Performance* enhancements on the *debugger* (which should be *60%-100%* faster now). - The *debugger* now only supports *Python 2.6 onwards* (keep on PyDev 5.5.0 for Python 2.5 or below). - Properly displaying variables when the *interactive console* is connected to a *debug session*. *#PyDev-776* - Providing a way for the debugger to support a user-specified version of Qt for debugging QThreads (*preferences > PyDev > Debug > Qt Threads*). - Fixed issue where a *native Qt signal is not callable* message was raised when connecting a signal to QThread.started. - Fixed issue in displaying variable (with *Ctrl+Shift+D*) when debugging. - Debug view toolbar icons no longer appearing stretched due to Set Next Statement icon having a different size. - *Code completion* - *super* is now properly recognized (code completion and find definition). - *pytest fixtures* are now properly recognized (code completion and find definition). - Suppress invalid completions on literals numbers (patch by Jonah Graham) - *Others* - It's now possible to save the PyUnit preferences to the project or user settings. - Upgraded *pep8* to the latest *pycodestyle*. - Upgraded to latest *autopep8*. - Fixed issue in Django shell if version >= 1.10 *#PyDev-752*. - Add support for *coverage 4.x* (minimum supported version is now 4.3). *#PyDev-691* - Syntax highlighting for *matmul operator* (was being considered a decorator). *#PyDev-771* - Making *PyLint* use the same thread pool used for code analysis. - String index out of range while reading buffer in AbstractShell. *#PyDev-768* What is PyDev? PyDev is an open-source Python IDE on top of Eclipse for Python, Jython and IronPython development. It comes with goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, interactive console, etc. Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com What is LiClipse? LiClipse is a PyDev standalone with goodies such as support for Multiple cursors, theming, TextMate bundles and a number of other languages such as Django Templates, Jinja2, Kivy Language, Mako Templates, Html, Javascript, etc. It's also a commercial counterpart which helps supporting the development of PyDev. Details on LiClipse: http://www.liclipse.com/ Cheers, -- Fabio Zadrozny ------------------------------ Software Developer LiClipse http://www.liclipse.com PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com PyVmMonitor - Python Profiler http://www.pyvmmonitor.com/ From torriem at gmail.com Thu Mar 23 10:26:40 2017 From: torriem at gmail.com (Michael Torrie) Date: Thu, 23 Mar 2017 08:26:40 -0600 Subject: Recompilation of Python3.6.x In-Reply-To: <5d56bddc-cb65-e216-7a37-4e2d417dbb3e@mailbox.org> References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> <5d56bddc-cb65-e216-7a37-4e2d417dbb3e@mailbox.org> Message-ID: On 03/23/2017 01:45 AM, Klaus Jantzen wrote: > The information must be somewhere because Python must have been compiled > frequently and correctly for the various (important) OSs before making > it available to the public. And I do not think that it is left up to > "your luck" that the required packages and libraries are present. The information is essentially present in the recipe files that create the binary packages. As new versions come out, the distro maintainers modify the recipe file (in the RPM world, that's a SPEC file, distributed with the SRPM packages) when needed, based on trial and error, and also on the release notes for the upstream project. In SRPM spec files, there is a list of "build-requires" that list what packages (usually -devel). For Debian, as you've been told a while back, apt has a command to install the dependencies needed to build something: apt build-dep python3 After that, you can download the latest Python 3 debian source package, and then modify it to build the newer tarball. https://www.debian.org/doc/manuals/apt-howto/ch-sourcehandling.en.html So to answer your question, the list of what's required to build something is built into the distro package system, and that's where it's also maintained. Also the default build options for packages are set there as well. From tomuxiong at gmx.com Thu Mar 23 10:47:14 2017 From: tomuxiong at gmx.com (Thomas Nyberg) Date: Thu, 23 Mar 2017 10:47:14 -0400 Subject: Recompilation of Python3.6.x In-Reply-To: <5d56bddc-cb65-e216-7a37-4e2d417dbb3e@mailbox.org> References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> <5d56bddc-cb65-e216-7a37-4e2d417dbb3e@mailbox.org> Message-ID: <3131e264-4361-33fd-94d8-b5b5464678dd@gmx.com> On 03/23/2017 03:45 AM, Klaus Jantzen wrote: > The information must be somewhere because Python must have been compiled > frequently and correctly for the various (important) OSs before making > it available to the public. And I do not think that it is left up to > "your luck" that the required packages and libraries are present. > Of course it's true that people don't just compile things by luck, but it's also true that the issue is kind of beyond cpython. The best you could really expect is for cpython to say the following libraries with the following major numbers are required (possibly with links to the websites for the sources). It's out of the cpython programmers control how these libraries are made available on the many different systems and distributions that python is used on. If you use it on distro a and you want to compile it, it's basically your responsibility to figure out how to get the libraries. So really the main conclusion is that you should probably figure out how to use your distribution wisely to find this information. For any systems providing something similar to apt-get build-dep it's pretty easy (which _is_ your situation and hence you have already solved your problem). For others...well if you choose to use such a system it's your responsibility. As much as it was irritating not learning these tricks earlier, you do now know them and should be fine going forward... Cheers, Thomas From grant.b.edwards at gmail.com Thu Mar 23 10:57:13 2017 From: grant.b.edwards at gmail.com (Grant Edwards) Date: Thu, 23 Mar 2017 14:57:13 +0000 (UTC) Subject: Recompilation of Python3.6.x References: <8e4af5bf-2e61-50ad-8300-233b4f14500e@mailbox.org> <0394cba8-3d5c-399c-ae41-57adf280363b@gmx.com> <5d56bddc-cb65-e216-7a37-4e2d417dbb3e@mailbox.org> Message-ID: On 2017-03-23, Klaus Jantzen wrote: >>> And you would need tables showing which libraires are required for >>> which Python features: tkinter is optional, crypto is optional (or >>> at least used to be), etc. >> >> That's a good idea - that would make the simple table have 4 >> columns: name, deb, rpm, python module (or "essential"). > > The information must be somewhere because Python must have been > compiled frequently and correctly for the various (important) OSs > before making it available to the public. For CPython, the information about what libraries are required is in the autoconf input files (e.g. configure.ac) in the CPython sources. http://www.gnu.org/software/autoconf/autoconf.html How you locate information about what _packages_ those libraries are in varies depending on which distro and packaging system are in use. > And I do not think that it is left up to "your luck" that the > required packages and libraries are present. When CPython is packaged for a Linux distro, those options and library depdencies are figured out and then encoded into the build scripts that are used for the distros respective packaging systems (the .ebuild file for Portage, the .spec file for RPM, the files inthe ./debian directory in a .deb package). If you're building CPython, you have two choices: 1) Use your distro's packaging system to build it. That will insure that all the required libraries are built/installed. 2) Build it using the normal untar-configure-make steps. It may take many tries at the 'configure' step as you install required libraries until the configure script is happy. _Usually_ once the configure step is done, the make shouldn't uncover any more missing libraries. -- Grant Edwards grant.b.edwards Yow! When you get your at PH.D. will you get able to gmail.com work at BURGER KING? From p.f.moore at gmail.com Thu Mar 23 11:56:31 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 23 Mar 2017 08:56:31 -0700 (PDT) Subject: Manager for project templates, that allows "incremental" feature addition In-Reply-To: References: <10cc3f5f-9345-4db7-846b-cd912a3771a9@googlegroups.com> <871stpzm23.fsf@metapensiero.it> Message-ID: <261b8b58-e013-4d76-9e30-3335dfcd0d54@googlegroups.com> On Wednesday, 22 March 2017 09:41:21 UTC, Lele Gaifax wrote: > This what I wrote and heavily use > > https://pypi.python.org/pypi/metapensiero.tool.tinject > > It seems to fit some, but not all, of your requested features. Thanks - it looks like it could be very useful. I'll certainly give it a try! Paul From p.f.moore at gmail.com Thu Mar 23 14:55:49 2017 From: p.f.moore at gmail.com (Paul Moore) Date: Thu, 23 Mar 2017 11:55:49 -0700 (PDT) Subject: Manager for project templates, that allows "incremental" feature addition In-Reply-To: <261b8b58-e013-4d76-9e30-3335dfcd0d54@googlegroups.com> References: <10cc3f5f-9345-4db7-846b-cd912a3771a9@googlegroups.com> <871stpzm23.fsf@metapensiero.it> <261b8b58-e013-4d76-9e30-3335dfcd0d54@googlegroups.com> Message-ID: On Thursday, 23 March 2017 15:56:43 UTC, Paul Moore wrote: > On Wednesday, 22 March 2017 09:41:21 UTC, Lele Gaifax wrote: > > This what I wrote and heavily use > > > > https://pypi.python.org/pypi/metapensiero.tool.tinject > > > > It seems to fit some, but not all, of your requested features. > > Thanks - it looks like it could be very useful. I'll certainly give it a try! Sadly, it doesn't support Windows, which is what I use. The "inquirer" dependency is the problem - it has a pinned dependency on an old version of readchar that has a bug (since fixed) on Windows, and it depends on blessings, which needs curses, which isn't in the stdlib on Windows, although I could get a 3rd party version. Pity, as it looked very interesting. Thanks anyway for the suggestion. Paul From lele at metapensiero.it Thu Mar 23 18:08:33 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Thu, 23 Mar 2017 23:08:33 +0100 Subject: Manager for project templates, that allows "incremental" feature addition References: <10cc3f5f-9345-4db7-846b-cd912a3771a9@googlegroups.com> <871stpzm23.fsf@metapensiero.it> <261b8b58-e013-4d76-9e30-3335dfcd0d54@googlegroups.com> Message-ID: <87efxn7iji.fsf@metapensiero.it> Paul Moore writes: > Sadly, it doesn't support Windows, which is what I use. I'm sorry, there is little I can do on that front, but if you come up with an alternative library, please let me know. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From matt.mailinglists at gmail.com Thu Mar 23 19:07:19 2017 From: matt.mailinglists at gmail.com (Matt) Date: Thu, 23 Mar 2017 18:07:19 -0500 Subject: SNMP Message-ID: What is easiest way to read and write SNMP values with Python? From jpolo at mail.usf.edu Thu Mar 23 21:57:37 2017 From: jpolo at mail.usf.edu (john polo) Date: Thu, 23 Mar 2017 20:57:37 -0500 Subject: syntax error in first-time user script Message-ID: Greetings, I am attempting to learn Python. I have no programming background. I'm on a computer with Windows 7. I checked the PATH in System Variables and Python and Python\Scripts are in the path. I have a book, Python for Biologists and it supplies example scripts, one is called comment.py. The output from comment.py is Comments are very useful! I use cd to get to the directory with the example scripts and open a command prompt with "python" and get the prompt. I type "python comment.py" and get " File "", line 1 python comment.py ^ SyntaxError: invalid syntax " Sorry, I realize this may not all line up like it does when I'm typing this in the email. The caret/error pointer is under the t in comment. I am not sure what is causing this error. If I type "import comment.py" the output is "Comments are very useful! Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'comment.py'; 'comment' " If I use IDLE shell: "python comment.py" "SyntaxError: invalid syntax" I know I can open the file in the editor and use F5, but shouldn't I be able to use a command from shell? How do I run comment.py from a command line without error? Or is that not possible? cheers, John From dev at kou.li Fri Mar 24 04:22:07 2017 From: dev at kou.li (Kouli) Date: Fri, 24 Mar 2017 09:22:07 +0100 Subject: SNMP In-Reply-To: References: Message-ID: Have a look at https://snimpy.readthedocs.io/en/latest/ On Fri, Mar 24, 2017 at 12:07 AM, Matt wrote: > What is easiest way to read and write SNMP values with Python? > -- > https://mail.python.org/mailman/listinfo/python-list > From __peter__ at web.de Fri Mar 24 05:36:07 2017 From: __peter__ at web.de (Peter Otten) Date: Fri, 24 Mar 2017 10:36:07 +0100 Subject: syntax error in first-time user script References: Message-ID: john polo wrote: > Greetings, > I am attempting to learn Python. I have no programming background. I'm > on a computer with Windows 7. I checked the PATH in System Variables and > Python and Python\Scripts are in the path. I have a book, Python for > Biologists and it supplies example scripts, one is called comment.py. > The output from comment.py is > > Comments are very useful! > > I use cd to get to the directory with the example scripts and open a > command prompt with "python" and get the prompt. I type > > "python comment.py" > > and get > > " File "", line 1 > python comment.py > ^ > SyntaxError: invalid syntax First, welcome, and a big Thank You for providing the tracebacks! After the C:> cd (the C:> is a placeholder for whatever prompt you see) do not invoke python without arguments, invoke it with the script name: C:> python comment.py > " > > Sorry, I realize this may not all line up like it does when I'm typing > this in the email. The caret/error pointer is under the t in comment. I > am not sure what is causing this error. > > If I type > > "import comment.py" In this case you are already running the Python interpreter (remember you invokded it with C:> python ) and that will successfully import the comment module (you must not give the .py extension, that's automatically added when the interpreter searches for the module) and then try to import the py submodule which fails (if there were such a module it would be in the file comment/py.py where comment is a directory and py both the filename and the extension). > > the output is > > "Comments are very useful! > Traceback (most recent call last): > File "", line 1, in > ModuleNotFoundError: No module named 'comment.py'; 'comment' > " > > If I use IDLE shell: > > "python comment.py" > > "SyntaxError: invalid syntax" > > I know I can open the file in the editor and use F5, but shouldn't I be > able to use a command from shell? How do I run comment.py from a command > line without error? Or is that not possible? > > cheers, > John From mal at europython.eu Fri Mar 24 06:49:17 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 24 Mar 2017 12:49:17 +0200 Subject: EuroPython 2017: Get ready for EuroPython Call for Proposals Message-ID: Thinking of giving your contribution to EuroPython? Starting from March 27th you can submit a proposal on every aspect of Python: programming from novice to advanced levels, applications and frameworks, or how you have been involved in introducing Python into your organization. We offer a variety of different contribution formats that you can present at EuroPython: from regular talks to panel discussions, from trainings to posters; if you have ideas to promote real-time human- to-human-interaction or want to run yourself a helpdesk to answer other people?s python questions, this is your chance. Read our different opportunities on our website https://ep2017.europython.eu/en/speakers/call-for-proposals/ and start drafting your ideas. *** Call for Proposals opens in just 3 days! *** Enjoy, -- EuroPython 2017 Team http://ep2017.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/845208294222368768 Thanks. From lele at metapensiero.it Fri Mar 24 07:51:02 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Fri, 24 Mar 2017 12:51:02 +0100 Subject: Manager for project templates, that allows "incremental" feature addition References: <10cc3f5f-9345-4db7-846b-cd912a3771a9@googlegroups.com> <871stpzm23.fsf@metapensiero.it> <261b8b58-e013-4d76-9e30-3335dfcd0d54@googlegroups.com> Message-ID: <87lgrugaft.fsf@metapensiero.it> Paul Moore writes: > On Thursday, 23 March 2017 15:56:43 UTC, Paul Moore wrote: > > Sadly, it doesn't support Windows, which is what I use. FYI, I just saw https://pypi.python.org/pypi/whaaaaat/0.4.0, that seems an alternative port of Inquirer.js. Unfortunately it's Py2 only :-\ If you can try it under Windows, maybe I could be convinced in contributing some Py3 compatibility fixes, and try to support that too in my tinject. ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From bgailer at gmail.com Fri Mar 24 10:11:04 2017 From: bgailer at gmail.com (Bob Gailer) Date: Fri, 24 Mar 2017 10:11:04 -0400 Subject: syntax error in first-time user script In-Reply-To: References: Message-ID: On Mar 24, 2017 4:53 AM, "john polo" wrote: > > Greetings, > I am attempting to learn Python. I have no programming background. I'm on a computer with Windows 7. I checked the PATH in System Variables and Python and Python\Scripts are in the path. I have a book, Python for Biologists and it supplies example scripts, one is called comment.py. The output from comment.py is > > Comments are very useful! > > I use cd to get to the directory with the example scripts We can assume you are at a Windows command prompt. It' a good idea too tell us that, so we don't have to assume! and open a command prompt with "python" and get the prompt. Assumptions / terminology again! Typing "python" normally invokes the python interpreter. Since you did not pass any arguments you get a window displaying the python interpreter prompt (>>>). I type > > "python comment.py" > > and get > > " File "", line 1 > python comment.py > ^ > SyntaxError: invalid syntax It is great (as John said) that you provided the traceback. It would have been even greater if you had given us the rest e.g, Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. C:\Users\bgailer>cd /examples C:\examples>python Python 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> python comment.py File "", line 1 python comment.py ^ SyntaxError: invalid syntax >>> Which brings up one other important matter: when writing us also tell us which python version you are using. In my example it is 3.3.5. > > Sorry, I realize this may not all line up like it does when I'm typing this in the email. The caret/error pointer is under the t in comment. I am not sure what is causing this error. > > If I type > > "import comment.py" > > the output is > > "Comments are very useful! > Traceback (most recent call last): > File "", line 1, in > ModuleNotFoundError: No module named 'comment.py'; 'comment' > " > > If I use IDLE shell: > > "python comment.py" > > "SyntaxError: invalid syntax" > > I know I can open the file in the editor and use F5, but shouldn't I be able to use a command from shell? How do I run comment.py from a command line without error? Or is that not possible? > > cheers, > John > -- > https://mail.python.org/mailman/listinfo/python-list From jpolo at mail.usf.edu Fri Mar 24 10:33:11 2017 From: jpolo at mail.usf.edu (john polo) Date: Fri, 24 Mar 2017 09:33:11 -0500 Subject: syntax error in first-time user script In-Reply-To: References: Message-ID: On 3/24/2017 9:11 AM, Bob Gailer wrote: > > On Mar 24, 2017 4:53 AM, "john polo" > wrote: > > > > Greetings, > > I am attempting to learn Python. I have no programming background. > I'm on a computer with Windows 7. I checked the PATH in System > Variables and Python and Python\Scripts are in the path. I have a > book, Python for Biologists and it supplies example scripts, one is > called comment.py. The output from comment.py is > > > > Comments are very useful! > > > > I use cd to get to the directory with the example scripts > > We can assume you are at a Windows command prompt. It' a good idea too > tell us that, so we don't have to assume! > > and open a command prompt with "python" and get the prompt. > > Assumptions / terminology again! Typing "python" normally invokes the > python interpreter. Since you did not pass any arguments you get a > window displaying the python interpreter prompt (>>>). > > I type > > > > "python comment.py" > > > > and get > > > > " File "", line 1 > > python comment.py > > ^ > > SyntaxError: invalid syntax > > It is great (as John said) that you provided the traceback. It would > have been even greater if you had given us the rest e.g, > > Microsoft Windows [Version 10.0.14393] > (c) 2016 Microsoft Corporation. All rights reserved. > > C:\Users\bgailer>cd /examples > > C:\examples>python > Python 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:35:05) [MSC v.1600 > 64 bit (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> python comment.py > File "", line 1 > python comment.py > ^ > SyntaxError: invalid syntax > >>> > > Which brings up one other important matter: when writing us also tell > us which python version you are using. In my example it is 3.3.5. > I'm using 3.6.0. > > > > Sorry, I realize this may not all line up like it does when I'm > typing this in the email. The caret/error pointer is under the t in > comment. I am not sure what is causing this error. > > > > If I type > > > > "import comment.py" > > > > the output is > > > > "Comments are very useful! > > Traceback (most recent call last): > > File "", line 1, in > > ModuleNotFoundError: No module named 'comment.py'; 'comment' > > " > > > > If I use IDLE shell: > > > > "python comment.py" > > > > "SyntaxError: invalid syntax" > > > > I know I can open the file in the editor and use F5, but shouldn't I > be able to use a command from shell? How do I run comment.py from a > command line without error? Or is that not possible? > > > > cheers, > > John > > -- > > https://mail.python.org/mailman/listinfo/python-list > > -- Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing had happened. -- Winston Churchill From abdul.sw84 at gmail.com Fri Mar 24 12:08:34 2017 From: abdul.sw84 at gmail.com (Abdul Abdul) Date: Fri, 24 Mar 2017 18:08:34 +0200 Subject: Python question Message-ID: Hello, I hope you are doing fine. I have added a question on StackOverflow and thought you might have an idea on it. This is the question . Thanks a lot for your kind support. Best, Abder From tjreedy at udel.edu Fri Mar 24 12:55:23 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 24 Mar 2017 12:55:23 -0400 Subject: syntax error in first-time user script In-Reply-To: References: Message-ID: On 3/23/2017 9:57 PM, john polo wrote: > If I use IDLE shell: > > "python comment.py" > > "SyntaxError: invalid syntax" IDLE's Shell runs your input with nearly identical results as with the standard interactive interpreter, including exceptions. > I know I can open the file in the editor and use F5, but shouldn't I be > able to use a command from shell? No. You enter Python statements, not terminal commands. > How do I run comment.py from a command line without error? At the Command Prompt window's prompt, such as 'C:\user\you>', enter python path/to/comment.py The path shown before the prompt char, '>', is the 'current working directory'. Learn to use the 'cd' command. -- Terry Jan Reedy From adam.c.bernier at kp.org Fri Mar 24 14:42:44 2017 From: adam.c.bernier at kp.org (adam.c.bernier) Date: Fri, 24 Mar 2017 11:42:44 -0700 (PDT) Subject: Subprocess .wait() is not waiting Message-ID: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> Hi, I am on Windows 7. Python 2.7 I'm trying to have a program run another program using `subprocess.Popen` import subprocess as sp args = shlex.split(args) proc = sp.Popen(args,stdout=sp.PIPE,stderr=sp.PIPE) out, err = proc.communicate() proc.wait() But it *sometimes* doesn't wait and the other program -- which generates a set of 14 Excel files -- does not complete before control is returned to the calling program. Any ideas on what I can do to make `subprocess.wait()` actually wait? Thanks in advance for any assistance you might be able to provide. From python.list at tim.thechases.com Fri Mar 24 15:35:15 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 24 Mar 2017 14:35:15 -0500 Subject: Surprised by the lack of constant folding Message-ID: <20170324143515.76fb7b02@bigbox.christie.dr> Playing around, I came across the following $ python3 Python 3.4.2 (default, Oct 8 2014, 10:45:20) [GCC 4.9.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from dis import dis >>> def f(x): ... return x * 1024 * 1024 ... >>> dis(f) 2 0 LOAD_FAST 0 (x) 3 LOAD_CONST 1 (1024) 6 BINARY_MULTIPLY 7 LOAD_CONST 1 (1024) 10 BINARY_MULTIPLY 11 RETURN_VALUE Is there any reason that Python doesn't do the constant folding of 1024 * 1024? Especially as it does constant folding if the order is reversed: >>> def f(x): ... return 1024 * 1024 * x ... >>> dis(f) 2 0 LOAD_CONST 2 (1048576) 3 LOAD_FAST 0 (x) 6 BINARY_MULTIPLY 7 RETURN_VALUE I'm cool with defining things as a constant and using those instead or front-loading my constants in my expressions, but the disparity struck me as a little odd. Any insights on the reasons/motivations for one and not the other? -tkc From ian.g.kelly at gmail.com Fri Mar 24 15:40:15 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 24 Mar 2017 13:40:15 -0600 Subject: Subprocess .wait() is not waiting In-Reply-To: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> Message-ID: On Fri, Mar 24, 2017 at 12:42 PM, adam.c.bernier wrote: > Hi, > > I am on Windows 7. Python 2.7 > > I'm trying to have a program run another program using `subprocess.Popen` > > import subprocess as sp > > args = shlex.split(args) > proc = sp.Popen(args,stdout=sp.PIPE,stderr=sp.PIPE) > out, err = proc.communicate() > proc.wait() > > But it *sometimes* doesn't wait and the other program -- which generates a set of 14 Excel files -- does not complete before control is returned to the calling program. > > Any ideas on what I can do to make `subprocess.wait()` actually wait? > > Thanks in advance for any assistance you might be able to provide. If that's what's happening it would be a bug. Are you sure that the other program isn't simply crashing or otherwise failing to complete? By the way, the wait in the code above is redundant because communicate already waits. From rosuav at gmail.com Fri Mar 24 15:49:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Mar 2017 06:49:13 +1100 Subject: Surprised by the lack of constant folding In-Reply-To: <20170324143515.76fb7b02@bigbox.christie.dr> References: <20170324143515.76fb7b02@bigbox.christie.dr> Message-ID: On Sat, Mar 25, 2017 at 6:35 AM, Tim Chase wrote: > $ python3 > Python 3.4.2 (default, Oct 8 2014, 10:45:20) > [GCC 4.9.1] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> from dis import dis >>>> def f(x): > ... return x * 1024 * 1024 > ... >>>> dis(f) > 2 0 LOAD_FAST 0 (x) > 3 LOAD_CONST 1 (1024) > 6 BINARY_MULTIPLY > 7 LOAD_CONST 1 (1024) > 10 BINARY_MULTIPLY > 11 RETURN_VALUE > > Is there any reason that Python doesn't do the constant folding of > 1024 * 1024? Especially as it does constant folding if the order is > reversed: > >>>> def f(x): > ... return 1024 * 1024 * x > ... >>>> dis(f) > 2 0 LOAD_CONST 2 (1048576) > 3 LOAD_FAST 0 (x) > 6 BINARY_MULTIPLY > 7 RETURN_VALUE > > > I'm cool with defining things as a constant and using those instead > or front-loading my constants in my expressions, but the disparity > struck me as a little odd. Any insights on the reasons/motivations > for one and not the other? The first example is: (x * 1024) * 1024 The second is: (1024 * 1024) * x The first one can't be constant-folded without a semantic change (Python can't know that x will always be a number, even if you do). Suggestion: Use a different operator, which binds more tightly. >>> def f(x): ... return x * 2**20 ... >>> dis(f) 2 0 LOAD_FAST 0 (x) 2 LOAD_CONST 3 (1048576) 4 BINARY_MULTIPLY 6 RETURN_VALUE Since this evaluates as x * (2**20), it can be constant-folded. ChrisA From ian.g.kelly at gmail.com Fri Mar 24 15:49:49 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 24 Mar 2017 13:49:49 -0600 Subject: Surprised by the lack of constant folding In-Reply-To: <20170324143515.76fb7b02@bigbox.christie.dr> References: <20170324143515.76fb7b02@bigbox.christie.dr> Message-ID: On Fri, Mar 24, 2017 at 1:35 PM, Tim Chase wrote: > Playing around, I came across the following > > $ python3 > Python 3.4.2 (default, Oct 8 2014, 10:45:20) > [GCC 4.9.1] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> from dis import dis >>>> def f(x): > ... return x * 1024 * 1024 > ... >>>> dis(f) > 2 0 LOAD_FAST 0 (x) > 3 LOAD_CONST 1 (1024) > 6 BINARY_MULTIPLY > 7 LOAD_CONST 1 (1024) > 10 BINARY_MULTIPLY > 11 RETURN_VALUE > > Is there any reason that Python doesn't do the constant folding of > 1024 * 1024? Because that expression is equivalent to (x * 1024) * 1024, not x * (1024 * 1024). If x is a built-in type like int or list then that may be equivalent to x * 1048576, but the compiler can't know that x is necessarily one of those things. From rosuav at gmail.com Fri Mar 24 15:50:49 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Mar 2017 06:50:49 +1100 Subject: Subprocess .wait() is not waiting In-Reply-To: References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> Message-ID: On Sat, Mar 25, 2017 at 6:40 AM, Ian Kelly wrote: > If that's what's happening it would be a bug. Are you sure that the > other program isn't simply crashing or otherwise failing to complete? > Or possibly is running asynchronously. Is this a GUI app? A lot of Windows GUI programs don't wait when you invoke them. ChrisA From adam.c.bernier at kp.org Fri Mar 24 15:55:14 2017 From: adam.c.bernier at kp.org (adam.c.bernier) Date: Fri, 24 Mar 2017 12:55:14 -0700 (PDT) Subject: Subprocess .wait() is not waiting In-Reply-To: References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> Message-ID: <592af9fc-e3c3-46cf-9d8d-0894078baa51@googlegroups.com> On Friday, March 24, 2017 at 12:51:02 PM UTC-7, Chris Angelico wrote: > On Sat, Mar 25, 2017 at 6:40 AM, Ian Kelly wrote: > > If that's what's happening it would be a bug. Are you sure that the > > other program isn't simply crashing or otherwise failing to complete? > > > > Or possibly is running asynchronously. Is this a GUI app? A lot of > Windows GUI programs don't wait when you invoke them. > > ChrisA Aha! Since the Excel app is a GUI app it's not waiting is that right? From adam.c.bernier at kp.org Fri Mar 24 15:55:50 2017 From: adam.c.bernier at kp.org (adam.c.bernier) Date: Fri, 24 Mar 2017 12:55:50 -0700 (PDT) Subject: Subprocess .wait() is not waiting In-Reply-To: <592af9fc-e3c3-46cf-9d8d-0894078baa51@googlegroups.com> References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> <592af9fc-e3c3-46cf-9d8d-0894078baa51@googlegroups.com> Message-ID: On Friday, March 24, 2017 at 12:55:30 PM UTC-7, adam.c.bernier wrote: > On Friday, March 24, 2017 at 12:51:02 PM UTC-7, Chris Angelico wrote: > > On Sat, Mar 25, 2017 at 6:40 AM, Ian Kelly wrote: > > > If that's what's happening it would be a bug. Are you sure that the > > > other program isn't simply crashing or otherwise failing to complete? > > > > > > > Or possibly is running asynchronously. Is this a GUI app? A lot of > > Windows GUI programs don't wait when you invoke them. > > > > ChrisA > > Aha! Since the Excel app is a GUI app it's not waiting is that right? If that's the case is there any workaround? From adam.c.bernier at kp.org Fri Mar 24 15:59:28 2017 From: adam.c.bernier at kp.org (adam.c.bernier) Date: Fri, 24 Mar 2017 12:59:28 -0700 (PDT) Subject: Subprocess .wait() is not waiting In-Reply-To: References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> Message-ID: On Friday, March 24, 2017 at 12:41:22 PM UTC-7, Ian wrote: > On Fri, Mar 24, 2017 at 12:42 PM, adam.c.bernier wrote: > > Hi, > > > > I am on Windows 7. Python 2.7 > > > > I'm trying to have a program run another program using `subprocess.Popen` > > > > import subprocess as sp > > > > args = shlex.split(args) > > proc = sp.Popen(args,stdout=sp.PIPE,stderr=sp.PIPE) > > out, err = proc.communicate() > > proc.wait() > > > > But it *sometimes* doesn't wait and the other program -- which generates a set of 14 Excel files -- does not complete before control is returned to the calling program. > > > > Any ideas on what I can do to make `subprocess.wait()` actually wait? > > > > Thanks in advance for any assistance you might be able to provide. > > If that's what's happening it would be a bug. Are you sure that the > other program isn't simply crashing or otherwise failing to complete? > > By the way, the wait in the code above is redundant because > communicate already waits. Thank you for the comment about the wait being redundant. Much appreciated. From duncan at invalid.invalid Fri Mar 24 16:00:08 2017 From: duncan at invalid.invalid (duncan smith) Date: Fri, 24 Mar 2017 20:00:08 +0000 Subject: Surprised by the lack of constant folding In-Reply-To: References: <20170324143515.76fb7b02@bigbox.christie.dr> Message-ID: On 24/03/17 19:35, Tim Chase wrote: > Playing around, I came across the following > > $ python3 > Python 3.4.2 (default, Oct 8 2014, 10:45:20) > [GCC 4.9.1] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> from dis import dis >>>> def f(x): > ... return x * 1024 * 1024 > ... >>>> dis(f) > 2 0 LOAD_FAST 0 (x) > 3 LOAD_CONST 1 (1024) > 6 BINARY_MULTIPLY > 7 LOAD_CONST 1 (1024) > 10 BINARY_MULTIPLY > 11 RETURN_VALUE > > Is there any reason that Python doesn't do the constant folding of > 1024 * 1024? Especially as it does constant folding if the order is > reversed: > >>>> def f(x): > ... return 1024 * 1024 * x > ... >>>> dis(f) > 2 0 LOAD_CONST 2 (1048576) > 3 LOAD_FAST 0 (x) > 6 BINARY_MULTIPLY > 7 RETURN_VALUE > > > I'm cool with defining things as a constant and using those instead > or front-loading my constants in my expressions, but the disparity > struck me as a little odd. Any insights on the reasons/motivations > for one and not the other? > > -tkc > > > Left to right evaluation? Depending on the type of x, x * 1024 * 1024 might not return the same result as x * (1024 * 1024). That's my guess. Duncan From rosuav at gmail.com Fri Mar 24 16:09:35 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Mar 2017 07:09:35 +1100 Subject: Subprocess .wait() is not waiting In-Reply-To: References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> <592af9fc-e3c3-46cf-9d8d-0894078baa51@googlegroups.com> Message-ID: On Sat, Mar 25, 2017 at 6:55 AM, adam.c.bernier wrote: > On Friday, March 24, 2017 at 12:55:30 PM UTC-7, adam.c.bernier wrote: >> On Friday, March 24, 2017 at 12:51:02 PM UTC-7, Chris Angelico wrote: >> > On Sat, Mar 25, 2017 at 6:40 AM, Ian Kelly wrote: >> > > If that's what's happening it would be a bug. Are you sure that the >> > > other program isn't simply crashing or otherwise failing to complete? >> > > >> > >> > Or possibly is running asynchronously. Is this a GUI app? A lot of >> > Windows GUI programs don't wait when you invoke them. >> > >> > ChrisA >> >> Aha! Since the Excel app is a GUI app it's not waiting is that right? > > If that's the case is there any workaround? Errr.... been a while since I messed with Windows.... from memory, I think you can "start /wait programname" to make it wait?? Worth a try, at least. Otherwise, your best bet would be to wait in a completely different way. Give the app a specific file name to use as a signal, and when it's done, it should create that file. You then watch for that file, and when it exists, you move on. ChrisA From ian.g.kelly at gmail.com Fri Mar 24 16:24:05 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 24 Mar 2017 14:24:05 -0600 Subject: Subprocess .wait() is not waiting In-Reply-To: References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> <592af9fc-e3c3-46cf-9d8d-0894078baa51@googlegroups.com> Message-ID: On Fri, Mar 24, 2017 at 2:09 PM, Chris Angelico wrote: > On Sat, Mar 25, 2017 at 6:55 AM, adam.c.bernier wrote: >> On Friday, March 24, 2017 at 12:55:30 PM UTC-7, adam.c.bernier wrote: >>> On Friday, March 24, 2017 at 12:51:02 PM UTC-7, Chris Angelico wrote: >>> > On Sat, Mar 25, 2017 at 6:40 AM, Ian Kelly wrote: >>> > > If that's what's happening it would be a bug. Are you sure that the >>> > > other program isn't simply crashing or otherwise failing to complete? >>> > > >>> > >>> > Or possibly is running asynchronously. Is this a GUI app? A lot of >>> > Windows GUI programs don't wait when you invoke them. >>> > >>> > ChrisA >>> >>> Aha! Since the Excel app is a GUI app it's not waiting is that right? >> >> If that's the case is there any workaround? > > Errr.... been a while since I messed with Windows.... from memory, I > think you can "start /wait programname" to make it wait?? Worth a try, > at least. start /wait is for batch scripts, specifically because by default start doesn't wait on GUI programs. I'm pretty sure that WaitForSingleObject (which Popen.wait uses) is perfectly capable of waiting on GUI programs (I would even bet dollars for donuts that this is exactly what start /wait does). Another possibility is that the subprocess itself is creating its own subprocesses and not waiting on them. If it terminates before its children, the wait() call will finish even though work is still being done. From adam.c.bernier at kp.org Fri Mar 24 16:35:14 2017 From: adam.c.bernier at kp.org (adam.c.bernier) Date: Fri, 24 Mar 2017 13:35:14 -0700 (PDT) Subject: Subprocess .wait() is not waiting In-Reply-To: References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> <592af9fc-e3c3-46cf-9d8d-0894078baa51@googlegroups.com> Message-ID: <40fa1f00-9c2a-4cb0-ab66-4d22d17699b0@googlegroups.com> On Friday, March 24, 2017 at 1:09:49 PM UTC-7, Chris Angelico wrote: > On Sat, Mar 25, 2017 at 6:55 AM, adam.c.bernier wrote: > > On Friday, March 24, 2017 at 12:55:30 PM UTC-7, adam.c.bernier wrote: > >> On Friday, March 24, 2017 at 12:51:02 PM UTC-7, Chris Angelico wrote: > >> > On Sat, Mar 25, 2017 at 6:40 AM, Ian Kelly wrote: > >> > > If that's what's happening it would be a bug. Are you sure that the > >> > > other program isn't simply crashing or otherwise failing to complete? > >> > > > >> > > >> > Or possibly is running asynchronously. Is this a GUI app? A lot of > >> > Windows GUI programs don't wait when you invoke them. > >> > > >> > ChrisA > >> > >> Aha! Since the Excel app is a GUI app it's not waiting is that right? > > > > If that's the case is there any workaround? > > Errr.... been a while since I messed with Windows.... from memory, I > think you can "start /wait programname" to make it wait?? Worth a try, > at least. > > Otherwise, your best bet would be to wait in a completely different > way. Give the app a specific file name to use as a signal, and when > it's done, it should create that file. You then watch for that file, > and when it exists, you move on. > > ChrisA Thank you! I will try the first answer here http://stackoverflow.com/questions/11615455/python-start-new-command-prompt-on-windows-and-wait-for-it-finish-exit and see where that gets me. Thanks again for your thoughts. From eryksun at gmail.com Fri Mar 24 16:36:56 2017 From: eryksun at gmail.com (eryk sun) Date: Fri, 24 Mar 2017 20:36:56 +0000 Subject: Subprocess .wait() is not waiting In-Reply-To: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> Message-ID: On Fri, Mar 24, 2017 at 6:42 PM, adam.c.bernier wrote: > > I am on Windows 7. Python 2.7 > > I'm trying to have a program run another program using `subprocess.Popen` > > import subprocess as sp > > args = shlex.split(args) Is this command supposed to run cross-platform? If not, then splitting it into a list is pointless. Windows uses a comand-line string, and Popen will just have to rebuild the command line from the list. > proc = sp.Popen(args,stdout=sp.PIPE,stderr=sp.PIPE) > out, err = proc.communicate() > proc.wait() > > But it *sometimes* doesn't wait and the other program -- which generates a set of > 14 Excel files -- does not complete before control is returned to the calling program. > > Any ideas on what I can do to make `subprocess.wait()` actually wait? > > Thanks in advance for any assistance you might be able to provide. Without knowing the command you're running, all we can do is speculate. It could be that it's an application that uses a single instance, in which case running another instance simply messages the main process and then exits. From adam.c.bernier at kp.org Fri Mar 24 16:44:28 2017 From: adam.c.bernier at kp.org (adam.c.bernier) Date: Fri, 24 Mar 2017 13:44:28 -0700 (PDT) Subject: Subprocess .wait() is not waiting In-Reply-To: References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> Message-ID: <0aef4047-57c3-42f4-a9af-83417151020c@googlegroups.com> On Friday, March 24, 2017 at 1:37:49 PM UTC-7, eryk sun wrote: > On Fri, Mar 24, 2017 at 6:42 PM, adam.c.bernier wrote: > > > > I am on Windows 7. Python 2.7 > > > > I'm trying to have a program run another program using `subprocess.Popen` > > > > import subprocess as sp > > > > args = shlex.split(args) > > Is this command supposed to run cross-platform? If not, then splitting > it into a list is pointless. Windows uses a comand-line string, and > Popen will just have to rebuild the command line from the list. > > > proc = sp.Popen(args,stdout=sp.PIPE,stderr=sp.PIPE) > > out, err = proc.communicate() > > proc.wait() > > > > But it *sometimes* doesn't wait and the other program -- which generates a set of > > 14 Excel files -- does not complete before control is returned to the calling program. > > > > Any ideas on what I can do to make `subprocess.wait()` actually wait? > > > > Thanks in advance for any assistance you might be able to provide. > > Without knowing the command you're running, all we can do is > speculate. It could be that it's an application that uses a single > instance, in which case running another instance simply messages the > main process and then exits. Thank you, eryk sun. The command is calling a Python script which makes calls to openpyxl to generate 14 Excel files. From eryksun at gmail.com Fri Mar 24 17:04:59 2017 From: eryksun at gmail.com (eryk sun) Date: Fri, 24 Mar 2017 21:04:59 +0000 Subject: Subprocess .wait() is not waiting In-Reply-To: References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> <592af9fc-e3c3-46cf-9d8d-0894078baa51@googlegroups.com> Message-ID: On Fri, Mar 24, 2017 at 8:24 PM, Ian Kelly wrote: > On Fri, Mar 24, 2017 at 2:09 PM, Chris Angelico wrote: > >> Errr.... been a while since I messed with Windows.... from memory, I >> think you can "start /wait programname" to make it wait?? Worth a try, >> at least. > > start /wait is for batch scripts, specifically because by default > start doesn't wait on GUI programs. I'm pretty sure that In interactive mode, cmd waits on console programs but not GUI programs. In a batch script or /c or /k command it always waits, in which case `start` is required to run without waiting. The /w[ait] option may be needed if you're using `start` for some other feature, such as creating a new console or setting the CPU affinity. Otherwise if you just need to wait in a batch script, then you probably don't need `start /w`. From eryksun at gmail.com Fri Mar 24 17:26:16 2017 From: eryksun at gmail.com (eryk sun) Date: Fri, 24 Mar 2017 21:26:16 +0000 Subject: Subprocess .wait() is not waiting In-Reply-To: <0aef4047-57c3-42f4-a9af-83417151020c@googlegroups.com> References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> <0aef4047-57c3-42f4-a9af-83417151020c@googlegroups.com> Message-ID: On Fri, Mar 24, 2017 at 8:44 PM, adam.c.bernier wrote: > On Friday, March 24, 2017 at 1:37:49 PM UTC-7, eryk sun wrote: > >> Without knowing the command you're running, all we can do is >> speculate. It could be that it's an application that uses a single >> instance, in which case running another instance simply messages the >> main process and then exits. > > Thank you, eryk sun. The command is calling a Python script which makes calls to > openpyxl to generate 14 Excel files. openpyxl should do all of the work in the process that Popen is waiting on. Is the command-line in `args` something like "C:\Python27\python.exe path\to\script.py"? From adam.c.bernier at kp.org Fri Mar 24 17:28:53 2017 From: adam.c.bernier at kp.org (adam.c.bernier) Date: Fri, 24 Mar 2017 14:28:53 -0700 (PDT) Subject: Subprocess .wait() is not waiting In-Reply-To: References: <18a5c7e6-d7d2-4f69-8ef7-c1923cda5397@googlegroups.com> <0aef4047-57c3-42f4-a9af-83417151020c@googlegroups.com> Message-ID: <12d88c43-8e83-43bc-b93f-43a5be009b40@googlegroups.com> On Friday, March 24, 2017 at 2:27:09 PM UTC-7, eryk sun wrote: > On Fri, Mar 24, 2017 at 8:44 PM, adam.c.bernier wrote: > > On Friday, March 24, 2017 at 1:37:49 PM UTC-7, eryk sun wrote: > > > >> Without knowing the command you're running, all we can do is > >> speculate. It could be that it's an application that uses a single > >> instance, in which case running another instance simply messages the > >> main process and then exits. > > > > Thank you, eryk sun. The command is calling a Python script which makes calls to > > openpyxl to generate 14 Excel files. > > openpyxl should do all of the work in the process that Popen is > waiting on. Is the command-line in `args` something like > "C:\Python27\python.exe path\to\script.py"? That's exactly right. From cs at zip.com.au Fri Mar 24 19:09:52 2017 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 25 Mar 2017 10:09:52 +1100 Subject: Python question In-Reply-To: References: Message-ID: <20170324230952.GA75800@cskk.homeip.net> On 24Mar2017 18:08, Abdul Abdul wrote: >I hope you are doing fine. I have added a question on StackOverflow and >thought you might have an idea on it. This is the question > Hi Adbul, Please just post the question here, with a nice descriptive Subject: line. It is quite possible for people to be reading this list when they do not have web access (eg offline on a train, as I sometimes do) and it is anyway annoying to have to open a web browser to see what you are asking about, and doubly annoying to copy from that question into the list for replies. Thank you, Cameron Simpson From jobmattcon at gmail.com Sat Mar 25 04:37:54 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Sat, 25 Mar 2017 01:37:54 -0700 (PDT) Subject: why and how to run forever and debug when error in for proc in psutil.process_iter()? Message-ID: <71d1fddd-7fdf-4049-9e81-442d1f8b55f7@googlegroups.com> expect below to run forever and keep running a fixed number of thread in python would like to kill tasks when process connect internet except chrome and explorer.exe i do this because MalwareBytes can not disconnect these existing trojan when my notebook connect internet after run a few minutes, the program stopped, but i have already kept create process, why the whole program end? why and how to debug when error in for proc in psutil.process_iter()? import os import psutil import multiprocessing import time import sys def cleantask(): p = os.popen("netstat -ano") while 1: line = p.readline() if "TCP" in line or "UDP" in line: linelist = line.split() if len(linelist) > 4: if "LISTEN" in str(linelist[3]): for proc in psutil.process_iter(): try: if "pop" not in str(proc.name).tolower(): os.system("taskkill /f /pid "+str(proc._pid)) except: dummy = 1 #print "Unexpected error:", sys.exc_info()[0] #print "Unexpected error:", sys.exc_info()[1] if "ESTABLISHED" in str(linelist[3]): if "127.0.0.1" not in str(linelist[2]): for proc in psutil.process_iter(): try: if str(linelist[4]) in str(proc._pid): print(str(linelist[2])+","+str(linelist[4])+","+proc.name) if "111.221" not in str(linelist[2]) and "explorer.exe" not in str(proc.name).tolower(): os.system("taskkill /f /pid "+str(proc._pid)) except: dummy = 1 #print "Unexpected error:", sys.exc_info()[0] #print "Unexpected error:", sys.exc_info()[1] print(line) if not line: break if __name__ == '__main__': print("main") try: numberofrunning = 0 plist = [] for ii in range(0,5): p = multiprocessing.Process(target=cleantask(), args=(0,)) p.start() plist.append(p) numberofrunning = numberofrunning + 1 time.sleep(1) for pp in plist: pp.join() if pp.is_alive() == False: numberofrunning = numberofrunning - 1 plist.remove(pp) if numberofrunning > 10: print "more than 10 process" else: print("number of process = " + str(numberofrunning)) if numberofrunning <= 5: p = multiprocessing.Process(target=cleantask(), args=(0,)) p.start() plist.append(p) numberofrunning = numberofrunning + 1 time.sleep(1) except: print "Unexpected error:", sys.exc_info()[0] print "Unexpected error:", sys.exc_info()[1] From jobmattcon at gmail.com Sat Mar 25 04:41:47 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Sat, 25 Mar 2017 01:41:47 -0700 (PDT) Subject: should i kill these two process with python? Message-ID: <3cf0862c-1091-4290-b1e9-86759011c809@googlegroups.com> TCP 127.0.0.1:1663 127.0.0.1:28091 ESTABLISHED 9900 TCP 127.0.0.1:28091 127.0.0.1:1663 ESTABLISHED 9532 above two process connect to itself, named ismagent and updateui.exe are they the malware software? TCP 127.0.0.1:1663 127.0.0.1:28091 ESTABLISHED 9900 TCP 127.0.0.1:7496 0.0.0.0:0 LISTENING 7496 TCP 127.0.0.1:27015 0.0.0.0:0 LISTENING 9968 TCP 127.0.0.1:28091 0.0.0.0:0 LISTENING 9532 TCP 127.0.0.1:28091 127.0.0.1:1663 ESTABLISHED 9532 TCP 127.0.0.1:43227 0.0.0.0:0 LISTENING 3772 TCP 127.0.0.1:50000 0.0.0.0:0 LISTENING 9532 TCP 192.168.1.102:1128 210.176.156.35:443 FIN_WAIT_2 5124 TCP 192.168.1.102:1509 64.233.188.102:443 ESTABLISHED 6700 TCP 192.168.1.102:1510 216.58.203.46:443 ESTABLISHED 6700 TCP 192.168.1.102:1511 216.58.203.46:443 ESTABLISHED 6700 TCP 192.168.1.102:1512 216.58.200.5:443 ESTABLISHED 6700 TCP 192.168.1.102:1513 172.217.26.195:443 ESTABLISHED 6700 TCP 192.168.1.102:1514 172.217.26.195:443 CLOSE_WAIT 6700 TCP 192.168.1.102:1898 111.221.29.156:443 ESTABLISHED 1544 From rosuav at gmail.com Sat Mar 25 04:52:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Mar 2017 19:52:33 +1100 Subject: should i kill these two process with python? In-Reply-To: <3cf0862c-1091-4290-b1e9-86759011c809@googlegroups.com> References: <3cf0862c-1091-4290-b1e9-86759011c809@googlegroups.com> Message-ID: On Sat, Mar 25, 2017 at 7:41 PM, Ho Yeung Lee wrote: > TCP 127.0.0.1:1663 127.0.0.1:28091 ESTABLISHED 9900 > TCP 127.0.0.1:28091 127.0.0.1:1663 ESTABLISHED 9532 > > above two process connect to itself, named ismagent and updateui.exe > > are they the malware software? > > > TCP 127.0.0.1:1663 127.0.0.1:28091 ESTABLISHED 9900 > TCP 127.0.0.1:7496 0.0.0.0:0 LISTENING 7496 > TCP 127.0.0.1:27015 0.0.0.0:0 LISTENING 9968 > TCP 127.0.0.1:28091 0.0.0.0:0 LISTENING 9532 > TCP 127.0.0.1:28091 127.0.0.1:1663 ESTABLISHED 9532 > TCP 127.0.0.1:43227 0.0.0.0:0 LISTENING 3772 > TCP 127.0.0.1:50000 0.0.0.0:0 LISTENING 9532 > TCP 192.168.1.102:1128 210.176.156.35:443 FIN_WAIT_2 5124 > TCP 192.168.1.102:1509 64.233.188.102:443 ESTABLISHED 6700 > TCP 192.168.1.102:1510 216.58.203.46:443 ESTABLISHED 6700 > TCP 192.168.1.102:1511 216.58.203.46:443 ESTABLISHED 6700 > TCP 192.168.1.102:1512 216.58.200.5:443 ESTABLISHED 6700 > TCP 192.168.1.102:1513 172.217.26.195:443 ESTABLISHED 6700 > TCP 192.168.1.102:1514 172.217.26.195:443 CLOSE_WAIT 6700 > TCP 192.168.1.102:1898 111.221.29.156:443 ESTABLISHED 1544 This question is about systems administration and has nothing to do with Python. To figure out what each connection represents, you'll have to figure out what programs are on the two ends. (In the case of listening sockets, figure out which program is listening.) Then research what's actually being done by those programs. A simple dump like this is not going to tell you much about whether it's malware. ChrisA From dieter at handshake.de Sat Mar 25 05:10:35 2017 From: dieter at handshake.de (dieter) Date: Sat, 25 Mar 2017 10:10:35 +0100 Subject: Python question References: Message-ID: <87tw6hu3g4.fsf@handshake.de> Abdul Abdul writes: > I hope you are doing fine. I have added a question on StackOverflow and > thought you might have an idea on it. This is the question > I do not want to go into the details of your concrete problem -- just give some general remarks about "pickle". "pickle" is used for serialization/deserialization of (most) Python objects: i.e. it can transform a Python object into a string (called a "pickle") and (later) reconstruct the object from the pickle. You should not be interested in the internal pickle structure -- keep at the Python level. For your concrete problem: unpickle your pickle file to get a Python object; construct a similar Python object with the new data; pickle that Python object. From steve+python at pearwood.info Sat Mar 25 06:50:17 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sat, 25 Mar 2017 21:50:17 +1100 Subject: Python question References: <20170324230952.GA75800@cskk.homeip.net> Message-ID: <58d64b6b$0$1598$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Mar 2017 10:09 am, Cameron Simpson wrote: > On 24Mar2017 18:08, Abdul Abdul wrote: >>I hope you are doing fine. I have added a question on StackOverflow and >>thought you might have an idea on it. This is the question >> > > Hi Adbul, > > Please just post the question here, with a nice descriptive Subject: line. > > It is quite possible for people to be reading this list when they do not > have web access (eg offline on a train, as I sometimes do) and it is > anyway annoying to have to open a web browser to see what you are asking > about, and doubly annoying to copy from that question into the list for > replies. I solve that problem by hitting Delete on the original post, ESPECIALLY if they BCC or CC me without a good excuse. As I was in this case: the OP BCCed me in his post. I'm not *that* special, so my guess is that he did a mass BCC of many regulars here, which makes this spam. Judging from the question on Stackoverflow, I think he's just trying to drive eyeballs to the question so he can get higher reputation. It is a silly question: he says he has a pickle file containing an image file, and he's asking (1) what's in the pickle file, and (2) how can he create an identical pickle file containing a different image. The answer to (1) is "Whatever you put in it". Or possibly malware: he links to an actual pickle file he has put up on-line somewhere. Anyone brave enough to unpickle it in a sandbox and report on whether it contains what he says it contains? Remember that pickles can contain arbitrary executable code. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From ian.g.kelly at gmail.com Sat Mar 25 10:38:56 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sat, 25 Mar 2017 08:38:56 -0600 Subject: Who are the "spacists"? In-Reply-To: <85inn2f6av.fsf@benfinney.id.au> References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> <509d90d6-d0b3-b430-9e94-437c23589c48@gmail.com> <85inn2f6av.fsf@benfinney.id.au> Message-ID: On Tue, Mar 21, 2017 at 7:28 PM, Ben Finney wrote: > Grant Edwards writes: > >> Question: is it still successfull trolling if we all knew that was the >> intent and are just playing along for the entertainment value? > > Yes, it creates more noise and drives away signal from people who don't > want to be in a noisy environment. That is success for the troll. +1. Arguing with trolls is like tic-tac-toe or global thermonuclear war: the only way to win is not to play. From tjreedy at udel.edu Sat Mar 25 16:10:35 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Mar 2017 16:10:35 -0400 Subject: Python question In-Reply-To: <58d64b6b$0$1598$c3e8da3$5496439d@news.astraweb.com> References: <20170324230952.GA75800@cskk.homeip.net> <58d64b6b$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 3/25/2017 6:50 AM, Steve D'Aprano wrote: > On Sat, 25 Mar 2017 10:09 am, Cameron Simpson wrote: > >> On 24Mar2017 18:08, Abdul Abdul wrote: >>> I hope you are doing fine. I have added a question on StackOverflow and >>> thought you might have an idea on it. This is the question >>> >> >> Hi Adbul, >> >> Please just post the question here, with a nice descriptive Subject: line. >> >> It is quite possible for people to be reading this list when they do not >> have web access (eg offline on a train, as I sometimes do) and it is >> anyway annoying to have to open a web browser to see what you are asking >> about, and doubly annoying to copy from that question into the list for >> replies. > > > I solve that problem by hitting Delete on the original post, ESPECIALLY if > they BCC or CC me without a good excuse. As I was in this case: the OP > BCCed me in his post. I'm not *that* special, so my guess is that he did a > mass BCC of many regulars here, which makes this spam. I got the BCC also and was puzzled why. -- Terry Jan Reedy From python at mrabarnett.plus.com Sat Mar 25 16:26:24 2017 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 25 Mar 2017 20:26:24 +0000 Subject: Python question In-Reply-To: References: <20170324230952.GA75800@cskk.homeip.net> <58d64b6b$0$1598$c3e8da3$5496439d@news.astraweb.com> Message-ID: <286b5eea-6586-69ae-580c-87901becf165@mrabarnett.plus.com> On 2017-03-25 20:10, Terry Reedy wrote: > On 3/25/2017 6:50 AM, Steve D'Aprano wrote: >> On Sat, 25 Mar 2017 10:09 am, Cameron Simpson wrote: >> >>> On 24Mar2017 18:08, Abdul Abdul wrote: >>>> I hope you are doing fine. I have added a question on StackOverflow and >>>> thought you might have an idea on it. This is the question >>>> >>> >>> Hi Adbul, >>> >>> Please just post the question here, with a nice descriptive Subject: line. >>> >>> It is quite possible for people to be reading this list when they do not >>> have web access (eg offline on a train, as I sometimes do) and it is >>> anyway annoying to have to open a web browser to see what you are asking >>> about, and doubly annoying to copy from that question into the list for >>> replies. >> >> >> I solve that problem by hitting Delete on the original post, ESPECIALLY if >> they BCC or CC me without a good excuse. As I was in this case: the OP >> BCCed me in his post. I'm not *that* special, so my guess is that he did a >> mass BCC of many regulars here, which makes this spam. > > I got the BCC also and was puzzled why. > Same here. From jpolo at mail.usf.edu Sat Mar 25 17:45:12 2017 From: jpolo at mail.usf.edu (john polo) Date: Sat, 25 Mar 2017 16:45:12 -0500 Subject: syntax error in first-time user script In-Reply-To: References: Message-ID: <55f70962-79fe-715a-e7fa-c72770cef370@mail.usf.edu> I had a misconception of how the Python interpreter works. If I have a script, call it example.py, in order to run it, I shouldn't be in the interpreter? In other words, I should be at the Windows command prompt, for example C:/test> python example.py and not >>> python example.py ? So, if I am already on >>> and have a problem with a script and need to edit it and want to run the script again, how do I do that? Do I exit the interpreter and start it again? Or is there a different way to run the script once the interpreter is active and I am at >>> ? Cheers, John From joel.goldstick at gmail.com Sat Mar 25 18:32:55 2017 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 25 Mar 2017 18:32:55 -0400 Subject: PEOPLE! PLEASE! [ WAS: Re: Who are the "spacists"? ] In-Reply-To: References: Message-ID: On Sat, Mar 25, 2017 at 3:40 PM, Gilmeh Serda wrote: > >>> So Python supports both spaces and tabs for indentation. > > People! > > This is as far from normal conversation about Python as it gets! > > Keep this shit to yourselves, PLEASE! > > Using an editor worth the name, makes it a non issue (since it can > convert between one and the other, Eclipse/LiClipse comes to mind). Get > real, and think before you post/send! > > -- > Gilmeh > -- > https://mail.python.org/mailman/listinfo/python-list +1 -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From torriem at gmail.com Sat Mar 25 19:01:49 2017 From: torriem at gmail.com (Michael Torrie) Date: Sat, 25 Mar 2017 17:01:49 -0600 Subject: PEOPLE! PLEASE! [ WAS: Re: Who are the "spacists"? ] In-Reply-To: References: Message-ID: On 03/25/2017 01:40 PM, Gilmeh Serda wrote: > >>> So Python supports both spaces and tabs for indentation. > > People! > > This is as far from normal conversation about Python as it gets! > > Keep this shit to yourselves, PLEASE! > > Using an editor worth the name, makes it a non issue (since it can > convert between one and the other, Eclipse/LiClipse comes to mind). Get > real, and think before you post/send! I agree, although this thread had pretty much died on its own before you posted to it. Our troll seems to have slunk off, having done his trolling. Peace had returned it seemed. Unless the mailing list mods finally banned the guy... either way I haven't seen any posts in a while. Also USENET has a long tradition of killfiles. And entire threads can be muted on most clients, including e-mail clients. I recommend you and everyone else use these tools. From python at lucidity.plus.com Sat Mar 25 20:11:42 2017 From: python at lucidity.plus.com (Erik) Date: Sun, 26 Mar 2017 00:11:42 +0000 Subject: Python question In-Reply-To: <286b5eea-6586-69ae-580c-87901becf165@mrabarnett.plus.com> References: <20170324230952.GA75800@cskk.homeip.net> <58d64b6b$0$1598$c3e8da3$5496439d@news.astraweb.com> <286b5eea-6586-69ae-580c-87901becf165@mrabarnett.plus.com> Message-ID: On 25/03/17 20:26, MRAB wrote: > On 2017-03-25 20:10, Terry Reedy wrote: >> On 3/25/2017 6:50 AM, Steve D'Aprano wrote: >>> they BCC or CC me without a good excuse. As I was in this case: the OP >>> BCCed me in his post. I'm not *that* special, so my guess is that he >>> did a >>> mass BCC of many regulars here, which makes this spam. >> >> I got the BCC also and was puzzled why. >> > Same here. Me too, and I'm hardly a prolific poster compared to some of you lot. E. From mikhailwas at gmail.com Sat Mar 25 20:24:34 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 26 Mar 2017 01:24:34 +0100 Subject: PEOPLE! PLEASE! [ WAS: Re: Who are the "spacists"? ] In-Reply-To: References: Message-ID: On 26 March 2017 at 00:01, Michael Torrie wrote: > On 03/25/2017 01:40 PM, Gilmeh Serda wrote: >> >>>> So Python supports both spaces and tabs for indentation. >> >> People! >> >> This is as far from normal conversation about Python as it gets! >> >> Keep this shit to yourselves, PLEASE! >> >> Using an editor worth the name, makes it a non issue (since it can >> convert between one and the other, Eclipse/LiClipse comes to mind). Get >> real, and think before you post/send! > > I agree, although this thread had pretty much died on its own before you > posted to it. Our troll seems to have slunk off, having done his > trolling. Peace had returned it seemed. Unless the mailing list mods > finally banned the guy... either way I haven't seen any posts in a while. Oh don't turn it into drama please, it was interesting discussion. Sad is that many are more in sociology than technology. From abdul.sw84 at gmail.com Sat Mar 25 20:31:17 2017 From: abdul.sw84 at gmail.com (Abdul Abdul) Date: Sun, 26 Mar 2017 02:31:17 +0200 Subject: Python question In-Reply-To: <20170324230952.GA75800@cskk.homeip.net> References: <20170324230952.GA75800@cskk.homeip.net> Message-ID: Hi Cameron, Thanks for your kind reply and suggestion. Sure, please find my question below. I also show the different edits made and what errors emerged after those edits. Thanks for your support! I have the following code portion for a convolutional neural network: import numpy as np import matplotlib.pyplot as plt import cifar_tools import tensorflow as tf data, labels = cifar_tools.read_data('C:\\Users\\abc\\Desktop\\temp') x = tf.placeholder(tf.float32, [None, 150 * 150]) y = tf.placeholder(tf.float32, [None, 2]) w1 = tf.Variable(tf.random_normal([5, 5, 1, 64])) b1 = tf.Variable(tf.random_normal([64])) w2 = tf.Variable(tf.random_normal([5, 5, 64, 64])) b2 = tf.Variable(tf.random_normal([64])) w3 = tf.Variable(tf.random_normal([6*6*64, 1024])) b3 = tf.Variable(tf.random_normal([1024])) w_out = tf.Variable(tf.random_normal([1024, 2])) b_out = tf.Variable(tf.random_normal([2])) def conv_layer(x,w,b): conv = tf.nn.conv2d(x,w,strides=[1,1,1,1], padding = 'SAME') conv_with_b = tf.nn.bias_add(conv,b) conv_out = tf.nn.relu(conv_with_b) return conv_out def maxpool_layer(conv,k=2): return tf.nn.max_pool(conv, ksize=[1,k,k,1], strides=[1,k,k,1], padding='SAME') def model(): x_reshaped = tf.reshape(x, shape=[-1,150,150,1]) conv_out1 = conv_layer(x_reshaped, w1, b1) maxpool_out1 = maxpool_layer(conv_out1) norm1 = tf.nn.lrn(maxpool_out1, 4, bias=1.0, alpha=0.001/9.0, beta=0.75) conv_out2 = conv_layer(norm1, w2, b2) maxpool_out2 = maxpool_layer(conv_out2) norm2 = tf.nn.lrn(maxpool_out2, 4, bias=1.0, alpha=0.001/9.0, beta=0.75) maxpool_reshaped = tf.reshape(maxpool_out2, [-1,w3.get_shape().as_list()[0]]) local = tf.add(tf.matmul(maxpool_reshaped, w3), b3) local_out = tf.nn.relu(local) out = tf.add(tf.matmul(local_out, w_out), b_out) return out model_op = model() cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(model_op, y)) train_op = tf.train.AdamOptimizer(learning_rate=0.001).minimize(cost) correct_pred = tf.equal(tf.argmax(model_op, 1), tf.argmax(y,1)) accuracy = tf.reduce_mean(tf.cast(correct_pred,tf.float32)) I'm reading `150x150` grayscale images, but couldn't understand the following error I'm having: EPOCH 0 Traceback (most recent call last): File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1021, in _do_call return fn(*args) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1003, in _run_fn status, run_metadata) File "C:\Python35\lib\contextlib.py", line 66, in __exit__ next(self.gen) File "C:\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 469, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 92416 values, but the requested shape requires a multiple of 2304 [[Node: Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](MaxPool_1, Reshape_1/shape)]] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "cnn.py", line 70, in _, accuracy_val = sess.run([train_op, accuracy], feed_dict={x: batch_data, y: batch_onehot_vals}) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 766, in run run_metadata_ptr) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 964, in _run feed_dict_string, options, run_metadata) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1014, in _do_run target_list, options, run_metadata) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1034, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 92416 values, but the requested shape requires a multiple of 2304 [[Node: Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](MaxPool_1, Reshape_1/shape)]] Caused by op 'Reshape_1', defined at: File "cnn.py", line 50, in model_op = model() File "cnn.py", line 43, in model maxpool_reshaped = tf.reshape(maxpool_out2, [-1,w3.get_shape().as_list()[0]]) File "C:\Python35\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2448, in reshape name=name) File "C:\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 759, in apply_op op_def=op_def) File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2240, in create_op original_op=self._default_original_op, op_def=op_def) File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 1128, in __init__ self._traceback = _extract_stack() InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 92416 values, but the requested shape requires a multiple of 2304 [[Node: Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](MaxPool_1, Reshape_1/shape)]] **EDIT-1** Got this new error after modifying based on those edits: x_reshaped = tf.reshape(x, shape=[-1,150,150,1]) batch_size = x_reshaped.get_shape().as_list()[0] ... Same code as above ... maxpool_reshaped = tf.reshape(maxpool_out2, [batch_size, -1]) Error: Traceback (most recent call last): File "cnn.py", line 52, in model_op = model() File "cnn.py", line 45, in model maxpool_reshaped = tf.reshape(maxpool_out2, [batch_size, -1]) File "C:\Python35\lib\site-packages\tensorflow\python\ops\gen_array_ops.py", line 2448, in reshape name=name) File "C:\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 493, in apply_op raise err File "C:\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 490, in apply_op preferred_dtype=default_dtype) File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 669, in convert_to_tensor ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref) File "C:\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py", line 176, in _constant_tensor_conversion_function return constant(v, dtype=dtype, name=name) File "C:\Python35\lib\site-packages\tensorflow\python\framework\constant_op.py", line 165, in constant tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape)) File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 441, in make_tensor_proto tensor_proto.string_val.extend([compat.as_bytes(x) for x in proto_values]) File "C:\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 441, in tensor_proto.string_val.extend([compat.as_bytes(x) for x in proto_values]) File "C:\Python35\lib\site-packages\tensorflow\python\util\compat.py", line 65, in as_bytes (bytes_or_text,)) TypeError: Expected binary or unicode string, got None **EDIT-2** After doing the following edits (in addtion to removing `batch_size`: w3 = tf.Variable(tf.random_normal([361, 256])) ... ... w_out = tf.Variable(tf.random_normal([256, 2])) I'm having the following error: EPOCH 0 W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\framework\op_kernel.cc:975] Invalid argument: logits and labels must be same size: logits_size=[256,2] labels_size=[1,2] [[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape_2, Reshape_3)]] Traceback (most recent call last): File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1021, in _do_call return fn(*args) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1003, in _run_fn status, run_metadata) File "C:\Python35\lib\contextlib.py", line 66, in __exit__ next(self.gen) File "C:\Python35\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 469, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.InvalidArgumentError: logits and labels must be same size: logits_size=[256,2] labels_size=[1,2] [[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape_2, Reshape_3)]] During handling of the above exception, another exception occurred: Traceback (most recent call last): File "cnn.py", line 73, in _, accuracy_val = sess.run([train_op, accuracy], feed_dict={x: batch_data, y: batch_onehot_vals}) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 766, in run run_metadata_ptr) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 964, in _run feed_dict_string, options, run_metadata) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1014, in _do_run target_list, options, run_metadata) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1034, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: logits and labels must be same size: logits_size=[256,2] labels_size=[1,2] [[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape_2, Reshape_3)]] Caused by op 'SoftmaxCrossEntropyWithLogits', defined at: File "cnn.py", line 55, in cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(model_op, y)) File "C:\Python35\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 1449, in softmax_cross_entropy_with_logits precise_logits, labels, name=name) File "C:\Python35\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 2265, in _softmax_cross_entropy_with_logits features=features, labels=labels, name=name) File "C:\Python35\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 759, in apply_op op_def=op_def) File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 2240, in create_op original_op=self._default_original_op, op_def=op_def) File "C:\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 1128, in __init__ self._traceback = _extract_stack() InvalidArgumentError (see above for traceback): logits and labels must be same size: logits_size=[256,2] labels_size=[1,2] [[Node: SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Reshape_2, Reshape_3)]] **EDIT-3** This is how the binary (pickled) file looks like [label, filename, data]: [array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]), array(['1.jpg', '10.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg'], dtype=' _, accuracy_val = sess.run([train_op, accuracy], feed_dict={x: batch_data, y: batch_onehot_vals}) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 766, in run run_metadata_ptr) File "C:\Python35\lib\site-packages\tensorflow\python\client\session.py", line 943, in _run % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape()))) ValueError: Cannot feed value of shape (1, 22500) for Tensor 'Placeholder:0', which has shape '(?, 576)' How can I solve this issue? Thanks. On Sat, Mar 25, 2017 at 1:09 AM, Cameron Simpson wrote: > On 24Mar2017 18:08, Abdul Abdul wrote: > >> I hope you are doing fine. I have added a question on StackOverflow and >> thought you might have an idea on it. This is the question >> > ring-a-file-similar-to-another-pickled-file> >> > > Hi Adbul, > > Please just post the question here, with a nice descriptive Subject: line. > > It is quite possible for people to be reading this list when they do not > have web access (eg offline on a train, as I sometimes do) and it is anyway > annoying to have to open a web browser to see what you are asking about, > and doubly annoying to copy from that question into the list for replies. > > Thank you, > Cameron Simpson > From python at deborahswanson.net Sat Mar 25 21:33:38 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Sat, 25 Mar 2017 18:33:38 -0700 Subject: why and how to run forever and debug when error in for proc in psutil.process_iter()? In-Reply-To: <71d1fddd-7fdf-4049-9e81-442d1f8b55f7@googlegroups.com> Message-ID: <00a401d2a5d0$fec52800$27b23dae@sambora> Someone here can probably help you, but they'll need your Python version, operating system, and full traceback. They get tired of saying so. In this case, the full traceback is needed to see what went wrong and when (after which statements). Ho Yeung Lee wrote, on Saturday, March 25, 2017 1:38 AM > > expect below to run forever and keep running a fixed number > of thread in python > > would like to kill tasks when process connect internet except > chrome and explorer.exe > > i do this because MalwareBytes can not disconnect these > existing trojan when my notebook connect internet > > after run a few minutes, the program stopped, but i have > already kept create process, why the whole program end? > > why and how to debug when error in for proc in psutil.process_iter()? > > > import os > import psutil > import multiprocessing > import time > import sys > > def cleantask(): > p = os.popen("netstat -ano") > while 1: > line = p.readline() > if "TCP" in line or "UDP" in line: > linelist = line.split() > if len(linelist) > 4: > if "LISTEN" in str(linelist[3]): > for proc in psutil.process_iter(): > try: > if "pop" not in str(proc.name).tolower(): > os.system("taskkill /f /pid > "+str(proc._pid)) > except: > dummy = 1 > #print "Unexpected error:", > sys.exc_info()[0] > #print "Unexpected error:", > sys.exc_info()[1] > if "ESTABLISHED" in str(linelist[3]): > if "127.0.0.1" not in str(linelist[2]): > for proc in psutil.process_iter(): > try: > if str(linelist[4]) in > str(proc._pid): > > print(str(linelist[2])+","+str(linelist[4])+","+proc.name) > if "111.221" not in > str(linelist[2]) and "explorer.exe" not in str(proc.name).tolower(): > os.system("taskkill /f > /pid "+str(proc._pid)) > except: > dummy = 1 > #print "Unexpected error:", > sys.exc_info()[0] > #print "Unexpected error:", > sys.exc_info()[1] > print(line) > if not line: break > > if __name__ == '__main__': > print("main") > try: > numberofrunning = 0 > plist = [] > for ii in range(0,5): > p = multiprocessing.Process(target=cleantask(), args=(0,)) > p.start() > plist.append(p) > numberofrunning = numberofrunning + 1 > time.sleep(1) > for pp in plist: > pp.join() > if pp.is_alive() == False: > numberofrunning = numberofrunning - 1 > plist.remove(pp) > if numberofrunning > 10: > print "more than 10 process" > else: > print("number of process = " + str(numberofrunning)) > if numberofrunning <= 5: > p = > multiprocessing.Process(target=cleantask(), args=(0,)) > p.start() > plist.append(p) > numberofrunning = numberofrunning + 1 > time.sleep(1) > except: > print "Unexpected error:", sys.exc_info()[0] > print "Unexpected error:", sys.exc_info()[1] > -- > https://mail.python.org/mailman/listinfo/python-list > From python at deborahswanson.net Sat Mar 25 21:38:37 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Sat, 25 Mar 2017 18:38:37 -0700 Subject: syntax error in first-time user script In-Reply-To: <55f70962-79fe-715a-e7fa-c72770cef370@mail.usf.edu> Message-ID: <00ab01d2a5d1$b0e76bb0$27b23dae@sambora> john polo wrote, on March 25, 2017 2:45 PM > > I had a misconception of how the Python interpreter works. If > I have a > script, call it example.py, in order to run it, I shouldn't be in the > interpreter? In other words, I should be at the Windows > command prompt, > for example > > C:/test> python example.py > > and not > > >>> python example.py > > ? > > So, if I am already on >>> and have a problem with a script > and need to > edit it and want to run the script again, how do I do that? Do I exit > the interpreter and start it again? Or is there a different > way to run > the script once the interpreter is active and I am at >>> ? > > Cheers, > John In IDLE, to run a script, open the .py file from the file menu and click Run Module from the Run menu. You can easily edit the .py file while it's open in the editor From python at deborahswanson.net Sat Mar 25 21:52:11 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Sat, 25 Mar 2017 18:52:11 -0700 Subject: should i kill these two process with python? In-Reply-To: Message-ID: <00b201d2a5d3$966bdee0$27b23dae@sambora> Chris Angelico wrote, on Saturday, March 25, 2017 1:53 AM > > On Sat, Mar 25, 2017 at 7:41 PM, Ho Yeung Lee > wrote: > > TCP 127.0.0.1:1663 127.0.0.1:28091 > ESTABLISHED 9900 > > TCP 127.0.0.1:28091 127.0.0.1:1663 > ESTABLISHED 9532 > > > > above two process connect to itself, named ismagent and updateui.exe > > > > are they the malware software? > > > > > > TCP 127.0.0.1:1663 127.0.0.1:28091 > ESTABLISHED 9900 > > TCP 127.0.0.1:7496 0.0.0.0:0 > LISTENING 7496 > > TCP 127.0.0.1:27015 0.0.0.0:0 > LISTENING 9968 > > TCP 127.0.0.1:28091 0.0.0.0:0 > LISTENING 9532 > > TCP 127.0.0.1:28091 127.0.0.1:1663 > ESTABLISHED 9532 > > TCP 127.0.0.1:43227 0.0.0.0:0 > LISTENING 3772 > > TCP 127.0.0.1:50000 0.0.0.0:0 > LISTENING 9532 > > TCP 192.168.1.102:1128 210.176.156.35:443 > FIN_WAIT_2 5124 > > TCP 192.168.1.102:1509 64.233.188.102:443 > ESTABLISHED 6700 > > TCP 192.168.1.102:1510 216.58.203.46:443 > ESTABLISHED 6700 > > TCP 192.168.1.102:1511 216.58.203.46:443 > ESTABLISHED 6700 > > TCP 192.168.1.102:1512 216.58.200.5:443 > ESTABLISHED 6700 > > TCP 192.168.1.102:1513 172.217.26.195:443 > ESTABLISHED 6700 > > TCP 192.168.1.102:1514 172.217.26.195:443 > CLOSE_WAIT 6700 > > TCP 192.168.1.102:1898 111.221.29.156:443 > ESTABLISHED 1544 > > This question is about systems administration and has nothing > to do with Python. > > To figure out what each connection represents, you'll have to > figure out what programs are on the two ends. (In the case of > listening sockets, figure out which program is listening.) > Then research what's actually being done by those programs. A > simple dump like this is not going to tell you much about > whether it's malware. > > ChrisA You can also look up the IP addresses with a DNS lookup tool that aren't your machine (127.0.0.1 and 192.168.1.102). This may be helpful if you recognize who they are, or you can google the IP addresses and/or their owners. If they're malware, Google will have lots of pages on them. This looks like a readout from Essential Net Tools running in Express mode. If you select Addvanced mode, ENT will tell you the process name and lots of other good stuff for each entry, plus ENT is a full network toolbox and you won't need Google. Deborah From cs at zip.com.au Sat Mar 25 22:55:56 2017 From: cs at zip.com.au (cs at zip.com.au) Date: Sun, 26 Mar 2017 13:55:56 +1100 Subject: Python question In-Reply-To: <58d64b6b$0$1598$c3e8da3$5496439d@news.astraweb.com> <286b5eea-6586-69ae-580c-87901becf165@mrabarnett.plus.com> References: <58d64b6b$0$1598$c3e8da3$5496439d@news.astraweb.com> <286b5eea-6586-69ae-580c-87901becf165@mrabarnett.plus.com> Message-ID: <20170326025556.GA63134@cskk.homeip.net> On 26Mar2017 00:11, Erik wrote: >On 25/03/17 20:26, MRAB wrote: >>On 2017-03-25 20:10, Terry Reedy wrote: >>>On 3/25/2017 6:50 AM, Steve D'Aprano wrote: >>>>they BCC or CC me without a good excuse. As I was in this case: the OP >>>>BCCed me in his post. I'm not *that* special, so my guess is that he >>>>did a >>>>mass BCC of many regulars here, which makes this spam. >>>I got the BCC also and was puzzled why. >>Same here. >Me too, and I'm hardly a prolific poster compared to some of you lot. Guys guys guys, 1: He BCCed the list, not us individually. Look at the headers. 2: I got a perfectly civil and informative response from him. So treat him as up front! Cheers, Cameron Simpson From arjun.janah at gmail.com Sun Mar 26 00:01:36 2017 From: arjun.janah at gmail.com (arjun.janah) Date: Sun, 26 Mar 2017 00:01:36 -0400 Subject: Installation issue with Python 3.6.1 for 64 bit Windows Message-ID: <58d73d21.56cc370a.298ce.a849@mx.google.com> Sent from my T-Mobile 4G LTE Device Hello, I am using an HP PC, brought in 2009, which currently has on it Windows 7 Ultimate, Service Pack 1. The processor is an AMD Turion 64 X2 Mobile Technology TL-62 2.10 GHz. Installed memory is 4.00 GB (3.75 GB usable) System type is 64-bit operating system. I went to?https://www.python.org/downloads/windows/ and chose the following:?Download?Windows x86-64 executable installerThe downloaded file appeared, in my Downloads folder, as: python-3.6.1-amd64.exe, with a filesize of 30,657 KB. I ran the file and it appeared to install properly. But when I tried to run Python from the Windows All Programs menu tab, I got the following message, in a small window by the window with a black screen: ------------------------------------------ python.exe - System Error The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem.------------------------------------------ I tried the following: (a) restarting Windows and trying again: same result; (a) running the installer file again and selecting repair: this stalled for a long time so I had to abort it; (b) restarting my computer, running the installer file again and selecting uninstall: this uninstalled Python, so it said; (c) running the installer file again and choosing install: this installed Python afresh. But then I had the same problem as at the start when I tried to run Python. Please advise. Thanks Arjun Janah < arjun.janah at gmail.com > From best_lay at yahoo.com Sun Mar 26 00:16:03 2017 From: best_lay at yahoo.com (Wildman) Date: Sat, 25 Mar 2017 23:16:03 -0500 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> Message-ID: On Tue, 21 Mar 2017 15:15:14 +0100, Mikhail V wrote: > And on linux console, by default one does not even have good > possibilities for text-mode pseudographics, it was more relevant > in DOS where one had rich possibilities and programmable > binary fonts. > > Mikhail Nonsense. -- GNU/Linux user #557453 The cow died so I don't need your bull! From ganesh1pal at gmail.com Sun Mar 26 02:47:40 2017 From: ganesh1pal at gmail.com (Ganesh Pal) Date: Sun, 26 Mar 2017 12:17:40 +0530 Subject: C-Python and Endianness Message-ID: Hello Team , I want to write the hexadecimal string that is passed from python as it is on disk in C , my problem is that the values are getting stored in little endian and the values are swapped it has been quite a pain for me to fix this , any suggestion on how to fix this (I am on Python 2.7 and Linux). Example : if I pass a PyObject i.e ?abcdef12345123? it should be written on disk at the given offset as it i.e. ?abcdef12345123? CLI: #inject_failures.py --optype=add --fixcrc=1 --object=baddr --baddr=2,3,773463552:512 --offset=16 --mirror=1 --op_value='abcdef12345123' --size=8 (op_value is the new variable that is passed as string ) static PyObject * py_corrupt_disk_object(PyObject *self, PyObject *args) { int size, optype, fixcrc; long offset; PyObject *baddr; char *op_value = NULL; if (!PyArg_ParseTuple(args,"Oliisi", &baddr, &offset, &size, &optype, &op_value,&fixcrc)) Py_RETURN_NONE; d_locn_t locn = {}; locn.idx.devid = ((struct py_ifs_baddr*)baddr)->baddr.devid; locn.idx.drive = ((struct py_ifs_baddr*)baddr)->baddr.drive; locn.idx.subidx = ((struct py_ifs_baddr*)baddr)->baddr._subblk; locn.idx.index = ((struct py_ifs_baddr*)baddr)->baddr._block; d_print("Printing args in py_corrupt_disk_object: \n"); d_print("offset %lu \n",offset); d_print("fixcrc %d \n",fixcrc); d_print("size %d \n",size); d_print("optype %d \n",optype); d_print("op_value %s \n",op_value); d_cpr_write(&locn, offset, size, optype, op_value, fixcrc); Py_RETURN_NONE; } PyObject* d_cpr_write(d_locn_t *locn, int offset, int size, int optype, char *op_value, int fixcrc) { cpr_obj* obj = NULL; struct po_typeinfo *tinfo = NULL; int obj_size = 0; d_print("The Values inside d_cpr_write():\n"); d_print("offset %d \n",offset); d_print("fixcrc %d \n",fixcrc); d_print("size %d \n",size); d_print("optype %d \n",optype); d_print("op_value %s \n",op_value); if (locn->idx.subidx & BADDR_SIZE_512) { obj_size = BUFFER_512; tinfo = find_object('i'); if (locn_iaddr_to_linsnap(locn) != d_OK) { d_log(d_ERR, "lin snap conversion failed\n"); Py_RETURN_NONE; } locn->flags |= DLFLAG_HASXIADDRHINT; locn->xiaddrhint = d_index_to_baddr(locn->idx); } else { obj_size = BUFFER_8192; tinfo = find_object('b'); } if (tinfo == NULL) { d_log(d_ERR, "Only Object i or b supported\n"); Py_RETURN_NONE; } obj = alloc_objarg(); // create cpr object obj->tinfo = tinfo; obj->locn = *locn; unsigned char *buff = NULL; if (!(buff = alloca(obj_size))) { d_log(d_ERR, "buffer allocation failed\n"); Py_RETURN_NONE; } int index, xfered, bit_offset; if ((xfered = (*obj->tinfo->read)(&obj->locn, buff, obj_size)) < 0) { d_log(d_ERR, "read failed %d\n", xfered); Py_RETURN_NONE; } if (obj->tinfo->insane != NULL) { if ((*obj->tinfo->insane)(&obj->locn, buff, obj_size, 0) < 0) { d_log(d_ERR, "%c object sanity check failed\n", obj->tinfo->type); Py_RETURN_NONE; } } d_print("Entering optype\n"); if (optype == 2) { //overwrite unsigned long opval = strtol(op_value, NULL, 16); d_print("after rev =%ld ", opval); memcpy(&buff[offset], &opval, sizeof(opval)); }//End of overwrite if (fixcrc) obj->locn.flags |= DLFLAG_WRITE_CRC; if (!obj->tinfo->write) { d_log(d_ERR, "no write function supported\n"); Py_RETURN_NONE; } if ((xfered = (*obj->tinfo->write)(&obj->locn, buff, obj_size)) < 0) { d_log(d_ERR, "write failed %d\n", xfered); Py_RETURN_NONE; } Py_RETURN_NONE; } Output: pipe1-2# inject_failures.py --optype=add --fixcrc=1 --object=baddr --baddr=2,3,773463552:512 --offset=16 --mirror=1 --op_value='abcdef12345123' --size=8 > /usr/local_qa/bin/isi_corrupt.py(848)main() -> if 'add' in options.optype and options.op_value is None: (Pdb) c c > /usr/local_qa/bin/ inject_failures.py (185)corrupt_diskobject() -> logging.info("Corrupting disk object %s at %s", obj_type, disk_object) (Pdb) c Printing args in py_corrupt_disk_object: offset 16 fixcrc 1 size 8 optype 2 op_value abcdef12345123 The Values inside d_cpr_write(): offset 16 fixcrc 1 size 8 optype 2 op_value abcdef12345123 Entering optype after rev =48358647703818531 If I do an hexdump on the file I can see that data is not written correctly Before: 00000010 e0 01 04 00 01 00 00 00 02 00 00 00 00 00 00 00 |................| After : 00000010 23 51 34 12 ef cd ab 00 02 00 00 00 00 00 00 00 |#Q4.............| ==> 1. I am on a little endian machine and is there a way that I can stop this translation and write the values as it ( looks like we are swapping the bytes )? 2. The value passed i.e op_value is a string and its getting printed correctly at C layer,my value is always a hex decimal string of size 14 or 7 bytes. 3. Is there something that I can take care in python layer to avoid this swap ? Regards, Ganesh From me.on.nzt at gmail.com Sun Mar 26 04:21:36 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 01:21:36 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL Message-ID: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> print('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) prints out: UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" (1, 'cyta.gr', '????? ????????', 'Greece', 'Windows', 'Chrome', '17-03-24 22:04:24', 'cyta.gr') How should i write the cursor.execute in order to be parsed properly? As i have it now %s does not get substituted. i use PyMySQL by the way and i have tried every possible combination even with % instead of a comma but still produces errors. From jussi.piitulainen at helsinki.fi Sun Mar 26 04:52:43 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Sun, 26 Mar 2017 11:52:43 +0300 Subject: Escaping confusion with Python 3 + MySQL References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> Message-ID: ????? ?????? writes: > print('''UPDATE visitors SET (pagesID, host, ref, location, useros, > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE > "%s"''', (pID, domain, ref, location, useros, browser, lastvisit, > domain) ) > > prints out: > > UPDATE visitors SET (pagesID, host, ref, location, useros, browser, > visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" (1, > 'cyta.gr', '????? ????????', 'Greece', 'Windows', 'Chrome', '17-03-24 > 22:04:24', 'cyta.gr') > > How should i write the cursor.execute in order to be parsed properly? > As i have it now %s does not get substituted. > i use PyMySQL by the way and i have tried every possible combination > even with % instead of a comma but still produces errors. You should include the actual statement that produces the errors, not a very different statement. And you should include the actual text of the error messages. To learn about PyMySQL cursor.execute, put "pymysql cursor execute" (without the quotes) to a search engine and find something like the following document (the first hit from google.fi for me). https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html That looks helpful to me. From steve+python at pearwood.info Sun Mar 26 05:55:13 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Sun, 26 Mar 2017 20:55:13 +1100 Subject: Python question References: <58d64b6b$0$1598$c3e8da3$5496439d@news.astraweb.com> <286b5eea-6586-69ae-580c-87901becf165@mrabarnett.plus.com> <20170326025556.GA63134@cskk.homeip.net> Message-ID: <58d79003$0$1599$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Mar 2017 01:55 pm, cs at zip.com.au wrote: > 1: He BCCed the list, not us individually. Look at the headers. BCCed addresses aren't visible in the headers. That's why they're BLIND CC. The lack of personal email addresses in the headers doesn't prove they weren't there. All the headers tell us is that he definitely posted to the list. (But we knew that!) Your interpretation doesn't explain why I received a copy sent to my personal email address. I read this via the newsgroup comp.lang.python, not the mailing list, and I'm not subscribed to the email mailing list. If the OP had merely BCCed the mailing list, I wouldn't have received a copy in my personal inbox. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From jobmattcon at gmail.com Sun Mar 26 07:32:02 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Sun, 26 Mar 2017 04:32:02 -0700 (PDT) Subject: why and how to run forever and debug when error in for proc in psutil.process_iter()? In-Reply-To: References: <71d1fddd-7fdf-4049-9e81-442d1f8b55f7@googlegroups.com> <00a401d2a5d0$fec52800$27b23dae@sambora> Message-ID: <74aff512-18ee-4b6c-a675-14261ad703e6@googlegroups.com> On Sunday, March 26, 2017 at 10:33:51 AM UTC+8, Deborah Swanson wrote: > Someone here can probably help you, but they'll need your Python > version, operating system, and full traceback. They get tired of saying > so. > > In this case, the full traceback is needed to see what went wrong and > when (after which statements). > > > Ho Yeung Lee wrote, on Saturday, March 25, 2017 1:38 AM > > > > expect below to run forever and keep running a fixed number > > of thread in python > > > > would like to kill tasks when process connect internet except > > chrome and explorer.exe > > > > i do this because MalwareBytes can not disconnect these > > existing trojan when my notebook connect internet > > > > after run a few minutes, the program stopped, but i have > > already kept create process, why the whole program end? > > > > why and how to debug when error in for proc in psutil.process_iter()? > > > > > > import os > > import psutil > > import multiprocessing > > import time > > import sys > > > > def cleantask(): > > p = os.popen("netstat -ano") > > while 1: > > line = p.readline() > > if "TCP" in line or "UDP" in line: > > linelist = line.split() > > if len(linelist) > 4: > > if "LISTEN" in str(linelist[3]): > > for proc in psutil.process_iter(): > > try: > > if "pop" not in str(proc.name).tolower(): > > os.system("taskkill /f /pid > > "+str(proc._pid)) > > except: > > dummy = 1 > > #print "Unexpected error:", > > sys.exc_info()[0] > > #print "Unexpected error:", > > sys.exc_info()[1] > > if "ESTABLISHED" in str(linelist[3]): > > if "127.0.0.1" not in str(linelist[2]): > > for proc in psutil.process_iter(): > > try: > > if str(linelist[4]) in > > str(proc._pid): > > > > print(str(linelist[2])+","+str(linelist[4])+","+proc.name) > > if "111.221" not in > > str(linelist[2]) and "explorer.exe" not in str(proc.name).tolower(): > > os.system("taskkill /f > > /pid "+str(proc._pid)) > > except: > > dummy = 1 > > #print "Unexpected error:", > > sys.exc_info()[0] > > #print "Unexpected error:", > > sys.exc_info()[1] > > print(line) > > if not line: break > > > > if __name__ == '__main__': > > print("main") > > try: > > numberofrunning = 0 > > plist = [] > > for ii in range(0,5): > > p = multiprocessing.Process(target=cleantask(), args=(0,)) > > p.start() > > plist.append(p) > > numberofrunning = numberofrunning + 1 > > time.sleep(1) > > for pp in plist: > > pp.join() > > if pp.is_alive() == False: > > numberofrunning = numberofrunning - 1 > > plist.remove(pp) > > if numberofrunning > 10: > > print "more than 10 process" > > else: > > print("number of process = " + str(numberofrunning)) > > if numberofrunning <= 5: > > p = > > multiprocessing.Process(target=cleantask(), args=(0,)) > > p.start() > > plist.append(p) > > numberofrunning = numberofrunning + 1 > > time.sleep(1) > > except: > > print "Unexpected error:", sys.exc_info()[0] > > print "Unexpected error:", sys.exc_info()[1] > > -- > > https://mail.python.org/mailman/listinfo/python-list > > after window update error, I can not login window and reset system and reinstall every thing python 2.7.12 there is no error when run, but it end after running a few minutes if commend the forever loop in main import os import psutil import multiprocessing import time import sys def cleantask(): bufsize = 0 f = open("d:\\killlist.txt",'a',bufsize) p = os.popen("netstat -ano") while 1: line = p.readline() if "TCP" in line or "UDP" in line: linelist = line.split() if len(linelist) > 4: if "LISTEN" in str(linelist[3]): for proc in psutil.process_iter(): try: if "pop" in str(proc.name).lower(): os.system("taskkill /f /pid "+str(proc._pid)) #print("here8") print(str(linelist[2])+","+str(linelist[4])+","+proc.name +" is killed ") #print("here9") path = proc.exe() print(str(linelist[2])+","+str(linelist[4])+","+proc.name +" at " + str(path)) #print("here10") except: dummy = 1 #print "Unexpected error:", sys.exc_info()[0] #print "Unexpected error:", sys.exc_info()[1] if "ESTAB" in str(linelist[3]): if "127.0.0.1" not in str(linelist[2]): for proc in psutil.process_iter(): try: if str(linelist[4]) in str(proc._pid): #print("here1a") print(str(linelist[2])+","+str(linelist[4])+","+str(proc.name)) #print("here2a") #print(str(linelist[2])+","+str(linelist[4])+","+proc.name) #print("here3a") if "111.221" in str(linelist[2]): dummy = 1 elif "explorer.exe" in str(proc.name).lower(): dummy = 1 elif "svchost" in str(proc.name).lower(): dummy = 1 elif "cmd" in str(proc.name).lower(): dummy = 1 else: os.system("taskkill /pid "+str(proc._pid)) #print("here1") print(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" is killed ") #print("here2") path = proc.exe() print(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" at " + str(path)) #print("here3") f.write(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" at " + str(path) +"\n") except: dummy = 1 print "Unexpected error:", sys.exc_info()[0] print "Unexpected error:", sys.exc_info()[1] #print("here6") f.write(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" can not kill at " + str(path) +"\n") #print("here7") f.flush() print(line) if not line: break f.close() if __name__ == '__main__': print("main") #while 1: try: numberofrunning = 0 plist = [] for ii in range(0,100): p = multiprocessing.Process(target=cleantask(), args=(0,)) p.start() plist.append(p) numberofrunning = numberofrunning + 1 time.sleep(1) for pp in plist: pp.join() if pp.is_alive() == False: numberofrunning = numberofrunning - 1 plist.remove(pp) if numberofrunning > 100: print "more than 100 process" else: print("number of process = " + str(numberofrunning)) if numberofrunning <= 90: p = multiprocessing.Process(target=cleantask(), args=(0,)) p.start() plist.append(p) numberofrunning = numberofrunning + 1 time.sleep(1) except: print "Unexpected error:", sys.exc_info()[0] print "Unexpected error:", sys.exc_info()[1] From cs at zip.com.au Sun Mar 26 07:35:24 2017 From: cs at zip.com.au (Cameron Simpson) Date: Sun, 26 Mar 2017 22:35:24 +1100 Subject: Python question In-Reply-To: <58d79003$0$1599$c3e8da3$5496439d@news.astraweb.com> References: <58d79003$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20170326113524.GA2791@cskk.homeip.net> On 26Mar2017 20:55, Steve D'Aprano wrote: >On Sun, 26 Mar 2017 01:55 pm, cs at zip.com.au wrote: >> 1: He BCCed the list, not us individually. Look at the headers. > >BCCed addresses aren't visible in the headers. That's why they're BLIND CC. Of course, but the received headers etc show it passed though the list. >The lack of personal email addresses in the headers doesn't prove they >weren't there. All the headers tell us is that he definitely posted to the >list. (But we knew that!) If the headers say it went though the list, _that_ copy went through the list, _not_ to your personal address (well, not from him; of course the list delivered it to you). >Your interpretation doesn't explain why I received a copy sent to my >personal email address. I read this via the newsgroup comp.lang.python, not >the mailing list, and I'm not subscribed to the email mailing list. If the >OP had merely BCCed the mailing list, I wouldn't have received a copy in my >personal inbox. Fair point. Though I thought I only got one copy, might be wrong. Cheers, Cameron Simpson From jobmattcon at gmail.com Sun Mar 26 07:40:09 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Sun, 26 Mar 2017 04:40:09 -0700 (PDT) Subject: why and how to run forever and debug when error in for proc in psutil.process_iter()? In-Reply-To: <74aff512-18ee-4b6c-a675-14261ad703e6@googlegroups.com> References: <71d1fddd-7fdf-4049-9e81-442d1f8b55f7@googlegroups.com> <00a401d2a5d0$fec52800$27b23dae@sambora> <74aff512-18ee-4b6c-a675-14261ad703e6@googlegroups.com> Message-ID: <38d007c6-d8ce-4da7-b3e9-de759ced14b0@googlegroups.com> On Sunday, March 26, 2017 at 7:32:12 PM UTC+8, Ho Yeung Lee wrote: > On Sunday, March 26, 2017 at 10:33:51 AM UTC+8, Deborah Swanson wrote: > > Someone here can probably help you, but they'll need your Python > > version, operating system, and full traceback. They get tired of saying > > so. > > > > In this case, the full traceback is needed to see what went wrong and > > when (after which statements). > > > > > > Ho Yeung Lee wrote, on Saturday, March 25, 2017 1:38 AM > > > > > > expect below to run forever and keep running a fixed number > > > of thread in python > > > > > > would like to kill tasks when process connect internet except > > > chrome and explorer.exe > > > > > > i do this because MalwareBytes can not disconnect these > > > existing trojan when my notebook connect internet > > > > > > after run a few minutes, the program stopped, but i have > > > already kept create process, why the whole program end? > > > > > > why and how to debug when error in for proc in psutil.process_iter()? > > > > > > > > > import os > > > import psutil > > > import multiprocessing > > > import time > > > import sys > > > > > > def cleantask(): > > > p = os.popen("netstat -ano") > > > while 1: > > > line = p.readline() > > > if "TCP" in line or "UDP" in line: > > > linelist = line.split() > > > if len(linelist) > 4: > > > if "LISTEN" in str(linelist[3]): > > > for proc in psutil.process_iter(): > > > try: > > > if "pop" not in str(proc.name).tolower(): > > > os.system("taskkill /f /pid > > > "+str(proc._pid)) > > > except: > > > dummy = 1 > > > #print "Unexpected error:", > > > sys.exc_info()[0] > > > #print "Unexpected error:", > > > sys.exc_info()[1] > > > if "ESTABLISHED" in str(linelist[3]): > > > if "127.0.0.1" not in str(linelist[2]): > > > for proc in psutil.process_iter(): > > > try: > > > if str(linelist[4]) in > > > str(proc._pid): > > > > > > print(str(linelist[2])+","+str(linelist[4])+","+proc.name) > > > if "111.221" not in > > > str(linelist[2]) and "explorer.exe" not in str(proc.name).tolower(): > > > os.system("taskkill /f > > > /pid "+str(proc._pid)) > > > except: > > > dummy = 1 > > > #print "Unexpected error:", > > > sys.exc_info()[0] > > > #print "Unexpected error:", > > > sys.exc_info()[1] > > > print(line) > > > if not line: break > > > > > > if __name__ == '__main__': > > > print("main") > > > try: > > > numberofrunning = 0 > > > plist = [] > > > for ii in range(0,5): > > > p = multiprocessing.Process(target=cleantask(), args=(0,)) > > > p.start() > > > plist.append(p) > > > numberofrunning = numberofrunning + 1 > > > time.sleep(1) > > > for pp in plist: > > > pp.join() > > > if pp.is_alive() == False: > > > numberofrunning = numberofrunning - 1 > > > plist.remove(pp) > > > if numberofrunning > 10: > > > print "more than 10 process" > > > else: > > > print("number of process = " + str(numberofrunning)) > > > if numberofrunning <= 5: > > > p = > > > multiprocessing.Process(target=cleantask(), args=(0,)) > > > p.start() > > > plist.append(p) > > > numberofrunning = numberofrunning + 1 > > > time.sleep(1) > > > except: > > > print "Unexpected error:", sys.exc_info()[0] > > > print "Unexpected error:", sys.exc_info()[1] > > > -- > > > https://mail.python.org/mailman/listinfo/python-list > > > > > after window update error, I can not login window and reset system and > reinstall every thing > > python 2.7.12 > > there is no error when run, but it end after running a few minutes > if commend the forever loop in main > > import os > import psutil > import multiprocessing > import time > import sys > > def cleantask(): > bufsize = 0 > f = open("d:\\killlist.txt",'a',bufsize) > p = os.popen("netstat -ano") > while 1: > line = p.readline() > if "TCP" in line or "UDP" in line: > linelist = line.split() > if len(linelist) > 4: > if "LISTEN" in str(linelist[3]): > for proc in psutil.process_iter(): > try: > if "pop" in str(proc.name).lower(): > os.system("taskkill /f /pid "+str(proc._pid)) > #print("here8") > print(str(linelist[2])+","+str(linelist[4])+","+proc.name +" is killed ") > #print("here9") > path = proc.exe() > print(str(linelist[2])+","+str(linelist[4])+","+proc.name +" at " + str(path)) > #print("here10") > except: > dummy = 1 > #print "Unexpected error:", sys.exc_info()[0] > #print "Unexpected error:", sys.exc_info()[1] > if "ESTAB" in str(linelist[3]): > if "127.0.0.1" not in str(linelist[2]): > for proc in psutil.process_iter(): > try: > if str(linelist[4]) in str(proc._pid): > #print("here1a") > print(str(linelist[2])+","+str(linelist[4])+","+str(proc.name)) > #print("here2a") > #print(str(linelist[2])+","+str(linelist[4])+","+proc.name) > > #print("here3a") > if "111.221" in str(linelist[2]): > dummy = 1 > elif "explorer.exe" in str(proc.name).lower(): > dummy = 1 > elif "svchost" in str(proc.name).lower(): > dummy = 1 > elif "cmd" in str(proc.name).lower(): > dummy = 1 > else: > os.system("taskkill /pid "+str(proc._pid)) > #print("here1") > print(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" is killed ") > #print("here2") > path = proc.exe() > print(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" at " + str(path)) > #print("here3") > f.write(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" at " + str(path) +"\n") > except: > dummy = 1 > print "Unexpected error:", sys.exc_info()[0] > print "Unexpected error:", sys.exc_info()[1] > #print("here6") > f.write(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" can not kill at " + str(path) +"\n") > #print("here7") > f.flush() > print(line) > if not line: break > f.close() > > > if __name__ == '__main__': > print("main") > #while 1: > try: > numberofrunning = 0 > plist = [] > for ii in range(0,100): > p = multiprocessing.Process(target=cleantask(), args=(0,)) > p.start() > plist.append(p) > numberofrunning = numberofrunning + 1 > time.sleep(1) > for pp in plist: > pp.join() > if pp.is_alive() == False: > numberofrunning = numberofrunning - 1 > plist.remove(pp) > if numberofrunning > 100: > print "more than 100 process" > else: > print("number of process = " + str(numberofrunning)) > if numberofrunning <= 90: > p = multiprocessing.Process(target=cleantask(), args=(0,)) > p.start() > plist.append(p) > numberofrunning = numberofrunning + 1 > time.sleep(1) > except: > print "Unexpected error:", sys.exc_info()[0] > print "Unexpected error:", sys.exc_info()[1] another problem is'psutil.AccessDenied' ??: ????????????Taskkill ?????????? 204.79.197.200:443,1384,> is killed Unexpected error: Unexpected error: psutil.AccessDenied (pid=0, name='System Idle Process') Unexpected error: os.system("taskkill /f /pid "+str(proc._pid)) #print("here1") From jobmattcon at gmail.com Sun Mar 26 07:42:21 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Sun, 26 Mar 2017 04:42:21 -0700 (PDT) Subject: why and how to run forever and debug when error in for proc in psutil.process_iter()? In-Reply-To: <38d007c6-d8ce-4da7-b3e9-de759ced14b0@googlegroups.com> References: <71d1fddd-7fdf-4049-9e81-442d1f8b55f7@googlegroups.com> <00a401d2a5d0$fec52800$27b23dae@sambora> <74aff512-18ee-4b6c-a675-14261ad703e6@googlegroups.com> <38d007c6-d8ce-4da7-b3e9-de759ced14b0@googlegroups.com> Message-ID: <6264f32b-6946-4331-a7f1-b01f55f6fc6a@googlegroups.com> On Sunday, March 26, 2017 at 7:40:20 PM UTC+8, Ho Yeung Lee wrote: > On Sunday, March 26, 2017 at 7:32:12 PM UTC+8, Ho Yeung Lee wrote: > > On Sunday, March 26, 2017 at 10:33:51 AM UTC+8, Deborah Swanson wrote: > > > Someone here can probably help you, but they'll need your Python > > > version, operating system, and full traceback. They get tired of saying > > > so. > > > > > > In this case, the full traceback is needed to see what went wrong and > > > when (after which statements). > > > > > > > > > Ho Yeung Lee wrote, on Saturday, March 25, 2017 1:38 AM > > > > > > > > expect below to run forever and keep running a fixed number > > > > of thread in python > > > > > > > > would like to kill tasks when process connect internet except > > > > chrome and explorer.exe > > > > > > > > i do this because MalwareBytes can not disconnect these > > > > existing trojan when my notebook connect internet > > > > > > > > after run a few minutes, the program stopped, but i have > > > > already kept create process, why the whole program end? > > > > > > > > why and how to debug when error in for proc in psutil.process_iter()? > > > > > > > > > > > > import os > > > > import psutil > > > > import multiprocessing > > > > import time > > > > import sys > > > > > > > > def cleantask(): > > > > p = os.popen("netstat -ano") > > > > while 1: > > > > line = p.readline() > > > > if "TCP" in line or "UDP" in line: > > > > linelist = line.split() > > > > if len(linelist) > 4: > > > > if "LISTEN" in str(linelist[3]): > > > > for proc in psutil.process_iter(): > > > > try: > > > > if "pop" not in str(proc.name).tolower(): > > > > os.system("taskkill /f /pid > > > > "+str(proc._pid)) > > > > except: > > > > dummy = 1 > > > > #print "Unexpected error:", > > > > sys.exc_info()[0] > > > > #print "Unexpected error:", > > > > sys.exc_info()[1] > > > > if "ESTABLISHED" in str(linelist[3]): > > > > if "127.0.0.1" not in str(linelist[2]): > > > > for proc in psutil.process_iter(): > > > > try: > > > > if str(linelist[4]) in > > > > str(proc._pid): > > > > > > > > print(str(linelist[2])+","+str(linelist[4])+","+proc.name) > > > > if "111.221" not in > > > > str(linelist[2]) and "explorer.exe" not in str(proc.name).tolower(): > > > > os.system("taskkill /f > > > > /pid "+str(proc._pid)) > > > > except: > > > > dummy = 1 > > > > #print "Unexpected error:", > > > > sys.exc_info()[0] > > > > #print "Unexpected error:", > > > > sys.exc_info()[1] > > > > print(line) > > > > if not line: break > > > > > > > > if __name__ == '__main__': > > > > print("main") > > > > try: > > > > numberofrunning = 0 > > > > plist = [] > > > > for ii in range(0,5): > > > > p = multiprocessing.Process(target=cleantask(), args=(0,)) > > > > p.start() > > > > plist.append(p) > > > > numberofrunning = numberofrunning + 1 > > > > time.sleep(1) > > > > for pp in plist: > > > > pp.join() > > > > if pp.is_alive() == False: > > > > numberofrunning = numberofrunning - 1 > > > > plist.remove(pp) > > > > if numberofrunning > 10: > > > > print "more than 10 process" > > > > else: > > > > print("number of process = " + str(numberofrunning)) > > > > if numberofrunning <= 5: > > > > p = > > > > multiprocessing.Process(target=cleantask(), args=(0,)) > > > > p.start() > > > > plist.append(p) > > > > numberofrunning = numberofrunning + 1 > > > > time.sleep(1) > > > > except: > > > > print "Unexpected error:", sys.exc_info()[0] > > > > print "Unexpected error:", sys.exc_info()[1] > > > > -- > > > > https://mail.python.org/mailman/listinfo/python-list > > > > > > > > after window update error, I can not login window and reset system and > > reinstall every thing > > > > python 2.7.12 > > > > there is no error when run, but it end after running a few minutes > > if commend the forever loop in main > > > > import os > > import psutil > > import multiprocessing > > import time > > import sys > > > > def cleantask(): > > bufsize = 0 > > f = open("d:\\killlist.txt",'a',bufsize) > > p = os.popen("netstat -ano") > > while 1: > > line = p.readline() > > if "TCP" in line or "UDP" in line: > > linelist = line.split() > > if len(linelist) > 4: > > if "LISTEN" in str(linelist[3]): > > for proc in psutil.process_iter(): > > try: > > if "pop" in str(proc.name).lower(): > > os.system("taskkill /f /pid "+str(proc._pid)) > > #print("here8") > > print(str(linelist[2])+","+str(linelist[4])+","+proc.name +" is killed ") > > #print("here9") > > path = proc.exe() > > print(str(linelist[2])+","+str(linelist[4])+","+proc.name +" at " + str(path)) > > #print("here10") > > except: > > dummy = 1 > > #print "Unexpected error:", sys.exc_info()[0] > > #print "Unexpected error:", sys.exc_info()[1] > > if "ESTAB" in str(linelist[3]): > > if "127.0.0.1" not in str(linelist[2]): > > for proc in psutil.process_iter(): > > try: > > if str(linelist[4]) in str(proc._pid): > > #print("here1a") > > print(str(linelist[2])+","+str(linelist[4])+","+str(proc.name)) > > #print("here2a") > > #print(str(linelist[2])+","+str(linelist[4])+","+proc.name) > > > > #print("here3a") > > if "111.221" in str(linelist[2]): > > dummy = 1 > > elif "explorer.exe" in str(proc.name).lower(): > > dummy = 1 > > elif "svchost" in str(proc.name).lower(): > > dummy = 1 > > elif "cmd" in str(proc.name).lower(): > > dummy = 1 > > else: > > os.system("taskkill /pid "+str(proc._pid)) > > #print("here1") > > print(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" is killed ") > > #print("here2") > > path = proc.exe() > > print(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" at " + str(path)) > > #print("here3") > > f.write(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" at " + str(path) +"\n") > > except: > > dummy = 1 > > print "Unexpected error:", sys.exc_info()[0] > > print "Unexpected error:", sys.exc_info()[1] > > #print("here6") > > f.write(str(linelist[2])+","+str(linelist[4])+","+str(proc.name) +" can not kill at " + str(path) +"\n") > > #print("here7") > > f.flush() > > print(line) > > if not line: break > > f.close() > > > > > > if __name__ == '__main__': > > print("main") > > #while 1: > > try: > > numberofrunning = 0 > > plist = [] > > for ii in range(0,100): > > p = multiprocessing.Process(target=cleantask(), args=(0,)) > > p.start() > > plist.append(p) > > numberofrunning = numberofrunning + 1 > > time.sleep(1) > > for pp in plist: > > pp.join() > > if pp.is_alive() == False: > > numberofrunning = numberofrunning - 1 > > plist.remove(pp) > > if numberofrunning > 100: > > print "more than 100 process" > > else: > > print("number of process = " + str(numberofrunning)) > > if numberofrunning <= 90: > > p = multiprocessing.Process(target=cleantask(), args=(0,)) > > p.start() > > plist.append(p) > > numberofrunning = numberofrunning + 1 > > time.sleep(1) > > except: > > print "Unexpected error:", sys.exc_info()[0] > > print "Unexpected error:", sys.exc_info()[1] > > > another problem is'psutil.AccessDenied' > > ??: ????????????Taskkill ?????????? > 204.79.197.200:443,1384,> is killed > Unexpected error: > Unexpected error: psutil.AccessDenied (pid=0, name='System Idle Process') > Unexpected error: > os.system("taskkill /f /pid "+str(proc._pid)) > #print("here1") is there any suspected malware process needed to kill but accessed denied to kill even with admin console in window 10 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > From mikhailwas at gmail.com Sun Mar 26 09:18:06 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 26 Mar 2017 15:18:06 +0200 Subject: Who are the "spacists"? In-Reply-To: References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> Message-ID: On 26 March 2017 at 06:16, Wildman via Python-list wrote: > On Tue, 21 Mar 2017 15:15:14 +0100, Mikhail V wrote: > >> And on linux console, by default one does not even have good >> possibilities for text-mode pseudographics, it was more relevant >> in DOS where one had rich possibilities and programmable >> binary fonts. >> >> Mikhail > > Nonsense. Why? IIRC I can do good pseudographics on linux only with extended unicode character sets, so yes it is possible, is that what you mean? From me.on.nzt at gmail.com Sun Mar 26 09:34:20 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 06:34:20 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> Message-ID: <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> with import cgitb; cgitb.enable() ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") that is all i get form error. error_log doesnt produce errors when iam trying cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) WHY the valued aren't getting substituted wi the aeguments i give it in to work with? From michael.vilain at gmail.com Sun Mar 26 09:39:17 2017 From: michael.vilain at gmail.com (MeV) Date: Sun, 26 Mar 2017 06:39:17 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> Message-ID: On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, ????? ?????? wrote: > with import cgitb; cgitb.enable() > > ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") > > that is all i get form error. error_log doesnt produce errors when iam trying > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', > (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > WHY the valued aren't getting substituted wi the aeguments i give it in to work with? The % construct is Python 2 and no longer supported in Python 3. You should read up on the "{}" and format method. https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting From me.on.nzt at gmail.com Sun Mar 26 09:41:31 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 06:41:31 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> Message-ID: <8c5f0443-c61b-4059-8d6f-576152d5932d@googlegroups.com> Ths is the whole snippert i'am trying so you can see what i'm tryong to do. [code] # if bot is contained in hostname update all previous database bot hostname entries with current bot hostname for bot in bots: if bot in host: domain = '.'.join( host.split('.')[-2:] ) cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) if cur.rowcount(): botfound = True break [/code] As if i have a syntactical error in someplace which i'am faling to see or PyMySQL wants special treatment regarding escaping special characters. From me.on.nzt at gmail.com Sun Mar 26 09:43:17 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 06:43:17 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> Message-ID: <2f7884c8-6c0a-49f6-b4f3-a6c48d7f2f5a@googlegroups.com> ?? ???????, 26 ??????? 2017 - 4:39:44 ?.?. UTC+3, ? ??????? MeV ??????: > On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, ????? ?????? wrote: > > with import cgitb; cgitb.enable() > > > > ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") > > > > that is all i get form error. error_log doesnt produce errors when iam trying > > > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', > > (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > > > WHY the valued aren't getting substituted wi the aeguments i give it in to work with? > > The % construct is Python 2 and no longer supported in Python 3. You should read up on the "{}" and format method. > > https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting Even with '{}' instead of '%s' iam still receiving similar errors. And lathough iam using '%s' up until now substituting worked okey. its htis where LIKE clause that is only failing. From me.on.nzt at gmail.com Sun Mar 26 09:48:49 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 06:48:49 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> Message-ID: <5103a14c-ea92-4997-a807-8d614a567ba4@googlegroups.com> ?? ???????, 26 ??????? 2017 - 4:39:44 ?.?. UTC+3, ? ??????? MeV ??????: > On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, ????? ?????? wrote: > > with import cgitb; cgitb.enable() > > > > ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") > > > > that is all i get form error. error_log doesnt produce errors when iam trying > > > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', > > (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > > > WHY the valued aren't getting substituted wi the aeguments i give it in to work with? > > The % construct is Python 2 and no longer supported in Python 3. You should read up on the "{}" and format method. > > https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting [code] cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE "{}"''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) [/code] now has the following response inside error_log [code] [Sun Mar 26 16:45:50.940077 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Error in sys.excepthook: [Sun Mar 26 16:45:50.940126 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Traceback (most recent call last): [Sun Mar 26 16:45:50.940151 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: File "/usr/local/lib/python3.5/cgitb.py", line 268, in __call__ [Sun Mar 26 16:45:50.940166 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: self.handle((etype, evalue, etb)) [Sun Mar 26 16:45:50.940189 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: File "/usr/local/lib/python3.5/cgitb.py", line 273, in handle [Sun Mar 26 16:45:50.940200 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: self.file.write(reset()) [Sun Mar 26 16:45:50.940220 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: ValueError: underlying buffer has been detached [Sun Mar 26 16:45:50.940225 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: [Sun Mar 26 16:45:50.940235 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Original exception was: [Sun Mar 26 16:45:50.940249 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Traceback (most recent call last): [Sun Mar 26 16:45:50.940265 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: File "metrites.py", line 355, in [Sun Mar 26 16:45:50.940298 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: (pID, domain, ref, location, useros, browser, lastvisit, domain) ) [Sun Mar 26 16:45:50.940329 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: File "/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 144, in execute [Sun Mar 26 16:45:50.940343 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: query = self.mogrify(query, args) [Sun Mar 26 16:45:50.940379 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: File "/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 135, in mogrify [Sun Mar 26 16:45:50.940398 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: query = query % self._escape_args(args, conn) [Sun Mar 26 16:45:50.940420 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: TypeError: not all arguments converted during string formatting [/code] From me.on.nzt at gmail.com Sun Mar 26 09:52:57 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 06:52:57 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <5103a14c-ea92-4997-a807-8d614a567ba4@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <5103a14c-ea92-4997-a807-8d614a567ba4@googlegroups.com> Message-ID: cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE "{}"'''.format(pID, domain, ref, location, useros, browser, lastvisit, domain) ) Same kind of output in the error-log even with this attempt. From songofacandy at gmail.com Sun Mar 26 10:03:54 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Sun, 26 Mar 2017 23:03:54 +0900 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> Message-ID: On Sun, Mar 26, 2017 at 10:34 PM, ????? ?????? wrote: > with import cgitb; cgitb.enable() > > ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") > > that is all i get form error. error_log doesnt produce errors when iam trying > This error came from MySQL. If there are no logs in error_log, it's your configuration issue. See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update statement syntax. From frank at chagford.com Sun Mar 26 10:07:34 2017 From: frank at chagford.com (Frank Millman) Date: Sun, 26 Mar 2017 16:07:34 +0200 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <8c5f0443-c61b-4059-8d6f-576152d5932d@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <8c5f0443-c61b-4059-8d6f-576152d5932d@googlegroups.com> Message-ID: "????? ??????" wrote in message news:8c5f0443-c61b-4059-8d6f-576152d5932d at googlegroups.com... > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE > %s''', > (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > As if i have a syntactical error in someplace which i'am faling to see or > PyMySQL wants special treatment regarding escaping special characters. > I don't know MySQL, but for most RDBMS's, the construction you show only works for INSERT statements. For UPDATE, you usually have to say - UPDATE {table} SET col_1 = val_1, col_2 = val_2 WHERE col_3 = val_3 ... Frank Millman From me.on.nzt at gmail.com Sun Mar 26 10:07:35 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 07:07:35 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> Message-ID: <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> ?? ???????, 26 ??????? 2017 - 5:04:27 ?.?. UTC+3, ? ??????? INADA Naoki This error came from MySQL. If there are no logs in error_log, it's > your configuration issue. > > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update > statement syntax. cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE "%{}%"'''.format(pID, domain, ref, location, useros, browser, lastvisit, domain) ) output of error-log: [code] [Sun Mar 26 16:45:50.940077 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Error in sys.excepthook: [Sun Mar 26 16:45:50.940126 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Traceback (most recent call last): [Sun Mar 26 16:45:50.940151 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: File "/usr/local/lib/python3.5/cgitb.py", line 268, in __call__ [Sun Mar 26 16:45:50.940166 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: self.handle((etype, evalue, etb)) [Sun Mar 26 16:45:50.940189 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: File "/usr/local/lib/python3.5/cgitb.py", line 273, in handle [Sun Mar 26 16:45:50.940200 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: self.file.write(reset()) [Sun Mar 26 16:45:50.940220 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: ValueError: underlying buffer has been detached [Sun Mar 26 16:45:50.940225 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: [Sun Mar 26 16:45:50.940235 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Original exception was: [Sun Mar 26 16:45:50.940249 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: Traceback (most recent call last): [Sun Mar 26 16:45:50.940265 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: File "metrites.py", line 355, in [Sun Mar 26 16:45:50.940298 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: (pID, domain, ref, location, useros, browser, lastvisit, domain) ) [Sun Mar 26 16:45:50.940329 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: File "/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 144, in execute [Sun Mar 26 16:45:50.940343 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: query = self.mogrify(query, args) [Sun Mar 26 16:45:50.940379 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: File "/usr/local/lib/python3.5/site-packages/pymysql/cursors.py", line 135, in mogrify [Sun Mar 26 16:45:50.940398 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: query = query % self._escape_args(args, conn) [Sun Mar 26 16:45:50.940420 2017] [cgi:error] [pid 2337] [client 178.59.182.161:13755] AH01215: TypeError: not all arguments converted during string formatting [/code] From ian.g.kelly at gmail.com Sun Mar 26 10:10:57 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 26 Mar 2017 08:10:57 -0600 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> Message-ID: On Sun, Mar 26, 2017 at 7:39 AM, MeV wrote: > On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, ????? ?????? wrote: >> with import cgitb; cgitb.enable() >> >> ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") >> >> that is all i get form error. error_log doesnt produce errors when iam trying >> >> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', >> (pID, domain, ref, location, useros, browser, lastvisit, domain) ) >> >> WHY the valued aren't getting substituted wi the aeguments i give it in to work with? > > The % construct is Python 2 and no longer supported in Python 3. You should read up on the "{}" and format method. > > https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting Rubbish, it works just fine in Python 3: Python 3.6.0 (default, Jan 1 2017, 22:51:19) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> '%s %s' % ('Hello', 'world') 'Hello world' And contrary to popular belief, it's not even deprecated (although use of the newer format method is encouraged). What's more, in this case it's part of the PEP 249 DBAPI specification: https://www.python.org/dev/peps/pep-0249/#paramstyle. As far as I know pymysql and DBAPI libraries in general don't even accept "{}". From ian.g.kelly at gmail.com Sun Mar 26 10:18:27 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 26 Mar 2017 08:18:27 -0600 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> Message-ID: On Sun, Mar 26, 2017 at 8:07 AM, ????? ?????? wrote: > ?? ???????, 26 ??????? 2017 - 5:04:27 ?.?. UTC+3, ? ??????? INADA Naoki This error came from MySQL. If there are no logs in error_log, it's >> your configuration issue. >> >> See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update >> statement syntax. > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE "%{}%"'''.format(pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > output of error-log: You need to change the placeholders back. The poster who told you to replace them was misinformed. From me.on.nzt at gmail.com Sun Mar 26 10:24:49 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 07:24:49 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> Message-ID: <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> ?? ???????, 26 ??????? 2017 - 5:19:27 ?.?. UTC+3, ? ??????? Ian ??????: > You need to change the placeholders back. The poster who told you to > replace them was misinformed. okey altered them back to cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%%s%" ''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) but now the problem is how to exact;y type the Where HOST like "%%%" I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. From best_lay at yahoo.com Sun Mar 26 10:28:43 2017 From: best_lay at yahoo.com (Wildman) Date: Sun, 26 Mar 2017 09:28:43 -0500 Subject: Who are the "spacists"? References: <1489873444l.9830606l.0l@psu.edu> <58cebff4$0$1595$c3e8da3$5496439d@news.astraweb.com> <58d013c3$0$1598$c3e8da3$5496439d@news.astraweb.com> <0ridndb9eIgmukzFnZ2dnUU7-fednZ2d@giganews.com> <871stqzqza.fsf@elektro.pacujo.net> Message-ID: On Sun, 26 Mar 2017 15:18:06 +0200, Mikhail V wrote: > On 26 March 2017 at 06:16, Wildman via Python-list > wrote: >> On Tue, 21 Mar 2017 15:15:14 +0100, Mikhail V wrote: >> >>> And on linux console, by default one does not even have good >>> possibilities for text-mode pseudographics, it was more relevant >>> in DOS where one had rich possibilities and programmable >>> binary fonts. >>> >>> Mikhail >> >> Nonsense. > > Why? IIRC I can do good pseudographics on linux only with extended > unicode character sets, so yes it is possible, is that what you mean? No. The same ASCII character set that was available in DOS is available in Linux without unicode. -- GNU/Linux user #557453 The cow died so I don't need your bull! From songofacandy at gmail.com Sun Mar 26 10:32:27 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Sun, 26 Mar 2017 23:32:27 +0900 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> Message-ID: > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. > >>> '%% %s %%s' % (42,) '% 42 %s' Use %% From me.on.nzt at gmail.com Sun Mar 26 10:35:47 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 14:35:47 +0000 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> Message-ID: i have tried that 2 days ago. Problem is that you maintained space before and after '%s' which wont work within like How would you type it without space as in "%%s%" ? ???? ???, 26 ??? 2017 ???? 5:32 ?.?., ?/? INADA Naoki < songofacandy at gmail.com> ??????: > > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. > > > > >>> '%% %s %%s' % (42,) > '% 42 %s' > > Use %% > -- What is now proved was at first only imagined! From songofacandy at gmail.com Sun Mar 26 10:38:35 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Sun, 26 Mar 2017 23:38:35 +0900 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> Message-ID: I used space only for readability. It's not required. >>> '%%%s%%' % (42,) '%42%' On Sun, Mar 26, 2017 at 11:35 PM, ????? ?????? wrote: > i have tried that 2 days ago. > > Problem is that you maintained space before and after '%s' which wont work > within like > > How would you type it without space as in "%%s%" ? > > ???? ???, 26 ??? 2017 ???? 5:32 ?.?., ?/? INADA Naoki > ??????: >> >> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. >> > >> >> >>> '%% %s %%s' % (42,) >> '% 42 %s' >> >> Use %% > > -- > What is now proved was at first only imagined! From alister.ware at ntlworld.com Sun Mar 26 10:38:47 2017 From: alister.ware at ntlworld.com (alister) Date: Sun, 26 Mar 2017 14:38:47 GMT Subject: Escaping confusion with Python 3 + MySQL References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> Message-ID: On Sun, 26 Mar 2017 07:24:49 -0700, ????? ?????? wrote: > ?? ???????, 26 ??????? 2017 - 5:19:27 ?.?. UTC+3, ? ??????? Ian ??????: > >> You need to change the placeholders back. The poster who told you to >> replace them was misinformed. > > okey altered them back to > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host > LIKE "%%s%" ''', > (pID, domain, ref, location, useros, > browser, lastvisit, domain) ) > > but now the problem is how to exact;y type the Where HOST like "%%%" > > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. as a quick thought (untested) it is probably best to have %s as your parameter for the Like clause & ad the sql wild-cards (% symbols) to the data you pass in as I think the expansion of %s adds quote marks which will certainly cause the sql parser issues. -- 'Charity ain't giving people what you wants to give, it's giving people what they need to get.' (Hogfather) From steve+python at pearwood.info Sun Mar 26 10:40:33 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 27 Mar 2017 01:40:33 +1100 Subject: Escaping confusion with Python 3 + MySQL References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> Message-ID: <58d7d2e2$0$22140$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Mar 2017 01:24 am, ????? ?????? wrote: > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. Use %% for a literal percent character. py> '%s %% %s' % ('hello', 'world') 'hello % world' -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From me.on.nzt at gmail.com Sun Mar 26 10:41:07 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 14:41:07 +0000 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> Message-ID: I see thank you for pointing that out. Now i'm receiving no error in error_log but when i'm running the script it displays this: ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") How to test this further? ???? ???, 26 ??? 2017 ???? 5:38 ?.?., ?/? INADA Naoki < songofacandy at gmail.com> ??????: > I used space only for readability. It's not required. > > >>> '%%%s%%' % (42,) > '%42%' > > On Sun, Mar 26, 2017 at 11:35 PM, ????? ?????? > wrote: > > i have tried that 2 days ago. > > > > Problem is that you maintained space before and after '%s' which wont > work > > within like > > > > How would you type it without space as in "%%s%" ? > > > > ???? ???, 26 ??? 2017 ???? 5:32 ?.?., ?/? INADA Naoki > > ??????: > >> > >> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. > >> > > >> > >> >>> '%% %s %%s' % (42,) > >> '% 42 %s' > >> > >> Use %% > > > > -- > > What is now proved was at first only imagined! > -- What is now proved was at first only imagined! From me.on.nzt at gmail.com Sun Mar 26 10:43:51 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 07:43:51 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> Message-ID: <46060114-0322-4347-8b46-121d7c9605c9@googlegroups.com> ?? ???????, 26 ??????? 2017 - 5:38:57 ?.?. UTC+3, ? ??????? alister ??????: > On Sun, 26 Mar 2017 07:24:49 -0700, ????? ?????? wrote: > > > ?? ???????, 26 ??????? 2017 - 5:19:27 ?.?. UTC+3, ? ??????? Ian ??????: > > > >> You need to change the placeholders back. The poster who told you to > >> replace them was misinformed. > > > > okey altered them back to > > > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, > > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host > > LIKE "%%s%" ''', > > > > (pID, domain, ref, location, useros, > > > > browser, lastvisit, domain) ) > > > > but now the problem is how to exact;y type the Where HOST like "%%%" > > > > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. > > > as a quick thought (untested) it is probably best to have %s as your > parameter for the Like clause & ad the sql wild-cards (% symbols) to the > data you pass in as I think the expansion of %s adds quote marks which > will certainly cause the sql parser issues. How do you propose writing that cur.execute statement Alister? From ian.g.kelly at gmail.com Sun Mar 26 10:48:07 2017 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 26 Mar 2017 08:48:07 -0600 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> Message-ID: On Sun, Mar 26, 2017 at 8:24 AM, ????? ?????? wrote: > ?? ???????, 26 ??????? 2017 - 5:19:27 ?.?. UTC+3, ? ??????? Ian ??????: > >> You need to change the placeholders back. The poster who told you to >> replace them was misinformed. > > okey altered them back to > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%%s%" ''', > (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > but now the problem is how to exact;y type the Where HOST like "%%%" > > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. The database wrapper won't do substitution into the middle of a string like that. Either concatenate the literal %'s on in the SQL statement or add them to the string before you pass it in, i.e. '%' + domain + '%' or '%%%s%%' % domain or '%{}%'.format(domain). From steve+python at pearwood.info Sun Mar 26 11:03:04 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 27 Mar 2017 02:03:04 +1100 Subject: Escaping confusion with Python 3 + MySQL References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <5103a14c-ea92-4997-a807-8d614a567ba4@googlegroups.com> Message-ID: <58d7d82a$0$1605$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Mar 2017 12:52 am, ????? ?????? wrote: > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, > browser, visits) VALUES ({}, {}, {}, {}, {}, {}, {}) WHERE host LIKE > "{}"'''.format(pID, domain, ref, location, useros, browser, lastvisit, > domain) ) > > Same kind of output in the error-log even with this attempt. Don't do that! Even if you fix the SQL errors, this is vulnerable to code injection attacks. If the caller can fool you into using a specially-made string for any of those parameters (pID, domain, ref, ...) they can execute any SQL code they like, without your knowledge. https://xkcd.com/327/ http://www.explainxkcd.com/wiki/index.php/Little_Bobby_Tables See also: http://bobby-tables.com/ -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From me.on.nzt at gmail.com Sun Mar 26 11:11:34 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 08:11:34 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> Message-ID: <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> ?? ???????, 26 ??????? 2017 - 5:49:00 ?.?. UTC+3, ? ??????? Ian ??????: > The database wrapper won't do substitution into the middle of a string > like that. Either concatenate the literal %'s on in the SQL statement > or add them to the string before you pass it in, i.e. '%' + domain + > '%' or '%%%s%%' % domain or '%{}%'.format(domain). I just tried: domain = '.'.join( host.split('.')[-2:] ) domain = '%' + domain + '%' cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" ''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) and i received no error in the error_log but ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, '%cyta.gr%', ' at line 1") which you can see at http://superhost.gr You said somethign about concatenating the literal % in the SQL to which i didnt actually i understand how to implement. From mikhailwas at gmail.com Sun Mar 26 11:17:23 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 26 Mar 2017 17:17:23 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) Message-ID: On 26 March 2017 at 16:28, Wildman via Python-list wrote: > On Sun, 26 Mar 2017 15:18:06 +0200, Mikhail V wrote: > >> On 26 March 2017 at 06:16, Wildman via Python-list >> wrote: >>> On Tue, 21 Mar 2017 15:15:14 +0100, Mikhail V wrote: >>> >>>> And on linux console, by default one does not even have good >>>> possibilities for text-mode pseudographics, it was more relevant >>>> in DOS where one had rich possibilities and programmable >>>> binary fonts. >>>> >>>> Mikhail >>> >>> Nonsense. >> >> Why? IIRC I can do good pseudographics on linux only with extended >> unicode character sets, so yes it is possible, is that what you mean? > > No. The same ASCII character set that was available in DOS is > available in Linux without unicode. Ok, now I have read that one can change the encoding in the terminal to get same table drawing characters (if one does not want to use unicode). But such a question: can one do it programmaticaly? And more important: can one use binary (bitmap) fonts in default modern linux console? If yes, can one patch them with custom tiles at the application start? In DOS, (I don't remember if in all versions or only some) one could do all this and this opens very rich possibilities for approximating of objects with tiles. The only limitations that one uses 255 tiles, but even this enables to build whole 'worlds' and state of the art apps. So I would call this pseudographics and not few sticks and corner tiles (which I cannot even define and upload easily). From steve+python at pearwood.info Sun Mar 26 11:18:54 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 27 Mar 2017 02:18:54 +1100 Subject: Python question References: <58d79003$0$1599$c3e8da3$5496439d@news.astraweb.com> <20170326113524.GA2791@cskk.homeip.net> Message-ID: <58d7dbe0$0$1603$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Mar 2017 10:35 pm, Cameron Simpson wrote: > On 26Mar2017 20:55, Steve D'Aprano wrote: >>On Sun, 26 Mar 2017 01:55 pm, cs at zip.com.au wrote: >>> 1: He BCCed the list, not us individually. Look at the headers. >> >>BCCed addresses aren't visible in the headers. That's why they're BLIND >>CC. > > Of course, but the received headers etc show it passed though the list. Sending to the list is not a bad thing. We know the OP sent to the list, because his post appeared on the list :-) The question is whether he BCCed a bunch of regulars or not. [...] > If the headers say it went though the list, _that_ copy went through the > list, _not_ to your personal address (well, not from him; of course the > list delivered it to you). Unfortunately I deleted the email so I can't look at the headers, but nevertheless I can categorically say that it didn't come from the mailing list, because the python-list at python.org mailing list doesn't have my address. I've always read this though the newsgroup. I do still have the relevant mail logs: Mar 25 03:08:36 ando postfix/smtpd[24188]: connect from mail-wr0-f194.google.com[209.85.128.194] Mar 25 03:08:37 ando postfix/smtpd[24188]: 2093D1204E2: client=mail-wr0-f194.google.com[209.85.128.194] Mar 25 03:08:37 ando postfix/cleanup[24192]: 2093D1204E2: message-id= Mar 25 03:08:37 ando postfix/qmgr[3004]: 2093D1204E2: from=, size=3258, nrcpt=1 (queue active) Mar 25 03:08:38 ando postfix/smtpd[24188]: disconnect from mail-wr0-f194.google.com[209.85.128.194] I'm not an expert, but to me that looks pretty convincing that the email came directly from Google, not from the mailing list. Am I wrong? >>Your interpretation doesn't explain why I received a copy sent to my >>personal email address. I read this via the newsgroup comp.lang.python, >>not the mailing list, and I'm not subscribed to the email mailing list. If >>the OP had merely BCCed the mailing list, I wouldn't have received a copy >>in my personal inbox. > > Fair point. Though I thought I only got one copy, might be wrong. Maybe you weren't one of the people he BCCed :-) -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From me.on.nzt at gmail.com Sun Mar 26 11:19:49 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 08:19:49 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> Message-ID: <58de5edb-5fc8-461a-908d-d275b7825794@googlegroups.com> domain = '.'.join( host.split('.')[-2:] ) domain = '%' + domain + '%' domain = '%%%s%%' % domain domain = '%{}%'.format(domain) cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" ''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) i just tried both of these 3 ways and the database wrapper failed on all of them respectively. they gave no error_log output though just the usual ProgrammingError(1064, .....) From breamoreboy at gmail.com Sun Mar 26 11:20:04 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sun, 26 Mar 2017 08:20:04 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> Message-ID: <828969c6-4885-47dd-9d6a-1b118f9d4d14@googlegroups.com> On Sunday, March 26, 2017 at 3:11:50 PM UTC+1, Ian wrote: > On Sun, Mar 26, 2017 at 7:39 AM, MeV wrote: > > On Sunday, March 26, 2017 at 6:34:30 AM UTC-7, ????? ?????? wrote: > >> with import cgitb; cgitb.enable() > >> > >> ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") > >> > >> that is all i get form error. error_log doesnt produce errors when iam trying > >> > >> cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', > >> (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > >> > >> WHY the valued aren't getting substituted wi the aeguments i give it in to work with? > > > > The % construct is Python 2 and no longer supported in Python 3. You should read up on the "{}" and format method. > > > > https://docs.python.org/3/tutorial/inputoutput.html#fancier-output-formatting > > Rubbish, it works just fine in Python 3: > > Python 3.6.0 (default, Jan 1 2017, 22:51:19) > [GCC 5.4.0 20160609] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> '%s %s' % ('Hello', 'world') > 'Hello world' > > And contrary to popular belief, it's not even deprecated (although use > of the newer format method is encouraged). What's more, in this case > it's part of the PEP 249 DBAPI specification: > https://www.python.org/dev/peps/pep-0249/#paramstyle. As far as I know > pymysql and DBAPI libraries in general don't even accept "{}". There was quite a chat about the issue of deprecated or not http://www.gossamer-threads.com/lists/python/dev/969817 Kindest regards. Mark Lawrence. From rosuav at gmail.com Sun Mar 26 11:27:44 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 02:27:44 +1100 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> Message-ID: On Mon, Mar 27, 2017 at 2:11 AM, ????? ?????? wrote: > ?? ???????, 26 ??????? 2017 - 5:49:00 ?.?. UTC+3, ? ??????? Ian ??????: > >> The database wrapper won't do substitution into the middle of a string >> like that. Either concatenate the literal %'s on in the SQL statement >> or add them to the string before you pass it in, i.e. '%' + domain + >> '%' or '%%%s%%' % domain or '%{}%'.format(domain). > > I just tried: > > domain = '.'.join( host.split('.')[-2:] ) > domain = '%' + domain + '%' > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" ''', > (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > > and i received no error in the error_log but > ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, '%cyta.gr%', ' at line 1") > > which you can see at http://superhost.gr > > You said somethign about concatenating the literal % in the SQL to which i didnt actually i understand how to implement. Stop panicking. Stop just trying one thing very quickly, getting an error message, and firing a post back to this list. Slow down and read the messages you are getting. You have already been told about UPDATE queries not using this syntax, and the error message is referring to that. You have an error in your SQL syntax; **check the manual**. This is the same problem that you had the last time you were here on this list - you had a different email address then, and I can't remember what name you were going by, but I won't quickly forget superhost.gr, which at the moment looks like Geocities found a new domain name. ChrisA From rosuav at gmail.com Sun Mar 26 11:37:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 02:37:11 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On Mon, Mar 27, 2017 at 2:17 AM, Mikhail V wrote: >>> Why? IIRC I can do good pseudographics on linux only with extended >>> unicode character sets, so yes it is possible, is that what you mean? >> >> No. The same ASCII character set that was available in DOS is >> available in Linux without unicode. > > Ok, now I have read that one can change the encoding in the terminal > to get same table drawing characters (if one does not want to use > unicode). Just use Unicode. Everything else, these days, is a subset of Unicode anyway. Unless you're stuck on the default Windows shell/terminal, you should be able to use UTF-8 everywhere and have the entire Unicode range available. For example, the IBM OEM box-drawing characters are available in Code Page 437... or as Unicode code points in the U+25xx range. > But such a question: can one do it programmaticaly? Set everything to UTF-8 and you don't have to. > And more important: can one use binary (bitmap) fonts in default modern > linux console? If yes, can one patch them with custom tiles at > the application start? If you really need something completely custom, it's not text any more. For example, suppose you redefine all the character images, and then someone copies and pastes into a web browser - can they search the web for the characters you're displaying, and will they mean the same things? If you've redefined images arbitrarily, they won't. More likely, you don't truly need something custom - what you need is a different subset of characters (maybe you need to mix Latin, Greek, and Hebrew letters, in order to show interlinear translation of the Bible). Instead of messing around with character sets, you can just use Unicode and have all of them available. > In DOS, (I don't remember if in all versions or only some) > one could do all this and this opens very rich possibilities for > approximating of objects with tiles. The only limitations > that one uses 255 tiles, but even this enables to build > whole 'worlds' and state of the art apps. So I would call this > pseudographics and not few sticks and corner tiles > (which I cannot even define and upload easily). Yeah; if my memory serves me, this was an IBM BIOS feature, so all versions of DOS would be equally able to do it. But it's basically a form of tile graphics, not text. Given how easily graphical programs can be built these days, I would strongly recommend that, rather than abusing pseudo-text as pseudo-graphics. Pick up Tk or GTK or wxWindows or something, or build your app to run in a web browser, or something like that. If what you're doing really is text, just with custom images, you MAY be able to ask your users to install a TTF or something. But I wouldn't use a program that demands that I reconfigure my terminal. ChrisA From rosuav at gmail.com Sun Mar 26 11:38:14 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 02:38:14 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On Mon, Mar 27, 2017 at 2:37 AM, Chris Angelico wrote: > Just use Unicode. Everything else, these days, is a subset of Unicode > anyway. (Caveat: There are a few counter-examples to my statement, but I very much doubt that someone who's talking about PC OEM graphics is going to be running into them.) ChrisA From steve+python at pearwood.info Sun Mar 26 11:38:51 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 27 Mar 2017 02:38:51 +1100 Subject: Escaping confusion with Python 3 + MySQL References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> Message-ID: <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Mar 2017 02:11 am, ????? ?????? wrote: > I just tried: > > domain = '.'.join( host.split('.')[-2:] ) > domain = '%' + domain + '%' > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" > ''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > and i received no error in the error_log but > ProgrammingError(1064, "You have an error in your SQL syntax; check the > manual that corresponds to your MariaDB server version for the right > syntax to use near '(pagesID, host, ref, location, useros, browser, > visits) VALUES (1, '%cyta.gr%', ' at line 1") Start by following the instructions given: check the manual that corresponds to your MariaDB server version for the right syntax to use just like the error message tells you to do. Are you sure that the domain needs to have leading and trailing percentage signs? "%cyta.gr%" instead of "cyta.gr"? Are you sure that the LIKE clause needs double quotes? LIKE "%s" Perhaps MariaDB requires single quotes: LIKE '%s' or perhaps no quotes at all: LIKE %s But I'm just guessing, because I haven't read the MariaDB manual. You should do so. > which you can see at http://superhost.gr Ah, Nikos, its been a long time! I thought I recognised your style of posting. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From me.on.nzt at gmail.com Sun Mar 26 11:40:40 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 08:40:40 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> Message-ID: <7c8316dd-189e-4d30-88f0-0c3240640aec@googlegroups.com> ?? ???????, 26 ??????? 2017 - 6:28:12 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Mon, Mar 27, 2017 at 2:11 AM, ????? ?????? wrote: > > ?? ???????, 26 ??????? 2017 - 5:49:00 ?.?. UTC+3, ? ??????? Ian ??????: > > > >> The database wrapper won't do substitution into the middle of a string > >> like that. Either concatenate the literal %'s on in the SQL statement > >> or add them to the string before you pass it in, i.e. '%' + domain + > >> '%' or '%%%s%%' % domain or '%{}%'.format(domain). > > > > I just tried: > > > > domain = '.'.join( host.split('.')[-2:] ) > > domain = '%' + domain + '%' > > > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" ''', > > (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > > > > > and i received no error in the error_log but > > ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, '%cyta.gr%', ' at line 1") > > > > which you can see at http://superhost.gr > > > > You said somethign about concatenating the literal % in the SQL to which i didnt actually i understand how to implement. > > Stop panicking. > > Stop just trying one thing very quickly, getting an error message, and > firing a post back to this list. > > Slow down and read the messages you are getting. > > You have already been told about UPDATE queries not using this syntax, > and the error message is referring to that. You have an error in your > SQL syntax; **check the manual**. > This is the same problem that you had the last time you were here on > this list - you had a different email address then, and I can't > remember what name you were going by, but I won't quickly forget > superhost.gr, which at the moment looks like Geocities found a new > domain name. > > ChrisA I'am reading all the answers and trying everything mentioned. As for the SQL syntax i dont see where the error is. I use many UPDATE statements within my scripts in exactyly the same why i have been showing them to you. The only UPDATE is failing is this one with the LIKE clause. I think that Ian's is correct saying that the substitution is ain't done as we intend form the database wrapper which is PyMYSQL. And last but not least it would be nice if you actually made a contributing comment regarding to my questions(which bothers me 3 days in a row by now) instead of making ironic remarks related to how my website looks like aesthitically to you. From me.on.nzt at gmail.com Sun Mar 26 11:48:42 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 08:48:42 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <016ed5d7-676d-420b-9e41-123e1fab0b5b@googlegroups.com> ?? ???????, 26 ??????? 2017 - 6:39:01 ?.?. UTC+3, ? ??????? Steve D'Aprano ??????: > On Mon, 27 Mar 2017 02:11 am, ????? ?????? wrote: > > > I just tried: > > > > domain = '.'.join( host.split('.')[-2:] ) > > domain = '%' + domain + '%' > > > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, > > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" > > ''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > > > and i received no error in the error_log but > > ProgrammingError(1064, "You have an error in your SQL syntax; check the > > manual that corresponds to your MariaDB server version for the right > > syntax to use near '(pagesID, host, ref, location, useros, browser, > > visits) VALUES (1, '%cyta.gr%', ' at line 1") > > Start by following the instructions given: > > check the manual that corresponds to your MariaDB server version > for the right syntax to use > > just like the error message tells you to do. > > Are you sure that the domain needs to have leading and trailing percentage > signs? "%cyta.gr%" instead of "cyta.gr"? > > Are you sure that the LIKE clause needs double quotes? > > LIKE "%s" > > Perhaps MariaDB requires single quotes: > > LIKE '%s' > > or perhaps no quotes at all: > > LIKE %s > > > But I'm just guessing, because I haven't read the MariaDB manual. You should > do so. > > > > which you can see at http://superhost.gr > > Ah, Nikos, its been a long time! I thought I recognised your style of > posting. Howdy Steve! Yes its me and yes its have been a long time! How are you?! Yeap still trying to make my webiste better and better every day. As for MariaDB i tried with single/double/no_quoting at all and it still produces ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") I think that Ian Kelly is right and it has soemthign to do with the databse wrapper not substituting properly the actual string contain in the LIKE clause between the double quotes. Perhaps i need to change pymysql with some other database interface or there is something other than that? From rosuav at gmail.com Sun Mar 26 11:58:02 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 02:58:02 +1100 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <016ed5d7-676d-420b-9e41-123e1fab0b5b@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <016ed5d7-676d-420b-9e41-123e1fab0b5b@googlegroups.com> Message-ID: On Mon, Mar 27, 2017 at 2:48 AM, ????? ?????? wrote: >> > which you can see at http://superhost.gr >> >> Ah, Nikos, its been a long time! I thought I recognised your style of >> posting. > > > Howdy Steve! > Yes its me and yes its have been a long time! How are you?! > Irony lost. ChrisA From me.on.nzt at gmail.com Sun Mar 26 12:01:32 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 09:01:32 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <016ed5d7-676d-420b-9e41-123e1fab0b5b@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <016ed5d7-676d-420b-9e41-123e1fab0b5b@googlegroups.com> Message-ID: <2e3de441-dae1-487d-8bcd-a87fa626246b@googlegroups.com> Currently to avoid any misinformations my code looks as follows: domain = '.'.join( host.split('.')[-2:] ) domain_query = '%%%s' % domain cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE %s''', (pID, domain, ref, location, useros, browser, lastvisit, domain_query) ) which as i saiddisplays no error in the error_log output just the ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") and i'am totally stuck. From nulla.epistola at web.de Sun Mar 26 12:03:13 2017 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sun, 26 Mar 2017 18:03:13 +0200 Subject: Installation issue with Python 3.6.1 for 64 bit Windows In-Reply-To: <58d73d21.56cc370a.298ce.a849@mx.google.com> References: <58d73d21.56cc370a.298ce.a849@mx.google.com> Message-ID: <41737ee1-d078-3142-cfec-3d161690c889@web.de> Am 26.03.2017 um 06:01 schrieb arjun.janah: > > Hello, > I am using an HP PC, brought in 2009, which currently has on it Windows 7 Ultimate, Service Pack 1. Did you do all Windows updates? > > System type is 64-bit operating system. > > I went to https://www.python.org/downloads/windows/ and chose the following: Download Windows x86-64 executable installerThe downloaded file appeared, in my Downloads folder, as: > > python-3.6.1-amd64.exe, with a filesize of 30,657 KB. > > I ran the file and it appeared to install properly. But when I tried to run Python from the Windows All Programs menu tab, I got the following message, in a small window by the window with a black screen: > ------------------------------------------ > python.exe - System Error > The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem.------------------------------------------ > > I tried the following: > > (a) restarting Windows and trying again: same result; > > (a) running the installer file again and selecting repair: > this stalled for a long time so I had to abort it; > > (b) restarting my computer, running the installer file again and selecting uninstall: this uninstalled Python, so it said; > > (c) running the installer file again and choosing install: this installed Python afresh. But then I had the same problem as at the start when I tried to run Python. > You need the dll mentioned in the error message, and you won't get it by repeatedly installing Python (I don't know why the message tells you to do that ...). You will have to get it from Microsoft instead. Googling the name of the dll will probably lead you to it quickly, the problem seems to be quite common. From nulla.epistola at web.de Sun Mar 26 12:03:13 2017 From: nulla.epistola at web.de (Sibylle Koczian) Date: Sun, 26 Mar 2017 18:03:13 +0200 Subject: Installation issue with Python 3.6.1 for 64 bit Windows In-Reply-To: <58d73d21.56cc370a.298ce.a849@mx.google.com> References: <58d73d21.56cc370a.298ce.a849@mx.google.com> Message-ID: <41737ee1-d078-3142-cfec-3d161690c889@web.de> Am 26.03.2017 um 06:01 schrieb arjun.janah: > > Hello, > I am using an HP PC, brought in 2009, which currently has on it Windows 7 Ultimate, Service Pack 1. Did you do all Windows updates? > > System type is 64-bit operating system. > > I went to https://www.python.org/downloads/windows/ and chose the following: Download Windows x86-64 executable installerThe downloaded file appeared, in my Downloads folder, as: > > python-3.6.1-amd64.exe, with a filesize of 30,657 KB. > > I ran the file and it appeared to install properly. But when I tried to run Python from the Windows All Programs menu tab, I got the following message, in a small window by the window with a black screen: > ------------------------------------------ > python.exe - System Error > The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from your computer. Try reinstalling the program to fix this problem.------------------------------------------ > > I tried the following: > > (a) restarting Windows and trying again: same result; > > (a) running the installer file again and selecting repair: > this stalled for a long time so I had to abort it; > > (b) restarting my computer, running the installer file again and selecting uninstall: this uninstalled Python, so it said; > > (c) running the installer file again and choosing install: this installed Python afresh. But then I had the same problem as at the start when I tried to run Python. > You need the dll mentioned in the error message, and you won't get it by repeatedly installing Python (I don't know why the message tells you to do that ...). You will have to get it from Microsoft instead. Googling the name of the dll will probably lead you to it quickly, the problem seems to be quite common. From joel.goldstick at gmail.com Sun Mar 26 12:05:26 2017 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 26 Mar 2017 12:05:26 -0400 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <016ed5d7-676d-420b-9e41-123e1fab0b5b@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <016ed5d7-676d-420b-9e41-123e1fab0b5b@googlegroups.com> Message-ID: On Sun, Mar 26, 2017 at 11:48 AM, ????? ?????? wrote: > ?? ???????, 26 ??????? 2017 - 6:39:01 ?.?. UTC+3, ? ??????? Steve D'Aprano ??????: >> On Mon, 27 Mar 2017 02:11 am, ????? ?????? wrote: >> >> > I just tried: >> > >> > domain = '.'.join( host.split('.')[-2:] ) >> > domain = '%' + domain + '%' >> > >> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, >> > browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" >> > ''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) >> > >> > and i received no error in the error_log but >> > ProgrammingError(1064, "You have an error in your SQL syntax; check the >> > manual that corresponds to your MariaDB server version for the right >> > syntax to use near '(pagesID, host, ref, location, useros, browser, >> > visits) VALUES (1, '%cyta.gr%', ' at line 1") >> >> Start by following the instructions given: >> >> check the manual that corresponds to your MariaDB server version >> for the right syntax to use >> >> just like the error message tells you to do. >> >> Are you sure that the domain needs to have leading and trailing percentage >> signs? "%cyta.gr%" instead of "cyta.gr"? >> >> Are you sure that the LIKE clause needs double quotes? >> >> LIKE "%s" >> >> Perhaps MariaDB requires single quotes: >> >> LIKE '%s' >> >> or perhaps no quotes at all: >> >> LIKE %s >> >> >> But I'm just guessing, because I haven't read the MariaDB manual. You should >> do so. >> >> >> > which you can see at http://superhost.gr >> >> Ah, Nikos, its been a long time! I thought I recognised your style of >> posting. Not long enough! > > > Howdy Steve! > Yes its me and yes its have been a long time! How are you?! > > Yeap still trying to make my webiste better and better every day. > > As for MariaDB i tried with single/double/no_quoting at all and it still produces > ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, 'cyta.gr', '' at line 1") > > I think that Ian Kelly is right and it has soemthign to do with the databse wrapper not substituting properly the actual string contain in the LIKE clause between the double quotes. > > Perhaps i need to change pymysql with some other database interface or there is something other than that? > -- > https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays From eryksun at gmail.com Sun Mar 26 12:39:49 2017 From: eryksun at gmail.com (eryk sun) Date: Sun, 26 Mar 2017 16:39:49 +0000 Subject: Installation issue with Python 3.6.1 for 64 bit Windows In-Reply-To: <58d73d21.56cc370a.298ce.a849@mx.google.com> References: <58d73d21.56cc370a.298ce.a849@mx.google.com> Message-ID: On Sun, Mar 26, 2017 at 4:01 AM, arjun.janah wrote: > > I ran the file and it appeared to install properly. But when I tried to run Python from > the Windows All Programs menu tab, I got the following message, in a small > window by the window with a black screen: > ------------------------------------------ > python.exe - System Error > The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is missing from > your computer. Try reinstalling the program to fix this problem. > > I tried the following: > > (a) restarting Windows and trying again: same result; > > (a) running the installer file again and selecting repair: > this stalled for a long time so I had to abort it; > > (b) restarting my computer, running the installer file again and selecting uninstall: > this uninstalled Python, so it said; > > (c) running the installer file again and choosing install: this installed Python afresh. > But then I had the same problem as at the start when I tried to run Python. Python's installer should try to install the Universal C runtime update, but this seems to fail frequently. If you want to help improve the installer, zip up Python's installation logs that are in your %Temp% directory to a single zip file; open an issue on bugs.python.org; and attach the zip file to the issue. You probably didn't get the CRT update from Windows Update because you don't have the option enabled to install recommended updates. Anyway, you can manually download and install Windows6.1-KB3118401-x64.msu (the 64-bit version for NT 6.1, i.e. Windows 7) from the following site: https://www.microsoft.com/en-us/download/details.aspx?id=50410 From me.on.nzt at gmail.com Sun Mar 26 12:56:58 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 09:56:58 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: Any ideas on how to make progress on that? After all its just an UPDATE with a WHERE clause?! Do you also think is DBI related issue? From mikhailwas at gmail.com Sun Mar 26 12:57:17 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 26 Mar 2017 18:57:17 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On 26 March 2017 at 17:37, Chris Angelico wrote: > On Mon, Mar 27, 2017 at 2:17 AM, Mikhail V wrote: >>>> Why? IIRC I can do good pseudographics on linux only with extended >>>> unicode character sets, so yes it is possible, is that what you mean? >>> >>> No. The same ASCII character set that was available in DOS is >>> available in Linux without unicode. >> >> Ok, now I have read that one can change the encoding in the terminal >> to get same table drawing characters (if one does not want to use >> unicode). > > Just use Unicode. Everything else, these days, is a subset of Unicode > anyway. Unless you're stuck on the default Windows shell/terminal, you > should be able to use UTF-8 everywhere and have the entire Unicode > range available. Yes I am 'stuck' on Windows console, and I use it for what it is made for - running command line tools. On Win 7 and 10, I can see UTF-8 chars everywhere. To be precise, to see entire range of chars, you need a _font_ in which someone have drawn those chars according to their understanding how those glyphs must look, nothing more. No need to say, that even for text only, monospaced cannot represent them even close to satisfying, and for Arabic for example they look ass ugly in monospaced. IOW, even a console-like apps would use proportional fonts in the future. > >> But such a question: can one do it programmaticaly? > > Set everything to UTF-8 and you don't have to. > >> And more important: can one use binary (bitmap) fonts in default modern >> linux console? If yes, can one patch them with custom tiles at >> the application start? > > If you really need something completely custom, it's not text any > more. Obvious fact, but if I need e.g. rounded corners in table drawing characters? Or I just want to fix some characters which look especially ugly? Create a new TTF? No, thanks, this would be worst nightmare to do without a special tool (which have prices with several zeros, otherwise just don't work and can even break things system-wide) > > More likely, you don't truly need something custom - what you need is > a different subset of characters (maybe you need to mix Latin, Greek, > and Hebrew letters, in order to show interlinear translation of the > Bible). Instead of messing around with character sets, you can just > use Unicode and have all of them available. If I was to deal with multiple language charsets in _my own_ rendering app, I would still use discrete encoding for inner algorithms. i.e. I would place separate charsets on separate code ranges. And for own standalone app, I would not use any TTF or anything vector-based font, since why? > >> In DOS, (I don't remember if in all versions or only some) >> one could do all this and this opens very rich possibilities for >> approximating of objects with tiles. The only limitations >> that one uses 255 tiles, but even this enables to build >> whole 'worlds' and state of the art apps. So I would call this >> pseudographics and not few sticks and corner tiles >> (which I cannot even define and upload easily). > > Yeah; if my memory serves me, this was an IBM BIOS feature, so all > versions of DOS would be equally able to do it. But it's basically a > form of tile graphics, not text. Given how easily graphical programs > can be built these days, I would strongly recommend that, rather than > abusing pseudo-text as pseudo-graphics. Pick up Tk or GTK or wxWindows > or something, or build your app to run in a web browser, or something > like that. Exactly, that is why I do so, and even if one wants to play around with console hacking, there is not so many documented ways to do it. In Windows, I can manually select raster fonts, so in pure theory, one could hack it with custom tiles, but since it is much easier to use a graphical library today, too few people are interested in it. Mikhail From songofacandy at gmail.com Sun Mar 26 13:05:22 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Mon, 27 Mar 2017 02:05:22 +0900 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: Read my mail again. > This error came from MySQL. If there are no logs in error_log, it's > your configuration issue. > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update > statement syntax. From me.on.nzt at gmail.com Sun Mar 26 13:10:56 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 17:10:56 +0000 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: I do not see why my UPDATE fails. cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s)''') works i dont have to update table set column1 = this value, column2=that value and so on It's just when the LIKE clause jumps in that is causing all this trouble.... How would you write it?! ???? ???, 26 ??? 2017 ???? 8:05 ?.?., ?/? INADA Naoki < songofacandy at gmail.com> ??????: > Read my mail again. > > > This error came from MySQL. If there are no logs in error_log, it's > > your configuration issue. > > > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update > > statement syntax. > -- What is now proved was at first only imagined! From rosuav at gmail.com Sun Mar 26 13:29:30 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 04:29:30 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On Mon, Mar 27, 2017 at 3:57 AM, Mikhail V wrote: > On 26 March 2017 at 17:37, Chris Angelico wrote: >> On Mon, Mar 27, 2017 at 2:17 AM, Mikhail V wrote: >>>>> Why? IIRC I can do good pseudographics on linux only with extended >>>>> unicode character sets, so yes it is possible, is that what you mean? >>>> >>>> No. The same ASCII character set that was available in DOS is >>>> available in Linux without unicode. >>> >>> Ok, now I have read that one can change the encoding in the terminal >>> to get same table drawing characters (if one does not want to use >>> unicode). >> >> Just use Unicode. Everything else, these days, is a subset of Unicode >> anyway. Unless you're stuck on the default Windows shell/terminal, you >> should be able to use UTF-8 everywhere and have the entire Unicode >> range available. > > Yes I am 'stuck' on Windows console, and I use it for what it is > made for - running command line tools. Not really stuck; even if you can't get off Windows, you should be able to move off the ancient terminal that you get by default. > On Win 7 and 10, I can see UTF-8 chars everywhere. > To be precise, to see entire range of chars, you need a _font_ > in which someone have drawn those chars according to their > understanding how those glyphs must look, nothing more. Duh? If you want characters to display, you need a font.... yes...? > No need to say, that even for text only, monospaced cannot > represent them even close to satisfying, and for Arabic for example they > look ass ugly in monospaced. > IOW, even a console-like apps would use proportional fonts in the future. Arabic text is written right-to-left. It's a lot more complicated than just whether your font is monospaced or not, particularly when you mix strongly-directional characters, weakly-directional characters, non-directional characters, and explicit directionality markers. If you mix RTL and LTR text, is the RTL text aligned to the right of the page, or the left? There is a LOT more than just your font to take care of here. If you want perfect handling of international text, you basically need to use a Unicode-compliant text renderer - and fortunately, most graphical engines these days come with exactly that. >>> And more important: can one use binary (bitmap) fonts in default modern >>> linux console? If yes, can one patch them with custom tiles at >>> the application start? >> >> If you really need something completely custom, it's not text any >> more. > > Obvious fact, but if I need e.g. rounded corners in table drawing > characters? Or I just want to fix some characters which look especially ugly? > Create a new TTF? No, thanks, this would be worst nightmare to > do without a special tool (which have prices with several zeros, otherwise > just don't work and can even break things system-wide) Rounded corners? ????? ????? ????? A good font should show this as a rounded box with cross-lines through it. The characters here are: U+256D BOX DRAWINGS LIGHT ARC DOWN AND RIGHT U+2500 BOX DRAWINGS LIGHT HORIZONTAL U+252C BOX DRAWINGS LIGHT DOWN AND HORIZONTAL U+2500 BOX DRAWINGS LIGHT HORIZONTAL U+256E BOX DRAWINGS LIGHT ARC DOWN AND LEFT U+000A LINE FEED U+251C BOX DRAWINGS LIGHT VERTICAL AND RIGHT U+2500 BOX DRAWINGS LIGHT HORIZONTAL U+253C BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL U+2500 BOX DRAWINGS LIGHT HORIZONTAL U+2524 BOX DRAWINGS LIGHT VERTICAL AND LEFT U+000A LINE FEED U+2570 BOX DRAWINGS LIGHT ARC UP AND RIGHT U+2500 BOX DRAWINGS LIGHT HORIZONTAL U+2534 BOX DRAWINGS LIGHT UP AND HORIZONTAL U+2500 BOX DRAWINGS LIGHT HORIZONTAL U+256F BOX DRAWINGS LIGHT ARC UP AND LEFT U+000A LINE FEED And if you think that some characters look ugly, you can create a font with just those characters in it. Thanks to font substitution, your font should be used for the characters it defines, but anything it doesn't will fall back on some other font, so you don't have to create representations for hundreds of thousands of Unicode characters. >> More likely, you don't truly need something custom - what you need is >> a different subset of characters (maybe you need to mix Latin, Greek, >> and Hebrew letters, in order to show interlinear translation of the >> Bible). Instead of messing around with character sets, you can just >> use Unicode and have all of them available. > > If I was to deal with multiple language charsets in _my own_ rendering > app, I would still use discrete encoding for inner algorithms. > i.e. I would place separate charsets on separate code ranges. > And for own standalone app, I would not use any TTF or > anything vector-based font, since why? Separate code ranges? You mean like allocating U+03xx to Greek, U+04xx to Cyrillic (Russian and friends), U+06xx to Arabic, etc? Sounds like a good plan.... >> Yeah; if my memory serves me, this was an IBM BIOS feature, so all >> versions of DOS would be equally able to do it. But it's basically a >> form of tile graphics, not text. Given how easily graphical programs >> can be built these days, I would strongly recommend that, rather than >> abusing pseudo-text as pseudo-graphics. Pick up Tk or GTK or wxWindows >> or something, or build your app to run in a web browser, or something >> like that. > > Exactly, that is why I do so, and even if one wants to play around > with console hacking, there is not so many documented > ways to do it. In Windows, I can manually select raster fonts, > so in pure theory, one could hack it with custom tiles, but > since it is much easier to use a graphical library today, > too few people are interested in it. It's easier AND better. Why mess around with the console config when you can just draw what you need? ChrisA From eryksun at gmail.com Sun Mar 26 13:38:38 2017 From: eryksun at gmail.com (eryk sun) Date: Sun, 26 Mar 2017 17:38:38 +0000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On Sun, Mar 26, 2017 at 3:37 PM, Chris Angelico wrote: > > Just use Unicode. Everything else, these days, is a subset of Unicode > anyway. Unless you're stuck on the default Windows shell/terminal, you > should be able to use UTF-8 everywhere and have the entire Unicode > range available. The Windows console can render any character in the BMP, but it requires configuring font linking for fallback fonts. It's Windows, so of course the supported UTF format is UTF-16. The console's UTF-8 support (codepage 65001) is too buggy to even consider using it. I don't know why you mention the shell. It has nothing to do with this. But, for what it's worth, the cmd shell is a Unicode application and always has been. It use the console's wide-character API. From steve+python at pearwood.info Sun Mar 26 13:43:28 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 27 Mar 2017 04:43:28 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) References: Message-ID: <58d7fdc3$0$1617$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Mar 2017 02:37 am, Chris Angelico wrote: > On Mon, Mar 27, 2017 at 2:17 AM, Mikhail V wrote: >>>> Why? IIRC I can do good pseudographics on linux only with extended >>>> unicode character sets, so yes it is possible, is that what you mean? >>> >>> No. The same ASCII character set that was available in DOS is >>> available in Linux without unicode. >> >> Ok, now I have read that one can change the encoding in the terminal >> to get same table drawing characters (if one does not want to use >> unicode). > > Just use Unicode. Everything else, these days, is a subset of Unicode > anyway. Unless you're stuck on the default Windows shell/terminal, you > should be able to use UTF-8 everywhere and have the entire Unicode > range available. For example, the IBM OEM box-drawing characters are > available in Code Page 437... or as Unicode code points in the U+25xx > range. You are absolutely correct in theory, but in practice the availability of glyphs in most fonts is only a tiny proportion of the Unicode range. And even when the glyphs are available, the quality often varies: for example, in all of the monospaced fonts I've looked at, the superscripts ??? are a different size to ???????, both vertically and horizontally. And I've come across a few fonts where the box drawing characters don't all line up. Don't misunderstand me: Unicode is a HUGE improvement over the Bad Old Days of dozens of incompatible character sets. But let's not pretend that it makes it *easy*. [...] >> And more important: can one use binary (bitmap) fonts in default modern >> linux console? If yes, can one patch them with custom tiles at >> the application start? > > If you really need something completely custom, it's not text any > more. That's not quite right. Unicode includes 137000 or so Private Use Characters, which anyone can define for their own purposes, "by private agreement". There's an unofficial registry of such private use characters here: http://www.evertype.com/standards/csur/ More info here: https://en.wikipedia.org/wiki/Private_Use_Areas > For example, suppose you redefine all the character images, and > then someone copies and pastes into a web browser - can they search > the web for the characters you're displaying, and will they mean the > same things? If you've redefined images arbitrarily, they won't. > > More likely, you don't truly need something custom - what you need is > a different subset of characters (maybe you need to mix Latin, Greek, > and Hebrew letters, in order to show interlinear translation of the > Bible). Instead of messing around with character sets, you can just > use Unicode and have all of them available. Assuming you have a text widget which is capable of displaying LTR and RTL text, and support for all the glyphs you need. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From eryksun at gmail.com Sun Mar 26 13:49:06 2017 From: eryksun at gmail.com (eryk sun) Date: Sun, 26 Mar 2017 17:49:06 +0000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On Sun, Mar 26, 2017 at 5:29 PM, Chris Angelico wrote: > Rounded corners? > > ????? > ????? > ????? This prints fine in the Windows console with Consolas as the font, but the older Courier New and Lucida Console fonts lack glyphs for the rounded corners. From arjun.janah at gmail.com Sun Mar 26 13:54:11 2017 From: arjun.janah at gmail.com (Arjun Janah) Date: Sun, 26 Mar 2017 13:54:11 -0400 Subject: Installation issue with Python 3.6.1 for 64 bit Windows In-Reply-To: References: <58d73d21.56cc370a.298ce.a849@mx.google.com> Message-ID: Thank you, Eryk Sun. On Mar 26, 2017 12:40 PM, "eryk sun" wrote: > On Sun, Mar 26, 2017 at 4:01 AM, arjun.janah > wrote: > > > > I ran the file and it appeared to install properly. But when I tried to > run Python from > > the Windows All Programs menu tab, I got the following message, in a > small > > window by the window with a black screen: > > ------------------------------------------ > > python.exe - System Error > > The program can't start because api-ms-win-crt-runtime-l1-1-0.dll is > missing from > > your computer. Try reinstalling the program to fix this problem. > > > > I tried the following: > > > > (a) restarting Windows and trying again: same result; > > > > (a) running the installer file again and selecting repair: > > this stalled for a long time so I had to abort it; > > > > (b) restarting my computer, running the installer file again and > selecting uninstall: > > this uninstalled Python, so it said; > > > > (c) running the installer file again and choosing install: this > installed Python afresh. > > But then I had the same problem as at the start when I tried to run > Python. > > Python's installer should try to install the Universal C runtime > update, but this seems to fail frequently. If you want to help improve > the installer, zip up Python's installation logs that are in your > %Temp% directory to a single zip file; open an issue on > bugs.python.org; and attach the zip file to the issue. > > You probably didn't get the CRT update from Windows Update because you > don't have the option enabled to install recommended updates. Anyway, > you can manually download and install Windows6.1-KB3118401-x64.msu > (the 64-bit version for NT 6.1, i.e. Windows 7) from the following > site: > > https://www.microsoft.com/en-us/download/details.aspx?id=50410 > From me.on.nzt at gmail.com Sun Mar 26 13:54:24 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 10:54:24 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <61d98fda-e43d-4cdc-addd-86b7aadbbc6c@googlegroups.com> ?? ???????, 26 ??????? 2017 - 8:06:07 ?.?. UTC+3, ? ??????? INADA Naoki ??????: > Read my mail again. > > > This error came from MySQL. If there are no logs in error_log, it's > > your configuration issue. > > > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update > > statement syntax. I cannot understand where the error is. Could you how it to me please? From rosuav at gmail.com Sun Mar 26 13:58:03 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 04:58:03 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On Mon, Mar 27, 2017 at 4:38 AM, eryk sun wrote: > On Sun, Mar 26, 2017 at 3:37 PM, Chris Angelico wrote: >> >> Just use Unicode. Everything else, these days, is a subset of Unicode >> anyway. Unless you're stuck on the default Windows shell/terminal, you >> should be able to use UTF-8 everywhere and have the entire Unicode >> range available. > > The Windows console can render any character in the BMP, but it > requires configuring font linking for fallback fonts. It's Windows, so > of course the supported UTF format is UTF-16. The console's UTF-8 > support (codepage 65001) is too buggy to even consider using it. Is it actually UTF-16, or is it UCS-2? > I don't know why you mention the shell. It has nothing to do with > this. But, for what it's worth, the cmd shell is a Unicode application > and always has been. It use the console's wide-character API. Because a lot of people on Windows don't understand the distinction, and it's common to hear people talk about "cmd.exe" when they really mean the graphical display. But I'm aware that pedantic correctness separates them completely. ChrisA From alister.ware at ntlworld.com Sun Mar 26 13:58:45 2017 From: alister.ware at ntlworld.com (alister) Date: Sun, 26 Mar 2017 17:58:45 GMT Subject: Escaping confusion with Python 3 + MySQL References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <46060114-0322-4347-8b46-121d7c9605c9@googlegroups.com> Message-ID: On Sun, 26 Mar 2017 07:43:51 -0700, ????? ?????? wrote: > ?? ???????, 26 ??????? 2017 - 5:38:57 ?.?. UTC+3, ? ??????? alister > ??????: >> On Sun, 26 Mar 2017 07:24:49 -0700, ????? ?????? wrote: >> >> > ?? ???????, 26 ??????? 2017 - 5:19:27 ?.?. UTC+3, ? ??????? Ian >> > ??????: >> > >> >> You need to change the placeholders back. The poster who told you to >> >> replace them was misinformed. >> > >> > okey altered them back to >> > >> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, >> > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE >> > host LIKE "%%s%" ''', >> > >> > >> (pID, domain, ref, location, useros, >> > >> > >> browser, lastvisit, domain) ) >> > >> > but now the problem is how to exact;y type the Where HOST like "%%%" >> > >> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. >> >> >> as a quick thought (untested) it is probably best to have %s as your >> parameter for the Like clause & ad the sql wild-cards (% symbols) to >> the data you pass in as I think the expansion of %s adds quote marks >> which will certainly cause the sql parser issues. > > How do you propose writing that cur.execute statement Alister? cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, >> > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE >> > host LIKE %s ''' but you will need to amend the data you pass so that the last element has the surrounding % characters . -- T-1's congested due to porn traffic to the news server. From eryksun at gmail.com Sun Mar 26 13:59:25 2017 From: eryksun at gmail.com (eryk sun) Date: Sun, 26 Mar 2017 17:59:25 +0000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On Sun, Mar 26, 2017 at 5:49 PM, eryk sun wrote: > On Sun, Mar 26, 2017 at 5:29 PM, Chris Angelico wrote: >> Rounded corners? >> >> ????? >> ????? >> ????? > > This prints fine in the Windows console with Consolas as the font, but > the older Courier New and Lucida Console fonts lack glyphs for the > rounded corners. I configured Consolas as a fallback for Lucida Console, and now it shows the rounded corners in the console, but it beats me why anyone would do that instead of simply using Consolas. From steve+python at pearwood.info Sun Mar 26 14:10:24 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 27 Mar 2017 05:10:24 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) References: Message-ID: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Mar 2017 03:57 am, Mikhail V wrote: [...] >>> And more important: can one use binary (bitmap) fonts in default modern >>> linux console? If yes, can one patch them with custom tiles at >>> the application start? >> >> If you really need something completely custom, it's not text any >> more. > > Obvious fact, but if I need e.g. rounded corners in table drawing > characters? Or I just want to fix some characters which look especially > ugly? Create a new TTF? No, thanks, this would be worst nightmare to > do without a special tool (which have prices with several zeros, otherwise > just don't work and can even break things system-wide) Don't be silly. It took me ten seconds on Google to find this: https://birdfont.org/ It is no charge for an open source licence, or $5 USD for a commercial licence. If that's too cheap, you can use FontCreator at just $79: http://www.high-logic.com/font-editor/fontcreator.html >> More likely, you don't truly need something custom - what you need is >> a different subset of characters (maybe you need to mix Latin, Greek, >> and Hebrew letters, in order to show interlinear translation of the >> Bible). Instead of messing around with character sets, you can just >> use Unicode and have all of them available. > > If I was to deal with multiple language charsets in _my own_ rendering > app, I would still use discrete encoding for inner algorithms. > i.e. I would place separate charsets on separate code ranges. Why? Because you think you know better than the thousands of professionals who have worked with text formats for decades? > And for own standalone app, I would not use any TTF or > anything vector-based font, since why? Right, because your users will *love* to see their native language displayed in a crappy bitmapped font with jagged or blurry edges. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Sun Mar 26 14:20:59 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 05:20:59 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58d7fdc3$0$1617$c3e8da3$5496439d@news.astraweb.com> References: <58d7fdc3$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 27, 2017 at 4:43 AM, Steve D'Aprano wrote: > On Mon, 27 Mar 2017 02:37 am, Chris Angelico wrote: > >> Just use Unicode. Everything else, these days, is a subset of Unicode >> anyway. Unless you're stuck on the default Windows shell/terminal, you >> should be able to use UTF-8 everywhere and have the entire Unicode >> range available. For example, the IBM OEM box-drawing characters are >> available in Code Page 437... or as Unicode code points in the U+25xx >> range. > > You are absolutely correct in theory, but in practice the availability of > glyphs in most fonts is only a tiny proportion of the Unicode range. And > even when the glyphs are available, the quality often varies: for example, > in all of the monospaced fonts I've looked at, the superscripts ??? are a > different size to ???????, both vertically and horizontally. And I've come > across a few fonts where the box drawing characters don't all line up. > > Don't misunderstand me: Unicode is a HUGE improvement over the Bad Old Days > of dozens of incompatible character sets. But let's not pretend that it > makes it *easy*. Unicode makes it about as easy as it can possibly be, given the diversity of human languages and their various needs, plus the reality that nobody has infinite resources for creating fonts. The most important thing is that you have a single universal specification that governs the interpretation of text, which means you can aim for that standard, and if a renderer doesn't match up to it, that's a bug that can be fixed, not behaviour that has to be maintained for backward compatibility. So, for instance, Eryk Sun commented that my rounded box example didn't render correctly in all fonts - but in the future, a new version of those fonts could be released, adding support for those characters. We *know* that the code points I used are permanently and irrevocably allocated to the purposes I used them for, so we can all be confident that they'll be used correctly if at all. >>> And more important: can one use binary (bitmap) fonts in default modern >>> linux console? If yes, can one patch them with custom tiles at >>> the application start? >> >> If you really need something completely custom, it's not text any >> more. > > That's not quite right. Unicode includes 137000 or so Private Use > Characters, which anyone can define for their own purposes, "by private > agreement". There's an unofficial registry of such private use characters > here: > > http://www.evertype.com/standards/csur/ > > More info here: > > https://en.wikipedia.org/wiki/Private_Use_Areas This is true, but at some point, it's not text any more. The PUAs are great if you're working with non-standard forms of text (eg Klingon, or Elvish), but aren't well suited to arbitrary graphics. You should be able to copy and paste text from one application into another and have it retain its meaning; the PUAs weaken this guarantee in that the applications have to agree to coexist, but within that, the same ability to copy and paste should hold. It sounds like Mikhail is trying to warp the console into something pseudo-graphical like a Roguelike game, but instead of designing the game around available glyphs, wants to design the glyphs to suit the game - and at that point, it's time to just go graphical, IMO. >> More likely, you don't truly need something custom - what you need is >> a different subset of characters (maybe you need to mix Latin, Greek, >> and Hebrew letters, in order to show interlinear translation of the >> Bible). Instead of messing around with character sets, you can just >> use Unicode and have all of them available. > > Assuming you have a text widget which is capable of displaying LTR and RTL > text, and support for all the glyphs you need. This is true. Fortunately, some measure of this is available in all the major GUI toolkits, although some applications need to have their own handling too. But here's what it takes to have full Unicode support in my MUD client: 1) Use GTK and Pango. That's the biggest part. 2) Due to the nature of MUDs, RTL text is still left-justified. 3) Due to the interaction of left-justified RTL text and indentation, special handling is needed for lines that begin with spaces and/or tabs and then an RTL character. (Solution: Prepend U+200E LEFT-TO-RIGHT MARK.) 4) Individual lines may be painted in multiple colours, so the text gets divided up and measured in pieces. I let Pango do the actual measurements. That's about it. Basically I just let Pango do all the heavy lifting; if it says this text in this font takes up this many pixels, that's how many pixels of width I allocate it. RTL? LTR? Mixed? No problem. It'll do all that for me. So yeah. Unicode isn't a panacea, and if you come from an ASCII-only environment, Unicode will look hard - but it's making life far easier than the alternatives would be. ChrisA From rosuav at gmail.com Sun Mar 26 14:29:43 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 05:29:43 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 27, 2017 at 5:10 AM, Steve D'Aprano wrote: >> And for own standalone app, I would not use any TTF or >> anything vector-based font, since why? > > Right, because your users will *love* to see their native language displayed > in a crappy bitmapped font with jagged or blurry edges. Side point: I have spent many hours wrestling with VLC to try to get a subtitles font that looks good for all the world's languages. My current setup has Latin, Cyrillic, and Greek looking great, Hebrew and Arabic looking adequate (I'm no expert so I don't know beyond that), but Thai, Chinese, Japanese, and Korean characters have jagged edges. Thanks guys. It's 2017 and we're still using bitmap fonts. ChrisA From rosuav at gmail.com Sun Mar 26 14:32:01 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 05:32:01 +1100 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <61d98fda-e43d-4cdc-addd-86b7aadbbc6c@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <61d98fda-e43d-4cdc-addd-86b7aadbbc6c@googlegroups.com> Message-ID: On Mon, Mar 27, 2017 at 4:54 AM, ????? ?????? wrote: > ?? ???????, 26 ??????? 2017 - 8:06:07 ?.?. UTC+3, ? ??????? INADA Naoki ??????: >> Read my mail again. >> >> > This error came from MySQL. If there are no logs in error_log, it's >> > your configuration issue. >> >> > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update >> > statement syntax. > > I cannot understand where the error is. > Could you how it to me please? Are people paying you to run their servers, and you're not even prepared to spend a few minutes reading the documentation before firing another post to a newsgroup/mailing list with thousands of participants? (Actually, I have no idea how many people read python-list/clp - 10K? 100K? 1M?) ChrisA From eryksun at gmail.com Sun Mar 26 14:37:11 2017 From: eryksun at gmail.com (eryk sun) Date: Sun, 26 Mar 2017 18:37:11 +0000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On Sun, Mar 26, 2017 at 5:58 PM, Chris Angelico wrote: >> The Windows console can render any character in the BMP, but it >> requires configuring font linking for fallback fonts. It's Windows, so >> of course the supported UTF format is UTF-16. The console's UTF-8 >> support (codepage 65001) is too buggy to even consider using it. > > Is it actually UTF-16, or is it UCS-2? Pedantically speaking it's UCS-2. Console buffers aren't necessarily valid UTF-16, i.e. they can have lone surrogate codes or invalid surrogate pairs. The way a surrogate code gets rendered depends on the font. It could be an empty box, a box containing a question mark, or simply empty space. That applies even if it's a valid UTF-16 surrogate pair, so the console can't display non-BMP characters such as emojis. They can be copied to the clipboard and displayed in another program. Windows file systems are also UCS-2. For the most part it's not an issue since the source of text and filenames will be valid UTF-16. From me.on.nzt at gmail.com Sun Mar 26 14:52:32 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 11:52:32 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <61d98fda-e43d-4cdc-addd-86b7aadbbc6c@googlegroups.com> Message-ID: <8ebad92f-e0e4-4652-aa49-4d26c4096440@googlegroups.com> ?? ???????, 26 ??????? 2017 - 9:32:13 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Mon, Mar 27, 2017 at 4:54 AM, ????? ?????? wrote: > > ?? ???????, 26 ??????? 2017 - 8:06:07 ?.?. UTC+3, ? ??????? INADA Naoki ??????: > >> Read my mail again. > >> > >> > This error came from MySQL. If there are no logs in error_log, it's > >> > your configuration issue. > >> > >> > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update > >> > statement syntax. > > > > I cannot understand where the error is. > > Could you how it to me please? > > Are people paying you to run their servers, and you're not even > prepared to spend a few minutes reading the documentation before > firing another post to a newsgroup/mailing list with thousands of > participants? (Actually, I have no idea how many people read > python-list/clp - 10K? 100K? 1M?) > > ChrisA So the answer is within that url link and i cannot see it?! Give me a hint! From me.on.nzt at gmail.com Sun Mar 26 14:54:38 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 11:54:38 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <46060114-0322-4347-8b46-121d7c9605c9@googlegroups.com> Message-ID: <1675223c-1239-4713-81cd-417331bb33b7@googlegroups.com> ?? ???????, 26 ??????? 2017 - 8:58:55 ?.?. UTC+3, ? ??????? alister ??????: > On Sun, 26 Mar 2017 07:43:51 -0700, ????? ?????? wrote: > > > ?? ???????, 26 ??????? 2017 - 5:38:57 ?.?. UTC+3, ? ??????? alister > > ??????: > >> On Sun, 26 Mar 2017 07:24:49 -0700, ????? ?????? wrote: > >> > >> > ?? ???????, 26 ??????? 2017 - 5:19:27 ?.?. UTC+3, ? ??????? Ian > >> > ??????: > >> > > >> >> You need to change the placeholders back. The poster who told you to > >> >> replace them was misinformed. > >> > > >> > okey altered them back to > >> > > >> > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, > >> > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE > >> > host LIKE "%%s%" ''', > >> > > >> > > >> (pID, domain, ref, location, useros, > >> > > >> > > >> browser, lastvisit, domain) ) > >> > > >> > but now the problem is how to exact;y type the Where HOST like "%%%" > >> > > >> > I MEAN HOW TO DIFFERENTIATE '%S' FROM LITERAL '%' character. > >> > >> > >> as a quick thought (untested) it is probably best to have %s as your > >> parameter for the Like clause & ad the sql wild-cards (% symbols) to > >> the data you pass in as I think the expansion of %s adds quote marks > >> which will certainly cause the sql parser issues. > > > > How do you propose writing that cur.execute statement Alister? > > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, > >> > useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE > >> > host LIKE %s ''' > > but you will need to amend the data you pass so that the last element > has the surrounding % characters . > > > -- > T-1's congested due to porn traffic to the news server. i have done so ith 3 different ways to prepare the string before sending it as an argument to update query as i mentioned in a previous post. Unfortunately all 3 ways weren't able to make the query work. From rosuav at gmail.com Sun Mar 26 14:57:31 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 05:57:31 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On Mon, Mar 27, 2017 at 5:37 AM, eryk sun wrote: > On Sun, Mar 26, 2017 at 5:58 PM, Chris Angelico wrote: >>> The Windows console can render any character in the BMP, but it >>> requires configuring font linking for fallback fonts. It's Windows, so >>> of course the supported UTF format is UTF-16. The console's UTF-8 >>> support (codepage 65001) is too buggy to even consider using it. >> >> Is it actually UTF-16, or is it UCS-2? > > Pedantically speaking it's UCS-2. Console buffers aren't necessarily > valid UTF-16, i.e. they can have lone surrogate codes or invalid > surrogate pairs. The way a surrogate code gets rendered depends on the > font. It could be an empty box, a box containing a question mark, or > simply empty space. That applies even if it's a valid UTF-16 surrogate > pair, so the console can't display non-BMP characters such as emojis. > They can be copied to the clipboard and displayed in another program. Exactly. So it's not supporting the entire Unicode range, but only the BMP. That restricts its usability for anything other than simple text. > Windows file systems are also UCS-2. For the most part it's not an > issue since the source of text and filenames will be valid UTF-16. I'm actually not sure on that one. Poking around on both Stack Overflow and MSDN suggests that NTFS does actually use UTF-16, which implies that lone surrogates should be errors, but I haven't proven this. In any case, file system encoding is relatively immaterial; it's file system *API* encoding that matters, and that means the CreateFileW function and its friends: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/gg269344(v=exchg.10).aspx My reading of this is that: a) The API is defined in terms of the WCHAR type, a 16-bit code unit. b) Limits are described in terms of "characters" (eg a max of 32767 for a path that starts "\\?\") c) ??? d) Profit?? I *think* it's the naive (and very common) hybrid of UCS-2 and UTF-16 that says "surrogates are allowed anywhere, and you're allowed to interpret pairs of them as UTF-16". But that's not a standard encoding. In actual UCS-2, surrogates are entirely disallowed; in UTF-16, they *must* be correctly paired. ChrisA From rosuav at gmail.com Sun Mar 26 15:04:11 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 06:04:11 +1100 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <8ebad92f-e0e4-4652-aa49-4d26c4096440@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <61d98fda-e43d-4cdc-addd-86b7aadbbc6c@googlegroups.com> <8ebad92f-e0e4-4652-aa49-4d26c4096440@googlegroups.com> Message-ID: On Mon, Mar 27, 2017 at 5:52 AM, ????? ?????? wrote: > ?? ???????, 26 ??????? 2017 - 9:32:13 ?.?. UTC+3, ? ??????? Chris Angelico ??????: >> On Mon, Mar 27, 2017 at 4:54 AM, ????? ?????? wrote: >> > ?? ???????, 26 ??????? 2017 - 8:06:07 ?.?. UTC+3, ? ??????? INADA Naoki ??????: >> >> Read my mail again. >> >> >> >> > This error came from MySQL. If there are no logs in error_log, it's >> >> > your configuration issue. >> >> >> >> > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update >> >> > statement syntax. >> > >> > I cannot understand where the error is. >> > Could you how it to me please? >> >> Are people paying you to run their servers, and you're not even >> prepared to spend a few minutes reading the documentation before >> firing another post to a newsgroup/mailing list with thousands of >> participants? (Actually, I have no idea how many people read >> python-list/clp - 10K? 100K? 1M?) >> >> ChrisA > > So the answer is within that url link and i cannot see it?! > > Give me a hint! You cannot see it? Why not - are you unable to access the web? Then track down the equivalent local documentation. I don't have MySQL or MariaDB installed here, but with PostgreSQL, I can fire up the CLI and get documentation on SQL commands. So no, I won't give you a hint until you get a clue. ChrisA From me.on.nzt at gmail.com Sun Mar 26 15:11:13 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 12:11:13 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <61d98fda-e43d-4cdc-addd-86b7aadbbc6c@googlegroups.com> <8ebad92f-e0e4-4652-aa49-4d26c4096440@googlegroups.com> Message-ID: <3e0d841c-1333-4fcb-87ee-92b7a0ea2353@googlegroups.com> ?? ???????, 26 ??????? 2017 - 10:04:31 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Mon, Mar 27, 2017 at 5:52 AM, ????? ?????? wrote: > > ?? ???????, 26 ??????? 2017 - 9:32:13 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > >> On Mon, Mar 27, 2017 at 4:54 AM, ????? ?????? wrote: > >> > ?? ???????, 26 ??????? 2017 - 8:06:07 ?.?. UTC+3, ? ??????? INADA Naoki ??????: > >> >> Read my mail again. > >> >> > >> >> > This error came from MySQL. If there are no logs in error_log, it's > >> >> > your configuration issue. > >> >> > >> >> > See https://dev.mysql.com/doc/refman/5.7/en/update.html for Update > >> >> > statement syntax. > >> > > >> > I cannot understand where the error is. > >> > Could you how it to me please? > >> > >> Are people paying you to run their servers, and you're not even > >> prepared to spend a few minutes reading the documentation before > >> firing another post to a newsgroup/mailing list with thousands of > >> participants? (Actually, I have no idea how many people read > >> python-list/clp - 10K? 100K? 1M?) > >> > >> ChrisA > > > > So the answer is within that url link and i cannot see it?! > > > > Give me a hint! > > You cannot see it? Why not - are you unable to access the web? Then > track down the equivalent local documentation. I don't have MySQL or > MariaDB installed here, but with PostgreSQL, I can fire up the CLI and > get documentation on SQL commands. > > So no, I won't give you a hint until you get a clue. > > ChrisA I can see it Chris, but i just cannot "see" it. If i remove the WHERE LIKE clause statement executes properly. Its when adding the clause that does not interpolated correctly. From breamoreboy at gmail.com Sun Mar 26 15:23:18 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sun, 26 Mar 2017 12:23:18 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> Message-ID: On Sunday, March 26, 2017 at 4:11:54 PM UTC+1, ????? ?????? wrote: > ?? ???????, 26 ??????? 2017 - 5:49:00 ?.?. UTC+3, ? ??????? Ian ??????: > > > The database wrapper won't do substitution into the middle of a string > > like that. Either concatenate the literal %'s on in the SQL statement > > or add them to the string before you pass it in, i.e. '%' + domain + > > '%' or '%%%s%%' % domain or '%{}%'.format(domain). > > I just tried: > > domain = '.'.join( host.split('.')[-2:] ) > domain = '%' + domain + '%' > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" ''', > (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > > and i received no error in the error_log but > ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, '%cyta.gr%', ' at line 1") > > which you can see at http://superhost.gr > > You said somethign about concatenating the literal % in the SQL to which i didnt actually i understand how to implement. I knew that I had a sense of deja vu about this https://mail.python.org/pipermail/python-list/2013-June/649809.html Kindest regards. Mark Lawrence From mikhailwas at gmail.com Sun Mar 26 15:25:16 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Sun, 26 Mar 2017 21:25:16 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 26 March 2017 at 20:10, Steve D'Aprano wrote: > On Mon, 27 Mar 2017 03:57 am, Mikhail V wrote: > > [...] >>>> And more important: can one use binary (bitmap) fonts in default modern >>>> linux console? If yes, can one patch them with custom tiles at >>>> the application start? >>> >>> If you really need something completely custom, it's not text any >>> more. >> >> Obvious fact, but if I need e.g. rounded corners in table drawing >> characters? Or I just want to fix some characters which look especially >> ugly? Create a new TTF? No, thanks, this would be worst nightmare to >> do without a special tool (which have prices with several zeros, otherwise >> just don't work and can even break things system-wide) > > Don't be silly. It took me ten seconds on Google to find this: > > https://birdfont.org/ > It takes you ten seconds to Google, and what if I ask you to take, say Courier New font TTF file (which includes not only vector information but all that is responsible for bitmap rendering, subpixeling, etc), then edit one character (and all corresponding information for subpixeling), then compile it as a new font, then install it on Win, without that making any conflicts, and without _any_ further glitches or changes in other characters, and no such things across all applications. If you'd try that, and you will succeed, _then_ I will publicly admit that I was silly. And paying even 50$ for correcting one glyph... well probably I'll do it if one gives guarantee that all above will work. > >>> More likely, you don't truly need something custom - what you need is >>> a different subset of characters (maybe you need to mix Latin, Greek, >>> and Hebrew letters, in order to show interlinear translation of the >>> Bible). Instead of messing around with character sets, you can just >>> use Unicode and have all of them available. >> >> If I was to deal with multiple language charsets in _my own_ rendering >> app, I would still use discrete encoding for inner algorithms. >> i.e. I would place separate charsets on separate code ranges. > > Why? Because you think you know better than the thousands of professionals > who have worked with text formats for decades? Sounds provocative, but yes, in some cases I know what I am doing ;-). But that is not because professionals does not know, there are many other aspects which come in play here. It depends on the use case, Unicode solves only some problems. I was talking only about _my own_ usage, it will be obviously incompatible e.g. for copy-pasting between othr apps. There are benefits to store language-specific values (+ their glyphs) in separate stacks. Anyway this discussion will require concrete examples and much deeper investigation. > >> And for own standalone app, I would not use any TTF or >> anything vector-based font, since why? > > Right, because your users will *love* to see their native language displayed > in a crappy bitmapped font with jagged or blurry edges. > I am working on text rendering algorithms an have prototyped several bitmap-based text rendering algorithms, both managed and prerendered approaches, and there is _nothing_ jagged or [incorrectly] blurred there, when one knows what he's doing of course. So it would be _very_ hard to catch me on incompetence here, but you can try, and feel free to do it :)))) FYI vector-based fonts were mainly motivated by print design. Modern GPUs have capabilities for fast vector glyph rendering, but it is not needed for screen rendering, much less when higher DPI displays will prevale. Mikhail From me.on.nzt at gmail.com Sun Mar 26 15:33:27 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 12:33:27 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> Message-ID: ?? ???????, 26 ??????? 2017 - 10:23:27 ?.?. UTC+3, ? ??????? bream... at gmail.com ??????: > On Sunday, March 26, 2017 at 4:11:54 PM UTC+1, ????? ?????? wrote: > > ?? ???????, 26 ??????? 2017 - 5:49:00 ?.?. UTC+3, ? ??????? Ian ??????: > > > > > The database wrapper won't do substitution into the middle of a string > > > like that. Either concatenate the literal %'s on in the SQL statement > > > or add them to the string before you pass it in, i.e. '%' + domain + > > > '%' or '%%%s%%' % domain or '%{}%'.format(domain). > > > > I just tried: > > > > domain = '.'.join( host.split('.')[-2:] ) > > domain = '%' + domain + '%' > > > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" ''', > > (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > > > > > and i received no error in the error_log but > > ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, '%cyta.gr%', ' at line 1") > > > > which you can see at http://superhost.gr > > > > You said somethign about concatenating the literal % in the SQL to which i didnt actually i understand how to implement. > > I knew that I had a sense of deja vu about this https://mail.python.org/pipermail/python-list/2013-June/649809.html > > Kindest regards. > > Mark Lawrence Since i'm incopetent as you suggest i'am show us your level of skills and expertise and provide a solution, otherwise you are also what you claim of me. From breamoreboy at gmail.com Sun Mar 26 15:50:37 2017 From: breamoreboy at gmail.com (breamoreboy at gmail.com) Date: Sun, 26 Mar 2017 12:50:37 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> Message-ID: <576ffeee-0caf-4e79-9a8e-a2b361a169d3@googlegroups.com> On Sunday, March 26, 2017 at 8:33:49 PM UTC+1, ????? ?????? wrote: > ?? ???????, 26 ??????? 2017 - 10:23:27 ?.?. UTC+3, ? ??????? bream... at gmail.com ??????: > > On Sunday, March 26, 2017 at 4:11:54 PM UTC+1, ????? ?????? wrote: > > > ?? ???????, 26 ??????? 2017 - 5:49:00 ?.?. UTC+3, ? ??????? Ian ??????: > > > > > > > The database wrapper won't do substitution into the middle of a string > > > > like that. Either concatenate the literal %'s on in the SQL statement > > > > or add them to the string before you pass it in, i.e. '%' + domain + > > > > '%' or '%%%s%%' % domain or '%{}%'.format(domain). > > > > > > I just tried: > > > > > > domain = '.'.join( host.split('.')[-2:] ) > > > domain = '%' + domain + '%' > > > > > > cur.execute('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" ''', > > > (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > > > > > > > > and i received no error in the error_log but > > > ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ref, location, useros, browser, visits) VALUES (1, '%cyta.gr%', ' at line 1") > > > > > > which you can see at http://superhost.gr > > > > > > You said somethign about concatenating the literal % in the SQL to which i didnt actually i understand how to implement. > > > > I knew that I had a sense of deja vu about this https://mail.python.org/pipermail/python-list/2013-June/649809.html > > > > Kindest regards. > > > > Mark Lawrence > > Since i'm incopetent as you suggest i'am show us your level of skills and expertise and provide a solution, otherwise you are also what you claim of me. *plonk* From rosuav at gmail.com Sun Mar 26 15:53:12 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 06:53:12 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Mar 27, 2017 at 6:25 AM, Mikhail V wrote: > On 26 March 2017 at 20:10, Steve D'Aprano wrote: >> On Mon, 27 Mar 2017 03:57 am, Mikhail V wrote: >> >> [...] >>>>> And more important: can one use binary (bitmap) fonts in default modern >>>>> linux console? If yes, can one patch them with custom tiles at >>>>> the application start? >>>> >>>> If you really need something completely custom, it's not text any >>>> more. >>> >>> Obvious fact, but if I need e.g. rounded corners in table drawing >>> characters? Or I just want to fix some characters which look especially >>> ugly? Create a new TTF? No, thanks, this would be worst nightmare to >>> do without a special tool (which have prices with several zeros, otherwise >>> just don't work and can even break things system-wide) >> >> Don't be silly. It took me ten seconds on Google to find this: >> >> https://birdfont.org/ >> > > It takes you ten seconds to Google, and what if I ask you > to take, say Courier New font TTF file (which includes not only > vector information but all that is responsible for bitmap > rendering, subpixeling, etc), then edit one character (and > all corresponding information for subpixeling), > then compile it as a new font, then install it on Win, > without that making any conflicts, and without _any_ > further glitches or changes in other characters, and no such > things across all applications. > If you'd try that, and you will succeed, _then_ I will publicly admit > that I was silly. > > And paying even 50$ for correcting one glyph... well > probably I'll do it if one gives guarantee that all above > will work. See previous comments about font substitution. Create a font with just one character in it. Use that font in your application. Voila! No changes to any other applications (because they'll still be using the original font), and no changes to any other characters. However, I'm impressed that you found a bug in a well-used font. http://www.catb.org/esr/faqs/smart-questions.html#idm46227256017920 Is it that decades of typographical research is incorrect, or that the designers of this font just sucked? You're pretty unambiguous in your description that you are "correcting" a glyph. Not adapting it to your own purposes - you're correcting something that's fundamentally wrong in someone else's font. Impressive. >> Why? Because you think you know better than the thousands of professionals >> who have worked with text formats for decades? > > Sounds provocative, but yes, in some cases I know what I am > doing ;-). > But that is not because professionals does not know, > there are many other aspects which come in play here. > It depends on the use case, Unicode solves only some > problems. > I was talking only about _my own_ usage, it > will be obviously incompatible e.g. for copy-pasting > between othr apps. > There are benefits to store language-specific values (+ their glyphs) > in separate stacks. > Anyway this discussion will require concrete > examples and much deeper investigation. I generally find that when people say that Unicode doesn't solve their problems and they need to roll their own, it's usually one of two possibilities: 1) "Their problems" are all about simplicity. They don't want to have to deal with all the complexities of real-world text, so they arbitrarily restrict things. 2) Unicode _would_ solve their problems, they just don't realize it. So if you're rolling your own text display system, you should start by making a signed declaration: """ I, the undersigned, acknowledge that my program is intentionally excluding everyone who does not fit the following requirements: [choose all applicable] [ ] Speaks English exclusively [ ] Uses no diacritical marks [ ] Writes all text top-to-bottom, left-to-right [ ] Uses only characters from the Basic Multilingual Plane [ ] Uses only characters from this codepage: ____ [ ] Uses a monospaced font [ ] Uses a proportionally-spaced font [ ] Uses this font: _____________ [ ] Uses a mouse [ ] Uses a keyboard [ ] Other: ___________________ (use additional pages if required) Signed: _______________ """ Sure, there are good reasons to place restrictions on people's text. But those restrictions are part of your public API and UI. Acknowledge them. Own them. And justify them. >>> And for own standalone app, I would not use any TTF or >>> anything vector-based font, since why? >> >> Right, because your users will *love* to see their native language displayed >> in a crappy bitmapped font with jagged or blurry edges. >> > > I am working on text rendering algorithms an have prototyped > several bitmap-based text rendering algorithms, > both managed and prerendered approaches, and there > is _nothing_ jagged or [incorrectly] blurred there, when > one knows what he's doing of course. > So it would be _very_ hard to catch me on incompetence > here, but you can try, and feel free to do it :)))) Sure. Render me two characters on a half-meter-wide 1920x1080 screen. I'll choose the exact size dynamically, at run-time, in response to the amount of chrome I have on the window. Make sure the two characters look perfect whether I make this a tiny marker on the screen, or make it completely fill the entire monitor. > FYI vector-based fonts were mainly motivated by print design. > Modern GPUs have capabilities for fast vector > glyph rendering, but it is not needed for screen rendering, > much less when higher DPI displays will prevale. Even if high-DPI displays *do* prevail, you still have to render text at a wide variety of pixel sizes. One character might have a box 10x19 pixels (that's what my MUD client is saying; the height of 19px is what it's using from line to line, and the estimated 10px width is based on the letter "n", and is used to convert from server-side character widths to actual measured widths), or it might be stretched to 568x1080 to fill the entire height of my screen. That letter might get rotated by 7.3 degrees counter-clockwise in order to place it tastefully into a logo. It could even be picked up and turned into a three-mile-high 3D object in a fully-rendered world, helping to spell out "SHARE AND ENJOY". Can your bitmapped font renderer handle all of that? ChrisA (If it can't, maybe it should go stick its head in a pig?) From rosuav at gmail.com Sun Mar 26 15:55:47 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 06:55:47 +1100 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> Message-ID: On Mon, Mar 27, 2017 at 6:33 AM, ????? ?????? wrote: > Since i'm incopetent as you suggest i'am show us your level of skills and expertise and provide a solution, otherwise you are also what you claim of me. It's not his problem. An expert does not have to provide solutions to prove his expertise, unless s/he is suffering from severe self-image problems. Someone who's getting paid to host other people's web sites, on the other hand, needs to solve the problems that come up. ChrisA From me.on.nzt at gmail.com Sun Mar 26 16:05:13 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 13:05:13 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> Message-ID: <2a3dc802-06fa-4970-896a-9ec484e225d5@googlegroups.com> ?? ???????, 26 ??????? 2017 - 10:56:07 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Mon, Mar 27, 2017 at 6:33 AM, ????? ?????? wrote: > > Since i'm incopetent as you suggest i'am show us your level of skills and expertise and provide a solution, otherwise you are also what you claim of me. > > It's not his problem. An expert does not have to provide solutions to > prove his expertise, unless s/he is suffering from severe self-image > problems. Someone who's getting paid to host other people's web sites, > on the other hand, needs to solve the problems that come up. > > ChrisA Okey although i beleive my UPDATE query to be correct i'll now try this: cur.execute('''UPDATE visitors SET pagesID=%s, host=%s, ref=%s, location=%s, useros=%s, browser=%s, visits=%s WHERE host LIKE %s''', (pID, domain, ref, location, useros, browser, lastvisit, domain_query) ) From me.on.nzt at gmail.com Sun Mar 26 16:13:13 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 13:13:13 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <2a3dc802-06fa-4970-896a-9ec484e225d5@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <2a3dc802-06fa-4970-896a-9ec484e225d5@googlegroups.com> Message-ID: <7ed4ae91-7547-4f1c-a80c-d3fc78b23bf0@googlegroups.com> ?? ???????, 26 ??????? 2017 - 11:05:34 ?.?. UTC+3, ? ??????? ????? ?????? ??????: > ?? ???????, 26 ??????? 2017 - 10:56:07 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > > On Mon, Mar 27, 2017 at 6:33 AM, ????? ?????? wrote: > > > Since i'm incopetent as you suggest i'am show us your level of skills and expertise and provide a solution, otherwise you are also what you claim of me. > > > > It's not his problem. An expert does not have to provide solutions to > > prove his expertise, unless s/he is suffering from severe self-image > > problems. Someone who's getting paid to host other people's web sites, > > on the other hand, needs to solve the problems that come up. > > > > ChrisA > > Okey although i beleive my UPDATE query to be correct i'll now try this: > > cur.execute('''UPDATE visitors SET pagesID=%s, host=%s, ref=%s, location=%s, useros=%s, browser=%s, visits=%s WHERE host LIKE %s''', (pID, domain, ref, location, useros, browser, lastvisit, domain_query) ) OMG!!! It actually worked! Can't believe that 3 days in a row i have tried everything concerning string manipulation and mysql escaping nd the error was the UPDATE itself.... OMG!!! From orgnut at yahoo.com Sun Mar 26 16:59:05 2017 From: orgnut at yahoo.com (Larry Hudson) Date: Sun, 26 Mar 2017 13:59:05 -0700 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> Message-ID: On 03/26/2017 01:21 AM, ????? ?????? wrote: > print('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > prints out: > > UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" (1, 'cyta.gr', '????? ????????', 'Greece', 'Windows', 'Chrome', '17-03-24 22:04:24', 'cyta.gr') > > How should i write the cursor.execute in order to be parsed properly? > As i have it now %s does not get substituted. You don't get the substitution because you're missing a %. Change: ... LIKE "%s"''', (pID, ... To: ... LIKE "%s"''' % (pID, ... -- -=- Larry -=- From me.on.nzt at gmail.com Sun Mar 26 17:23:46 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 14:23:46 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> Message-ID: <27e5d492-a70d-4ede-b94a-a70b269526e6@googlegroups.com> ?? ???????, 26 ??????? 2017 - 11:59:21 ?.?. UTC+3, ? ??????? Larry Hudson ??????: > On 03/26/2017 01:21 AM, ????? ?????? wrote: > > print('''UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s"''', (pID, domain, ref, location, useros, browser, lastvisit, domain) ) > > > > prints out: > > > > UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" (1, 'cyta.gr', '????? ????????', 'Greece', 'Windows', 'Chrome', '17-03-24 22:04:24', 'cyta.gr') > > > > How should i write the cursor.execute in order to be parsed properly? > > As i have it now %s does not get substituted. > > You don't get the substitution because you're missing a %. > > Change: > ... LIKE "%s"''', (pID, ... > To: > ... LIKE "%s"''' % (pID, ... > > -- > -=- Larry -=- No, i have tried it many times. It fails and is prone to sql injection within a cursor execute. As i understood i can have UPDATE syntax be as similar to INSERT like (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) each column needs to be set respectively as column1 = value1, column2 = value 2 and so on. From eryksun at gmail.com Sun Mar 26 18:09:43 2017 From: eryksun at gmail.com (eryk sun) Date: Sun, 26 Mar 2017 22:09:43 +0000 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: On Sun, Mar 26, 2017 at 6:57 PM, Chris Angelico wrote: > > In actual UCS-2, surrogates are entirely disallowed; in UTF-16, they *must* be > correctly paired. Strictly-speaking UCS-2 disallows codes that aren't defined by the standard, but the kernel couldn't be that restrictive. Unicode was a moving target in the period that NT was developed (1988-93). The object manager simply allows any 16-bit code in object names, except its path separator, backslash. Since a UNICODE_STRING is counted, even NUL is allowed in object names. But that's uncommon and should be avoided since the user-mode API uses null-terminated strings. The file-system runtime library further restricts this by reserving NUL, ASCII control codes, forward slash, pipe, and the wildcard characters asterisk, question mark, double quote, less than, and greater than. The rules are loosened for NTFS named streams, which only reserve NUL, forward slash, and backslash. >> Windows file systems are also UCS-2. For the most part it's not an >> issue since the source of text and filenames will be valid UTF-16. > > I'm actually not sure on that one. Poking around on both Stack > Overflow and MSDN suggests that NTFS does actually use UTF-16, which > implies that lone surrogates should be errors, but I haven't proven > this. In any case, file system encoding is relatively immaterial; it's > file system *API* encoding that matters, and that means the > CreateFileW function and its friends: Sure, the file system itself can use any encoding, but Microsoft use a permissive UCS-2 in its file systems. The API uses 16-bit WCHARs, and except for a relatively small set of codes (assuming it uses the FsRtl), the system generally doesn't care about the values. Let's review the major actors. CreateFile uses the runtime library in ntdll.dll to fill in an OBJECT_ATTRIBUTES [1] with a UNICODE_STRING [2]. This is where the current-directory handle is set as the attributes RootDirectory handle for relative paths; where slash is replaced with backslash; and where weird MS-DOS rules are applied, such as DOS device names and trimming trailing spaces. Once it has a native object attributes record, it calls the real system call NtCreateFile [3]. In kernel mode this in turn calls the I/O manager function IoCreateFile [4], which creates an open packet and calls the object manger function ObOpenObjectByName. Now it's time for path parsing. In the normal case the system traverses several object directories and object symbolic links before finally arriving at an I/O device (e.g. \??\C: => \Global??\C: => \Device\HarddiskVolume2). Parsing the rest of the path is in the hands of the I/O manager via the Device object's ParseProcedure. The I/O manager creates a File object and an I/O request packet (IRP) for the major function IRP_MJ_CREATE [5] and calls the driver for the device stack via IoCallDriver [6]. If the device is a volume that's managed by a file-system driver (e.g. ntfs.sys), the file-system parses the remaining path to open or create the directory/file/stream and complete the IRP. The object manager creates a handle for the File object in the handle table of the calling process, and this handle value is finally passed back to the caller. [1]: https://msdn.microsoft.com/en-us/library/ff557749 [2]: https://msdn.microsoft.com/en-us/library/ff564879 [3]: https://msdn.microsoft.com/en-us/library/ff566424 [4]: https://msdn.microsoft.com/en-us/library/ff548418 [5]: https://msdn.microsoft.com/en-us/library/ff548630 [6]: https://msdn.microsoft.com/en-us/library/ff548336 The object manager only cares about its path separator, backslash, until it arrives at an object type that it doesn't manage, such as a Device object. If a file system uses the FsRtl, then the remaining path is subject to Windows file-system rules. It would be ill-advised to diverge from these rules. > I *think* it's the naive (and very common) hybrid of UCS-2 and UTF-16 It's just the way the system evolved over time. UTF-16 wasn't standardized until 1996 circa NT 4.0. Windows started integrating it around NT 5 (Windows 2000), primarily for the GUI controls in the windowing system that directly affect text processing for most applications. It was good enough to leave most of the lower layers of the system passively naive when it comes to UTF-16. From songofacandy at gmail.com Sun Mar 26 19:26:58 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Mon, 27 Mar 2017 08:26:58 +0900 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: > i dont have to update table set column1 = this value, column2=that value and > so on Why do you think so? Did you really read the manual? mysql> create table test_update (a int primary key, b int, c int); Query OK, 0 rows affected (0.02 sec) mysql> insert into test_update values (1, 2, 3); Query OK, 1 row affected (0.00 sec) mysql> update test_update set (b, c) values (4, 5) where a = 1; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(b, c) values (4, 5) where a = 1' at line 1 mysql> update test_update set b=4, c=5 where a = 1; Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 > > It's just when the LIKE clause jumps in that is causing all this trouble.... Your MariaDB said: > check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ... MariaDB / MySQL shows part of your SQL from where they failed to parse. In your case, your MariaDB can't parse from '(' LIKE clause is not problem for this issue? From mikhailwas at gmail.com Sun Mar 26 19:42:21 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Mon, 27 Mar 2017 01:42:21 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 26 March 2017 at 21:53, Chris Angelico wrote: > On Mon, Mar 27, 2017 at 6:25 AM, Mikhail V wrote: >> On 26 March 2017 at 20:10, Steve D'Aprano wrote: >>> On Mon, 27 Mar 2017 03:57 am, Mikhail V wrote: >>> >>> [...] >>>>>> And more important: can one use binary (bitmap) fonts in default modern >>>>>> linux console? If yes, can one patch them with custom tiles at >>>>>> the application start? >>>>> >>>>> If you really need something completely custom, it's not text any >>>>> more. >>>> >>>> Obvious fact, but if I need e.g. rounded corners in table drawing >>>> characters? Or I just want to fix some characters which look especially >>>> ugly? Create a new TTF? No, thanks, this would be worst nightmare to >>>> do without a special tool (which have prices with several zeros, otherwise >>>> just don't work and can even break things system-wide) >>> >>> Don't be silly. It took me ten seconds on Google to find this: >>> >>> https://birdfont.org/ >>> >> >> It takes you ten seconds to Google, and what if I ask you >> to take, say Courier New font TTF file (which includes not only >> vector information but all that is responsible for bitmap >> rendering, subpixeling, etc), then edit one character (and >> all corresponding information for subpixeling), >> then compile it as a new font, then install it on Win, >> without that making any conflicts, and without _any_ >> further glitches or changes in other characters, and no such >> things across all applications. >> If you'd try that, and you will succeed, _then_ I will publicly admit >> that I was silly. >> >> And paying even 50$ for correcting one glyph... well >> probably I'll do it if one gives guarantee that all above >> will work. > > See previous comments about font substitution. Create a font with just > one character in it. Use that font in your application. Voila! No > changes to any other applications (because they'll still be using the > original font), and no changes to any other characters. Good tip, I'll try that. Though still one need an app, even for one character, and it'll need fallback setup on each computer I use. Dont get it wrong, I don't say it is impossible. There are guys that have figured out such things and I've read once something about hacking bitmap and subpixeling information directly in the font file, but I was not stubborn enough to learn that. > Is it that decades of typographical research is incorrect, or that the > designers of this font just sucked? You're pretty unambiguous in your > description that you are "correcting" a glyph. Not adapting it to your > own purposes - you're correcting something that's fundamentally wrong > in someone else's font. Impressive. Call it "modify for own purpose" if it sounds better. In Courier, the brackets are too small, tilde char is too much like hyphen, some other minor things. And Courier New bold is best readable (for me ;) font on Win so I don't want another font, which has better brackets, but less readable. And as said, if possible I avoid monospaced font where possible, so this means that probably I'll need to modfy some other fonts too. >>>> And for own standalone app, I would not use any TTF or >>>> anything vector-based font, since why? >>> >>> Right, because your users will *love* to see their native language displayed >>> in a crappy bitmapped font with jagged or blurry edges. >>> >> >> I am working on text rendering algorithms an have prototyped >> several bitmap-based text rendering algorithms, >> both managed and prerendered approaches, and there >> is _nothing_ jagged or [incorrectly] blurred there, when >> one knows what he's doing of course. >> So it would be _very_ hard to catch me on incompetence >> here, but you can try, and feel free to do it :)))) > > Sure. Render me two characters on a half-meter-wide 1920x1080 screen. > I'll choose the exact size dynamically, at run-time, in response to > the amount of chrome I have on the window. Make sure the two > characters look perfect whether I make this a tiny marker on the > screen, or make it completely fill the entire monitor. > [...] > Even if high-DPI displays *do* prevail, you still have to render > text at a wide variety of pixel sizes. Seems like you are jumping from one corner case to another. In general, if you want huge letters or some design tasks (e.g. huge letters for a print) you can use vector paths. But remember that a photo or a bitmap texture will not become new information if you convert each pixel to a vector square, or circle. It is only question of scalability. Concentrate on these points: - Restrict the case to display only - Making one letter fill half of a monitor, or rotating it arbitrary, has little to do with reading text on a monitor in real situation. - Your understanding of "look perfect" and relation with information cognition (e.g. a retro game upscaled with integer scaler versus a remake of this game made completely with higher resolution sprites - will you say that the latter feels much better?) - "Render text at a wide variety of pixel sizes": yes, one can do this all only with bitmap information, if one uses appropriate image sources and algorithms. This gives perfect results. And there are few interesting solutions for performance optimisations without breaking the distance precision (e.g. currently subpixeling on Windows is used, but there are other good ways without subpixeling) In real application, you can achieve this with real-time vector rendering, but it will be simply not worth it, since you will gain no improvement of reading experience. So the possibility to render huge letters and then inspecting the tangents of all curves with a looking glass will not count as an argument by choice decision for a reader software for example (for each given task, there is concrete optimal solution) And all text I currently read on my monitor are prerendered bitmaps, refined manually for frequently used sizes, and that is how it should be made. IOW there are much more important aspects than the ability to scale a text line from 600 px to 601 px wide, if you know what I mean. Mikhail From python.list at tim.thechases.com Sun Mar 26 20:15:39 2017 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 26 Mar 2017 19:15:39 -0500 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: Message-ID: <20170326191539.02def931@bigbox.christie.dr> On 2017-03-27 02:37, Chris Angelico wrote: > > In DOS, (I don't remember if in all versions or only some) > > one could do all this and this opens very rich possibilities for > > approximating of objects with tiles. The only limitations > > that one uses 255 tiles, but even this enables to build > > whole 'worlds' and state of the art apps. So I would call this > > pseudographics and not few sticks and corner tiles > > (which I cannot even define and upload easily). > > Yeah; if my memory serves me, this was an IBM BIOS feature, so all > versions of DOS would be equally able to do it. But it's basically a > form of tile graphics, not text. It was a function of the EGA/VGA card (maybe CGA? Though I think that might have been limited to the upper 128 chars while the lower 128 were fixed), not the IBM BIOS. But yes, there were font-editors for the EGA/VGA fonts and, once set, they'd appear even in things like WordPerfect, QuattroPro, Lotus, or Turbo Pascal. All the rage back in my 286-wolfenstein3d-playing-turbopascal-programming days. ;-) -tkc From steve+python at pearwood.info Sun Mar 26 20:33:49 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Mon, 27 Mar 2017 11:33:49 +1100 Subject: Escaping confusion with Python 3 + MySQL References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <2a3dc802-06fa-4970-896a-9ec484e225d5@googlegroups.com> <7ed4ae91-7547-4f1c-a80c-d3fc78b23bf0@googlegroups.com> Message-ID: <58d85df0$0$1622$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Mar 2017 07:13 am, ????? ?????? wrote: > OMG!!! It actually worked! > > Can't believe that 3 days in a row i have tried everything concerning > string manipulation and mysql escaping nd the error was the UPDATE > itself.... You tried everything except what we told you, over and over and over again: READ THE MANUAL. The error message told you it was a SQL syntax error, but no, you insisted that you knew better, and refused to do what the error message said. So you wasted three days due to your own stubbornness and laziness. I have no sympathy for your self-inflicted problems. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From me.on.nzt at gmail.com Sun Mar 26 22:39:54 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 19:39:54 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5b045f7e-1c63-45ad-ad5e-5385f33e06e1@googlegroups.com> ?? ???????, 27 ??????? 2017 - 2:27:31 ?.?. UTC+3, ? ??????? INADA Naoki ??????: > > i dont have to update table set column1 = this value, column2=that value and > > so on > > Why do you think so? Did you really read the manual? > > mysql> create table test_update (a int primary key, b int, c int); > Query OK, 0 rows affected (0.02 sec) > > mysql> insert into test_update values (1, 2, 3); > Query OK, 1 row affected (0.00 sec) > > mysql> update test_update set (b, c) values (4, 5) where a = 1; > ERROR 1064 (42000): You have an error in your SQL syntax; check the > manual that corresponds to your MySQL server version for the right > syntax to use near '(b, c) values (4, 5) where a = 1' at line 1 > > mysql> update test_update set b=4, c=5 where a = 1; > Query OK, 1 row affected (0.01 sec) > Rows matched: 1 Changed: 1 Warnings: 0 > > > > > It's just when the LIKE clause jumps in that is causing all this trouble.... > > Your MariaDB said: > > > check the manual that corresponds to your MariaDB server version for the right syntax to use near '(pagesID, host, ... > > MariaDB / MySQL shows part of your SQL from where they failed to parse. > In your case, your MariaDB can't parse from '(' > LIKE clause is not problem for this issue? Yes indeed it is. I was just so sure that UPDATE was working like INSERT and i was persistent that the WHERE LIKE clause was cauing this. I'am still surprised that: > mysql> update test_update set (b, c) values (4, 5) where a = 1; is failign to parse. It just seems so undoubtly straightforward and correct syntactically. From rosuav at gmail.com Sun Mar 26 22:42:46 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 13:42:46 +1100 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <5b045f7e-1c63-45ad-ad5e-5385f33e06e1@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <5b045f7e-1c63-45ad-ad5e-5385f33e06e1@googlegroups.com> Message-ID: On Mon, Mar 27, 2017 at 1:39 PM, ????? ?????? wrote: >> MariaDB / MySQL shows part of your SQL from where they failed to parse. >> In your case, your MariaDB can't parse from '(' >> LIKE clause is not problem for this issue? > > Yes indeed it is. > I was just so sure that UPDATE was working like INSERT and i was persistent that the WHERE LIKE clause was cauing this. > > I'am still surprised that: >> mysql> update test_update set (b, c) values (4, 5) where a = 1; > > is failign to parse. It just seems so undoubtly straightforward and correct syntactically. So when people told you to read the docs, what did you do, exactly? ChrisA From me.on.nzt at gmail.com Sun Mar 26 22:52:27 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 19:52:27 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <5b045f7e-1c63-45ad-ad5e-5385f33e06e1@googlegroups.com> Message-ID: <22b18365-ca0e-46b9-9e51-f68ae201b36e@googlegroups.com> ?? ???????, 27 ??????? 2017 - 5:43:01 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Mon, Mar 27, 2017 at 1:39 PM, ????? ?????? wrote: > >> MariaDB / MySQL shows part of your SQL from where they failed to parse. > >> In your case, your MariaDB can't parse from '(' > >> LIKE clause is not problem for this issue? > > > > Yes indeed it is. > > I was just so sure that UPDATE was working like INSERT and i was persistent that the WHERE LIKE clause was cauing this. > > > > I'am still surprised that: > >> mysql> update test_update set (b, c) values (4, 5) where a = 1; > > > > is failign to parse. It just seems so undoubtly straightforward and correct syntactically. > > So when people told you to read the docs, what did you do, exactly? > > ChrisA Its NOT that i have not read it exactly, but for some strange reason i was under the belief that the way i had syntactically typed the UPDATE query was correctly and more consistent and similar to thr INSERT query and it was prefered to me over the other one. UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" Its still a mystery to em whay this fails syntactically when at the same time INSERT works like that. We give each columnn a specific value i don't see why it must only be written as UPDATE visitors SET a=1, b=2, c=3 ... WHERE host LIKE %s. i knew that would work, but the first way although proven syntactically wrong seems so right ..... From rosuav at gmail.com Sun Mar 26 23:00:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Mar 2017 14:00:20 +1100 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <22b18365-ca0e-46b9-9e51-f68ae201b36e@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <5b045f7e-1c63-45ad-ad5e-5385f33e06e1@googlegroups.com> <22b18365-ca0e-46b9-9e51-f68ae201b36e@googlegroups.com> Message-ID: On Mon, Mar 27, 2017 at 1:52 PM, ????? ?????? wrote: > Its NOT that i have not read it exactly, but for some strange reason i was under the belief that the way i had syntactically typed the UPDATE query was correctly and more consistent and similar to thr INSERT query and it was prefered to me over the other one. > > UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" > > Its still a mystery to em whay this fails syntactically when at the same time INSERT works like that. > > We give each columnn a specific value i don't see why it must only be written as UPDATE visitors SET a=1, b=2, c=3 ... WHERE host LIKE %s. > > i knew that would work, but the first way although proven syntactically wrong seems so right ..... It'd be even more logical to write: UPDATE visitors INCREMENT visits WHERE host CONTAINS %s; I should just use that syntax, and if it doesn't work, I'm going to post onto a mailing list until it magically starts working. It's NOT that I haven't read the docs - I'm just going to wilfully ignore them. Okay, I'm done now. ChrisA From gerald.britton at gmail.com Sun Mar 26 23:03:43 2017 From: gerald.britton at gmail.com (Gerald Britton) Date: Sun, 26 Mar 2017 23:03:43 -0400 Subject: [Python-ideas] Proposal: Query language extension to Python (PythonQL) Message-ID: (Forgot the subject) > >* On 25 Mar 2017, at 15:51, Gerald Britton > wrote: > *> >* On 25 March 2017 at 11:24, Pavel Velikhov >> wrote: > *>* > No, the current solution is temporary because we just don?t have the > *>* > manpower to > *>* > implement the full thing: a real system that will rewrite parts of PythonQL > *>* > queries and > *>* > ship them to underlying databases. We need a real query optimizer and smart > *>* > wrappers > *>* > for this purpose. But we?ll build one of these for demo purposes soon > *>* > (either a Spark > *>* > wrapper or a PostgreSQL wrapper). > *>* One thought, if you're lacking in manpower now, then proposing > *>* inclusion into core Python means that the core dev team will be taking > *>* on an additional chunk of code that is already under-resourced. That > *>* rings alarm bells for me - how would you imagine the work needed to > *>* merge PythonQL into the core Python grammar would be resourced? > *>* I should say that in practice, I think that the solution is relatively > *>* niche, and overlaps quite significantly with existing Python features, > *>* so I don't really see a compelling case for inclusion. The parallel > *>* with C# and LINQ is interesting here - LINQ is a pretty cool > *>* technology, but I don't see it in widespread use in general-purpose C# > *>* projects (disclaimer: I don't get to see much C# code, so my > *>* experience is limited). > *> >* I see lots of C# code, but (thankfully) not so much LINQ to SQL. Yes, it is a cool technology. But I sometimes have a problem with the SQL it generates. Since I'm also a SQL developer, I'm sensitive to how queries are constructed, for performance reasons, as well as how they look, for readability and aesthetic reasons. > *> >* LINQ queries can generate poorly-performing SQL, since LINQ is a basically a translator, but not an AI. As far as appearances go, LINQ queries can look pretty gnarly, especially if they include sub queries or a few joins. That makes it hard for the SQL dev (me!) to read and understand if there are performance problems (which there often are, in my experience) > *> We want to go beyond being a basic translator. Especially if the common use-case will be integrating multiple databases. We can also introduce decent-looking hints (maybe not always decent looking) to generate better plans. Not sure about asethetics though... >* So, I would tend to code the SQL separately and put it in a SQL view, function or stored procedure. I can still parse the results with LINQ (not LINQ to SQL), which is fine. > *> >* For similar reasons, I'm not a huge fan of ORMs either. Probably my bias towards designing the database first and building up queries to meet the business goals before writing a line of Python, C#, or the language de jour. > * This sounds completely reasonable, but this means you?re tied to a specific DBMS (especially if you?re using a lot of built-in functions that are usually very specific to a database). PythonQL (when it has enough functionality) should give you independence. True though not always needed. e.g. at present I'm working for a large company with thousands of db servers in all the popular flavors. The probability of changing even one of them to a different vendor is essentially zero. The costs and dependencies far outweigh any hoped-for advantage. At the same time, I'm happy to optimize the SQL for different target environments. If I lack the specific expertise, I know where to go to find it. The Adapter pattern helps here. It's actually more important for me to build queries that can be used in multiple client languages. We're using Java, C++, C#, F#, VB, ... and Python, of course (and probably others that I don't know we use). I can optimize the query once and not worry about the clients messing it up. -- Gerald Britton, MCSE-DP, MVP LinkedIn Profile: http://ca.linkedin.com/in/geraldbritton From me.on.nzt at gmail.com Sun Mar 26 23:04:31 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Sun, 26 Mar 2017 20:04:31 -0700 (PDT) Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <5b045f7e-1c63-45ad-ad5e-5385f33e06e1@googlegroups.com> <22b18365-ca0e-46b9-9e51-f68ae201b36e@googlegroups.com> Message-ID: <47db4e13-4733-4d14-86fa-5561f23f7a4b@googlegroups.com> ?? ???????, 27 ??????? 2017 - 6:00:34 ?.?. UTC+3, ? ??????? Chris Angelico ??????: > On Mon, Mar 27, 2017 at 1:52 PM, ????? ?????? wrote: > > Its NOT that i have not read it exactly, but for some strange reason i was under the belief that the way i had syntactically typed the UPDATE query was correctly and more consistent and similar to thr INSERT query and it was prefered to me over the other one. > > > > UPDATE visitors SET (pagesID, host, ref, location, useros, browser, visits) VALUES (%s, %s, %s, %s, %s, %s, %s) WHERE host LIKE "%s" > > > > Its still a mystery to em whay this fails syntactically when at the same time INSERT works like that. > > > > We give each columnn a specific value i don't see why it must only be written as UPDATE visitors SET a=1, b=2, c=3 ... WHERE host LIKE %s. > > > > i knew that would work, but the first way although proven syntactically wrong seems so right ..... > > It'd be even more logical to write: > > UPDATE visitors INCREMENT visits WHERE host CONTAINS %s; > > I should just use that syntax, and if it doesn't work, I'm going to > post onto a mailing list until it magically starts working. It's NOT > that I haven't read the docs - I'm just going to wilfully ignore them. > > Okay, I'm done now. > > ChrisA Okey i have taken my lesson. I should have written it as the doc suggested instead of being persistent on finding what was worng in the way i had written it.... From altaurog at gmail.com Mon Mar 27 02:01:59 2017 From: altaurog at gmail.com (altaurog at gmail.com) Date: Sun, 26 Mar 2017 23:01:59 -0700 (PDT) Subject: pgcopy 1.2.0 Message-ID: <04b1bef3-19dd-4024-9be5-34f43cc3b63d@googlegroups.com> pgcopy 1.2.0 is now available! pgcopy is a small utility for fast inserts to postgresql using binary copy. features: * Support for many datatypes * Tested with python 2.7 and 3.3 - 3.6 * Works with postgresql versions 8.4 - 9.6 * Cache data on disk or in memory * Supports explicit db schema From johann.spies at gmail.com Mon Mar 27 03:52:05 2017 From: johann.spies at gmail.com (Johann Spies) Date: Mon, 27 Mar 2017 09:52:05 +0200 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <47db4e13-4733-4d14-86fa-5561f23f7a4b@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <5b045f7e-1c63-45ad-ad5e-5385f33e06e1@googlegroups.com> <22b18365-ca0e-46b9-9e51-f68ae201b36e@googlegroups.com> <47db4e13-4733-4d14-86fa-5561f23f7a4b@googlegroups.com> Message-ID: ?????, I am glad that you solved the problem. I am not using mysql but postgresql. When I get a problem using python to communicate with the database, one of my first steps will be to determine whether the error is a python (maybe psycopg-related) related error or a database error. What I do then is to use the string python is sending to the database and try to run that on the commandline interface to the database (psgl) or something like pgadmin3. Mysql have similar tools. Once you have determined that it a database related problem, it should be easy to sort it out on that side. If it works on the database the rest of the problem should be solved on the python side. Maybe this approach would have saved you some time. Regards Johann -- Because experiencing your loyal love is better than life itself, my lips will praise you. (Psalm 63:3) From mal at europython.eu Mon Mar 27 04:20:59 2017 From: mal at europython.eu (M.-A. Lemburg) Date: Mon, 27 Mar 2017 10:20:59 +0200 Subject: EuroPython 2017: Call for Proposals is open Message-ID: We?re looking for proposals on every aspect of Python: programming from novice to advanced levels, applications and frameworks, or how you have been involved in introducing Python into your organization. EuroPython is a community conference and we are eager to hear about your experience. Please also forward this Call for Proposals to anyone that you feel may be interested. *** https://ep2017.europython.eu/en/call-for-proposals/ *** Submissions will be open until Sunday, April 16, 23:59:59 CEST Please note that we will not have a second call for proposals as we did in 2016, so if you want to enter a proposal, please consider to do this in the next few days. For full details, please see the above CFP page. We have many exciting things waiting for you: * PyData EuroPython 2017 as part of EuroPython * a whole range of interesting formats, including talks, training sessions, panels, interactive sessions, posters and helpdesks * tracks to focus on more specific domains, including the revived EuroPython Business Track * speaker discounts for more than just talks and trainings Enjoy, -- EuroPython 2017 Team http://ep2017.europython.eu/ http://www.europython-society.org/ PS: Please forward or retweet to help us reach all interested parties: https://twitter.com/europython/status/846274948003958784 Thanks. From me.on.nzt at gmail.com Mon Mar 27 05:03:18 2017 From: me.on.nzt at gmail.com (=?UTF-8?B?zp3Or866zr/PgiDOks6tz4HOs86/z4I=?=) Date: Mon, 27 Mar 2017 09:03:18 +0000 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <19c6bc3e-9255-437b-8287-074fb2c068ea@googlegroups.com> <6b8df203-a0a0-4267-a6a4-fd685627a6d2@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <5b045f7e-1c63-45ad-ad5e-5385f33e06e1@googlegroups.com> <22b18365-ca0e-46b9-9e51-f68ae201b36e@googlegroups.com> <47db4e13-4733-4d14-86fa-5561f23f7a4b@googlegroups.com> Message-ID: Thank you very much Johann. i was using print(update wuery here) and i was seeing that print was able to parser the query and that consused me as to why execute wont do the same since with print all values was gettign substituted. of course pymysql doesnt behave the same with print but until i fugure that out cost me lots of time. ???? ???, 27 ??? 2017 ???? 10:52 ?.?., ?/? Johann Spies < johann.spies at gmail.com> ??????: > ?????, > > I am glad that you solved the problem. > > I am not using mysql but postgresql. When I get a problem using python to > communicate with the database, one of my first steps will be to determine > whether the error is a python (maybe psycopg-related) related error or a > database error. What I do then is to use the string python is sending to > the database and try to run that on the commandline interface to the > database (psgl) or something like pgadmin3. Mysql have similar tools. > > Once you have determined that it a database related problem, it should be > easy to sort it out on that side. If it works on the database the rest of > the problem should be solved on the python side. > > Maybe this approach would have saved you some time. > > Regards > Johann > -- > Because experiencing your loyal love is better than life itself, > my lips will praise you. (Psalm 63:3) > -- What is now proved was at first only imagined! From antoon.pardon at rece.vub.ac.be Mon Mar 27 05:34:38 2017 From: antoon.pardon at rece.vub.ac.be (Antoon Pardon) Date: Mon, 27 Mar 2017 11:34:38 +0200 Subject: C-Python and Endianness In-Reply-To: References: Message-ID: <28bfac08-37fc-cb1f-bfa4-0fa033f162c2@rece.vub.ac.be> Op 26-03-17 om 08:47 schreef Ganesh Pal: > Hello Team , > > > > > I want to write the hexadecimal string that is passed from python as it > is on disk in C , my problem is that the values are getting stored in > little endian and Are you sure you are passing a string? Or are you passing a number and expecting a particulare result when you hexdump the file? > the values are swapped it has been quite a pain for me to fix this , any > suggestion on how to fix this (I am on Python 2.7 and Linux). Why is this a problem? This is how things usually work on little endians machines. If you are just reading and writing numbers in a binary way this will work without a problem. However you may need to be carefull when transferring the file to a bigendian machine. So why do you perceive this swapping as a problem to be fixed? -- Antoon. From zopyxfilter at gmail.com Mon Mar 27 07:40:35 2017 From: zopyxfilter at gmail.com (filtered) Date: Mon, 27 Mar 2017 13:40:35 +0200 Subject: Using/compiling pyuno with Python 3.6 Message-ID: I am running CentOS 7.1 with LibreOffice 5.0.6.2. I have installed the official pyuno package from CentOS. I installed Python 3.6.1 from the sources and now I am trying to import pyuno which fails with ajung at dev.zopyx.com:~/src/docx> bin/python Python 3.6.1 (default, Mar 27 2017, 13:27:24) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux ajung at dev.zopyx.com:~/src/docx> bin/python -c "import uno" Traceback (most recent call last): File "", line 1, in File "/home/ajung/src/docx/uno.py", line 24, in import pyuno ImportError: dynamic module does not define module export function (PyInit_pyuno) Is there a straight forward way for compiling pyuno myself? I could not find any official documentation, links to various posts are older than 5 years... Andreas From jsmcmahon3 at gmail.com Mon Mar 27 17:34:59 2017 From: jsmcmahon3 at gmail.com (James McMahon) Date: Mon, 27 Mar 2017 17:34:59 -0400 Subject: Logging from different python scripts to different output files Message-ID: I'm struggling with Python logging. Have tried to apply several examples I have found in the open source literature, but can't get it to work. What I need to do is this: I have two python scripts, a.py and b.py. Each is called by NiFi ExecuteScript processor repeatedly against many incoming flowfiles. In every case I need to output log messages to two distinct and different log files. My scripts run in the same Python interpreter, which as i understand it means they rely on the same root level logger. I have tried establishing non-root loggers for each, and associating distinct file handles for each to those loggers. My output still appears in multiple log files, and appears to be repeating in increasing numbers each time I try a test run (first test, output line appeared in log once. second test, twice. third test, three times, etc). Is there an example that anyone knows of that demonstrates how two concurrently running python scripts within the same interpreter can direct output to two distinct log files? Thanks in advance for any help. From jan at hyper-world.de Mon Mar 27 17:57:18 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Mon, 27 Mar 2017 17:57:18 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 Message-ID: Hi, I have a program which uses twice as much memory when I run it in Python 3.6 than when I run it in Python 3.5 (about 60GB instead of 30GB). I tried to find the reason for that, but the cumulated size (measured with sys.getsizeof) of all objects returned by gc.get_objects accumulates only to about 17GB in both cases. The program also uses NumPy and I tried tracking allocations with the NumPy allocation tracker in the relevant part of the program, but again the number of allocations are almost identical and the reported maximum memory usage perfectly agrees (it is about 18GB). Any ideas where this significant increase in memory consumption could come from? Or any ideas how to further debug this? Looking at the changelog it seems that the only change in Python 3.6 affecting memory usage is the new dict implementation which is supposed to be more memory efficient. In fact, this is what I find if I run the program with a smaller test cases. There the memory consumption is less with Python 3.6. Cheers, Jan From __peter__ at web.de Mon Mar 27 18:30:12 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 28 Mar 2017 00:30:12 +0200 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 References: Message-ID: Jan Gosmann wrote: > Hi, > > I have a program which uses twice as much memory when I run it in Python > 3.6 than when I run it in Python 3.5 (about 60GB instead of 30GB). I > tried to find the reason for that, but the cumulated size (measured with > sys.getsizeof) of all objects returned by gc.get_objects accumulates > only to about 17GB in both cases. The program also uses NumPy and I > tried tracking allocations with the NumPy allocation tracker in the > relevant part of the program, but again the number of allocations are > almost identical and the reported maximum memory usage perfectly agrees > (it is about 18GB). > > Any ideas where this significant increase in memory consumption could > come from? Or any ideas how to further debug this? > > Looking at the changelog it seems that the only change in Python 3.6 > affecting memory usage is the new dict implementation which is supposed > to be more memory efficient. In fact, this is what I find if I run the > program with a smaller test cases. There the memory consumption is less > with Python 3.6. Are you perchance comparing 32-bit Python 3.5 with 64-bit Python 3.6? From jan at hyper-world.de Mon Mar 27 18:38:29 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Mon, 27 Mar 2017 18:38:29 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: Message-ID: On 27 Mar 2017, at 18:30, Peter Otten wrote: > Are you perchance comparing 32-bit Python 3.5 with 64-bit Python 3.6? I don't think so. [sys.maxsize](https://docs.python.org/3/library/platform.html#cross-platform) indicates both to be 64-bit. From rosuav at gmail.com Mon Mar 27 18:42:28 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Mar 2017 09:42:28 +1100 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: Message-ID: On Tue, Mar 28, 2017 at 8:57 AM, Jan Gosmann wrote: > I have a program which uses twice as much memory when I run it in Python 3.6 > than when I run it in Python 3.5 (about 60GB instead of 30GB). I tried to > find the reason for that, but the cumulated size (measured with > sys.getsizeof) of all objects returned by gc.get_objects accumulates only to > about 17GB in both cases. The program also uses NumPy and I tried tracking > allocations with the NumPy allocation tracker in the relevant part of the > program, but again the number of allocations are almost identical and the > reported maximum memory usage perfectly agrees (it is about 18GB). > > Any ideas where this significant increase in memory consumption could come > from? Or any ideas how to further debug this? Are you able to share the program? I could try it on my system and see if the same thing happens. ChrisA From jan at hyper-world.de Mon Mar 27 19:01:02 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Mon, 27 Mar 2017 19:01:02 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: Message-ID: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> On 27 Mar 2017, at 18:42, Chris Angelico wrote: > Are you able to share the program? I could try it on my system and see > if the same thing happens. Yes, it is on GitHub (use the fixes branch): https://github.com/ctn-archive/gosmann-frontiers2017/tree/fixes Installation instructions are in the readme. The command I'm running is `python scripts/log_reduction.py spaun` I was looking at the output of htop to see the memory consumption. The `time` built-in of the zsh might report a lower memory usage (I'm running it right now to make sure), which would also be surprising. But I'm certain that Python 3.6 uses more memory because the run time increases due to using the swap partition. If you run the program, it will take an initial 10?15 minutes of processing during which the memory usage should increase to roughly 10GB. Then the output ?[INFO] Optimizing model...? will be printed after which the memory usage continues to increase to around 30GB (maybe a bit more with Python 3.6). This constitutes a first ?optimization pass? that will be ended with the message ?[INFO] Pass 1 [views]: Reduced 996917 to 913666 operators in 62.519006s.? Then in the second optimization pass the memory consumption will continue to increase with Python 3.6 (up to ~60GB being consumed, where less than 5GB should be due to other processes, though the virtual and resident memory reported for the Python process are only ~42GB and ~30GB respectively) and in later passes it will start decreasing again. With Python 3.5 the memory consumption stays about 30GB and decreases in later passes. Let me know if you have more questions. From rosuav at gmail.com Mon Mar 27 20:00:37 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Mar 2017 11:00:37 +1100 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> Message-ID: On Tue, Mar 28, 2017 at 10:01 AM, Jan Gosmann wrote: > Yes, it is on GitHub (use the fixes branch): > https://github.com/ctn-archive/gosmann-frontiers2017/tree/fixes > Installation instructions are in the readme. > The command I'm running is python scripts/log_reduction.py spaun Working on it. By the way, since you're aiming this at recent Python versions, you could skip the 'virtualenv' external dependency and use the built-in 'venv' package: $ python3 -m venv env I'm a little confused here. When I install PIP requirements, it wants to set up OpenCL, but your README seems to be contrasting your implementation with the OpenCL one. Or is that for the sake of benchmarking, so you can compare one against the other? In any case, I've installed nvidia-opencl-dev and it seems to be happy. How long should I expect this to run for? Now testing under CPython 3.7. ChrisA From rosuav at gmail.com Mon Mar 27 20:12:58 2017 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Mar 2017 11:12:58 +1100 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> Message-ID: On Tue, Mar 28, 2017 at 11:00 AM, Chris Angelico wrote: > In any case, I've installed nvidia-opencl-dev and it seems to be > happy. How long should I expect this to run for? > > Now testing under CPython 3.7. > It ran for about 14 minutes, then memory usage spiked and went into the page file. Used roughly 8GB of RAM prior to that point, I think? Unfortunately, I don't think my hard disk is fast enough for this to run through the page file in any reasonable time. ChrisA From greg.ewing at canterbury.ac.nz Mon Mar 27 20:14:21 2017 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Tue, 28 Mar 2017 13:14:21 +1300 Subject: Escaping confusion with Python 3 + MySQL In-Reply-To: <22b18365-ca0e-46b9-9e51-f68ae201b36e@googlegroups.com> References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <5b045f7e-1c63-45ad-ad5e-5385f33e06e1@googlegroups.com> <22b18365-ca0e-46b9-9e51-f68ae201b36e@googlegroups.com> Message-ID: ????? ?????? wrote: > Its still a mystery to em whay this fails syntactically when at the same time > INSERT works like that. I don't think *anyone* understands why SQL was designed with INSERT and UPDATE having completely different syntaxes. But it was, and we have to live with it. -- Greg From python at deborahswanson.net Mon Mar 27 21:40:12 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 27 Mar 2017 18:40:12 -0700 Subject: Using/compiling pyuno with Python 3.6 In-Reply-To: Message-ID: <011b01d2a764$3e7774f0$27b23dae@sambora> filtered wrote, on Monday, March 27, 2017 4:41 AM > > I am running CentOS 7.1 with LibreOffice 5.0.6.2. > > I have installed the official pyuno package from CentOS. > > I installed Python 3.6.1 from the sources and now I am trying > to import pyuno which fails with > > ajung at dev.zopyx.com:~/src/docx> bin/python > Python 3.6.1 (default, Mar 27 2017, 13:27:24) > [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux > > ajung at dev.zopyx.com:~/src/docx> bin/python -c "import uno" > Traceback (most recent call last): File "", line 1, > in File "/home/ajung/src/docx/uno.py", line 24, in > import pyuno > ImportError: dynamic module does not define module export function > (PyInit_pyuno) > > Is there a straight forward way for compiling pyuno myself? I > could not find any official documentation, links to various > posts are older than 5 years... > > Andreas I have no idea how to compile pyuno from sources. But if I were in your place, I'd look for other repositories that might have pyuno. It's been awhile since I had a Linux machine (it was also CentOS) and I generally found multiple repositories to try when the standard one failed. From eric.frederich at gmail.com Mon Mar 27 21:59:53 2017 From: eric.frederich at gmail.com (Eric Frederich) Date: Mon, 27 Mar 2017 21:59:53 -0400 Subject: Windows / ctypes issue with custom build Message-ID: I built my own Python 2.7.13 for Windows because I'm using bindings to a 3rd party application which were built with Visual Studio 2012. I started to code up some stuff using the "click" module and found an error when using click.echo with any kind of unicode input. Python 2.7.13 (default, Mar 27 2017, 11:11:01) [MSC v.1700 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import click >>> click.echo('Hello World') Hello World >>> click.echo(u'Hello World') Traceback (most recent call last): File "", line 1, in File "C:\Users\eric\my_env\lib\site-packages\click\utils.py", line 259, in echo file.write(message) File "C:\Users\eric\my_env\lib\site-packages\click\_winconsole.py", line 180, in write return self._text_stream.write(x) File "C:\Users\eric\my_env\lib\site-packages\click\_compat.py", line 63, in write return io.TextIOWrapper.write(self, x) File "C:\Users\eric\my_env\lib\site-packages\click\_winconsole.py", line 164, in write raise OSError(self._get_error_message(GetLastError())) OSError: Windows error 6 If I download and install the Python 2.7.13 64-bit installer I don't get this issue. It echo's just fine. I have looked into this a lot and am at a loss right now. I'm not too familiar with Windows, Visual Studio, or ctypes. I spent some time looking at the code path to produce the smallest file (without click) which demonstrates this problem (see below) It produces the same "Windows error 6"... again, this works fine with the python installed from the 2.7.13 64 bit MSI installer. Can someone share the process used to create the Windows installers? Is this a manual process or is it automated? Maybe I'm missing some important switch to msbuild or something. Any help or ideas are appreciated. I cannot use a downloaded copy of Python... it needs to be built with a specific version, update, patch, etc of Visual Studio. All I did was 1) clone cpython from github and checkout 2.7.13 2) edit some xp stuff out of tk stuff to get it to compile on Windows Server 2003 In `externals\tk-8.5.15.0\win\Makefile.in` remove `ttkWinXPTheme.$(OBJEXT)` line In `externals\tk-8.5.15.0\win\makefile.vc` remove `$(TMP_DIR)\ttkWinXPTheme.obj` line In `externals\tk-8.5.15.0\win\ttkWinMonitor.c` remove 2 `TtkXPTheme_Init` lines In `PCbuild\tcltk.props` change VC9 to VC11 at the bottom 3) PCbuild\build.bat -e -p x64 "/p:PlatformToolset=v110" After that I created an "install" by copying .exe, .pyd, .dll files, ran get-pip.py, then python -m pip install virtualenv, then virtualenv my_env, then activated it, then did a pip install click. But with this stripped down version you don't need pip, virtualenv or click... just ctypes. You could probably even build it without the -e switch to build.bat. from ctypes import byref, POINTER, py_object, pythonapi, Structure, windll from ctypes import c_char, c_char_p, c_int, c_ssize_t, c_ulong, c_void_p c_ssize_p = POINTER(c_ssize_t) kernel32 = windll.kernel32 STDOUT_HANDLE = kernel32.GetStdHandle(-11) PyBUF_SIMPLE = 0 MAX_BYTES_WRITTEN = 32767 class Py_buffer(Structure): _fields_ = [ ('buf', c_void_p), ('obj', py_object), ('len', c_ssize_t), ('itemsize', c_ssize_t), ('readonly', c_int), ('ndim', c_int), ('format', c_char_p), ('shape', c_ssize_p), ('strides', c_ssize_p), ('suboffsets', c_ssize_p), ('internal', c_void_p) ] _fields_.insert(-1, ('smalltable', c_ssize_t * 2)) bites = u"Hello World".encode('utf-16-le') bytes_to_be_written = len(bites) buf = Py_buffer() pythonapi.PyObject_GetBuffer(py_object(bites), byref(buf), PyBUF_SIMPLE) buffer_type = c_char * buf.len buf = buffer_type.from_address(buf.buf) code_units_to_be_written = min(bytes_to_be_written, MAX_BYTES_WRITTEN) // 2 code_units_written = c_ulong() kernel32.WriteConsoleW(STDOUT_HANDLE, buf, code_units_to_be_written, byref(code_units_written), None) bytes_written = 2 * code_units_written.value if bytes_written == 0 and bytes_to_be_written > 0: raise OSError('Windows error %s' % kernel32.GetLastError()) From torriem at gmail.com Mon Mar 27 22:36:08 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 27 Mar 2017 20:36:08 -0600 Subject: Using/compiling pyuno with Python 3.6 In-Reply-To: References: Message-ID: <1806c8a2-5e0c-80be-1c35-8f46cd9308a9@gmail.com> On 03/27/2017 05:40 AM, filtered wrote: > I am running CentOS 7.1 with LibreOffice 5.0.6.2. > > I have installed the official pyuno package from CentOS. > > I installed Python 3.6.1 from the sources and now I am trying to import > pyuno which fails with > > ajung at dev.zopyx.com:~/src/docx> bin/python > Python 3.6.1 (default, Mar 27 2017, 13:27:24) > [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux > > ajung at dev.zopyx.com:~/src/docx> bin/python -c "import uno" > Traceback (most recent call last): > File "", line 1, in > File "/home/ajung/src/docx/uno.py", line 24, in > import pyuno > ImportError: dynamic module does not define module export function > (PyInit_pyuno) > > Is there a straight forward way for compiling pyuno myself? I could not > find any official documentation, > links to various posts are older than 5 years... Pretty sure PyUno is Python 2 only. Looks like there might be an alternative in the form of unotools: https://pypi.python.org/pypi/unotools From jf_byrnes at comcast.net Mon Mar 27 23:13:13 2017 From: jf_byrnes at comcast.net (Jim) Date: Mon, 27 Mar 2017 22:13:13 -0500 Subject: Using/compiling pyuno with Python 3.6 In-Reply-To: <1806c8a2-5e0c-80be-1c35-8f46cd9308a9@gmail.com> References: <1806c8a2-5e0c-80be-1c35-8f46cd9308a9@gmail.com> Message-ID: On 03/27/2017 09:36 PM, Michael Torrie wrote: > On 03/27/2017 05:40 AM, filtered wrote: >> I am running CentOS 7.1 with LibreOffice 5.0.6.2. >> >> I have installed the official pyuno package from CentOS. >> >> I installed Python 3.6.1 from the sources and now I am trying to import >> pyuno which fails with >> >> ajung at dev.zopyx.com:~/src/docx> bin/python >> Python 3.6.1 (default, Mar 27 2017, 13:27:24) >> [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux >> >> ajung at dev.zopyx.com:~/src/docx> bin/python -c "import uno" >> Traceback (most recent call last): >> File "", line 1, in >> File "/home/ajung/src/docx/uno.py", line 24, in >> import pyuno >> ImportError: dynamic module does not define module export function >> (PyInit_pyuno) >> >> Is there a straight forward way for compiling pyuno myself? I could not >> find any official documentation, >> links to various posts are older than 5 years... > > Pretty sure PyUno is Python 2 only. Looks like there might be an > alternative in the form of unotools: > https://pypi.python.org/pypi/unotools > I don't know if this is of any help but I am running Mint 18 with Python 3.5 and I have a package installed called python3-uno which is described as "Python-UNO bridge". Maybe CentOS has a similarly name package. regards, Jim From jan at hyper-world.de Mon Mar 27 23:15:12 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Mon, 27 Mar 2017 23:15:12 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> Message-ID: On 27 Mar 2017, at 20:00, Chris Angelico wrote: > By the way, since you're aiming this at recent Python versions, you > could skip the 'virtualenv' external dependency and use the built-in > 'venv' package: > > $ python3 -m venv env Yeah, I know about venv. The last time I tried it, there was still some issue that prevented me from using it and I'm also still targeting 2.7 too. > I'm a little confused here. When I install PIP requirements, it wants > to set up OpenCL, but your README seems to be contrasting your > implementation with the OpenCL one. Or is that for the sake of > benchmarking, so you can compare one against the other? Right, the PIP requirements are more than actually required for this particular problem. But it is indeed for benchmarking comparing different backends for a neural network simulator. For the log_reduction.py script the nengo==2.3.1 and numpy==1.12.0 are probably sufficient. > In any case, I've installed nvidia-opencl-dev and it seems to be > happy. How long should I expect this to run for? On an Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz with 32GB RAM it probably takes about 30 minutes with Python 3.5; longer with 3.6 because things get written to the swap partition. Jan From jan at hyper-world.de Mon Mar 27 23:25:43 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Mon, 27 Mar 2017 23:25:43 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> Message-ID: On 27 Mar 2017, at 20:12, Chris Angelico wrote: > On Tue, Mar 28, 2017 at 11:00 AM, Chris Angelico > wrote: >> In any case, I've installed nvidia-opencl-dev and it seems to be >> happy. How long should I expect this to run for? >> >> Now testing under CPython 3.7. >> > > It ran for about 14 minutes, then memory usage spiked and went into > the page file. Used roughly 8GB of RAM prior to that point, I think? > Unfortunately, I don't think my hard disk is fast enough for this to > run through the page file in any reasonable time. Yeah, it will be problematic with less than 32GB. My latest findings: The zsh `time` built-in reports a maximum of only 30GB used which seems to correspond to the resident memory size, while the virtual memory size exceeds 40GB for the process and the total memory allocated over all processes exceeds 60GB (with the main contribution from the process that supposedly only uses ~40GB). My best idea about what's going on at the moment is that memory fragmentation is worse in Python 3.6 for some reason. The virtual memory size indicates that a large address space is acquired, but the resident memory size is smaller indicating that not all of that address space is actually used. In fact, the code might be especially bad to fragmentation because it takes a lot of small NumPy arrays and concatenates them into larger arrays. But I'm still surprised that this is only a problem with Python 3.6 (if this hypothesis is correct). Jan From torriem at gmail.com Mon Mar 27 23:49:09 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 27 Mar 2017 21:49:09 -0600 Subject: Using/compiling pyuno with Python 3.6 In-Reply-To: References: <1806c8a2-5e0c-80be-1c35-8f46cd9308a9@gmail.com> Message-ID: On 03/27/2017 09:13 PM, Jim wrote: > I don't know if this is of any help but I am running Mint 18 with Python > 3.5 and I have a package installed called python3-uno which is described > as "Python-UNO bridge". Maybe CentOS has a similarly name package. You're right. In fact it looks like LibreOffice 5.3 at least ships with Python 3.5 as part of the package, and comes with pyuno as part of that. Try running the python binary from the LibreOffice install directory (on my machine that is /opt/libreoffice5.3/program/python). I'm not sure how to work with pyuno outside of the LO-shipped python. From zopyxfilter at gmail.com Tue Mar 28 00:09:27 2017 From: zopyxfilter at gmail.com (filtered) Date: Tue, 28 Mar 2017 06:09:27 +0200 Subject: Using/compiling pyuno with Python 3.6 In-Reply-To: References: <1806c8a2-5e0c-80be-1c35-8f46cd9308a9@gmail.com> Message-ID: Sorry but all your answers are pointless. I clearly asked about compiling PyUno MYSELF with a self-compiled Python 3.6.1 installation. Is this so hard to understand? Why do you give unrelated comments to a clear questions? Sometimes it is better to be quiet. -aj 2017-03-28 5:49 GMT+02:00 Michael Torrie : > On 03/27/2017 09:13 PM, Jim wrote: > > I don't know if this is of any help but I am running Mint 18 with Python > > 3.5 and I have a package installed called python3-uno which is described > > as "Python-UNO bridge". Maybe CentOS has a similarly name package. > > You're right. In fact it looks like LibreOffice 5.3 at least ships with > Python 3.5 as part of the package, and comes with pyuno as part of that. > Try running the python binary from the LibreOffice install directory (on > my machine that is > /opt/libreoffice5.3/program/python). I'm not sure how to work with > pyuno outside of the LO-shipped python. > > -- > https://mail.python.org/mailman/listinfo/python-list > From torriem at gmail.com Tue Mar 28 00:33:55 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 27 Mar 2017 22:33:55 -0600 Subject: Using/compiling pyuno with Python 3.6 In-Reply-To: References: <1806c8a2-5e0c-80be-1c35-8f46cd9308a9@gmail.com> Message-ID: <4fa426c0-303f-bbb1-7df2-268ac78d5229@gmail.com> On 03/27/2017 10:09 PM, filtered wrote: > Sorry but all your answers are pointless. Possibly. > I clearly asked about compiling PyUno MYSELF with a self-compiled > Python 3.6.1 installation. Is this so hard to understand? Why do you give > unrelated comments to a clear questions? Sometimes clear questions don't have easy answers. Or rather there's a process of problem solving and Jim and I were exploring that process a bit. But I don't think any of us will go further with it now. I did find the source code for pyuno in the main LO tree, but it doesn't look easy to build out of tree, but that's just at first glance. I suspect you'll find better information on one of the LO mailing lists or forums, provided you don't react to them as you have to this list! > Sometimes it is better to be quiet. Indeed. Good luck. ciao From torriem at gmail.com Tue Mar 28 00:36:36 2017 From: torriem at gmail.com (Michael Torrie) Date: Mon, 27 Mar 2017 22:36:36 -0600 Subject: Using/compiling pyuno with Python 3.6 In-Reply-To: References: <1806c8a2-5e0c-80be-1c35-8f46cd9308a9@gmail.com> Message-ID: On 03/27/2017 10:09 PM, filtered wrote: > Sorry but all your answers are pointless. Possibly. > I clearly asked about compiling PyUno MYSELF with a self-compiled > Python 3.6.1 installation. Is this so hard to understand? Why do you give > unrelated comments to a clear questions? Sometimes clear questions don't have easy answers. Or rather there's a process of problem solving and Jim and I were exploring that process a bit. But I don't think any of us will go further with it now. I did find the source code for pyuno in the main LO tree, but it doesn't look easy to build out of tree, but that's just at first glance. I suspect you'll find better information on one of the LO mailing lists or forums, provided you don't react to them as you have to this list! > Sometimes it is better to be quiet. Indeed. Good luck. ciao From python at deborahswanson.net Tue Mar 28 00:41:28 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Mon, 27 Mar 2017 21:41:28 -0700 Subject: Using/compiling pyuno with Python 3.6 In-Reply-To: Message-ID: <013201d2a77d$90d5b180$27b23dae@sambora> filtered wrote, on March 27, 2017 9:09 PM > > Sorry but all your answers are pointless. > > I clearly asked about compiling PyUno MYSELF with a > self-compiled Python 3.6.1 installation. Is this so hard to > understand? Why do you give unrelated comments to a clear > questions? Sometimes it is better to be quiet. > > -aj If you really only wanted to know how to compile PyUno with a self-compiled Python 3.6.1 installation, it muddied the waters considerably that you first went on at length about your difficulties importing PyUno. It appeared that your main objective was to have an importable installation of PyUno, and it would have been better to omit the error details if all you wanted to know is how to compile it. Maybe not as clear a question as you imagine. > 2017-03-28 5:49 GMT+02:00 Michael Torrie : > > > On 03/27/2017 09:13 PM, Jim wrote: > > > I don't know if this is of any help but I am running Mint 18 with > > > Python 3.5 and I have a package installed called > python3-uno which > > > is described as "Python-UNO bridge". Maybe CentOS has a similarly > > > name package. > > > > You're right. In fact it looks like LibreOffice 5.3 at least ships > > with Python 3.5 as part of the package, and comes with > pyuno as part > > of that. Try running the python binary from the LibreOffice install > > directory (on my machine that is > /opt/libreoffice5.3/program/python). > > I'm not sure how to work with pyuno outside of the > LO-shipped python. > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > -- > https://mail.python.org/mailman/listinfo/python-list > From jussi.piitulainen at helsinki.fi Tue Mar 28 01:09:17 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Tue, 28 Mar 2017 08:09:17 +0300 Subject: Escaping confusion with Python 3 + MySQL References: <728b7b7a-a927-4636-b780-f7365e37ae43@googlegroups.com> <2cd2cc90-cba0-46ab-8893-dd12ecee6551@googlegroups.com> <6f3d24ec-9add-4db5-abe5-dc0708129d44@googlegroups.com> <58d7e08c$0$22142$c3e8da3$5496439d@news.astraweb.com> <5b045f7e-1c63-45ad-ad5e-5385f33e06e1@googlegroups.com> <22b18365-ca0e-46b9-9e51-f68ae201b36e@googlegroups.com> Message-ID: Gregory Ewing writes: > ????? ?????? wrote: > >> Its still a mystery to em whay this fails syntactically when at the >> same time INSERT works like that. > > I don't think *anyone* understands why SQL was designed with > INSERT and UPDATE having completely different syntaxes. > But it was, and we have to live with it. A story I heard is that IBM had two competing teams working to design a database system. One team understood programming languages. The other team understood storage system layouts. The latter team won, and their system grew up to be SQL. From __peter__ at web.de Tue Mar 28 03:08:37 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 28 Mar 2017 09:08:37 +0200 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 References: Message-ID: Jan Gosmann wrote: > On 27 Mar 2017, at 18:30, Peter Otten wrote: > >> Are you perchance comparing 32-bit Python 3.5 with 64-bit Python 3.6? > > I don't think so. > [sys.maxsize](https://docs.python.org/3/library/platform.html#cross-platform) > indicates both to be 64-bit. While my original idea was obviously nonsense given the amount of memory you deal with I still cling to the underlying idea. Perhaps numpy's default integer type has changed (assuming you are using integer arrays, I did look at, but not into your code)? You could compare >>> numpy.array([42]).itemsize 8 for the two interpreters. From jldunn2000 at gmail.com Tue Mar 28 04:09:30 2017 From: jldunn2000 at gmail.com (loial) Date: Tue, 28 Mar 2017 01:09:30 -0700 (PDT) Subject: newbie question re classes and self Message-ID: <7545c7c1-63cb-4e00-99a3-2fdad0f62896@googlegroups.com> Can I pass self(or all its variables) to a class? Basically, how do I make all the variables defined in self in the calling python script available to the python class I want to call? From __peter__ at web.de Tue Mar 28 04:43:15 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 28 Mar 2017 10:43:15 +0200 Subject: Logging from different python scripts to different output files References: Message-ID: James McMahon wrote: > I'm struggling with Python logging. Have tried to apply several examples I > have found in the open source literature, but can't get it to work. What I > need to do is this: I have two python scripts, a.py and b.py. Each is > called by NiFi ExecuteScript processor repeatedly against many incoming > flowfiles. In every case I need to output log messages to two distinct and > different log files. My scripts run in the same Python interpreter, which > as i understand it means they rely on the same root level logger. I have > tried establishing non-root loggers for each, and associating distinct > file handles for each to those loggers. > > My output still appears in multiple log files, and appears to be repeating > in increasing numbers each time I try a test run (first test, output line > appeared in log once. second test, twice. third test, three times, etc). > Is there an example that anyone knows of that demonstrates how two > concurrently running python scripts within the same interpreter can direct > output to two distinct log files? Thanks in advance for any help. Here's a simple example: $ cat logme.py import logging a = logging.getLogger("a") b = logging.getLogger("b") def add_handler(logger, filename): if logger.hasHandlers(): print("add_handler() called twice for logger {!r}".format(logger.name)) return formatter = logging.Formatter(logging.BASIC_FORMAT) handler = logging.FileHandler(filename) handler.setFormatter(formatter) logger.addHandler(handler) add_handler(a, "logs/a.log") add_handler(b, "logs/b.log") a.warn("foo") b.warn("bar") The 'if logger.hasHandlers(): ...' check is for debugging purposes, in your actual code a.py would only contain import logging a = logging.getLogger("a") a.warn("whatever") The corresponding setup code import logging a = logging.getLogger("a") add_handler(a, "logs/a.log") should only run once. From __peter__ at web.de Tue Mar 28 05:09:18 2017 From: __peter__ at web.de (Peter Otten) Date: Tue, 28 Mar 2017 11:09:18 +0200 Subject: newbie question re classes and self References: <7545c7c1-63cb-4e00-99a3-2fdad0f62896@googlegroups.com> Message-ID: loial wrote: > Can I pass self(or all its variables) to a class? > > Basically, how do I make all the variables defined in self in the calling > python script available to the python class I want to call? Inside a method you can access attributes of an instance as self.whatever: >>> class A: ... def foo(self): ... self.bar = 42 ... def baz(self): ... print(self.bar) ... >>> a = A() >>> a.baz() # bar attribute not yet set Traceback (most recent call last): File "", line 1, in File "", line 5, in baz AttributeError: 'A' object has no attribute 'bar' >>> a.foo() # sets bar >>> a.baz() # successfully print the newly created bar attribute 42 The class itself has no access to bar. In the rare case where you want to share data between instances you can use a class attribute: >>> class B: ... bar = 42 ... >>> x = B() >>> y = B() >>> x.bar 42 >>> y.bar 42 If neither is what you want please give a concrete example or a more detailed plain-english description. From jobmattcon at gmail.com Tue Mar 28 05:37:35 2017 From: jobmattcon at gmail.com (Ho Yeung Lee) Date: Tue, 28 Mar 2017 02:37:35 -0700 (PDT) Subject: how to group own any one common in the list? Message-ID: <3bf09079-574d-4582-b93e-4338804a2043@googlegroups.com> aaa = ["a","ab","c","b","bc"] def similar(aa): similarset = [] for ii in range(0,len(aa)): for jj in range(ii,len(aa)): if ii <> jj: print("("+str(ii)+","+str(jj)+")") if (aa[ii] in aa[jj]) or (aa[jj] in aa[ii]): print(aa[ii] + " is similar with " + aa[jj]) similarset.append([aa[ii],aa[jj]]) return similarset print similar(aaa) do not know how to edit following code to group own any one common in the list? import itertools bb = similar(aaa) from operator import itemgetter [list(g) for _,g in itertools.groupby(sorted(bb),(itemgetter(0,1) and itemgetter(1,0)))] Expected result: group 1 [['a', 'ab'], [['ab', 'b']] group 2 [['b', 'bc'], [['c', 'bc']] From songofacandy at gmail.com Tue Mar 28 06:11:24 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Tue, 28 Mar 2017 19:11:24 +0900 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> Message-ID: I can't reproduce it. I managed to install pyopencl and run the script. It takes more than 2 hours, and uses only 7GB RAM. Maybe, some faster backend for OpenCL is required? I used Microsoft Azure Compute, Standard_A4m_v2 (4 cores, 32 GB memory) instance. More easy way to reproduce is needed... > My best idea about what's going on at the moment is that memory > fragmentation is worse in Python 3.6 for some reason. The virtual memory > size indicates that a large address space is acquired, but the resident > memory size is smaller indicating that not all of that address space is > actually used. In fact, the code might be especially bad to fragmentation > because it takes a lot of small NumPy arrays and concatenates them into > larger arrays. But I'm still surprised that this is only a problem with > Python 3.6 (if this hypothesis is correct). > > Jan Generally speaking, VMM vs RSS doesn't mean fragmentation. If RSS : total allocated memory ratio is bigger than 1.5, it may be fragmentation. And large VMM won't cause swap. Only RSS is meaningful. From tjreedy at udel.edu Tue Mar 28 09:44:57 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Mar 2017 09:44:57 -0400 Subject: newbie question re classes and self In-Reply-To: <7545c7c1-63cb-4e00-99a3-2fdad0f62896@googlegroups.com> References: <7545c7c1-63cb-4e00-99a3-2fdad0f62896@googlegroups.com> Message-ID: On 3/28/2017 4:09 AM, loial wrote: > Can I pass self(or all its variables) to a class? In Python, every argument to every function is an instance of some class. The function can access any attribute of the arguments it receives with arg.attribute. -- Terry Jan Reedy From jan at hyper-world.de Tue Mar 28 11:07:53 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Tue, 28 Mar 2017 11:07:53 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: Message-ID: <646D4953-5C29-4BAA-A192-1214E0D8A037@hyper-world.de> On 28 Mar 2017, at 3:08, Peter Otten wrote: > Perhaps numpy's default integer type has changed (assuming you are using > integer arrays, I did look at, but not into your code)? > > You could compare > >>>> numpy.array([42]).itemsize > 8 > > for the two interpreters. Both report 8 for integer and float point arrays. From jan at hyper-world.de Tue Mar 28 11:29:17 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Tue, 28 Mar 2017 11:29:17 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> Message-ID: <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> On 28 Mar 2017, at 6:11, INADA Naoki wrote: > I managed to install pyopencl and run the script. It takes more than > 2 hours, and uses only 7GB RAM. > Maybe, some faster backend for OpenCL is required? > > I used Microsoft Azure Compute, Standard_A4m_v2 (4 cores, 32 GB > memory) instance. I suppose that the computing power of the Azure instance might not be sufficient and it takes much longer to get to the phase where the memory requirements increase? Have you access to the output that was produced? By the way, this has nothing to do with OpenCL. OpenCL isn't used by the log_reduction.py script at all. It is listed in the dependencies because some other things use it. > More easy way to reproduce is needed... Yes, I agree, but it's not super easy (all the smaller existing examples don't exhibit the problem so far), but I'll see what I can do. >> My best idea about what's going on at the moment is that memory >> fragmentation is worse in Python 3.6 for some reason. The virtual >> memory >> size indicates that a large address space is acquired, but the >> resident >> memory size is smaller indicating that not all of that address space >> is >> actually used. In fact, the code might be especially bad to >> fragmentation >> because it takes a lot of small NumPy arrays and concatenates them >> into >> larger arrays. But I'm still surprised that this is only a problem >> with >> Python 3.6 (if this hypothesis is correct). >> >> Jan > > Generally speaking, VMM vs RSS doesn't mean fragmentation. > If RSS : total allocated memory ratio is bigger than 1.5, it may be > fragmentation. > And large VMM won't cause swap. Only RSS is meaningful. I suppose you are right that from the VMM and RSS numbers one cannot deduce fragmentation. But I think RSS in this case might not be meaningful either. My understanding from [the Wikipedia description] is that it doesn't account for parts of the memory that have been written to the swap. Or in other words RSS will never exceed the size of the physical RAM. VSS is also only partially useful because it just gives the size of the address space of which not all might be used? Anyways, I'm getting a swap usage of about 30GB with Python 3.6 and zsh's time reports 2339977 page faults from disk vs. 107 for Python 3.5. I have some code to measure the unique set size (USS) and will see what numbers I get with that. Jan From vishnuprasadh at gmail.com Tue Mar 28 11:59:07 2017 From: vishnuprasadh at gmail.com (vishnuprasadh at gmail.com) Date: Tue, 28 Mar 2017 08:59:07 -0700 (PDT) Subject: AH01215: ImportError: No module named PIL: - python script unable to recognize PIL when running from apache2 config Message-ID: <4d8860d7-7810-4e76-8829-70c958a9013c@googlegroups.com> What did you do? I have configured in apache httpd.conf - enabling of mod_cgi.so and httpd-vhosts.conf. In httpd-vhosts have following conifguration. Basically am trying to capture all /images/ pattern, read have that process using a index.py script and return back as image/jpeg content. ServerAdmin abc.xyz at bbc.com ServerName www.groc-example.com ServerAlias groc-example.com Alias "/images/" "/var/www/images/" DirectoryIndex index.py ErrorLog "/private/var/log/apache2/groc-example-images-error_log" CustomLog "/private/var/log/apache2/groc-access-log" common Options +ExecCGI Allow from all Require all granted ForceType text/html AddHandler cgi-script .py In the index.py am just trying to start the script by trying to import the image. It doenst work i.e. recognize at all. The same import of PIL works from python2/python3 interface in spyder or pycharm or commandlines. If I remove PIL import statement, the html works or prints out to browser. #! /usr/bin/env python from PIL import Image print "" print "hello world" print "--" print "" What did you expect to happen? python script to recognize PIL but it doesnt recognize. I have uninstalled PIL-SIMD multiple times and reinstalled but it isnt working. Though I have both python2 and python3, default am using python2 and so is apache CGI interface. What actually happened? I capture following error in apache logs. AH01215: from PIL import Image: /var/www/images/index.py AH01215: ImportError: No module named PIL: /var/www/images/index.py What versions of Pillow and Python are you using? Python 2.7.12 Pillow-SIMD Pillow-SIMD (4.0.0.post0) Please help if this wont resolve, I have to completely move away from python. From rosuav at gmail.com Tue Mar 28 12:05:04 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Mar 2017 03:05:04 +1100 Subject: AH01215: ImportError: No module named PIL: - python script unable to recognize PIL when running from apache2 config In-Reply-To: <4d8860d7-7810-4e76-8829-70c958a9013c@googlegroups.com> References: <4d8860d7-7810-4e76-8829-70c958a9013c@googlegroups.com> Message-ID: On Wed, Mar 29, 2017 at 2:59 AM, wrote: > Please help if this wont resolve, I have to completely move away from python. How about, instead, moving away from CGI? Switch to Apache's modpython. I've deployed several Python-based web sites without difficulties. ChrisA From jf_byrnes at comcast.net Tue Mar 28 12:28:26 2017 From: jf_byrnes at comcast.net (Jim) Date: Tue, 28 Mar 2017 11:28:26 -0500 Subject: Using/compiling pyuno with Python 3.6 In-Reply-To: <013201d2a77d$90d5b180$27b23dae@sambora> References: <013201d2a77d$90d5b180$27b23dae@sambora> Message-ID: On 03/27/2017 11:41 PM, Deborah Swanson wrote: > filtered wrote, on March 27, 2017 9:09 PM >> >> Sorry but all your answers are pointless. >> >> I clearly asked about compiling PyUno MYSELF with a >> self-compiled Python 3.6.1 installation. Is this so hard to >> understand? Why do you give unrelated comments to a clear >> questions? Sometimes it is better to be quiet. >> >> -aj > > If you really only wanted to know how to compile PyUno with a > self-compiled Python 3.6.1 installation, it muddied the waters > considerably that you first went on at length about your difficulties > importing PyUno. It appeared that your main objective was to have an > importable installation of PyUno, and it would have been better to omit > the error details if all you wanted to know is how to compile it. Maybe > not as clear a question as you imagine. > Exactly. I'm sorry I misunderstood the question. I also thought the goal was to have a working installation of Python 3.6.1 and Pyuno. Regards, Jim > >> 2017-03-28 5:49 GMT+02:00 Michael Torrie : >> >>> On 03/27/2017 09:13 PM, Jim wrote: >>>> I don't know if this is of any help but I am running Mint 18 with >>>> Python 3.5 and I have a package installed called >> python3-uno which >>>> is described as "Python-UNO bridge". Maybe CentOS has a similarly >>>> name package. >>> >>> You're right. In fact it looks like LibreOffice 5.3 at least ships >>> with Python 3.5 as part of the package, and comes with >> pyuno as part >>> of that. Try running the python binary from the LibreOffice install >>> directory (on my machine that is >> /opt/libreoffice5.3/program/python). >>> I'm not sure how to work with pyuno outside of the >> LO-shipped python. >>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > From rosuav at gmail.com Tue Mar 28 12:35:45 2017 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Mar 2017 03:35:45 +1100 Subject: AH01215: ImportError: No module named PIL: - python script unable to recognize PIL when running from apache2 config In-Reply-To: <621733ca-41f0-89f9-a914-d00857f86875@gmail.com> References: <4d8860d7-7810-4e76-8829-70c958a9013c@googlegroups.com> <621733ca-41f0-89f9-a914-d00857f86875@gmail.com> Message-ID: On Wed, Mar 29, 2017 at 3:32 AM, Karim wrote: > > On 28/03/2017 18:05, Chris Angelico wrote: >> >> On Wed, Mar 29, 2017 at 2:59 AM, wrote: >>> >>> Please help if this wont resolve, I have to completely move away from >>> python. >> >> How about, instead, moving away from CGI? Switch to Apache's >> modpython. I've deployed several Python-based web sites without >> difficulties. >> >> ChrisA > > > Ah ok. What do you think of Django? (Bouncing back to the list because I think the private message was unintentional. Apologies if I'm misreading your intentions.) Not hugely experienced with Django; I mainly use Flask. But they're fairly similar in style and structure. Either way, you make yourself an importable package/module that has all your code in it, and then you set up WSGI so that Apache can call on you. ChrisA From kliateni at gmail.com Tue Mar 28 12:44:21 2017 From: kliateni at gmail.com (Karim) Date: Tue, 28 Mar 2017 18:44:21 +0200 Subject: AH01215: ImportError: No module named PIL: - python script unable to recognize PIL when running from apache2 config In-Reply-To: References: <4d8860d7-7810-4e76-8829-70c958a9013c@googlegroups.com> <621733ca-41f0-89f9-a914-d00857f86875@gmail.com> Message-ID: <82a11abc-bfb1-6be8-dc38-fc3537e78a81@gmail.com> On 28/03/2017 18:35, Chris Angelico wrote: > On Wed, Mar 29, 2017 at 3:32 AM, Karim wrote: >> On 28/03/2017 18:05, Chris Angelico wrote: >>> On Wed, Mar 29, 2017 at 2:59 AM, wrote: >>>> Please help if this wont resolve, I have to completely move away from >>>> python. >>> How about, instead, moving away from CGI? Switch to Apache's >>> modpython. I've deployed several Python-based web sites without >>> difficulties. >>> >>> ChrisA >> >> Ah ok. What do you think of Django? > (Bouncing back to the list because I think the private message was > unintentional. Apologies if I'm misreading your intentions.) > > Not hugely experienced with Django; I mainly use Flask. But they're > fairly similar in style and structure. Either way, you make yourself > an importable package/module that has all your code in it, and then > you set up WSGI so that Apache can call on you. > > ChrisA Thank you Chris! From israel at ravnalaska.net Tue Mar 28 13:25:33 2017 From: israel at ravnalaska.net (Israel Brewster) Date: Tue, 28 Mar 2017 09:25:33 -0800 Subject: Proper way to run CherryPy app as a daemon? Message-ID: I am wanting to run a CherryPy app as a daemon on CentOS 6 using an init.d script. By subscribing to the "Daemonizer" and PIDFile cherrypy plugins, I have been able to write an init.d script that starts and stops my CherryPy application. There's only one problem: it would appear that the program daemonizes, thus allowing the init.d script to return a good start, as soon as I call cherrypy.engine.start(), but *before* the cherrypy app has actually started. Particularly, this occurs before cherrypy has bound to the desired port. The end result is that running "service start" returns OK, indicating that the app is now running, even when it cannot bind to the port, thus preventing it from actually starting. This is turn causes issues with my clustering software which thinks it started just fine, when in fact it never *really* started. As such, is there a way to delay the demonization until I call cherrypy.engine.block()? Or some other way to prevent the init.d script from indicating a successful start until the process has actually bound to the needed port and fully started? What is the proper way of doing this? Thanks! ----------------------------------------------- Israel Brewster Systems Analyst II Ravn Alaska 5245 Airport Industrial Rd Fairbanks, AK 99709 (907) 450-7293 ----------------------------------------------- From songofacandy at gmail.com Tue Mar 28 14:21:13 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Wed, 29 Mar 2017 03:21:13 +0900 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: On Wed, Mar 29, 2017 at 12:29 AM, Jan Gosmann wrote: > On 28 Mar 2017, at 6:11, INADA Naoki wrote: > >> I managed to install pyopencl and run the script. It takes more than >> 2 hours, and uses only 7GB RAM. >> Maybe, some faster backend for OpenCL is required? >> >> I used Microsoft Azure Compute, Standard_A4m_v2 (4 cores, 32 GB >> memory) instance. > > > I suppose that the computing power of the Azure instance might not be > sufficient and it takes much longer to get to the phase where the memory > requirements increase? Have you access to the output that was produced? > I suppose smaller and faster benchmark is better to others looking for it. I already stopped the azure instance. > By the way, this has nothing to do with OpenCL. OpenCL isn't used by the > log_reduction.py script at all. It is listed in the dependencies because > some other things use it. Oh, it took my time much to run the benchmark... All difficult dependencies are required to run the benchmark. > >> More easy way to reproduce is needed... > > > Yes, I agree, but it's not super easy (all the smaller existing examples > don't exhibit the problem so far), but I'll see what I can do. > There are no need to make swapping. Looking difference of normal RAM usage is enough. There are no maxrss difference in "smaller existing examples"? > > I suppose you are right that from the VMM and RSS numbers one cannot deduce > fragmentation. But I think RSS in this case might not be meaningful either. > My understanding from [the Wikipedia description] is that it doesn't account > for parts of the memory that have been written to the swap. Or in other > words RSS will never exceed the size of the physical RAM. VSS is also only > partially useful because it just gives the size of the address space of > which not all might be used? I just meant "VSS is not evidence of fragmentation. Don't suppose fragmentation cause the problem.". > > Anyways, I'm getting a swap usage of about 30GB with Python 3.6 and zsh's > time reports 2339977 page faults from disk vs. 107 for Python 3.5. > > I have some code to measure the unique set size (USS) and will see what > numbers I get with that. > > Jan I want to investigate RAM usage, without any swapping. Regards, From fpm at u.washington.edu Tue Mar 28 14:51:04 2017 From: fpm at u.washington.edu (Frank Miles) Date: Tue, 28 Mar 2017 18:51:04 -0000 (UTC) Subject: Multiprocessing queue in py2.7 Message-ID: I tried running a bit of example code from the py2.7 docs (16.6.1.2. Exchanging objects between processes) only to have it fail. The code is simply: # ------------ from multiprocessing import Process, Queue def f(q): q.put([42, None, 'hello']) if __name__ == '__main__': q = Queue() p = Process(target=f, args=(q,)) p.start() print q.get() # prints "[42, None, 'hello']" p.join() # --------------- But what happens is f() fails: Traceback (most recent call last): File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap self.run() File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run self._target(*self._args, **self._kwargs) File "x.py", line 4, in f q.put([42, None, "Hello"]) AttributeError: 'int' object has no attribute 'put' This is on a Debian jessie host, though eventually it needs to run on a raspberry pi 3 {and uses other library code that needs py2.7}. Thanks in advance for those marvelous clues! -F From python at mrabarnett.plus.com Tue Mar 28 15:10:08 2017 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 28 Mar 2017 20:10:08 +0100 Subject: Multiprocessing queue in py2.7 In-Reply-To: References: Message-ID: <5b219409-a34e-d2fd-c300-58e873903070@mrabarnett.plus.com> On 2017-03-28 19:51, Frank Miles wrote: > I tried running a bit of example code from the py2.7 docs > (16.6.1.2. Exchanging objects between processes) > only to have it fail. The code is simply: > # ------------ > from multiprocessing import Process, Queue > > def f(q): > q.put([42, None, 'hello']) > > if __name__ == '__main__': > q = Queue() > p = Process(target=f, args=(q,)) > p.start() > print q.get() # prints "[42, None, 'hello']" > p.join() > # --------------- > But what happens is f() fails: > > Traceback (most recent call last): > File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap > self.run() > File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run > self._target(*self._args, **self._kwargs) > File "x.py", line 4, in f > q.put([42, None, "Hello"]) > AttributeError: 'int' object has no attribute 'put' > > This is on a Debian jessie host, though eventually it needs to > run on a raspberry pi 3 {and uses other library code that needs > py2.7}. > > Thanks in advance for those marvelous clues! > Insert a print to see what's being passed to f: def f(q): print 'Argument is', q q.put([42, None, 'hello']) Is it an int? If it is, have another look at where the process is created and what is being passed. Print that out too. From zljubisic at gmail.com Tue Mar 28 15:36:29 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Tue, 28 Mar 2017 12:36:29 -0700 (PDT) Subject: pandas creating a new column based on row values Message-ID: <471f8d92-664e-4667-a0b5-bbeea22878d0@googlegroups.com> This doesn't work: import pandas as pd def myfunc(): return 'Start_{}_{}_{}_{}_End'.format(df['coverage'], df['name'], df['reports'], df['year']) data = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'], 'year': [2012, 2012, 2013, 2014, 2014], 'reports': [4, 24, 31, 2, 3], 'coverage': [25, 94, 57, 62, 70]} df = pd.DataFrame(data, index = ['Cochice', 'Pima', 'Santa Cruz', 'Maricopa', 'Yuma']) print(df) df['New'] = df.apply(myfunc(), axis=1) TypeError: ("'str' object is not callable", 'occurred at index Cochice') Can I somehow generate a new column by concatenating values for the other columns in a row? Expected result for column 'New' would be: Start_Jason_2012_4_25_End Start_Molly_2012_24_94_End Start_Tina_2013_31_57_End Start_Jake_2014_2_62_End From tjreedy at udel.edu Tue Mar 28 15:38:38 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Mar 2017 15:38:38 -0400 Subject: Multiprocessing queue in py2.7 In-Reply-To: References: Message-ID: On 3/28/2017 2:51 PM, Frank Miles wrote: > I tried running a bit of example code from the py2.7 docs > (16.6.1.2. Exchanging objects between processes) > only to have it fail. The code is simply: > # ------------ > from multiprocessing import Process, Queue > > def f(q): > q.put([42, None, 'hello']) > > if __name__ == '__main__': > q = Queue() > p = Process(target=f, args=(q,)) > p.start() > print q.get() # prints "[42, None, 'hello']" > p.join() > # --------------- Cut and pasted, this runs as specified on 2.7.13 on Win 10 > But what happens is f() fails: > > Traceback (most recent call last): > File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap > self.run() > File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run > self._target(*self._args, **self._kwargs) > File "x.py", line 4, in f > q.put([42, None, "Hello"]) > AttributeError: 'int' object has no attribute 'put' This says that the arg bound to q in f is an int rather than a Queue. Are you sure that you posted the code that you ran? > This is on a Debian jessie host, though eventually it needs to > run on a raspberry pi 3 {and uses other library code that needs > py2.7}. > > Thanks in advance for those marvelous clues! -- Terry Jan Reedy From codewizard at gmail.com Tue Mar 28 15:43:23 2017 From: codewizard at gmail.com (codewizard at gmail.com) Date: Tue, 28 Mar 2017 12:43:23 -0700 (PDT) Subject: pandas creating a new column based on row values In-Reply-To: <471f8d92-664e-4667-a0b5-bbeea22878d0@googlegroups.com> References: <471f8d92-664e-4667-a0b5-bbeea22878d0@googlegroups.com> Message-ID: On Tuesday, March 28, 2017 at 3:36:57 PM UTC-4, zlju... at gmail.com wrote: > [snip] > > Can I somehow generate a new column by concatenating values for the other columns in a row? > Try this (not tested): def myfunc(row): return 'Start_{}_{}_{}_{}_End'.format(row['coverage'], row['name'], row['reports'], row['year']) df['New'] = df.apply(myfunc, axis=1) From tjreedy at udel.edu Tue Mar 28 15:47:37 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 28 Mar 2017 15:47:37 -0400 Subject: AH01215: ImportError: No module named PIL: - python script unable to recognize PIL when running from apache2 config In-Reply-To: <4d8860d7-7810-4e76-8829-70c958a9013c@googlegroups.com> References: <4d8860d7-7810-4e76-8829-70c958a9013c@googlegroups.com> Message-ID: On 3/28/2017 11:59 AM, vishnuprasadh at gmail.com wrote: > I capture following error in apache logs. > AH01215: from PIL import Image: /var/www/images/index.py > AH01215: ImportError: No module named PIL: /var/www/images/index.py A general response to this particular message is a) check spelling in code matches actual filename b) check search path "import sys; print(sys.path)" and then see if the path contains the directory actually containing the module For this specific case, follow Chris's advice. -- Terry Jan Reedy From fpm at u.washington.edu Tue Mar 28 16:16:48 2017 From: fpm at u.washington.edu (Frank Miles) Date: Tue, 28 Mar 2017 20:16:48 -0000 (UTC) Subject: Multiprocessing queue in py2.7 References: Message-ID: On Tue, 28 Mar 2017 15:38:38 -0400, Terry Reedy wrote: > On 3/28/2017 2:51 PM, Frank Miles wrote: >> I tried running a bit of example code from the py2.7 docs >> (16.6.1.2. Exchanging objects between processes) >> only to have it fail. The code is simply: >> # ------------ >> from multiprocessing import Process, Queue >> >> def f(q): >> q.put([42, None, 'hello']) >> >> if __name__ == '__main__': >> q = Queue() >> p = Process(target=f, args=(q,)) >> p.start() >> print q.get() # prints "[42, None, 'hello']" >> p.join() >> # --------------- > > Cut and pasted, this runs as specified on 2.7.13 on Win 10 > >> But what happens is f() fails: >> >> Traceback (most recent call last): >> File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap >> self.run() >> File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run >> self._target(*self._args, **self._kwargs) >> File "x.py", line 4, in f >> q.put([42, None, "Hello"]) >> AttributeError: 'int' object has no attribute 'put' > > This says that the arg bound to q in f is an int rather than a Queue. > Are you sure that you posted the code that you ran? > >> This is on a Debian jessie host, though eventually it needs to >> run on a raspberry pi 3 {and uses other library code that needs >> py2.7}. >> >> Thanks in advance for those marvelous clues! Argghh! I missed one stupid typo. Somehow had a '1' instead of the 'q' in the Process(..) line. My bad. Sorry for the noise, and thanks!! -F From zljubisic at gmail.com Tue Mar 28 16:52:00 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Tue, 28 Mar 2017 13:52:00 -0700 (PDT) Subject: pandas creating a new column based on row values In-Reply-To: References: <471f8d92-664e-4667-a0b5-bbeea22878d0@googlegroups.com> Message-ID: It works. Thank you very much. :) From zljubisic at gmail.com Tue Mar 28 17:00:45 2017 From: zljubisic at gmail.com (zljubisic at gmail.com) Date: Tue, 28 Mar 2017 14:00:45 -0700 (PDT) Subject: pandas dataframe, find duplicates and add suffix Message-ID: <5c15090c-34c1-4ded-a550-5207fae53a98@googlegroups.com> In dataframe import pandas as pd data = {'model': ['first', 'first', 'second', 'second', 'second', 'third', 'third'], 'dtime': ['2017-01-01_112233', '2017-01-01_112234', '2017-01-01_112234', '2017-01-01_112234', '2017-01-01_112234', '2017-01-01_112235', '2017-01-01_112235'], } df = pd.DataFrame(data, index = ['a.jpg', 'b.jpg', 'c.jpg', 'd.jpg', 'e.jpg', 'f.jpg', 'g.jpg'], columns=['model', 'dtime']) print(df.head(10)) model dtime a.jpg first 2017-01-01_112233 b.jpg first 2017-01-01_112234 c.jpg second 2017-01-01_112234 d.jpg second 2017-01-01_112234 e.jpg second 2017-01-01_112234 f.jpg third 2017-01-01_112235 g.jpg third 2017-01-01_112235 within model, there are duplicate dtime values. For example, rows d and e are duplicates of the c row. Row g is duplicate of the f row. For each duplicate (within model) I would like to add suffix (starting from 1) to the dtime value. Something like this: model dtime a.jpg first 2017-01-01_112233 b.jpg first 2017-01-01_112234 c.jpg second 2017-01-01_112234 d.jpg second 2017-01-01_112234-1 e.jpg second 2017-01-01_112234-2 f.jpg third 2017-01-01_112235 g.jpg third 2017-01-01_112235-1 How to do that? From __peter__ at web.de Wed Mar 29 02:58:49 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 29 Mar 2017 08:58:49 +0200 Subject: Logging from different python scripts to different output files References: Message-ID: James McMahon wrote: [Please keep the discussion on the list] > Thank you Peter. Is it necessary to employ a close() on the handlers and a > shutdown() on the loggers themselves? -Jim Not unless you run into problems with the default mechanism -- logging.shutdown() is scheduled via atexit.register() and invoked when the application terminates normally. From arpitamishrarkm at gmail.com Wed Mar 29 04:23:32 2017 From: arpitamishrarkm at gmail.com (arpitamishrarkm at gmail.com) Date: Wed, 29 Mar 2017 01:23:32 -0700 (PDT) Subject: K&L graph partitioning code offer In-Reply-To: <7bftca$lai@abc.ksu.ksu.edu>#1/1> References: <7bftca$lai@abc.ksu.ksu.edu>#1/1> Message-ID: <844b8ab9-19bf-40b6-9173-3dec67b6ea64@googlegroups.com> Hi I am planning to tweak the Kernighan Lin algorithm a bit use coercing of certain vertices .I was wondering if u would be kind enough to share the python code with me so that i can include my idea in it. From arpitamishrarkm at gmail.com Wed Mar 29 04:29:13 2017 From: arpitamishrarkm at gmail.com (arpitamishrarkm at gmail.com) Date: Wed, 29 Mar 2017 01:29:13 -0700 (PDT) Subject: K&L graph partitioning code offer In-Reply-To: <7bftca$lai@abc.ksu.ksu.edu>#1/1> References: <7bftca$lai@abc.ksu.ksu.edu>#1/1> Message-ID: <673735b2-659e-4edc-b866-f989541415a5@googlegroups.com> Hi I am planning to tweak the Kernighan Lin algorithm a bit use coercing of certain vertices .I was wondering if u would be kind enough to share the python code with me so that i can include my idea in it. From steve+python at pearwood.info Wed Mar 29 05:45:38 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Wed, 29 Mar 2017 20:45:38 +1100 Subject: K&L graph partitioning code offer References: <7bftca$lai@abc.ksu.ksu.edu>#1/1> <673735b2-659e-4edc-b866-f989541415a5@googlegroups.com> Message-ID: <58db8243$0$1606$c3e8da3$5496439d@news.astraweb.com> On Wed, 29 Mar 2017 07:29 pm, arpitamishrarkm at gmail.com wrote: > Hi > I am planning to tweak the Kernighan Lin algorithm a bit use coercing of > certain vertices .I was wondering if u would be kind enough to share the > python code with me so that i can include my idea in it. https://www.google.com.au/search?q=Kernighan+Lin+algorithm+python https://duckduckgo.com/?q=python+Kernighan+Lin+algorithm -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From skip.montanaro at gmail.com Wed Mar 29 12:04:45 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 29 Mar 2017 11:04:45 -0500 Subject: logging.LogRecord asctime aattribute - easily override somehow? Message-ID: Short of going into some Formatter creation exercise (which seems like overkill to me, and somewhat obscure), is there some way to easily change the format of the logging.LogRecord's asctime attribute? Thx, Skip From lyngwyst at gmail.com Wed Mar 29 12:06:00 2017 From: lyngwyst at gmail.com (lyngwyst at gmail.com) Date: Wed, 29 Mar 2017 09:06:00 -0700 (PDT) Subject: Python under PowerShell adds characters Message-ID: I wrote a Python script, which executed as intended on Linux and from cmd.exe on Windows. Then, I ran it from the PowerShell command line, all print statements added ^@ after every character. Have you seen this? Do you know how to prevent this? Thank you, Jay From jussi.piitulainen at helsinki.fi Wed Mar 29 12:39:19 2017 From: jussi.piitulainen at helsinki.fi (Jussi Piitulainen) Date: Wed, 29 Mar 2017 19:39:19 +0300 Subject: Python under PowerShell adds characters References: Message-ID: lyngwyst at gmail.com writes: > I wrote a Python script, which executed as intended on Linux and from > cmd.exe on Windows. Then, I ran it from the PowerShell command line, > all print statements added ^@ after every character. > > Have you seen this? Do you know how to prevent this? Script is printing UTF-16 or something, viewer is expecting ASCII or some eight bit code and making null bytes visible as ^@. Python gets some default encoding from its environment. There are ways to set the default, and ways to override the default in the script. For example, you can specify an encoding when you open a file. From __peter__ at web.de Wed Mar 29 12:39:59 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 29 Mar 2017 18:39:59 +0200 Subject: logging.LogRecord asctime aattribute - easily override somehow? References: Message-ID: Skip Montanaro wrote: > Short of going into some Formatter creation exercise (which seems like > overkill to me, and somewhat obscure), is there some way to easily > change the format of the logging.LogRecord's asctime attribute? > > Thx, > > Skip Like >>> import logging >>> logging.basicConfig(format="%(asctime)s" + logging.BASIC_FORMAT, datefmt="***%A***") >>> logging.warn("foo") ***Wednesday***WARNING:root:foo ? From skip.montanaro at gmail.com Wed Mar 29 13:07:35 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 29 Mar 2017 12:07:35 -0500 Subject: logging.LogRecord asctime aattribute - easily override somehow? In-Reply-To: References: Message-ID: >>> import logging >>> logging.basicConfig(format="%(asctime)s" + logging.BASIC_FORMAT, datefmt="***%A***") >>> logging.warn("foo") ***Wednesday***WARNING:root:foo Thanks, Peter. I suppose a bit more detail of my environment would have helped. I'm actually using the logging package indirectly via Flask. After a quick skim of Flask's code, it didn't look like the Flask author considered that users might want to do their own thing with logging. I think I could override the Flask.logger property and chuck in something like your code. I'll just suffer for the time being with my "two word" timestamps. Whoever thought you'd want to break up timestamps into two words by default, and hard-code a comma as the separator between seconds and milliseconds? Just for the record, for my own standalone code I never use the logging module. I just have a simple Logger class which does all I need. The logging module (and log4j) have always seemed to me to be an overly general solution in search of a problem. Skip From jladasky at itu.edu Wed Mar 29 13:17:57 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Wed, 29 Mar 2017 10:17:57 -0700 (PDT) Subject: K&L graph partitioning code offer In-Reply-To: <844b8ab9-19bf-40b6-9173-3dec67b6ea64@googlegroups.com> References: <7bftca$lai@abc.ksu.ksu.edu>#1/1> <844b8ab9-19bf-40b6-9173-3dec67b6ea64@googlegroups.com> Message-ID: On Wednesday, March 29, 2017 at 1:23:48 AM UTC-7, arpitam... at gmail.com wrote: > Hi > I am planning to tweak the Kernighan Lin algorithm a bit use coercing of certain vertices .I was wondering if u would be kind enough to share the python code with me so that i can include my idea in it. Good luck getting the code you want from Dean Hall, his post is from 1999! (Is 18 years a record for thread necromancy?) From eryksun at gmail.com Wed Mar 29 13:22:45 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 29 Mar 2017 17:22:45 +0000 Subject: Python under PowerShell adds characters In-Reply-To: References: Message-ID: On Wed, Mar 29, 2017 at 4:06 PM, wrote: > I wrote a Python script, which executed as intended on Linux and > from cmd.exe on Windows. Then, I ran it from the PowerShell >command line, all print statements added ^@ after every character. ISE is the only command-line environment that's specific to PowerShell. Surely you wouldn't be running Python scripts in ISE. If powershell.exe is run normally, then it's a console application. python.exe would inherit the console handle, and that's the end of its interaction with PowerShell. At most PowerShell (or any process that's attached to the console) may have set the console to a different output codepage via SetConsoleOutputCP or set the mode on the screen buffer via SetConsoleMode. As far as I know, neither of these can make the console print "^@" as a representation of NUL. It only shows "^@" in the input buffer when you type Ctrl+2, which is what most terminals do. For example: >>> s = sys.stdin.read(6) spam^@ >>> s 'spam\x00\n' >>> print(s) spam From lyngwyst at gmail.com Wed Mar 29 13:42:25 2017 From: lyngwyst at gmail.com (Jay Braun) Date: Wed, 29 Mar 2017 10:42:25 -0700 (PDT) Subject: Python under PowerShell adds characters In-Reply-To: References: Message-ID: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> On Wednesday, March 29, 2017 at 10:28:58 AM UTC-7, eryk sun wrote: > On Wed, Mar 29, 2017 at 4:06 PM, wrote: > > I wrote a Python script, which executed as intended on Linux and > > from cmd.exe on Windows. Then, I ran it from the PowerShell > >command line, all print statements added ^@ after every character. > > ISE is the only command-line environment that's specific to > PowerShell. Surely you wouldn't be running Python scripts in ISE. > > If powershell.exe is run normally, then it's a console application. > python.exe would inherit the console handle, and that's the end of its > interaction with PowerShell. At most PowerShell (or any process that's > attached to the console) may have set the console to a different > output codepage via SetConsoleOutputCP or set the mode on the screen > buffer via SetConsoleMode. As far as I know, neither of these can make > the console print "^@" as a representation of NUL. It only shows "^@" > in the input buffer when you type Ctrl+2, which is what most terminals > do. For example: > > >>> s = sys.stdin.read(6) > spam^@ > >>> s > 'spam\x00\n' > >>> print(s) > spam I'm not using ISE. I'm using a pre-edited script, and running it with the python command. Consider the following simple script named hello.py (Python 2.7): print "Hello" If I enter: python hello.py > out.txt from cmd.exe I get a 6-character file (characters plus new-line). from PowerShell I get an extract ^@ character after every character j From torriem at gmail.com Wed Mar 29 13:46:34 2017 From: torriem at gmail.com (Michael Torrie) Date: Wed, 29 Mar 2017 11:46:34 -0600 Subject: K&L graph partitioning code offer In-Reply-To: References: <7bftca$lai@abc.ksu.ksu.edu> <844b8ab9-19bf-40b6-9173-3dec67b6ea64@googlegroups.com> Message-ID: On 03/29/2017 11:17 AM, jladasky at itu.edu wrote: > On Wednesday, March 29, 2017 at 1:23:48 AM UTC-7, arpitam... at gmail.com wrote: >> Hi >> I am planning to tweak the Kernighan Lin algorithm a bit use coercing of certain vertices .I was wondering if u would be kind enough to share the python code with me so that i can include my idea in it. > > Good luck getting the code you want from Dean Hall, his post is from 1999! > > (Is 18 years a record for thread necromancy?) I don't see any reply to a post from 1998 here... What post are you talking about? From rosuav at gmail.com Wed Mar 29 14:09:33 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2017 05:09:33 +1100 Subject: Python under PowerShell adds characters In-Reply-To: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> Message-ID: On Thu, Mar 30, 2017 at 4:42 AM, Jay Braun wrote: > Consider the following simple script named hello.py (Python 2.7): > > print "Hello" > > If I enter: > > python hello.py > out.txt > > from cmd.exe I get a 6-character file (characters plus new-line). > > from PowerShell I get an extract ^@ character after every character Sounds like cmd and PS are setting the output encodings differently. Does the same thing occur with Python 3.6? Try adding this to your script: import sys print(sys.stdout.encoding) and run it in the same two environments (no redirection needed). Do they give you the same thing? My suspicion is that you're running cmd.exe in the default Windows console, and PowerShell in some different console. But it's hard to be sure. ChrisA From eryksun at gmail.com Wed Mar 29 14:19:46 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 29 Mar 2017 18:19:46 +0000 Subject: Python under PowerShell adds characters In-Reply-To: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> Message-ID: On Wed, Mar 29, 2017 at 5:42 PM, Jay Braun wrote: > > I'm not using ISE. I'm using a pre-edited script, and running it with the python command. > > Consider the following simple script named hello.py (Python 2.7): > > print "Hello" > > If I enter: > python hello.py > out.txt > > from cmd.exe I get a 6-character file (characters plus new-line). > from PowerShell I get an extract ^@ character after every character You didn't say you were redirecting the output to a file. That's a completely different story for PowerShell -- and far more frustrating. cmd.exe implements redirecting a program's output to a file by temporarily changing its own StandardOutput to the file; spawing the process, which inherits the StandardOutput handle; and then changing back to its original StandardOutput (typically a console screen buffer). The program can write whatever it wants to the file, and cmd isn't involved in any way. PowerShell is far more invasive. Instead of giving the child process a handle for the file, it gives it a handle for a *pipe*. PowerShell reads from the pipe, and like an annoying busybody that no asked for, decodes the output as text, processes it (e.g. replacing newlines), and writes the processed data to the file. For example: PS C:\Temp> $script = "import sys; sys.stdout.buffer.write(b'\n')" PS C:\Temp> python -c $script > test.txt PS C:\Temp> python -c "print(open('test.txt', 'rb').read())" b'\xff\xfe\r\x00\n\x00' I wrote a single byte, b'\n', but PowerShell decoded it, replaced "\n" with "\r\n", and wrote it as UTF-16 with a BOM. From rosuav at gmail.com Wed Mar 29 14:23:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2017 05:23:20 +1100 Subject: Python under PowerShell adds characters In-Reply-To: References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> Message-ID: On Thu, Mar 30, 2017 at 5:19 AM, eryk sun wrote: > PowerShell is far more invasive. Instead of giving the child process a > handle for the file, it gives it a handle for a *pipe*. PowerShell > reads from the pipe, and like an annoying busybody that no asked for, > decodes the output as text, processes it (e.g. replacing newlines), > and writes the processed data to the file. For example: > > PS C:\Temp> $script = "import sys; sys.stdout.buffer.write(b'\n')" > PS C:\Temp> python -c $script > test.txt > PS C:\Temp> python -c "print(open('test.txt', 'rb').read())" > b'\xff\xfe\r\x00\n\x00' > > I wrote a single byte, b'\n', but PowerShell decoded it, replaced "\n" > with "\r\n", and wrote it as UTF-16 with a BOM. Lolwut? So PS can't handle binary redirection whatsoever. Fascinating. ChrisA From rgaddi at highlandtechnology.invalid Wed Mar 29 14:29:15 2017 From: rgaddi at highlandtechnology.invalid (Rob Gaddi) Date: Wed, 29 Mar 2017 11:29:15 -0700 Subject: Python under PowerShell adds characters In-Reply-To: References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> Message-ID: On 03/29/2017 11:23 AM, Chris Angelico wrote: > On Thu, Mar 30, 2017 at 5:19 AM, eryk sun wrote: >> PowerShell is far more invasive. Instead of giving the child process a >> handle for the file, it gives it a handle for a *pipe*. PowerShell >> reads from the pipe, and like an annoying busybody that no asked for, >> decodes the output as text, processes it (e.g. replacing newlines), >> and writes the processed data to the file. For example: >> >> PS C:\Temp> $script = "import sys; sys.stdout.buffer.write(b'\n')" >> PS C:\Temp> python -c $script > test.txt >> PS C:\Temp> python -c "print(open('test.txt', 'rb').read())" >> b'\xff\xfe\r\x00\n\x00' >> >> I wrote a single byte, b'\n', but PowerShell decoded it, replaced "\n" >> with "\r\n", and wrote it as UTF-16 with a BOM. > > Lolwut? > > So PS can't handle binary redirection whatsoever. Fascinating. > > ChrisA > Engineer 1: Man, that old DOS shell we keep emulating is just getting older and clunkier. Engineer 2: I know, we should rewrite it. You know, whole new thing, really modernize it. E1: So, like, bring in bash like everyone else? E2: No, better. How about something that integrates with no preexisting workflow in the world. E1: Wait, but what commands would it use? E2: New ones. E1: But, then how would it behave? E2: Totally new. Never before seen. New commands, new semantics, whole 9 yards. If anyone's ever used it, I don't want to. E1: I love this plan. -- Rob Gaddi, Highland Technology -- www.highlandtechnology.com Email address domain is currently out of order. See above to fix. From lyngwyst at gmail.com Wed Mar 29 14:30:26 2017 From: lyngwyst at gmail.com (Jay Braun) Date: Wed, 29 Mar 2017 11:30:26 -0700 (PDT) Subject: Python under PowerShell adds characters In-Reply-To: References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> Message-ID: On Wednesday, March 29, 2017 at 11:20:45 AM UTC-7, eryk sun wrote: > On Wed, Mar 29, 2017 at 5:42 PM, Jay Braun wrote: > > > > I'm not using ISE. I'm using a pre-edited script, and running it with the python command. > > > > Consider the following simple script named hello.py (Python 2.7): > > > > print "Hello" > > > > If I enter: > > python hello.py > out.txt > > > > from cmd.exe I get a 6-character file (characters plus new-line). > > from PowerShell I get an extract ^@ character after every character > > You didn't say you were redirecting the output to a file. That's a > completely different story for PowerShell -- and far more frustrating. > > cmd.exe implements redirecting a program's output to a file by > temporarily changing its own StandardOutput to the file; spawing the > process, which inherits the StandardOutput handle; and then changing > back to its original StandardOutput (typically a console screen > buffer). The program can write whatever it wants to the file, and cmd > isn't involved in any way. > > PowerShell is far more invasive. Instead of giving the child process a > handle for the file, it gives it a handle for a *pipe*. PowerShell > reads from the pipe, and like an annoying busybody that no asked for, > decodes the output as text, processes it (e.g. replacing newlines), > and writes the processed data to the file. For example: > > PS C:\Temp> $script = "import sys; sys.stdout.buffer.write(b'\n')" > PS C:\Temp> python -c $script > test.txt > PS C:\Temp> python -c "print(open('test.txt', 'rb').read())" > b'\xff\xfe\r\x00\n\x00' > > I wrote a single byte, b'\n', but PowerShell decoded it, replaced "\n" > with "\r\n", and wrote it as UTF-16 with a BOM. You are correct. Sorry I omitted that in my first post. Thank you for your help. j From rosuav at gmail.com Wed Mar 29 14:39:19 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2017 05:39:19 +1100 Subject: Python under PowerShell adds characters In-Reply-To: References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> Message-ID: On Thu, Mar 30, 2017 at 5:29 AM, Rob Gaddi wrote: > Engineer 1: Man, that old DOS shell we keep emulating is just getting older > and clunkier. > > Engineer 2: I know, we should rewrite it. You know, whole new thing, really > modernize it. > > E1: So, like, bring in bash like everyone else? > > E2: No, better. How about something that integrates with no preexisting > workflow in the world. > > E1: Wait, but what commands would it use? > > E2: New ones. My understanding of PowerShell is more like this: E1: Man, batch files are so clunky. It's a ridiculous hodge-podge. E2: Yeah, every shell ever written is clunky. Let's do our own thing and make it more like a scripting language. E1: Cool! Only, we won't use an existing language, we'll make our own, because it'll be better. E2: I love this plan. We've had discussions on this list about using Python as a job control shell, and the usual response is: Python sucks as a command executor. It's just not designed for that. The clunkiness of bash is precisely BECAUSE it's designed to be convenient and comfortable for a sysadmin. All those weird splitting and escaping rules are because (a) the easiest way to do piping, command sequencing, etc is with symbols, (b) you can't stop people from using those symbols in file names or arguments, and (c) it's a pain to have to quote every single string. AIUI PowerShell is somewhat like VBScript, only it isn't quite that either. But it's definitely more like a scripting language than a shell language. ChrisA From marko at pacujo.net Wed Mar 29 15:13:02 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 29 Mar 2017 22:13:02 +0300 Subject: Python under PowerShell adds characters References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> Message-ID: <87wpb799s1.fsf@elektro.pacujo.net> eryk sun : > PowerShell is far more invasive. Instead of giving the child process a > handle for the file, it gives it a handle for a *pipe*. PowerShell > reads from the pipe, and like an annoying busybody that no asked for, > decodes the output as text, You mean, a bit like Python3 does? Marko From rosuav at gmail.com Wed Mar 29 15:29:07 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2017 06:29:07 +1100 Subject: Python under PowerShell adds characters In-Reply-To: <87wpb799s1.fsf@elektro.pacujo.net> References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 30, 2017 at 6:13 AM, Marko Rauhamaa wrote: > eryk sun : >> PowerShell is far more invasive. Instead of giving the child process a >> handle for the file, it gives it a handle for a *pipe*. PowerShell >> reads from the pipe, and like an annoying busybody that no asked for, >> decodes the output as text, > > You mean, a bit like Python3 does? If you open a file in Python 3, you can choose whether to open it as text or binary. When you print text to stdout, well, it's text, so of course it has to be encoded appropriately; if you're doing something unusual (like a CGI script creating an image file), you can override the default and change stdout to be binary. But normally, the standard streams are connected ultimately to a human, so they're text. The problem is that PS is decoding and then re-encoding instead of simply telling the process what encoding to use. That's just wrong. ChrisA From __peter__ at web.de Wed Mar 29 15:35:20 2017 From: __peter__ at web.de (Peter Otten) Date: Wed, 29 Mar 2017 21:35:20 +0200 Subject: logging.LogRecord asctime aattribute - easily override somehow? References: Message-ID: Skip Montanaro wrote: >>>> import logging >>>> logging.basicConfig(format="%(asctime)s" + logging.BASIC_FORMAT, >>>> datefmt="***%A***") logging.warn("foo") > ***Wednesday***WARNING:root:foo > > Thanks, Peter. I suppose a bit more detail of my environment would > have helped. I'm actually using the logging package indirectly via > Flask. After a quick skim of Flask's code, it didn't look like the > Flask author considered that users might want to do their own thing > with logging. I think I could override the Flask.logger property and > chuck in something like your code. I'll just suffer for the time being > with my "two word" timestamps. $ cat hello.py from flask import Flask import functools import flask.logging flask.logging.Formatter = functools.partial( flask.logging.Formatter, datefmt="%A" ) app = Flask(__name__) @app.route('/') def hello_world(): app.logger.critical("test") return 'Hello, World!' $ FLASK_APP=hello.py python -m flask run & [1] 6028 $ * Serving Flask app "hello" * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) $ curl http://127.0.0.1:5000/ [Wednesday] CRITICAL in hello: test 127.0.0.1 - - [29/Mar/2017 21:26:38] "GET / HTTP/1.1" 200 - Hello, World!$ > Whoever thought you'd want to break up > timestamps into two words by default, and hard-code a comma as the > separator between seconds and milliseconds? In Germany the comma is the decimal separator, so this doesn't look like two words to my eye. However, the culprit is https://en.wikipedia.org/wiki/ISO_8601 """ A decimal mark, either a comma or a dot (without any preference as stated in resolution 10 of the 22nd General Conference CGPM in 2003,[16] but with a preference for a comma according to ISO 8601:2004)[17] is used as a separator between the time element and its fraction """ > > Just for the record, for my own standalone code I never use the > logging module. I just have a simple Logger class which does all I > need. The logging module (and log4j) have always seemed to me to be an > overly general solution in search of a problem. > > Skip From marko at pacujo.net Wed Mar 29 15:47:24 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Wed, 29 Mar 2017 22:47:24 +0300 Subject: Python under PowerShell adds characters References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> Message-ID: <87o9wj986r.fsf@elektro.pacujo.net> Chris Angelico : > But normally, the standard streams are connected ultimately to a > human, so they're text. Huh? The standard input is the workload and the standard output is the result of the computation. Arguably, the standard error stream is meant for humans. Marko From eryksun at gmail.com Wed Mar 29 15:59:33 2017 From: eryksun at gmail.com (eryk sun) Date: Wed, 29 Mar 2017 19:59:33 +0000 Subject: Python under PowerShell adds characters In-Reply-To: <87wpb799s1.fsf@elektro.pacujo.net> References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> Message-ID: On Wed, Mar 29, 2017 at 7:13 PM, Marko Rauhamaa wrote: > eryk sun : >> PowerShell is far more invasive. Instead of giving the child process a >> handle for the file, it gives it a handle for a *pipe*. PowerShell >> reads from the pipe, and like an annoying busybody that no asked for, >> decodes the output as text, > > You mean, a bit like Python3 does? The closest to what we're talking about here would be using subprocess.Popen and friends to create pipelines and redirect output to files. Opening a file defaults to text mode in Python for how Python access the file, but if you pass a file descriptor as Popen's stdout argument, Python isn't acting as a middle man. The child process writes directly to the file. PowerShell makes itself a middle man in the cases of file redirection and pipelines. It does this to enable all of the capabilities of its object pipeline. That's fine. But, IMO, there should be a simple way to get the plain-old redirection and piping in which the shell is not a middle man. The simplest way I know to do that in PowerShell is to run the command line via `cmd /c`. But I'm no PowerShell expert. From jan at hyper-world.de Wed Mar 29 16:19:08 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Wed, 29 Mar 2017 16:19:08 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: On 28 Mar 2017, at 14:21, INADA Naoki wrote: > On Wed, Mar 29, 2017 at 12:29 AM, Jan Gosmann > wrote: > > I suppose smaller and faster benchmark is better to others looking for > it. > I already stopped the azure instance. > [...] > There are no maxrss difference in "smaller existing examples"? > [...] > I want to investigate RAM usage, without any swapping. Running further trials indicate that the problem actually is related to swapping. If I reduce the model size in the benchmark slightly so that everything fits into the main memory, the problem disappears. Only when the memory usage exceeds the 32GB that I have, Python 3.6 will acquire way more memory (from the swap) than Python 3.5. Jan From skip.montanaro at gmail.com Wed Mar 29 17:49:44 2017 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Wed, 29 Mar 2017 16:49:44 -0500 Subject: logging.LogRecord asctime aattribute - easily override somehow? In-Reply-To: References: Message-ID: Skip> Whoever thought you'd want to break up Skip> timestamps into two words by default, and hard-code a comma as the Skip> separator between seconds and milliseconds? Peter> In Germany the comma is the decimal separator, so this doesn't look like two Peter> words to my eye. The "two words" reference I made was to the space separating the date and time. (I'd prefer a "T" separating date and time, as downstream log processing tools can be slightly simpler, since they don't have to collapse two fields into one.) The comma separator in the seconds field is fine if that's appropriate for your environment, though it appears to be hard-coded, not locale-specific: default_time_format = '%Y-%m-%d %H:%M:%S' default_msec_format = '%s,%03d' If I parse such times in a straightforward way in my locale (C or en_US.utf8), extracting the seconds as a floating point number is, once again, more complex than it ought to be, as a comma is not the proper decimal point in my locale(s). Skip From jladasky at itu.edu Wed Mar 29 18:27:38 2017 From: jladasky at itu.edu (jladasky at itu.edu) Date: Wed, 29 Mar 2017 15:27:38 -0700 (PDT) Subject: K&L graph partitioning code offer In-Reply-To: References: <7bftca$lai@abc.ksu.ksu.edu> <844b8ab9-19bf-40b6-9173-3dec67b6ea64@googlegroups.com> Message-ID: On Wednesday, March 29, 2017 at 10:46:56 AM UTC-7, Michael Torrie wrote: > On 03/29/2017 11:17 AM, j... at itu.edu wrote: > > On Wednesday, March 29, 2017 at 1:23:48 AM UTC-7, arpitam... at gmail.com wrote: > >> Hi > >> I am planning to tweak the Kernighan Lin algorithm a bit use coercing of certain vertices .I was wondering if u would be kind enough to share the python code with me so that i can include my idea in it. > > > > Good luck getting the code you want from Dean Hall, his post is from 1999! > > > > (Is 18 years a record for thread necromancy?) > > I don't see any reply to a post from 1998 here... What post are you > talking about? The Google Groups interface shows that the first post in this thread is as follows: > From: dwh... at ksu.edu (Dean Hall) > Subject: K&L graph partitioning code offer > Date: 1999/03/01 > Message-ID: <7bftca$lai at abc.ksu.ksu.edu>#1/1 > X-Deja-AN: 450257007 > Summary: K&L two-way partitioning algorithm coded in Python > X-Complaints-To: ab... at ksu.edu > X-Trace: cnn.ksu.ksu.edu 920352972 10308 129.130.12.3 (2 Mar 1999 05:36:12 GMT) > Organization: Kansas State University > Keywords: graph theory partition Kernighan Lin K&L > NNTP-Posting-Date: 2 Mar 1999 05:36:12 GMT > Newsgroups: comp.lang.python > > Hello, > > If anyone is interested in the Kernighan & Lin partitioning algorithm, > I've coded it in Python. > For those that don't know, the K&L algorithm finds a > pair of partitions of a set that has the locally minimum > number of edges between the two partitions (cutsize). > > I implemented a dumb Graph class (vertices and egdes), > then a KLPartitioner class. > Then, for fun ('cuz that's what Python is), > I wrote a class that uses Tkinter to display the resulting graph. > > I don't read the newsgroups much, > so email me if you wanna see the code. > > > !!Dean > dwh... at ksu.edu From steve+python at pearwood.info Wed Mar 29 20:12:22 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 30 Mar 2017 11:12:22 +1100 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: <58dc4d69$0$1599$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Mar 2017 07:19 am, Jan Gosmann wrote: > Running further trials indicate that the problem actually is related to > swapping. If I reduce the model size in the benchmark slightly so that > everything fits into the main memory, the problem disappears. Only when > the memory usage exceeds the 32GB that I have, Python 3.6 will acquire > way more memory (from the swap) than Python 3.5. If you can demonstrate this effect using simple example code without the external dependencies (using nothing but the standard library) and people can replicate it, I think it should be reported as a bug. If you are right, it does sound like a performance regression. Maybe there's a way to fix that. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Wed Mar 29 20:14:58 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 30 Mar 2017 11:14:58 +1100 Subject: Python under PowerShell adds characters References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> <87o9wj986r.fsf@elektro.pacujo.net> Message-ID: <58dc4e04$0$1599$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Mar 2017 06:47 am, Marko Rauhamaa wrote: > Chris Angelico : >> But normally, the standard streams are connected ultimately to a >> human, so they're text. > > Huh? The standard input is the workload Which is usually typed by a human, read from a file containing human-readable text, a file-name intended to be read by a human, or some other data in human-readable form. > and the standard output is the result of the computation. Which is generally intended to be read by a human. > Arguably, the standard error stream is meant for humans. Just like the rest of the computation. Relatively few command-line computations are performed by machines, for machines, using machine-friendly human-hostile formats. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Wed Mar 29 20:32:23 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2017 11:32:23 +1100 Subject: Python under PowerShell adds characters In-Reply-To: <58dc4e04$0$1599$c3e8da3$5496439d@news.astraweb.com> References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> <87o9wj986r.fsf@elektro.pacujo.net> <58dc4e04$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Mar 30, 2017 at 11:14 AM, Steve D'Aprano wrote: > Just like the rest of the computation. Relatively few command-line > computations are performed by machines, for machines, using > machine-friendly human-hostile formats. And even most computations performed by machines for machines are done using human-friendly transmission formats. Trying to brain-storm actually human-hostile formats... let's see. There's extremely low-level protocols like IP, TCP, DNS, and X11. There are (de)compression tools like gzip, where byte size is the entire point of the utility. There's XML, of course, which isn't exactly machine-friendly, but is pretty human-hostile. And most crypto is done with byte streams rather than text. Beyond that, pretty much everything is text. Ever since I started git-managing my /etc directory, I've been seeing changes made by various programs being reflected there - in text files. Internet protocols are almost exclusively text. Unless you say otherwise, most Unix utilities consume and emit text, even when they're in "machine readable" mode - for example, a number of git commands support a "--porcelain" option that removes color codes and pretty formatting, and also uses a format that's guaranteed to be stable, but it's still text. Despite fundamentally working with bit operations and numbers, computers today are still heavily text-aligned. Might have something to do with the fact that they're programmed by humans... ChrisA From jan at hyper-world.de Wed Mar 29 21:16:45 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Wed, 29 Mar 2017 21:16:45 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: <58dc4d69$0$1599$c3e8da3$5496439d@news.astraweb.com> References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> <58dc4d69$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0D1A837A-FD65-4C50-AC81-FE97D7E42EDC@hyper-world.de> On 29 Mar 2017, at 20:12, Steve D'Aprano wrote: > If you can demonstrate this effect using simple example code without > the > external dependencies (using nothing but the standard library) and > people > can replicate it, I think it should be reported as a bug. I probably won't be able to demonstrate the effect with simple example code because I haven't the slightest idea what is causing it. Also, I'm not sure how much more time I want to invest in this. After all it is a problem that might never get noticed by any users of the software. Jan From rantingrickjohnson at gmail.com Wed Mar 29 22:50:44 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 29 Mar 2017 19:50:44 -0700 (PDT) Subject: newbie question re classes and self In-Reply-To: <7545c7c1-63cb-4e00-99a3-2fdad0f62896@googlegroups.com> References: <7545c7c1-63cb-4e00-99a3-2fdad0f62896@googlegroups.com> Message-ID: <6a71d8f2-d6ee-4e09-89f6-a1e026974313@googlegroups.com> On Tuesday, March 28, 2017 at 3:09:45 AM UTC-5, loial wrote: > Can I pass self(or all its variables) to a class? > Basically, how do I make all the variables defined in self > in the calling python script available to the python class > I want to call? Your question, as presented, is difficult to understand, and the phrase "variables defined in self", is quite absurd. I'm making a wild assumption here, but perhaps you want to "bulk-set" or "bulk-query" all the attributes of a class instance externally? If so, depending on how the object was defined, there are a few ways to achieve this. However, my advanced powers of perception tell me that you might be using Python in an incorrect manner, but i cannot be sure until you explain this problem in more detail. So if you can provide us a simple code example, or even psuedo code, that would be very helpful. From rantingrickjohnson at gmail.com Wed Mar 29 23:19:59 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 29 Mar 2017 20:19:59 -0700 (PDT) Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> <58dc4d69$0$1599$c3e8da3$5496439d@news.astraweb.com> <0D1A837A-FD65-4C50-AC81-FE97D7E42EDC@hyper-world.de> Message-ID: <517fe120-4834-448d-887f-138e2422e54c@googlegroups.com> On Wednesday, March 29, 2017 at 8:17:01 PM UTC-5, Jan Gosmann wrote: > On 29 Mar 2017, at 20:12, Steve D'Aprano wrote: > > > If you can demonstrate this effect using simple example > > code without the external dependencies (using nothing but > > the standard library) and people can replicate it, I think > > it should be reported as a bug. > > I probably won't be able to demonstrate the effect with > simple example code because I haven't the slightest idea > what is causing it. Also, I'm not sure how much more time I > want to invest in this. After all it is a problem that > might never get noticed by any users of the software. Really? How could your clients not notice 60 GB of memory usage unless they are running some kind of mad-dog insane top-of-the-line hardware? (Got Benjamins???) Of course, in the case they are not DARPA scientist supported by a viturally unlimited supply of tax dollars provided by the endless toils of American slave-bots, how could they ignore the thrashing? o_O From rosuav at gmail.com Wed Mar 29 23:31:13 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2017 14:31:13 +1100 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: <517fe120-4834-448d-887f-138e2422e54c@googlegroups.com> References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> <58dc4d69$0$1599$c3e8da3$5496439d@news.astraweb.com> <0D1A837A-FD65-4C50-AC81-FE97D7E42EDC@hyper-world.de> <517fe120-4834-448d-887f-138e2422e54c@googlegroups.com> Message-ID: On Thu, Mar 30, 2017 at 2:19 PM, Rick Johnson wrote: > On Wednesday, March 29, 2017 at 8:17:01 PM UTC-5, Jan Gosmann wrote: >> On 29 Mar 2017, at 20:12, Steve D'Aprano wrote: >> >> > If you can demonstrate this effect using simple example >> > code without the external dependencies (using nothing but >> > the standard library) and people can replicate it, I think >> > it should be reported as a bug. >> >> I probably won't be able to demonstrate the effect with >> simple example code because I haven't the slightest idea >> what is causing it. Also, I'm not sure how much more time I >> want to invest in this. After all it is a problem that >> might never get noticed by any users of the software. > > Really? How could your clients not notice 60 GB of memory > usage unless they are running some kind of mad-dog insane > top-of-the-line hardware? (Got Benjamins???) Of course, in > the case they are not DARPA scientist supported by a > viturally unlimited supply of tax dollars provided by the > endless toils of American slave-bots, how could they ignore > the thrashing? o_O Did you read the project's README? This is a dramatic reduction from the normal memory usage of this kind of job. So, yes, they *are* going to have top-of-the-line hardware. If you're doing a job that normally would require 256GB of RAM, and instead of being able to run in 40GB, it needs 60GB, are you going to notice? You probably have 64GB or 128GB. ChrisA From rantingrickjohnson at gmail.com Wed Mar 29 23:53:35 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 29 Mar 2017 20:53:35 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d7fdc3$0$1617$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3fda49ff-1907-493c-a465-7e68bb86b7b1@googlegroups.com> On Sunday, March 26, 2017 at 1:21:18 PM UTC-5, Chris Angelico wrote: > On Mon, Mar 27, 2017 at 4:43 AM, Steve D'Aprano > wrote: > [...] So, for instance, Eryk Sun commented that my rounded > box example didn't render correctly in all fonts - but in > the future, a new version of those fonts could be released, > adding support for those characters. We *know* that the > code points I used are permanently and irrevocably > allocated to the purposes I used them for, so we can all be > confident that they'll be used correctly if at all. You place a lot of faith in the supposed "immutability of Unicode code points", but a lot people have placed a lot of faith in many past and current encoding systems, only to be bamboozled by the gatekeepers some time later. > > That's not quite right. Unicode includes 137000 or so > > Private Use Characters, which anyone can define for their > > own purposes, "by private agreement". There's an > > unofficial registry of such private use characters here: And so, although Unicode was created to solve the endless compatibility problems between multiple archaic encoding systems, the designers thought it necessary to add a "custom space" that will keep the incompatibilities on life support. Smart. *REALLY* smart. And people _wonder_ why Dylan was a disgruntled laureate... From rantingrickjohnson at gmail.com Thu Mar 30 00:21:56 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 29 Mar 2017 21:21:56 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> On Sunday, March 26, 2017 at 2:53:49 PM UTC-5, Chris Angelico wrote: > On Mon, Mar 27, 2017 at 6:25 AM, Mikhail V wrote: > > On 26 March 2017 at 20:10, Steve D'Aprano wrote: > >> On Mon, 27 Mar 2017 03:57 am, Mikhail V wrote: > I generally find that when people say that Unicode doesn't > solve their problems and they need to roll their own, it's > usually one of two possibilities: 1) "Their problems" are > all about simplicity. They don't want to have to deal with > all the complexities of real-world text, so they > arbitrarily restrict things. There are only so many hours in the day Chris. Not every progammer has the time to cater to every selfish desire of every potential client. You try to create the best product you can, but at the end of the process, there will always be someone (or a group of someones) who are unhappy with the result. > 2) Unicode _would_ solve their problems, they just don't > realize it. So if you're rolling your own text display > system, you should start by making a signed declaration: > > """ > I, the undersigned, acknowledge that my program is > intentionally excluding everyone who does not fit the > following requirements: [choose all applicable] > > [ ] Speaks English exclusively Of course, your comment presupposing that every programmer is fluent in every natural language. Which is not only impractical, it's impossible. > [ ] Uses no diacritical marks Why is it my responsibiliy to encode my text with pronuciation tutorials? Are we adults here or what? > [ ] Writes all text top-to-bottom, left-to-right Not my problem. Learn the King's English or go wait for extinction to arrive. > [ ] Uses only characters from the Basic Multilingual Plane > [ ] Uses only characters from this codepage: ____ > [ ] Uses a monospaced font > [ ] Uses a proportionally-spaced font > [ ] Uses this font: _____________ > [ ] Uses a mouse > [ ] Uses a keyboard > [ ] Other: ___________________ > (use additional pages if required) What don't you add these: [ ] Has the ability to read and comprehend at a high school level. [ ] Has functioning visual receptors. [ ] Has a functioning brain. [ ] Is not currently in a vegetative state > Sure, there are good reasons to place restrictions on > people's text. But those restrictions are part of your > public API and UI. Acknowledge them. Own them. And justify > them. The only justifaction required is the bottom line. If your products generate profit, then you're doing something right. Besides, you don't need _everyone_ on the planet to buy your product to be a success. Unlike the business practices of Apple, we would be wise to leave plenty of room for others to enter the market. Competition is good for everyone. Monopolies are evil. From rantingrickjohnson at gmail.com Thu Mar 30 00:28:06 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Wed, 29 Mar 2017 21:28:06 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> Message-ID: <414ec9a4-8b68-4db4-971a-26685ba5c8a9@googlegroups.com> On Sunday, March 26, 2017 at 6:42:36 PM UTC-5, Mikhail V wrote: > And all text I currently read on my monitor are prerendered > bitmaps, refined manually for frequently used sizes, and > that is how it should be made. IOW there are much more > important aspects than the ability to scale a text line > from 600 px to 601 px wide, if you know what I mean. LOL! From marko at pacujo.net Thu Mar 30 00:29:48 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 30 Mar 2017 07:29:48 +0300 Subject: Python under PowerShell adds characters References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> <87o9wj986r.fsf@elektro.pacujo.net> <58dc4e04$0$1599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <87inmr8k03.fsf@elektro.pacujo.net> Steve D'Aprano : > On Thu, 30 Mar 2017 06:47 am, Marko Rauhamaa wrote: >> Huh? The standard input is the workload > > Which is usually typed by a human, read from a file containing > human-readable text, a file-name intended to be read by a human, or > some other data in human-readable form. The main point is that it is supposed to be processed programmatically. It is somewhat rare that you type in the standard input. In particular, you want to be able to form useful pipelines from commands. Of course, in grand UNIX tradition, you strive to design your interchange formats to be also marginally applicable for human interaction (XML, base64 etc). >> and the standard output is the result of the computation. > Which is generally intended to be read by a human. That is more often the case. However, you want the format to be rigorous so it can be easily parsed programmatically. > Relatively few command-line computations are performed by machines, > for machines, using machine-friendly human-hostile formats. Didn't count them. Still, I'd expect not having to deal with Unicode decoding exceptions with arbitrary input. There recently was a related debate on the Guile mailing list. Like Python3, Guile2 is sensitive to illegal UTF-8 on the command line and in the standard streams. An emacs developer was urging Guile developers to follow emacs's example and support a superset of UTF-8 and Unicode where all byte strings can be bijectively mapped into text. Python3 partially does a similar thing, but only when dealing with pathnames. Marko From steve at pearwood.info Thu Mar 30 01:06:04 2017 From: steve at pearwood.info (Steven D'Aprano) Date: 30 Mar 2017 05:06:04 GMT Subject: Python under PowerShell adds characters References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> <87o9wj986r.fsf@elektro.pacujo.net> <58dc4e04$0$1599$c3e8da3$5496439d@news.astraweb.com> <87inmr8k03.fsf@elektro.pacujo.net> Message-ID: <58dc923c$0$2751$c3e8da3$76491128@news.astraweb.com> On Thu, 30 Mar 2017 07:29:48 +0300, Marko Rauhamaa wrote: [...] > I'd expect not having to deal with Unicode > decoding exceptions with arbitrary input. That's just silly. If you have *arbitrary* bytes, not all byte-sequences are valid Unicode, so you have to expect decoding exceptions, if you're processing text. Coming back to your complaint: Python 3 might default to automatically decoding stdin to Unicode, but you can choose to read stdin as bytes if you so wish. > There recently was a related debate on the Guile mailing list. Like > Python3, Guile2 is sensitive to illegal UTF-8 on the command line and in > the standard streams. An emacs developer was urging Guile developers to > follow emacs's example and support a superset of UTF-8 and Unicode where > all byte strings can be bijectively mapped into text. I'd like to read that. Got a link? -- Steve From rosuav at gmail.com Thu Mar 30 01:43:39 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2017 16:43:39 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> Message-ID: On Thu, Mar 30, 2017 at 3:21 PM, Rick Johnson wrote: > On Sunday, March 26, 2017 at 2:53:49 PM UTC-5, Chris Angelico wrote: >> On Mon, Mar 27, 2017 at 6:25 AM, Mikhail V wrote: >> > On 26 March 2017 at 20:10, Steve D'Aprano wrote: >> >> On Mon, 27 Mar 2017 03:57 am, Mikhail V wrote: > >> I generally find that when people say that Unicode doesn't >> solve their problems and they need to roll their own, it's >> usually one of two possibilities: 1) "Their problems" are >> all about simplicity. They don't want to have to deal with >> all the complexities of real-world text, so they >> arbitrarily restrict things. > > There are only so many hours in the day Chris. Not every > progammer has the time to cater to every selfish desire of > every potential client. You try to create the best product > you can, but at the end of the process, there will always be > someone (or a group of someones) who are unhappy with the > result. Except that it doesn't actually take very much work to call on someone else's library, which is what you get when you use Unicode properly. (At least, assuming you're using a decent language like Python, which comes with Unicode libraries, and a decent GUI toolkit if you're going that way.) >> """ >> I, the undersigned, acknowledge that my program is >> intentionally excluding everyone who does not fit the >> following requirements: [choose all applicable] >> >> [ ] Speaks English exclusively > > Of course, your comment presupposing that every programmer > is fluent in every natural language. Which is not only > impractical, it's impossible. Nope. I can't speak Mandarin, but I can make absolutely sure that all my programs can accept Chinese characters. A friend of mine sent me an audio file with a name that included some Chinese, and I was able to handle it no problem. >> [ ] Uses no diacritical marks > > Why is it my responsibiliy to encode my text with > pronuciation tutorials? Are we adults here or what? > >> [ ] Writes all text top-to-bottom, left-to-right > > Not my problem. Learn the King's English or go wait for > extinction to arrive. And these two cement your parochialism thoroughly in everyone's minds. "Pronunciation tutorials", eh? Sure. Tell that to everyone who speaks Spanish, Turkish, Norwegian, German, or Vietnamese, all of which use diacritical marks to distinguish between letters. English is the weird language in that it uses letter pairs instead of adorned letters (eg "ch" and "sh" instead of "?" and "?"). Also, which king are you referring to, exactly? Whose English do you speak? > What don't you add these: > > [ ] Has the ability to read and comprehend at a high > school level. > [ ] Has functioning visual receptors. > [ ] Has a functioning brain. > [ ] Is not currently in a vegetative state Nah. If I did, I'd have to say "[ ] Is not trolling python-list" as well. >> Sure, there are good reasons to place restrictions on >> people's text. But those restrictions are part of your >> public API and UI. Acknowledge them. Own them. And justify >> them. > > The only justifaction required is the bottom line. If your > products generate profit, then you're doing something right. > Besides, you don't need _everyone_ on the planet to buy your > product to be a success. Unlike the business practices of > Apple, we would be wise to leave plenty of room for others > to enter the market. Competition is good for everyone. > Monopolies are evil. Riiiiiight. What's the "bottom line" for open source software? How do you measure whether your product is generating a profit or not? ChrisA From marko at pacujo.net Thu Mar 30 01:43:46 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 30 Mar 2017 08:43:46 +0300 Subject: Python under PowerShell adds characters References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> <87o9wj986r.fsf@elektro.pacujo.net> <58dc4e04$0$1599$c3e8da3$5496439d@news.astraweb.com> <87inmr8k03.fsf@elektro.pacujo.net> <58dc923c$0$2751$c3e8da3$76491128@news.astraweb.com> Message-ID: <87efxf8gkt.fsf@elektro.pacujo.net> Steven D'Aprano : > On Thu, 30 Mar 2017 07:29:48 +0300, Marko Rauhamaa wrote: >> I'd expect not having to deal with Unicode decoding exceptions with >> arbitrary input. > > That's just silly. If you have *arbitrary* bytes, not all > byte-sequences are valid Unicode, so you have to expect decoding > exceptions, if you're processing text. The input is not in my control, and bailing out may not be an option: $ echo $'aa\n\xdd\naa' | grep aa aa aa $ echo $'\xdd' | python2 -c 'import sys; sys.stdin.read(1)' $ echo $'\xdd' | python3 -c 'import sys; sys.stdin.read(1)' Traceback (most recent call last): File "", line 1, in File "/usr/lib64/python3.5/codecs.py", line 321, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 0: invalid continuation byte Note that "grep" is also locale-aware. >> There recently was a related debate on the Guile mailing list. Like >> Python3, Guile2 is sensitive to illegal UTF-8 on the command line and >> in the standard streams. An emacs developer was urging Guile >> developers to follow emacs's example and support a superset of UTF-8 >> and Unicode where all byte strings can be bijectively mapped into >> text. > > I'd like to read that. Got a link? Marko From rosuav at gmail.com Thu Mar 30 01:48:59 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2017 16:48:59 +1100 Subject: Python under PowerShell adds characters In-Reply-To: <87efxf8gkt.fsf@elektro.pacujo.net> References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> <87o9wj986r.fsf@elektro.pacujo.net> <58dc4e04$0$1599$c3e8da3$5496439d@news.astraweb.com> <87inmr8k03.fsf@elektro.pacujo.net> <58dc923c$0$2751$c3e8da3$76491128@news.astraweb.com> <87efxf8gkt.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 30, 2017 at 4:43 PM, Marko Rauhamaa wrote: > The input is not in my control, and bailing out may not be an option: > > $ echo > aa\n\xdd\naa' | grep aa > aa > aa > $ echo \xdd' | python2 -c 'import sys; sys.stdin.read(1)' > $ echo \xdd' | python3 -c 'import sys; sys.stdin.read(1)' > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python3.5/codecs.py", line 321, in decode > (result, consumed) = self._buffer_decode(data, self.errors, final) > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 0: > invalid continuation byte > > Note that "grep" is also locale-aware. So what exactly does byte value 0xDD mean in your stream? And if you say "it doesn't matter", then why are you assigning meaning to byte value 0x0A in your first example? Truly binary data doesn't give any meaning to 0x0A. ChrisA From marko at pacujo.net Thu Mar 30 01:57:00 2017 From: marko at pacujo.net (Marko Rauhamaa) Date: Thu, 30 Mar 2017 08:57:00 +0300 Subject: Python under PowerShell adds characters References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> <87o9wj986r.fsf@elektro.pacujo.net> <58dc4e04$0$1599$c3e8da3$5496439d@news.astraweb.com> <87inmr8k03.fsf@elektro.pacujo.net> <58dc923c$0$2751$c3e8da3$76491128@news.astraweb.com> <87efxf8gkt.fsf@elektro.pacujo.net> Message-ID: <87a8838fyr.fsf@elektro.pacujo.net> Chris Angelico : > On Thu, Mar 30, 2017 at 4:43 PM, Marko Rauhamaa wrote: >> The input is not in my control, and bailing out may not be an option: >> >> $ echo >> aa\n\xdd\naa' | grep aa >> aa >> aa >> $ echo \xdd' | python2 -c 'import sys; sys.stdin.read(1)' >> $ echo \xdd' | python3 -c 'import sys; sys.stdin.read(1)' >> Traceback (most recent call last): >> File "", line 1, in >> File "/usr/lib64/python3.5/codecs.py", line 321, in decode >> (result, consumed) = self._buffer_decode(data, self.errors, final) >> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 0: >> invalid continuation byte >> >> Note that "grep" is also locale-aware. > > So what exactly does byte value 0xDD mean in your stream? > > And if you say "it doesn't matter", then why are you assigning meaning > to byte value 0x0A in your first example? Truly binary data doesn't > give any meaning to 0x0A. What I'm saying is that every program must behave in a minimally controlled manner regardless of its inputs (which are not in its control). With UTF-8, it is dangerously easy to write programs that explode surprisingly. What's more, resyncing after such exceptions is not at all easy. I would venture to guess that few Python programs even try to do that. Marko From rosuav at gmail.com Thu Mar 30 02:03:20 2017 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Mar 2017 17:03:20 +1100 Subject: Python under PowerShell adds characters In-Reply-To: <87a8838fyr.fsf@elektro.pacujo.net> References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> <87o9wj986r.fsf@elektro.pacujo.net> <58dc4e04$0$1599$c3e8da3$5496439d@news.astraweb.com> <87inmr8k03.fsf@elektro.pacujo.net> <58dc923c$0$2751$c3e8da3$76491128@news.astraweb.com> <87efxf8gkt.fsf@elektro.pacujo.net> <87a8838fyr.fsf@elektro.pacujo.net> Message-ID: On Thu, Mar 30, 2017 at 4:57 PM, Marko Rauhamaa wrote: > What I'm saying is that every program must behave in a minimally > controlled manner regardless of its inputs (which are not in its > control). With UTF-8, it is dangerously easy to write programs that > explode surprisingly. What's more, resyncing after such exceptions is > not at all easy. I would venture to guess that few Python programs even > try to do that. If you expect to get a series of decimal integers, and you find a "Q" in the middle, is it dangerously easy for your program blow up? How do you resync after that? Do these questions even make sense? Not in my opinion; you got invalid data, so you throw an exception and stop reading data. ChrisA From songofacandy at gmail.com Thu Mar 30 04:30:22 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Thu, 30 Mar 2017 17:30:22 +0900 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: > > Running further trials indicate that the problem actually is related to > swapping. If I reduce the model size in the benchmark slightly so that > everything fits into the main memory, the problem disappears. Only when the > memory usage exceeds the 32GB that I have, Python 3.6 will acquire way more > memory (from the swap) than Python 3.5. > > Jan > -- It's very hard to believe... I think there are some factor other than swap cause the problem. Or, can't it reproducible in 64GB RAM machine? From pavol.lisy at gmail.com Thu Mar 30 08:23:03 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Thu, 30 Mar 2017 14:23:03 +0200 Subject: pandas dataframe, find duplicates and add suffix In-Reply-To: <5c15090c-34c1-4ded-a550-5207fae53a98@googlegroups.com> References: <5c15090c-34c1-4ded-a550-5207fae53a98@googlegroups.com> Message-ID: On 3/28/17, zljubisic at gmail.com wrote: > In dataframe > > import pandas as pd > > data = {'model': ['first', 'first', 'second', 'second', 'second', 'third', > 'third'], > 'dtime': ['2017-01-01_112233', '2017-01-01_112234', > '2017-01-01_112234', '2017-01-01_112234', '2017-01-01_112234', > '2017-01-01_112235', '2017-01-01_112235'], > } > df = pd.DataFrame(data, index = ['a.jpg', 'b.jpg', 'c.jpg', 'd.jpg', > 'e.jpg', 'f.jpg', 'g.jpg'], columns=['model', 'dtime']) > > print(df.head(10)) > > model dtime > a.jpg first 2017-01-01_112233 > b.jpg first 2017-01-01_112234 > c.jpg second 2017-01-01_112234 > d.jpg second 2017-01-01_112234 > e.jpg second 2017-01-01_112234 > f.jpg third 2017-01-01_112235 > g.jpg third 2017-01-01_112235 > > within model, there are duplicate dtime values. > For example, rows d and e are duplicates of the c row. > Row g is duplicate of the f row. > > For each duplicate (within model) I would like to add suffix (starting from > 1) to the dtime value. Something like this: > > model dtime > a.jpg first 2017-01-01_112233 > b.jpg first 2017-01-01_112234 > c.jpg second 2017-01-01_112234 > d.jpg second 2017-01-01_112234-1 > e.jpg second 2017-01-01_112234-2 > f.jpg third 2017-01-01_112235 > g.jpg third 2017-01-01_112235-1 > > How to do that? > -- > https://mail.python.org/mailman/listinfo/python-list > I am not expert, just played a little... This one could work: gb = df.groupby([df.model, df.dtime]) df.dtime = df.dtime + gb.cumcount().apply(lambda a:str(-a) if a else '') this one is probably more readable: df.dtime = df.dtime + [str(-a) if a else '' for a in gb.cumcount()] I don't know which one is better in memory consumption and/or speed. This small dataframe gave me: %timeit -r 5 df.dtime + gb.cumcount().apply(lambda a:str(-a) if a else '') 1000 loops, best of 5: 387 ?s per loop %timeit -r 5 df.dtime + [str(-a) if a else '' for a in gb.cumcount()] 1000 loops, best of 5: 324 ?s per loop PL. From pavol.lisy at gmail.com Thu Mar 30 08:48:19 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Thu, 30 Mar 2017 14:48:19 +0200 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: On 3/29/17, Jan Gosmann wrote: > On 28 Mar 2017, at 14:21, INADA Naoki wrote: > >> On Wed, Mar 29, 2017 at 12:29 AM, Jan Gosmann >> wrote: >> >> I suppose smaller and faster benchmark is better to others looking for >> it. >> I already stopped the azure instance. >> [...] >> There are no maxrss difference in "smaller existing examples"? >> [...] >> I want to investigate RAM usage, without any swapping. > > Running further trials indicate that the problem actually is related to > swapping. If I reduce the model size in the benchmark slightly so that > everything fits into the main memory, the problem disappears. Only when > the memory usage exceeds the 32GB that I have, Python 3.6 will acquire > way more memory (from the swap) than Python 3.5. > > Jan > -- > https://mail.python.org/mailman/listinfo/python-list Could you add table comparing time benchmarks when memory is bigger? (if your hypothesis is true and memory measurement tools are right than time difference has to be huge) Did you compare "pip list" results? There could be more differences in your environments (not only python version). For example different numpy versions or some missing packages could change game. I tried to search "except.*ImportError" in your repository, but I am not sure that it could change it significantly... ( https://github.com/ctn-archive/gosmann-frontiers2017/search?utf8=%E2%9C%93&q=ImportError&type= This one seems suspitious - sparse matrix class could be game changer from scipy.sparse import bsr_matrix assert bsr_matrix except (ValueError, ImportError): return False ) This one doesn't seems suspicious to me (but who knows?): try: import faulthandler faulthandler.enable() except: pass PL. From steve+python at pearwood.info Thu Mar 30 08:54:37 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Thu, 30 Mar 2017 23:54:37 +1100 Subject: Python under PowerShell adds characters References: <3a3a93ad-f642-48ce-adbc-3cdaa1739987@googlegroups.com> <87wpb799s1.fsf@elektro.pacujo.net> <87o9wj986r.fsf@elektro.pacujo.net> <58dc4e04$0$1599$c3e8da3$5496439d@news.astraweb.com> <87inmr8k03.fsf@elektro.pacujo.net> <58dc923c$0$2751$c3e8da3$76491128@news.astraweb.com> <87efxf8gkt.fsf@elektro.pacujo.net> Message-ID: <58dd000f$0$1621$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Mar 2017 04:43 pm, Marko Rauhamaa wrote: > Steven D'Aprano : > >> On Thu, 30 Mar 2017 07:29:48 +0300, Marko Rauhamaa wrote: >>> I'd expect not having to deal with Unicode decoding exceptions with >>> arbitrary input. >> >> That's just silly. If you have *arbitrary* bytes, not all >> byte-sequences are valid Unicode, so you have to expect decoding >> exceptions, if you're processing text. > > The input is not in my control, and bailing out may not be an option: You have to deal with bad input *somehow*. You can't just say it will never happen. If bailing out is not an option, then perhaps the solution is not to read stdin as Unicode text, if there's a chance that it actually doesn't contain Unicode text. Otherwise, you have to deal with any errors. ("Deal with" can include the case of not dealing with them at all, and just letting your script raise an exception.) > $ echo $'aa\n\xdd\naa' | grep aa > aa > aa > $ echo $'\xdd' | python2 -c 'import sys; sys.stdin.read(1)' > $ echo $'\xdd' | python3 -c 'import sys; sys.stdin.read(1)' > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib64/python3.5/codecs.py", line 321, in decode > (result, consumed) = self._buffer_decode(data, self.errors, final) > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xdd in position 0: > invalid continuation byte As I said, what did you expect? You choose to read from stdin as Unicode text, then fed it something that wasn't Unicode text. That's no different from expecting to read a file name, then passing an ASCII NUL byte. Something is going to break, somewhere, so you have to deal with it. I'm not sure if there are better ways, but one way of dealing with this is to bypass the text layer and read from the raw byte-oriented stream: [steve at ando ~]$ echo $'\xdd' | python3 -c 'import sys; print(sys.stdin.buffer.read(1))' b'\xdd' You have a choice. The default choice is aimed at the most-common use-case, which is that input will be text, but its not the only choice. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From mikhailwas at gmail.com Thu Mar 30 09:25:47 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 30 Mar 2017 15:25:47 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> Message-ID: On 30 March 2017 at 07:43, Chris Angelico wrote: > On Thu, Mar 30, 2017 at 3:21 PM, Rick Johnson > wrote: >> On Sunday, March 26, 2017 at 2:53:49 PM UTC-5, Chris Angelico wrote: >>> On Mon, Mar 27, 2017 at 6:25 AM, Mikhail V wrote: >>> > On 26 March 2017 at 20:10, Steve D'Aprano wrote: >>> >> On Mon, 27 Mar 2017 03:57 am, Mikhail V wrote: >> >>> """ >>> I, the undersigned, acknowledge that my program is >>> intentionally excluding everyone who does not fit the >>> following requirements: [choose all applicable] >>> >>> [ ] Speaks English exclusively >> >> Of course, your comment presupposing that every programmer >> is fluent in every natural language. Which is not only >> impractical, it's impossible. > > Nope. I can't speak Mandarin, but I can make absolutely sure that all > my programs can accept Chinese characters. A friend of mine sent me an > audio file with a name that included some Chinese, and I was able to > handle it no problem. > Naming files is another point. Generally if I can't speak Mandarin, I have no right to make support for it since I know nothing about this language nor do I know their symbols. >>> [ ] Uses no diacritical marks >> >> Why is it my responsibiliy to encode my text with >> pronuciation tutorials? Are we adults here or what? >> >>> [ ] Writes all text top-to-bottom, left-to-right >> >> Not my problem. Learn the King's English or go wait for >> extinction to arrive. > > And these two cement your parochialism thoroughly in everyone's minds. > "Pronunciation tutorials", eh? Sure. Tell that to everyone who speaks > Spanish, Turkish, Norwegian, German, or Vietnamese, all of which use > diacritical marks to distinguish between letters. English is the weird > language in that it uses letter pairs instead of adorned letters (eg > "ch" and "sh" instead of "?" and "?"). Because "Pronunciation tutorials" is one of rare excuses to use those special characters at all. Now do you know how many phonetical systems linguist have invented over past 200 years? Will you find all them in Unicode? And why you need them today, if you can learn pronunciation by audio tutorials? And letter pair usage is not for fun there, I think we've discussed this some time ago on python-ideas, it is merely a political problem, since every 'king' in each land suddenly thinks that he is a genius typographer and adds few custom characters to Latin after he realizes that there is no sense in forcing everyone to use some outdated system, or even rolls his own bizzare system (e.g. Hangul). >> What don't you add these: >> >> [ ] Has the ability to read and comprehend at a high >> school level. >> [ ] Has functioning visual receptors. >> [ ] Has a functioning brain. >> [ ] Is not currently in a vegetative state > > Nah. If I did, I'd have to say "[ ] Is not trolling python-list" as well. Call me a bigot, but I would say: [x] people, become adult finally and stop playing with your funny hieroglyphs, use Latin set, and concentrate on real problems. If I produce an arcade game or an IDE, would it lose much if I don't include Unicode support? I personally would not do it even in the fear of punishment. Mikhail From steve+python at pearwood.info Thu Mar 30 10:14:41 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 31 Mar 2017 01:14:41 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> Message-ID: <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Mar 2017 03:21 pm, Rick Johnson wrote: > On Sunday, March 26, 2017 at 2:53:49 PM UTC-5, Chris Angelico wrote: >> On Mon, Mar 27, 2017 at 6:25 AM, Mikhail V wrote: >> > On 26 March 2017 at 20:10, Steve D'Aprano >> > wrote: >> >> On Mon, 27 Mar 2017 03:57 am, Mikhail V wrote: > >> I generally find that when people say that Unicode doesn't >> solve their problems and they need to roll their own, it's >> usually one of two possibilities: 1) "Their problems" are >> all about simplicity. They don't want to have to deal with >> all the complexities of real-world text, so they >> arbitrarily restrict things. > > There are only so many hours in the day Chris. Not every > progammer has the time to cater to every selfish desire of > every potential client. Oh, you're one of *those* coders. The ones who believe that if they personally don't need something, nobody needs it. Listen, I'm 100% in favour of the open source model. I think that coders who scratch their own itch is a great way to produce some really fantastic software. Look at the Linux kernel, and think about how that has evolved from Linus Torvalds scratching his own itch. It can also produce some real garbage too, usually from the kind of coder whose answer to everything is "you don't need to do that". But whatever, its a free country. If you don't want to support a subset of your potential users, or customers, that's entirely up to you. The honest truth is that most software ends up languishing in obscurity, only used by a relative handful of people, so its quite unlikely that you'll every have any users wanting support for Old Persian or Ogham. But if you have any users at all, there's a good chance they'll want to write their name correctly even if they are called Z?e, or include the trademarked name of their Awesome? product, or write the name of that hot new metal band TH??SH?R, or use emoji, or to refer to ? and ?F temperatures. You might call it "selfish" for somebody to want to spell their name correctly, or write in their native language, but selfish or not if you don't give your users the features they want, they are unlikely to use your software. Outside of the Democratic People's Republic of Trumpistan, the world is full of about seven billion people who don't have any interest in your ASCII-only software. It's not 1970 any more, the world is connected. And the brilliant thing about Unicode is that for a little bit of effort you can support Z?e and her French girlfriends, and that Swedish metal band with the umlauts, and the President's Russian backers, and once you've done that, you get at least partial support for Hebrew and Chinese and Korean and Vietnamese and a dozen different Indian languages, and even Old Persian and Ogham, FOR FREE. So if you're wanting to create "the best product you can", why *wouldn't* you use Unicode? > You try to create the best product you can, > but at the end of the process, there will always be > someone (or a group of someones) who are unhappy with the > result. [...] >> [ ] Speaks English exclusively > > Of course, your comment presupposing that every programmer > is fluent in every natural language. Which is not only > impractical, it's impossible. Don't be silly. You don't have to be fluent in a language in order for your program to support users who are. All you have to do is not stop them from using their own native language by forcing them to use ASCII and nothing but ASCII. Of course, if you want to *localise* your UI to their language, then you need somebody to translate error messages, menus, window titles, etc. I'll grant that's not always an easy job. But aren't you lucky, you speak one of a handful of lingua francas in the world, so the chances are your users will be pathetically grateful if all you do is let them type in their own language. Actual UI localisation is a bonus. >> [ ] Uses no diacritical marks > > Why is it my responsibiliy to encode my text with > pronuciation tutorials? Are we adults here or what? Now you're just being absurd. Supporting diacritics doesn't mean you are responsible for teaching your users what they're for. They already know. That's why they want to use them. Diacritics are for: - distinguishing between words which look the same, but have different pronunciation; - distinguishing between different letters of the alphabet, like dotted-i and dotless-? (or ? and ?-with-a-dot, if you prefer), or a and ?; - distinguishing between words which look and sound the same but mean something different; - and making band names look ???? and annoy old fuddy-duddies. >> [ ] Writes all text top-to-bottom, left-to-right > > Not my problem. Learn the King's English or go wait for > extinction to arrive. Which king? Harald V speaks Norwegian, Felipe VI speaks Spanish, Hamad bin Isa speaks whatever they speak in Bahrain (probably Arabic), Norodom Sihamoni speaks Cambodian, Vajiralongkorn speaks Thai, Mswati III speaks Swazi, Abdullah II speaks Jordanian (Arabic?), Willem-Alexander speaks Dutch, Salman bin Abdul'aziz speaks Arabic. I've probably missed a few other kings. When extinction arrives, speaking English isn't going to hold it at bay. If anything, English speakers (or at least, *American* speakers) are likely to be the ones bringing it on. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From steve+python at pearwood.info Thu Mar 30 10:16:48 2017 From: steve+python at pearwood.info (Steve D'Aprano) Date: Fri, 31 Mar 2017 01:16:48 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> Message-ID: <58dd1350$0$1611$c3e8da3$5496439d@news.astraweb.com> On Fri, 31 Mar 2017 12:25 am, Mikhail V wrote: > Call me a bigot Okay. You're a bigot. -- Steve ?Cheer up,? they said, ?things could be worse.? So I cheered up, and sure enough, things got worse. From rosuav at gmail.com Thu Mar 30 10:59:18 2017 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Mar 2017 01:59:18 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dd1350$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd1350$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Mar 31, 2017 at 1:16 AM, Steve D'Aprano wrote: > On Fri, 31 Mar 2017 12:25 am, Mikhail V wrote: > >> Call me a bigot > > Okay. You're a bigot. +1 QOTD ChrisA From saxri89 at gmail.com Thu Mar 30 11:06:48 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Thu, 30 Mar 2017 08:06:48 -0700 (PDT) Subject: django authentication multi upload files Message-ID: <02b0d23a-3c7e-411b-9065-ecc4618d987a@googlegroups.com> I have create I simple Django auth project and I need to add the user to can upload some images. multi upload images from internet views.py from django.shortcuts import render from django.http import HttpResponse def Form(request): return render(request, "index/form.html", {}) def Upload(request): for count, x in enumerate(request.FILES.getlist("files")): def process(f): with open('/Users/Michel/django_1.8/projects/upload/media/file_' + str(count), 'wb+') as destination: for chunk in f.chunks(): destination.write(chunk) process(x) return HttpResponse("File(s) uploaded!") but how to define that to multi upload images in specific unique folder for any user. first I use login_required and in destination I use user_directory_path. But how to define the code in the views.py to work with authentication per user. for example for user_1 upload images in your folder for user_1 in folder for user_2. medels.py def user_directory_path(instance, filename): return 'user_{0}/{1}'.format(instance.user.id, filename) class MyModel(models.Model): user = models.ForeignKey(User, unique=True) upload = models.ImageField(upload_to=user_directory_path) From saxri89 at gmail.com Thu Mar 30 11:07:31 2017 From: saxri89 at gmail.com (Xristos Xristoou) Date: Thu, 30 Mar 2017 08:07:31 -0700 (PDT) Subject: add processing images in the model.py using django Message-ID: <489dcfdd-398a-4517-9819-3639794451a2@googlegroups.com> want to create a simple image processing using Django. my tasks is easy I have some user a simple model and that user can upload images in my project using html form or django form and then that images saves to upload_to='mypath' in upload from my model. but I have some questions : I have a simple image processing in my views.py if the processing complete success then create new image and I want that image to add in the upload from my model . how to do that in Django ? models.py class MyModel(models.Model): user = models.ForeignKey(User) upload = models.ImageField(upload_to='mypath/personal/folder/per/user') views.py def index(request): form = ImageUploadForm(request.POST or None, request.FILES or None) if request.method == "POST" and form.is_valid(): image_file = request.FILES['image'].read() ''' image processing new image ''' return render_to_response("blog/success.html", {"new image":new image}) return render_to_response('blog/images.html', {'form': form}, RequestContext(request)) From torriem at gmail.com Thu Mar 30 11:36:39 2017 From: torriem at gmail.com (Michael Torrie) Date: Thu, 30 Mar 2017 09:36:39 -0600 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <6641a3fa-9189-973a-a553-d4428cf5d82f@gmail.com> On 03/30/2017 08:14 AM, Steve D'Aprano wrote: >> Why is it my responsibiliy to encode my text with >> pronuciation tutorials? Are we adults here or what? > > Now you're just being absurd. Ahh yes, good old RR with his reductio ad absurdum fallacies when he's lost the argument. From mikhailwas at gmail.com Thu Mar 30 11:57:12 2017 From: mikhailwas at gmail.com (Mikhail V) Date: Thu, 30 Mar 2017 17:57:12 +0200 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 30 March 2017 at 16:14, Steve D'Aprano wrote: > On Thu, 30 Mar 2017 03:21 pm, Rick Johnson wrote: > >> On Sunday, March 26, 2017 at 2:53:49 PM UTC-5, Chris Angelico wrote: >>> On Mon, Mar 27, 2017 at 6:25 AM, Mikhail V wrote: >>> > On 26 March 2017 at 20:10, Steve D'Aprano >>> > wrote: >>> [ ] Uses no diacritical marks >> >> Why is it my responsibiliy to encode my text with >> pronuciation tutorials? Are we adults here or what? > > Now you're just being absurd. Supporting diacritics doesn't mean you are > responsible for teaching your users what they're for. They already know. > That's why they want to use them. > > Diacritics are for: > > - distinguishing between words which look the same, but have > different pronunciation; > > - distinguishing between different letters of the alphabet, like > dotted-i and dotless-? (or ? and ?-with-a-dot, if you prefer), > or a and ?; > > - distinguishing between words which look and sound the same but > mean something different; > > - and making band names look ???? and annoy old fuddy-duddies. > Steve, it is not bad to want to spell your name using spelling which was taught you in the school. But it is bad to stay in illusion that there is something good in using accents. As said it _is_ selfish to force people to use e.g. umlauts and noun Capitalisations in German. It is an big obstacle for reading and burdle for typing. Initially it has nothing to do with people's choice, it is politics only. I can speak and write German fluently, so I know how much better would it be without those odd spelling rules. So don't mix the spoken language and writing system - spoken language will never be extinct, but most writing systems will be obsolete and should be obsolete (you can call me bigot again ;-) Some other interesting aspects: if I localise a software in Russian language and use Cyrillic letters, english speakers will not be able to read _anything_, and if I'll use Latin letters instead, then non-russian users will be at least able to read something, so if you know some Russian spoken language it will be much more help for you. Concrete software example - lets say I make an IDE. It is far more important to give the users mechanisms to customize the glyphs (e.g. edit math signs) than supporting Unicode. And therefore it is much more important to make those font format definitions transparent, non-bloated and easily editable. Where is it all? Mikhail From rhodri at kynesim.co.uk Thu Mar 30 12:10:19 2017 From: rhodri at kynesim.co.uk (Rhodri James) Date: Thu, 30 Mar 2017 17:10:19 +0100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> <58dd12d2$0$1611$c3e8da3$5496439d@news.astraweb.com> Message-ID: <59128b80-0398-4100-411d-73184ed787c0@kynesim.co.uk> On 30/03/17 16:57, Mikhail V wrote: > Steve, it is not bad to want to spell your name using spelling which > was taught you in the school. But it is bad to stay in illusion that there > is something good in using accents. *plonk* -- Rhodri James *-* Kynesim Ltd From songofacandy at gmail.com Thu Mar 30 13:34:33 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Fri, 31 Mar 2017 02:34:33 +0900 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: I reproduced the issue. This is very usual, memory usage issue. Slashing is just a result of large memory usage. After 1st pass of optimization, RAM usage is 20GB+ on Python 3.5 and 30GB on Python 3.6. And Python 3.6 starts slashing in 2nd optimization pass. I enabled tracemalloc while 1st pass. Results is end of this mail. It seems frozenset() cause regression, but I'm not sure yet. I don't know what is contents of frozenset yet. (I know almost nothing about this application). Jan, do you know about what this is? Could you make script which just runs `transitive_closure(edges)` with edges similar to `log_reduction.py spaun`? I'll dig into it later, maybe next week. --- Python 3.6.1 1191896 memory blocks: 22086104.2 KiB File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", line 85 reachables[vertex] = frozenset(reachables[vertex]) File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", line 410 self.dependents = transitive_closure(self.dg.forward) 602986 memory blocks: 51819.1 KiB File "", line 14 File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", line 634 first_view=None, v_offset=0, v_size=0, v_base=None) Python 3.5.3 1166804 memory blocks: 11116407.0 KiB File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", line 85 reachables[vertex] = frozenset(reachables[vertex]) File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", line 410 self.dependents = transitive_closure(self.dg.forward) 602989 memory blocks: 51819.3 KiB File "", line 14 File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", line 634 first_view=None, v_offset=0, v_size=0, v_base=None) From songofacandy at gmail.com Thu Mar 30 14:04:15 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Fri, 31 Mar 2017 03:04:15 +0900 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: Maybe, this commit make this regression. https://github.com/python/cpython/commit/4897300276d870f99459c82b937f0ac22450f0b6 Old: minused = (so->used + other->used)*2 (L619) New: minused = so->used + other->used (L620) minused = (minused > 50000) ? minused * 2 : minused * 4; (L293) So size of small set is doubled. $ /usr/bin/python3 Python 3.5.2+ (default, Sep 22 2016, 12:18:14) [GCC 6.2.0 20160927] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> s = set(range(10)) >>> sys.getsizeof(frozenset(s)) 736 >>> $ python3 Python 3.6.0 (default, Dec 30 2016, 20:49:54) [GCC 6.2.0 20161005] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> s = set(range(10)) >>> sys.getsizeof(frozenset(s)) 1248 >>> On Fri, Mar 31, 2017 at 2:34 AM, INADA Naoki wrote: > I reproduced the issue. > This is very usual, memory usage issue. Slashing is just a result of > large memory usage. > > After 1st pass of optimization, RAM usage is 20GB+ on Python 3.5 and > 30GB on Python 3.6. > And Python 3.6 starts slashing in 2nd optimization pass. > > I enabled tracemalloc while 1st pass. Results is end of this mail. > It seems frozenset() cause regression, but I'm not sure yet. > I don't know what is contents of frozenset yet. (I know almost > nothing about this application). > > Jan, do you know about what this is? > Could you make script which just runs `transitive_closure(edges)` with > edges similar to > `log_reduction.py spaun`? > > I'll dig into it later, maybe next week. > > --- > Python 3.6.1 > 1191896 memory blocks: 22086104.2 KiB > File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", > line 85 > reachables[vertex] = frozenset(reachables[vertex]) > File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", > line 410 > self.dependents = transitive_closure(self.dg.forward) > 602986 memory blocks: 51819.1 KiB > File "", line 14 > File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", > line 634 > first_view=None, v_offset=0, v_size=0, v_base=None) > > Python 3.5.3 > 1166804 memory blocks: 11116407.0 KiB > File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", > line 85 > reachables[vertex] = frozenset(reachables[vertex]) > File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", > line 410 > self.dependents = transitive_closure(self.dg.forward) > 602989 memory blocks: 51819.3 KiB > File "", line 14 > File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", > line 634 > first_view=None, v_offset=0, v_size=0, v_base=None) From songofacandy at gmail.com Thu Mar 30 14:09:55 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Fri, 31 Mar 2017 03:09:55 +0900 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: Filed an issue: https://bugs.python.org/issue29949 Thanks for your report, Jan. On Fri, Mar 31, 2017 at 3:04 AM, INADA Naoki wrote: > Maybe, this commit make this regression. > > https://github.com/python/cpython/commit/4897300276d870f99459c82b937f0ac22450f0b6 > > Old: > minused = (so->used + other->used)*2 (L619) > > New: > minused = so->used + other->used (L620) > minused = (minused > 50000) ? minused * 2 : minused * 4; (L293) > > So size of small set is doubled. > > $ /usr/bin/python3 > Python 3.5.2+ (default, Sep 22 2016, 12:18:14) > [GCC 6.2.0 20160927] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> s = set(range(10)) >>>> sys.getsizeof(frozenset(s)) > 736 >>>> > > $ python3 > Python 3.6.0 (default, Dec 30 2016, 20:49:54) > [GCC 6.2.0 20161005] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> s = set(range(10)) >>>> sys.getsizeof(frozenset(s)) > 1248 >>>> > > > > On Fri, Mar 31, 2017 at 2:34 AM, INADA Naoki wrote: >> I reproduced the issue. >> This is very usual, memory usage issue. Slashing is just a result of >> large memory usage. >> >> After 1st pass of optimization, RAM usage is 20GB+ on Python 3.5 and >> 30GB on Python 3.6. >> And Python 3.6 starts slashing in 2nd optimization pass. >> >> I enabled tracemalloc while 1st pass. Results is end of this mail. >> It seems frozenset() cause regression, but I'm not sure yet. >> I don't know what is contents of frozenset yet. (I know almost >> nothing about this application). >> >> Jan, do you know about what this is? >> Could you make script which just runs `transitive_closure(edges)` with >> edges similar to >> `log_reduction.py spaun`? >> >> I'll dig into it later, maybe next week. >> >> --- >> Python 3.6.1 >> 1191896 memory blocks: 22086104.2 KiB >> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 85 >> reachables[vertex] = frozenset(reachables[vertex]) >> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 410 >> self.dependents = transitive_closure(self.dg.forward) >> 602986 memory blocks: 51819.1 KiB >> File "", line 14 >> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 634 >> first_view=None, v_offset=0, v_size=0, v_base=None) >> >> Python 3.5.3 >> 1166804 memory blocks: 11116407.0 KiB >> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 85 >> reachables[vertex] = frozenset(reachables[vertex]) >> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 410 >> self.dependents = transitive_closure(self.dg.forward) >> 602989 memory blocks: 51819.3 KiB >> File "", line 14 >> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 634 >> first_view=None, v_offset=0, v_size=0, v_base=None) From jan at hyper-world.de Thu Mar 30 14:14:37 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Thu, 30 Mar 2017 14:14:37 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: <6e398b4c-5758-69e2-f966-6b88717e67ae@hyper-world.de> That's great news. I'm busy with other things right now, but will look into your findings in more detail later. On 03/30/2017 02:09 PM, INADA Naoki wrote: > Filed an issue: https://bugs.python.org/issue29949 > > Thanks for your report, Jan. > > On Fri, Mar 31, 2017 at 3:04 AM, INADA Naoki wrote: >> Maybe, this commit make this regression. >> >> https://github.com/python/cpython/commit/4897300276d870f99459c82b937f0ac22450f0b6 >> >> Old: >> minused = (so->used + other->used)*2 (L619) >> >> New: >> minused = so->used + other->used (L620) >> minused = (minused > 50000) ? minused * 2 : minused * 4; (L293) >> >> So size of small set is doubled. >> >> $ /usr/bin/python3 >> Python 3.5.2+ (default, Sep 22 2016, 12:18:14) >> [GCC 6.2.0 20160927] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import sys >>>>> s = set(range(10)) >>>>> sys.getsizeof(frozenset(s)) >> 736 >> $ python3 >> Python 3.6.0 (default, Dec 30 2016, 20:49:54) >> [GCC 6.2.0 20161005] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> import sys >>>>> s = set(range(10)) >>>>> sys.getsizeof(frozenset(s)) >> 1248 >> >> >> On Fri, Mar 31, 2017 at 2:34 AM, INADA Naoki wrote: >>> I reproduced the issue. >>> This is very usual, memory usage issue. Slashing is just a result of >>> large memory usage. >>> >>> After 1st pass of optimization, RAM usage is 20GB+ on Python 3.5 and >>> 30GB on Python 3.6. >>> And Python 3.6 starts slashing in 2nd optimization pass. >>> >>> I enabled tracemalloc while 1st pass. Results is end of this mail. >>> It seems frozenset() cause regression, but I'm not sure yet. >>> I don't know what is contents of frozenset yet. (I know almost >>> nothing about this application). >>> >>> Jan, do you know about what this is? >>> Could you make script which just runs `transitive_closure(edges)` with >>> edges similar to >>> `log_reduction.py spaun`? >>> >>> I'll dig into it later, maybe next week. >>> >>> --- >>> Python 3.6.1 >>> 1191896 memory blocks: 22086104.2 KiB >>> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >>> line 85 >>> reachables[vertex] = frozenset(reachables[vertex]) >>> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >>> line 410 >>> self.dependents = transitive_closure(self.dg.forward) >>> 602986 memory blocks: 51819.1 KiB >>> File "", line 14 >>> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >>> line 634 >>> first_view=None, v_offset=0, v_size=0, v_base=None) >>> >>> Python 3.5.3 >>> 1166804 memory blocks: 11116407.0 KiB >>> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >>> line 85 >>> reachables[vertex] = frozenset(reachables[vertex]) >>> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >>> line 410 >>> self.dependents = transitive_closure(self.dg.forward) >>> 602989 memory blocks: 51819.3 KiB >>> File "", line 14 >>> File "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >>> line 634 >>> first_view=None, v_offset=0, v_size=0, v_base=None) From songofacandy at gmail.com Thu Mar 30 14:19:12 2017 From: songofacandy at gmail.com (INADA Naoki) Date: Fri, 31 Mar 2017 03:19:12 +0900 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: <6e398b4c-5758-69e2-f966-6b88717e67ae@hyper-world.de> References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> <6e398b4c-5758-69e2-f966-6b88717e67ae@hyper-world.de> Message-ID: FYI, this small patch may fix your issue: https://gist.github.com/methane/8faf12621cdb2166019bbcee65987e99 From Ross.Boylan at ucsf.edu Thu Mar 30 16:57:33 2017 From: Ross.Boylan at ucsf.edu (Boylan, Ross) Date: Thu, 30 Mar 2017 20:57:33 +0000 Subject: error in syntax description for comprehensions? Message-ID: https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries describes the syntax for comprehensions as comprehension ::= expression comp_for comp_for ::= [ASYNC] "for" target_list "in" or_test [comp_iter] comp_iter ::= comp_for | comp_if comp_if ::= "if" expression_nocond [comp_iter] Is the comp_for missing an argument after "in"? One has to follow the definition of or_test and its components, but I can't find anything that results to a single variable or expression. Actually, I'm not sure what or_test would do there either with or without an additional element following "in". Ross Boylan From ned at nedbatchelder.com Thu Mar 30 19:31:41 2017 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 30 Mar 2017 16:31:41 -0700 (PDT) Subject: error in syntax description for comprehensions? In-Reply-To: References: Message-ID: On Thursday, March 30, 2017 at 4:59:03 PM UTC-4, Boylan, Ross wrote: > https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries > describes the syntax for comprehensions as > comprehension ::= expression comp_for > comp_for ::= [ASYNC] "for" target_list "in" or_test [comp_iter] > comp_iter ::= comp_for | comp_if > comp_if ::= "if" expression_nocond [comp_iter] > > Is the comp_for missing an argument after "in"? > One has to follow the definition of or_test and its components, but I can't find anything that results to a single variable or expression. > > Actually, I'm not sure what or_test would do there either with or without an additional element following "in". Syntax grammars can be obtuse. An or_test can be an and_test, which can be a not_test, which can be a comparison. It continues from there. The whole chain of "can be" is: or_test and_test not_test comparison or_expr xor_expr and_expr shift_expr a_expr m_expr u_expr power primary atom identifier ... and identifier is what you are looking for. --Ned. From python at mrabarnett.plus.com Thu Mar 30 20:18:34 2017 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 31 Mar 2017 01:18:34 +0100 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: On 2017-03-30 19:04, INADA Naoki wrote: > Maybe, this commit make this regression. > > https://github.com/python/cpython/commit/4897300276d870f99459c82b937f0ac22450f0b6 > > Old: > minused = (so->used + other->used)*2 (L619) > > New: > minused = so->used + other->used (L620) > minused = (minused > 50000) ? minused * 2 : minused * 4; (L293) > > So size of small set is doubled. > > $ /usr/bin/python3 > Python 3.5.2+ (default, Sep 22 2016, 12:18:14) > [GCC 6.2.0 20160927] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> s = set(range(10)) >>>> sys.getsizeof(frozenset(s)) > 736 >>>> > > $ python3 > Python 3.6.0 (default, Dec 30 2016, 20:49:54) > [GCC 6.2.0 20161005] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> s = set(range(10)) >>>> sys.getsizeof(frozenset(s)) > 1248 >>>> Copying a small set _might_ double its memory usage. Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> s = set(range(10)) >>> sys.getsizeof(s) 736 >>> sys.getsizeof(set(s)) 736 >>> >>> sys.getsizeof(set(set(s))) 736 Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> s = set(range(10)) >>> sys.getsizeof(s) 736 >>> sys.getsizeof(set(s)) 1248 >>> >>> sys.getsizeof(set(set(s))) 1248 >>> From tjreedy at udel.edu Thu Mar 30 20:43:21 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Mar 2017 20:43:21 -0400 Subject: error in syntax description for comprehensions? In-Reply-To: References: Message-ID: On 3/30/2017 4:57 PM, Boylan, Ross wrote: > https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries > describes the syntax for comprehensions as > comprehension ::= expression comp_for > comp_for ::= [ASYNC] "for" target_list "in" or_test [comp_iter] > comp_iter ::= comp_for | comp_if > comp_if ::= "if" expression_nocond [comp_iter] > > Is the comp_for missing an argument after "in"? The or_test *is* the 'argument'. > One has to follow the definition of or_test and its components, > but I can't find anything that results to a single variable > or expression. An or_test *is* a single expression. Like all python expressions, it evaluates to a python object. In this case, the object is passed to iter() and so the object must be an iterable. >>> a, b = None, range(3) >>> a or b range(0, 3) >>> for i in a or b: print(i) 0 1 2 -- Terry Jan Reedy From pavol.lisy at gmail.com Fri Mar 31 00:09:14 2017 From: pavol.lisy at gmail.com (Pavol Lisy) Date: Fri, 31 Mar 2017 06:09:14 +0200 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: On 3/30/17, INADA Naoki wrote: > Maybe, this commit make this regression. > > https://github.com/python/cpython/commit/4897300276d870f99459c82b937f0ac22450f0b6 > > Old: > minused = (so->used + other->used)*2 (L619) > > New: > minused = so->used + other->used (L620) > minused = (minused > 50000) ? minused * 2 : minused * 4; (L293) > > So size of small set is doubled. > > $ /usr/bin/python3 > Python 3.5.2+ (default, Sep 22 2016, 12:18:14) > [GCC 6.2.0 20160927] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> s = set(range(10)) >>>> sys.getsizeof(frozenset(s)) > 736 >>>> > > $ python3 > Python 3.6.0 (default, Dec 30 2016, 20:49:54) > [GCC 6.2.0 20161005] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import sys >>>> s = set(range(10)) >>>> sys.getsizeof(frozenset(s)) > 1248 >>>> > > > > On Fri, Mar 31, 2017 at 2:34 AM, INADA Naoki > wrote: >> I reproduced the issue. >> This is very usual, memory usage issue. Slashing is just a result of >> large memory usage. >> >> After 1st pass of optimization, RAM usage is 20GB+ on Python 3.5 and >> 30GB on Python 3.6. >> And Python 3.6 starts slashing in 2nd optimization pass. >> >> I enabled tracemalloc while 1st pass. Results is end of this mail. >> It seems frozenset() cause regression, but I'm not sure yet. >> I don't know what is contents of frozenset yet. (I know almost >> nothing about this application). >> >> Jan, do you know about what this is? >> Could you make script which just runs `transitive_closure(edges)` with >> edges similar to >> `log_reduction.py spaun`? >> >> I'll dig into it later, maybe next week. >> >> --- >> Python 3.6.1 >> 1191896 memory blocks: 22086104.2 KiB >> File >> "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 85 >> reachables[vertex] = frozenset(reachables[vertex]) >> File >> "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 410 >> self.dependents = transitive_closure(self.dg.forward) >> 602986 memory blocks: 51819.1 KiB >> File "", line 14 >> File >> "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 634 >> first_view=None, v_offset=0, v_size=0, v_base=None) >> >> Python 3.5.3 >> 1166804 memory blocks: 11116407.0 KiB >> File >> "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 85 >> reachables[vertex] = frozenset(reachables[vertex]) >> File >> "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 410 >> self.dependents = transitive_closure(self.dg.forward) >> 602989 memory blocks: 51819.3 KiB >> File "", line 14 >> File >> "/home/inada-n/work/gosmann-frontiers2017/gosmann_frontiers2017/optimized/optimizer.py", >> line 634 >> first_view=None, v_offset=0, v_size=0, v_base=None) > -- > https://mail.python.org/mailman/listinfo/python-list > Interesting. 1. using set_table_resize with growing factor 2 or 4 doesn't seem to be optimal for constructing (immutable) frozenset from set. 2. growth factor 2 could be too big too ( https://en.wikipedia.org/wiki/Dynamic_array#Growth_factor ,https://github.com/python/cpython/blob/80ec8364f15857c405ef0ecb1e758c8fc6b332f7/Objects/listobject.c#L58 ) PL. From lopium at gmail.com Fri Mar 31 04:27:54 2017 From: lopium at gmail.com (Ricardo A Baila) Date: Fri, 31 Mar 2017 01:27:54 -0700 (PDT) Subject: Spam user Message-ID: <058a9744-44bf-4e6b-ae1d-28e1e348e60b@googlegroups.com> Hi all, Could someone remove wucbadruc at gmx.com from the group? Thanks Ricardo From lopium at gmail.com Fri Mar 31 04:31:14 2017 From: lopium at gmail.com (Ricardo A Baila) Date: Fri, 31 Mar 2017 01:31:14 -0700 (PDT) Subject: Spam user In-Reply-To: <058a9744-44bf-4e6b-ae1d-28e1e348e60b@googlegroups.com> References: <058a9744-44bf-4e6b-ae1d-28e1e348e60b@googlegroups.com> Message-ID: <7770d247-5ee7-4dd9-956f-13b3755db97a@googlegroups.com> Le vendredi 31 mars 2017 10:28:08 UTC+2, Ricardo A Baila a ?crit?: > Hi all, > > Could someone remove wucbadruc at gmx.com from the group? > > Thanks > Ricardo And johnnypoponny at gmx.com as well. Didn't go deep on the issue but could it be @gmx.com the issue? Or at least, as the message is always the same, couldn't admins filter it or something? It's getting to proportions in terms of frequency where it makes the group really unreadable. Best, Ricardo From lele at metapensiero.it Fri Mar 31 05:07:06 2017 From: lele at metapensiero.it (Lele Gaifax) Date: Fri, 31 Mar 2017 11:07:06 +0200 Subject: Spam user References: <058a9744-44bf-4e6b-ae1d-28e1e348e60b@googlegroups.com> Message-ID: <87wpb5izlx.fsf@metapensiero.it> Ricardo A Baila writes: > Could someone remove wucbadruc at gmx.com from the group? Strange, I could not see such messages, neither in the newsgroup (gmane) nor on the ML archives. Are you sure you are not receiving those as private messages? ciao, lele. -- nickname: Lele Gaifax | Quando vivr? di quello che ho pensato ieri real: Emanuele Gaifas | comincer? ad aver paura di chi mi copia. lele at metapensiero.it | -- Fortunato Depero, 1929. From tjreedy at udel.edu Fri Mar 31 05:22:52 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Mar 2017 05:22:52 -0400 Subject: Spam user In-Reply-To: <87wpb5izlx.fsf@metapensiero.it> References: <058a9744-44bf-4e6b-ae1d-28e1e348e60b@googlegroups.com> <87wpb5izlx.fsf@metapensiero.it> Message-ID: On 3/31/2017 5:07 AM, Lele Gaifax wrote: > Ricardo A Baila writes: Are you reading through Google Groups? >> Could someone remove wucbadruc at gmx.com from the group? > Strange, I could not see such messages, neither in the newsgroup (gmane) nor > on the ML archives. If so, send your request to the Google Group admins, who allow much spam filtered out by python.org. And/or switch to reading the python.org list or the news.gmane.org newsgroup mirror. > Are you sure you are not receiving those as private messages? GG trash is more likely. -- Terry Jan Reedy From ammammata at tiscalinet.it Fri Mar 31 06:07:23 2017 From: ammammata at tiscalinet.it (Ammammata) Date: Fri, 31 Mar 2017 10:07:23 +0000 (UTC) Subject: Spam user References: <058a9744-44bf-4e6b-ae1d-28e1e348e60b@googlegroups.com> Message-ID: Il giorno Fri 31 Mar 2017 10:27:54a, *Ricardo A Baila* ha inviato su comp.lang.python il messaggio news:058a9744-44bf-4e6b-ae1d-28e1e348e60b at googlegroups.com. Vediamo cosa ha scritto: > User-Agent: G2/1.0 > > Could someone remove wucbadruc at gmx.com from the group? > you better switch to a decent newsreader and learn how to use filters ;) g2 has no plonk list -- /-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\ -=- -=- -=- -=- -=- -=- -=- -=- - -=- >>>>> http://www.bb2002.it :) <<<<< ........... [ al lavoro ] ........... From zouyuheng1998 at gmail.com Fri Mar 31 09:52:09 2017 From: zouyuheng1998 at gmail.com (Yuheng Zou) Date: Fri, 31 Mar 2017 06:52:09 -0700 (PDT) Subject: Developing a Python JIT and have trouble Message-ID: I am building a Python JIT, so I want to change the interp->eval_frame to my own function. I built a C++ library which contains EvalFrame function, and then use dlopen and dlsym to use it. It looks like this: extern "C" PyObject *EvalFrame(PyFrameObject *f, int throwflag) { return _PyEval_EvalFrameDefault(f, throwflag); } I added following code to Python/pylifecycle.c at function _Py_InitializeEx_Private(Python version is 3.6.1): void *pyjit = NULL; pyjit = dlopen("../cmake-build-debug/libPubbon.dylib", 0); if (pyjit != NULL) { interp->eval_frame = (_PyFrameEvalFunction)dlsym(pyjit, "EvalFrame"); //interp->eval_frame = _PyEval_EvalFrameDefault; } Then something strange happened. I used LLDB to trace the variables. When it ran at EvalFrame, the address of f pointer didn't change, but f->f_lineno changed. Then when I ran python.exe, I got Segmentation Fault. Why the address of the pointer didn't change, but the context change? I am working on Mac OS X and Python 3.6.1. I want to know how to replace _PyEval_EvalFrameDefault in interp->eval_frame with my own function. From duncan at invalid.invalid Fri Mar 31 12:50:23 2017 From: duncan at invalid.invalid (duncan smith) Date: Fri, 31 Mar 2017 17:50:23 +0100 Subject: table class - inheritance, delegation? Message-ID: Hello, I need to code up a table class, which will be based on numpy arrays. Essentially it needs to behave like a numpy array, but with a variable associated with each array dimension. It must (at least partially) satisfy the API of an existing class. The main reason for the new class is to avoid the creation of new axes and the transpositions that were required for elementwise operations on instances of the original class. So when summing across axes I will retain all the dimensions. My inclination is to go for composition. e.g. (all following code untested) class Table(object): def __init__(self, values, variables): self.values = values # numpy array self.all_variables = variables self.var_ind_map = dict(zip(variables, range(len(variables)))) @property def variables(self): return [v for dim, v in zip(self.values.shape, self.all_variables) if not dim == 1] variables is required by the API. Most binary operators will behave exactly as for numpy arrays. e.g. def __mul__(self, other): return self.__class__(self.values * other.values, self.all_variables) I can write a factory method to generate many of these, and maybe another factory method for __neg__, __pos__, __abs__ etc. But I then have to deal with __rsub__, __rdiv__ etc. and all I'm doing is emulating the behaviour of numpy arrays. I also need to handle multipication / division etc. by e.g. floats in exactly the same way as numpy. What I can't immediately see is a clean way of doing this with delegation. But I'm unsure that inheritance is the best way to go (the class will be very lightweight compared to numpy arrays). Any advice welcome. I'm currently using Python 2.7 (but will make the move to 3 at some point). Cheers. Duncan From jan at hyper-world.de Fri Mar 31 15:52:29 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Fri, 31 Mar 2017 15:52:29 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> <58dc4d69$0$1599$c3e8da3$5496439d@news.astraweb.com> <0D1A837A-FD65-4C50-AC81-FE97D7E42EDC@hyper-world.de> <517fe120-4834-448d-887f-138e2422e54c@googlegroups.com> Message-ID: <12fed4a5-72b4-37fa-7923-1144843dfcd2@hyper-world.de> On 03/29/2017 11:31 PM, Chris Angelico wrote: > On Thu, Mar 30, 2017 at 2:19 PM, Rick Johnson > wrote: >> [...] >> Really? How could your clients not notice 60 GB of memory >> usage unless they are running some kind of mad-dog insane >> top-of-the-line hardware? (Got Benjamins???) Of course, in >> the case they are not DARPA scientist supported by a >> viturally unlimited supply of tax dollars provided by the >> endless toils of American slave-bots, how could they ignore >> the thrashing? o_O > Did you read the project's README? This is a dramatic reduction from > the normal memory usage of this kind of job. So, yes, they *are* going > to have top-of-the-line hardware. If you're doing a job that normally > would require 256GB of RAM, and instead of being able to run in 40GB, > it needs 60GB, are you going to notice? You probably have 64GB or > 128GB. > > ChrisA Actually, it is not memory, but time improvements. Most people won't run models of the size of Spaun, so usually the memory requirements will be much lower Jan From jan at hyper-world.de Fri Mar 31 17:01:05 2017 From: jan at hyper-world.de (Jan Gosmann) Date: Fri, 31 Mar 2017 17:01:05 -0400 Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> <6e398b4c-5758-69e2-f966-6b88717e67ae@hyper-world.de> Message-ID: <7969c87f-0eed-5b64-6693-c7ff4b45537f@hyper-world.de> On 03/30/2017 02:19 PM, INADA Naoki wrote: > FYI, this small patch may fix your issue: > https://gist.github.com/methane/8faf12621cdb2166019bbcee65987e99 I can verify that the patch fixes the issue for me. Do you still need more information about the `transitive_closure` function and my usage of sets and frozensets? Or any other way I can be helpful in fixing this? (There are a few questions in this thread that I haven't answered so far, but as the problem seems to be identified it might not be worth spending time on that.) Jan From mrjean1 at gmail.com Fri Mar 31 17:05:17 2017 From: mrjean1 at gmail.com (MrJean1) Date: Fri, 31 Mar 2017 14:05:17 -0700 (PDT) Subject: Program uses twice as much memory in Python 3.6 than in Python 3.5 In-Reply-To: References: <60CBD113-61BD-4736-AFBB-963CF89D823D@hyper-world.de> <83C9F43F-1716-4956-AB08-742B300186A8@hyper-world.de> Message-ID: Similarly, on macOS 10.12.3 Sierra: % python3.5 Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 08:49:46) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> s = set(range(10)) >>> sys.getsizeof(s) 736 >>> sys.getsizeof(set(s)) 736 >>> sys.getsizeof(set(set(s))) 736 >>> % python3 Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> s = set(range(10)) >>> sys.getsizeof(s) 736 >>> sys.getsizeof(set(s)) 1248 >>> sys.getsizeof(set(set(s))) 1248 >>> % python2 Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> s = set(range(10)) >>> sys.getsizeof(s) 744 >>> sys.getsizeof(set(s)) 744 >>> sys.getsizeof(set(set(s))) 744 >>> From 2019.cavanaughc at fpsedu.org Fri Mar 31 19:12:48 2017 From: 2019.cavanaughc at fpsedu.org (2019.cavanaughc at fpsedu.org) Date: Fri, 31 Mar 2017 16:12:48 -0700 (PDT) Subject: Program Error Help - Python 3.1 Message-ID: Hello I've been coding for about 1 or 2 months and i have encountered a problem with a 'while' statement. It keeps looping even when the statement is false, here is the code. The code is for a game that I'm making that resembles the Oregon Trial. -Thanks for your help! import random deep = random.randint(1, 30) width = random.randint(15, 50) print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nYou have approched a river.") answer8 = "" while answer8 != ("1") or answer8 != ("2"): print("\nWhat would you like to do?") print("\t\t 1) Attempt to wade across the river") print("\t\t 2) Attempt to float across the river") print("\t\t 3) Find out more about the river.") answer8 = input("\nWhat is your choice? ") if answer8 == 3: print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThe river is", deep, "feet deep and", width, "feet long.") input("\n\nPress ENTER to continue. ") if answer8 == 1: if deep <= 5 and deep >=0: print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nYou made it across.") input("\n\nPress ENTER to continue. ") else: print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThere has been an accendint.") input("\n\nPress ENTER to continue. ") if answer8 == 2: if deep >=6: print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nYou made it across.") input("\n\nPress ENTER to continue. ") else: print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nThere has been an accendint.") input("\n\nPress ENTER to continue. ") input("\n\nPress ENTER to exit. ") From tjreedy at udel.edu Fri Mar 31 19:33:35 2017 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Mar 2017 19:33:35 -0400 Subject: Program Error Help - Python 3.1 In-Reply-To: References: Message-ID: On 3/31/2017 7:12 PM, 2019.cavanaughc at fpsedu.org wrote: > Hello I've been coding for about 1 or 2 months If at all possible, start with 3.6, not 3.1. > and i have encountered a problem with a 'while' statement. You should assume that your code is buggy. That is true even of experts. > It keeps looping even when the statement is false, False. > here is the code. > while answer8 != ("1") or answer8 != ("2"): which is always True. -- Terry Jan Reedy From larry.martell at gmail.com Fri Mar 31 19:38:35 2017 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 31 Mar 2017 23:38:35 +0000 Subject: Program Error Help - Python 3.1 In-Reply-To: References: Message-ID: On Fri, Mar 31, 2017 at 4:16 PM <2019.cavanaughc at fpsedu.org> wrote: > while answer8 != ("1") or answer8 != ("2"): This statement is always true. Think about it. > > From cs at zip.com.au Fri Mar 31 19:42:48 2017 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 1 Apr 2017 10:42:48 +1100 Subject: Program Error Help - Python 3.1 In-Reply-To: References: Message-ID: <20170331234248.GA59845@cskk.homeip.net> On 31Mar2017 16:12, 2019.cavanaughc at fpsedu.org <2019.cavanaughc at fpsedu.org> wrote: >Hello I've been coding for about 1 or 2 months and i have encountered a problem with a 'while' statement. It keeps looping even when the statement is false, here is the code. The code is for a game that I'm making that resembles the Oregon Trial. Obviously the statement (well, "test") isn't false! Let's look: [...] >answer8 = "" >while answer8 != ("1") or answer8 != ("2"): [...] Answer8 cannot be both "1" and also "2". Therefore, it will always _not_ be equal to at least one of "1" and "2". Therefore this test is always true. You might better write this: while answer8 not in ("1", "2"): or: while not( answer8 == "1" or answer8 == "2" ): BTW, you need to decide whther you're working in strings or integers. input() in Python 3 returns a string. If you want to test against strings, fine. However, if you want to test against numbers you need to convert the string to a number: answer8n = int(answer8) and then test against answer8n. Cheers, Cameron Simpson From carl.caulkett at gmail.com Fri Mar 31 20:03:56 2017 From: carl.caulkett at gmail.com (Carl Caulkett) Date: Fri, 31 Mar 2017 19:03:56 -0500 Subject: VirtualEnvs (venv) and Powershell Message-ID: Hello everyone, I've just started to investigate VirtualEnvironments as a means of preventing my 3rd party code becoming chaotic. I've discovered that venv's can be managed quite effectively using Powershell. When Activate.ps1 is run, the PowerShell changes to indicate that the venv is active which is nice. However despite the official documention, there doesn't seem to be a corresponding Deactivate.ps1. There is a deactivate.bat but that doesn't appear to switch the paths back to their pre-env state. What I would really like is a Git-Bash based alternative to Powershell to manage my Virtual Environments. Has anyone dicovered tools or techniques to achieve this? Thanks for any response -- Carl From rantingrickjohnson at gmail.com Fri Mar 31 21:17:26 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 31 Mar 2017 18:17:26 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> Message-ID: On Thursday, March 30, 2017 at 12:43:59 AM UTC-5, Chris Angelico wrote: > Except that it doesn't actually take very much work to call > on someone else's library, which is what you get when you > use Unicode properly. (At least, assuming you're using a > decent language like Python, which comes with Unicode > libraries, and a decent GUI toolkit if you're going that > way.) Really. Since when does Python come with a "decent GUI kit"? > Nope. I can't speak Mandarin, but I can make absolutely > sure that all my programs can accept Chinese characters. A > friend of mine sent me an audio file with a name that > included some Chinese, and I was able to handle it no > problem. Most people just quietly change the filename and move on, but if you want to spend the extra time worrying about every foreign charactor, you certainly have that right. But you don't have a right to lecture everyone else about your new found religion. Sometimes, as we pat our self-righteous selves on the back, we forget that our incessant proselytizing for the "religion of inclusivity" is only helping multi-national corporations attain evermore market share (...somewhere, in a corporate penthouse perched high above the peasants who scurry below, a CEO dons a most devilish grin...). The iPhone has come to dominate every market in the world. And in some ways (being a revolutionary device and all) this is good, however there are downsides to this complete and total domination. Indeed, the iPhone customer has become something of a bedazzled twit, lusting after whatever superficial marking ploys are pulled from Jobs' decomposing arse. What does this have to do with coders, you ask? Well, we are merely pawns in a greater game... > >> [ ] Uses no diacritical marks > > > > Why is it my responsibility to encode my text with > > pronunciation tutorials? Are we adults here or what? > > > >> [ ] Writes all text top-to-bottom, left-to-right > > > > Not my problem. Learn the King's English or go wait for > > extinction to arrive. > > And these two cement your parochialism thoroughly in > everyone's minds. "Pronunciation tutorials", eh? Sure. Tell > that to everyone who speaks Spanish, Turkish, Norwegian, > German, or Vietnamese, all of which use diacritical marks > to distinguish between letters. English is the weird > language in that it uses letter pairs instead of adorned > letters (eg "ch" and "sh" instead of "?" and "?"). Well, it seems the designers of English knew a thing or two about time machines long before GvR did. Hmm, that makes wonder if ol' GvR ever worked at a patent office...? > Also, which king are you referring to, exactly? Whose > English do you speak? Only "right-proper English", old chap. ;-) > > The only justification required is the bottom line. If your > > products generate profit, then you're doing something > > right. Besides, you don't need _everyone_ on the planet to > > buy your product to be a success. Unlike the business > > practices of Apple, we would be wise to leave plenty of > > room for others to enter the market. Competition is good > > for everyone. Monopolies are evil. > > Riiiiiight. What's the "bottom line" for open source > software? How do you measure whether your product is > generating a profit or not? Easy. You count the number of active community members. You also closely observe the "community health tends" over time. Having a small community today is not necessarily a bad thing if the community is healthy and growing. OTOH, a large unhealthy community today could be a ghost town tomorrow. Biologist refer to that phenomenon as extinction. Which is neither good nor profitable. Rectangular sheets of paper with dead presidents printed on them are not the only source of profits. Crowd sourcing can be quite a profitable enterprise even in the absence of money -- that is, *IF*, and only *IF* -- you invest the time required to lower barriers of entry and foster participation from diverse external sources. Social homogeny and intellectual isolation lead to collective oblivion. From rosuav at gmail.com Fri Mar 31 21:31:27 2017 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Apr 2017 12:31:27 +1100 Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: References: <58d80413$0$1595$c3e8da3$5496439d@news.astraweb.com> <626fc6cf-0cf9-4efa-a3ff-f9ca2ddcb7fd@googlegroups.com> Message-ID: On Sat, Apr 1, 2017 at 12:17 PM, Rick Johnson wrote: > On Thursday, March 30, 2017 at 12:43:59 AM UTC-5, Chris Angelico wrote: >> Except that it doesn't actually take very much work to call >> on someone else's library, which is what you get when you >> use Unicode properly. (At least, assuming you're using a >> decent language like Python, which comes with Unicode >> libraries, and a decent GUI toolkit if you're going that >> way.) > > Really. Since when does Python come with a "decent GUI kit"? I didn't say it came with one; I said you should use (a) a decent language, and (b) a decent GUI toolkit. Both do exist, but with Python, the best GUI toolkits are installed with pip rather than being part of the standard library. >> Nope. I can't speak Mandarin, but I can make absolutely >> sure that all my programs can accept Chinese characters. A >> friend of mine sent me an audio file with a name that >> included some Chinese, and I was able to handle it no >> problem. > > Most people just quietly change the filename and move on, > but if you want to spend the extra time worrying about every > foreign charactor, you certainly have that right. But you > don't have a right to lecture everyone else about your new > found religion. I suppose you'd be okay with all file names being upper-case 8.3 format, and that anyone who wants mixed case and/or longer names should have no right to lecture people either. >> > The only justification required is the bottom line. If your >> > products generate profit, then you're doing something >> > right. Besides, you don't need _everyone_ on the planet to >> > buy your product to be a success. Unlike the business >> > practices of Apple, we would be wise to leave plenty of >> > room for others to enter the market. Competition is good >> > for everyone. Monopolies are evil. >> >> Riiiiiight. What's the "bottom line" for open source >> software? How do you measure whether your product is >> generating a profit or not? > > Easy. You count the number of active community members. You > also closely observe the "community health tends" over time. > Having a small community today is not necessarily a bad > thing if the community is healthy and growing. OTOH, a large > unhealthy community today could be a ghost town tomorrow. > Biologist refer to that phenomenon as extinction. Which is > neither good nor profitable. > > Rectangular sheets of paper with dead presidents printed on > them are not the only source of profits. Crowd sourcing can > be quite a profitable enterprise even in the absence of > money -- that is, *IF*, and only *IF* -- you invest the time > required to lower barriers of entry and foster participation > from diverse external sources. Social homogeny and > intellectual isolation lead to collective oblivion. I think you need to define the bottom line with something more stable than a greased roller skating rink. ChrisA From python at deborahswanson.net Fri Mar 31 21:34:02 2017 From: python at deborahswanson.net (Deborah Swanson) Date: Fri, 31 Mar 2017 18:34:02 -0700 Subject: Developing a Python JIT and have trouble In-Reply-To: Message-ID: <009201d2aa88$0b900df0$27b23dae@sambora> Yuheng Zou wrote, on Friday, March 31, 2017 6:52 AM > > I am building a Python JIT, so I want to change the > interp->eval_frame to my own function. > > I built a C++ library which contains EvalFrame function, and > then use dlopen and dlsym to use it. It looks like this: > > extern "C" PyObject *EvalFrame(PyFrameObject *f, int throwflag) { > return _PyEval_EvalFrameDefault(f, throwflag); > } > I added following code to Python/pylifecycle.c at function > _Py_InitializeEx_Private(Python version is 3.6.1): > > void *pyjit = NULL; > pyjit = dlopen("../cmake-build-debug/libPubbon.dylib", 0); > if (pyjit != NULL) { > interp->eval_frame = (_PyFrameEvalFunction)dlsym(pyjit, > "EvalFrame"); > //interp->eval_frame = _PyEval_EvalFrameDefault; > } > Then something strange happened. I used LLDB to trace the > variables. When it ran at EvalFrame, the address of f pointer > didn't change, but f->f_lineno changed. > > Then when I ran python.exe, I got Segmentation Fault. > > Why the address of the pointer didn't change, but the context change? > > I am working on Mac OS X and Python 3.6.1. I want to know how > to replace _PyEval_EvalFrameDefault in interp->eval_frame > with my own function. Hi Yuheng, There might be some C coders on this list, maybe even a few who are proficient in both C & Python. But this list is predominantly made up of Python coders, and you may not get a reply. Personally, I don't know C well enough nor am I familiar with the EvalFrame you mention to respond to your question. Shiboya From rantingrickjohnson at gmail.com Fri Mar 31 22:00:22 2017 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Fri, 31 Mar 2017 19:00:22 -0700 (PDT) Subject: Text-mode apps (Was :Who are the "spacists"?) In-Reply-To: <58dcbaaf$0$2751$c3e8da3$76491128@news.astraweb.com> References: <58d7fdc3$0$1617$c3e8da3$5496439d@news.astraweb.com> <3fda49ff-1907-493c-a465-7e68bb86b7b1@googlegroups.com> <58dcbaaf$0$2751$c3e8da3$76491128@news.astraweb.com> Message-ID: <5b2cca48-1fda-4474-9f1f-a13db682a740@googlegroups.com> On Thursday, March 30, 2017 at 2:58:53 AM UTC-5, Steven D'Aprano wrote: > On Wed, 29 Mar 2017 20:53:35 -0700, Rick Johnson wrote: > > > On Sunday, March 26, 2017 at 1:21:18 PM UTC-5, Chris Angelico wrote: > >> On Mon, Mar 27, 2017 at 4:43 AM, Steve D'Aprano wrote: [...] > > You place a lot of faith in the supposed "immutability of > > Unicode code points", but a lot people have placed a lot > > of faith in many past and current encoding systems, only > > to be bamboozled by the gatekeepers some time later. > > So far, Unicode has kept that promise not to move or rename > code points. Promises are not worth the paper they are written on -- unless you have them officially notarize, then they might be worth "something". > They haven't done so even when they've made embarrassing > mistakes, like giving characters the completely wrong name. So they're screw-ups, but at least they're "honest screwups"? MmmKay. Got it. > That makes Unicode more stable than ASCII, which has gone > through a number of incompatible changes since the very > first version back in 1963 (I think it was 63?). Why does every comparison of Unicode end with some cheap jab at ASCII? It brings back horrible memories of Obama blaming Bush for everything. I mean, sure, Bush was a total idiot and he trampled the constitution with his Tony Lama's on more than one occasion, but after the hundred-thousandth time of hearing Obama decry "Hey, but Bush did it -- WAH!", it starts to get really old, really fast. At some point, both Obama and Unicode have to put their big boy pants on and take responsibility for their own mistakes and short comings. And with the Trump election and the Brexit referendum, we can see that Obama took it on the shorts. > To put it another way: > > Unicode character ? (U+0414 CYRILLIC CAPITAL LETTER DE) is > no more likely to change to another character than ASCII > character 0x41 is likely to change from "A" to "Z". > Trusting the stability of Unicode is a pretty safe bet. I don't understand how that argument supports your beloved Unicode over ASCII? > > And so, although Unicode was created to solve the endless > > compatibility problems between multiple archaic encoding > > systems, the designers thought it necessary to add a > > "custom space" that will keep the incompatibilities on > > life support. > > No, that's not how it works. The PUAs really are for > *PRIVATE* use. If your in-house application wants some > dedicated, custom characters (say, for your company logo), > there are three ways you can do it, starting from the > dumbest: > > - pick some existing code point that you think nobody will > ever use, like "Q" say, and turn that into your logo; > > - pick some *currently* unused code point, and hope that it > will not become used; > > - pick a code point from the PUA which is permanently > reserved for private use by private agreement. > > You can't expect other people's applications to treat that > code point as your logo (or whatever special purpose you > give it), but that's okay, you couldn't expect that in any > case. The problem is, as has always been the case with encodings, is that some random dev will create a so-called "private" code point, and others, liking what they see, will adopt the same code point into their own projects. And after enough of these "emulations" occur, you've created a new unofficial de facto standard. And we're all back to square one again. Another possibility, and one that this community is all to familiar with, is that the Unicode gatekeepers could intentionally isolate themselves from the user base and withdraw into their ivory towers, thereby creating a large swath of disillusioned folks who look to the PUA for their collective salvation. And again, we are back to square one. It could be that the PUA is to Unicode what type-hints are to Python. Something to think about... > One of the excellent ways the PUAs have been used is by > medieval researchers. They have been collecting the various > special characters used by medieval scribes, and by private > agreement putting them into a PUA area where special > purpose software can use it. That way they can determine > which of the thousands of special characters used by > medieval monks are actually significant enough to graduate > to genuine Unicode characters, and which are best handled > some other way. And what if the gatekeepers refuse to graduate those special chars? And what if, in response, the natives become restless? A revolt. That's what! And their liberty will be found not in the new lands, but in the PUA.