Python Launcher Pops Up When Py-based App Is Running (Mac)

2023-09-17 Thread James Greenham via Python-list
e del.icio.us 
<http://del.icio.us/>)")
cmdparser.add_option("-o", "--filename", type="string",default="",
   metavar="NAME", help="save images as NAME-full.png,NAME-thumb.png etc")
cmdparser.add_option("-F", "--fullsize", action="store_true",
   help="only create fullsize screenshot")
cmdparser.add_option("-T", "--thumb", action="store_true",
   help="only create thumbnail sreenshot")
cmdparser.add_option("-C", "--clipped", action="store_true",
   help="only create clipped thumbnail screenshot")
cmdparser.add_option("-d", "--datestamp", action="store_true",
   help="include date in filename")
cmdparser.add_option("-D", "--dir",type="string",default="./",
   help="directory to place images into")
cmdparser.add_option("--delay",type="float",default=0,
   help="delay between page load finishing and screenshot")
cmdparser.add_option("--noimages", action="store_true",
   help="don't load images")
cmdparser.add_option("--debug", action="store_true",
   help=optparse.SUPPRESS_HELP)
(options, args) = cmdparser.parse_args()
if len(args) == 0:
cmdparser.print_usage()
return
if options.filename:
if len(args) != 1 or args[0] == "-":
  print "--filename option requires exactly one url"
  sys.stdout.flush()
  return
if options.scale == 0:
  cmdparser.error("scale cannot be zero")
# make sure we're outputing something
if not (options.fullsize or options.thumb or options.clipped):
  options.fullsize = True
  options.thumb = True
  options.clipped = True
# work out the initial size of the browser window
#  (this might need to be larger so clipped image is right size)
options.initWidth = (options.clipwidth / options.scale)
options.initHeight = (options.clipheight / options.scale)
if options.width>options.initWidth:
   options.initWidth = options.width
if options.height>options.initHeight:
   options.initHeight = options.height

app = AppKit.NSApplication.sharedApplication()

# create an app delegate
delegate = AppDelegate.alloc().init()
AppKit.NSApp().setDelegate_(delegate)

# create a window
rect = Foundation.NSMakeRect(0,0,100,100)
win = AppKit.NSWindow.alloc()
win.initWithContentRect_styleMask_backing_defer_ (rect, 
AppKit.NSBorderlessWindowMask, 2, 0)
if options.debug:
  win.orderFrontRegardless()
# create a webview object
webview = WebKit.WebView.alloc()
webview.initWithFrame_(rect)
# turn off scrolling so the content is actually x wide and not x-15
webview.mainFrame().frameView().setAllowsScrolling_(objc.NO)

webview.setPreferencesIdentifier_('webkit2png')
webview.preferences().setLoadsImagesAutomatically_(not options.noimages)

# add the webview to the window
win.setContentView_(webview)

# create a LoadDelegate
loaddelegate = WebkitLoad.alloc().init()
loaddelegate.options = options
loaddelegate.urls = args
webview.setFrameLoadDelegate_(loaddelegate)

app.run()

if __name__ == '__main__' : main()


Best,
James

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why does IDLE use a subprocess?

2023-05-31 Thread James Schaffler via Python-list
On Tuesday, May 30th, 2023 at 10:18 PM, Chris Angelico wrote:
> Yep, what you're seeing there is the namespace and nothing else. But
> if you mess with an actual builtin object, it'll be changed for the
> other interpreter too.
> 
> > > > import ctypes
> > > > ctypes.cast(id(42), ctypes.POINTER(ctypes.c_int))[6] = 43
> > > > 41+1
> 
> 43
> 
> > > > from code import InteractiveInterpreter
> > > > interp = InteractiveInterpreter()
> > > > interp.runcode("print(41+1)")
> 
> 43
> 
> (Note that this only works in CPython and only with integers small
> enough to be in the cache, meaning that there is only one such object
> representing that integer.)
> 
> The same is true of C extensions, which often have their own internal
> state, and that state isn't isolated to a single interpreter.
> 
> Better isolation is coming with PEP 554
> https://peps.python.org/pep-0554/ which also has some great
> information about what currently is NOT isolated. (Also, even then,
> some things won't be fully isolated; I think that the ctypes trick
> above might still affect a subinterpreter even in a post-PEP554
> world.)

Amazing example! Thank you everyone for the detailed responses - will be sure 
to check out the PEP as well.

Jim
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why does IDLE use a subprocess?

2023-05-30 Thread James Schaffler via Python-list
On Tuesday, May 30th, 2023 at 9:14 PM, Greg Ewing wrote:
> Globals you create by executing code in the REPL have their own
> namespace. But everything else is shared -- builtins, imported
> Python modules, imported C extension modules, etc. etc.

Thanks for the explanation. Could you elaborate on precisely how "everything 
else is shared"? As far as I understand, if you run the following code:

from code import InteractiveInterpreter
interp = InteractiveInterpreter()
import numpy as np
interp.runcode("np.__name__")

this will result in the error
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'np' is not defined

which seems to imply that imports in the parent shell are not shared with 
interpreters and vice versa (if you swap the places of the import and the 
__name__ call).

Thanks,
Jim
-- 
https://mail.python.org/mailman/listinfo/python-list


Why does IDLE use a subprocess?

2023-05-30 Thread James Schaffler via Python-list
Originally posted to idle-dev, but thought this might be a better place. Let me 
know if it isn't.

Hi,

I was curious about the internals of IDLE, and noticed that IDLE uses executes 
user code in a "subprocess" that's separate from the Python interpreter that is 
running IDLE itself (which does tasks such as making the window and coloring 
the text).

As far as I understand, IDLE runs a modified version of 
code.InteractiveInterpreter by sending user code through a socket. Even the 
IDLE documentation says that without a subprocess, "user code is not isolated 
from IDLE itself." However, some minimal testing of InteractiveInterpreter 
leads me to believe that the Interpreter object has its own view of 
local/global variables and therefore shouldn't be able to affect the calling 
interpreter (please correct me if I'm wrong).

So my question is a combination of "Why does IDLE use a subprocess?" and "Why 
is InteractiveInterpreter not secure enough?" What possible security 
vulnerabilities exist if one uses IDLE without the subprocess? If anyone knows 
(or could point me to information on) why IDLE is designed this way, I'd really 
appreciate it. Thank you!

Jim
-- 
https://mail.python.org/mailman/listinfo/python-list


JOB | Linux Platform Engineer (India and Singapore)

2023-04-24 Thread James Tobin
Hello, i'm working with an employer that is looking to hire a Linux
platform engineer for their office in India and Singapore that has
experience in automation and management of platform configuration from
both an onprem and cloud perspective.  Consequently, I had hoped that
some members may like to discuss further; off-list.  I can be reached
using "JamesBTobin (at) Gmail (dot) Com".  Kind regards, James
-- 
https://mail.python.org/mailman/listinfo/python-list


JOB | Lead Linux Sysadmin (Edinburgh/London)

2023-03-08 Thread James Tobin
Hello, I'm working with an employer that is looking to hire someone in
(Edinburgh or London) that can administer on-prem and vmware
platforms.  Consequently, I had hoped that some members of this group
may like to discuss further.  I can be reached using "JamesBTobin (at)
Gmail (dot) Com".  Kind regards, James
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-02 Thread James Tsai
在 2022年9月2日星期五 UTC+2 00:17:23, 写道:
> On 02Sep2022 07:01, Chris Angelico  wrote: 
> >On Fri, 2 Sept 2022 at 06:55, James Tsai  wrote: 
> >> No but very often when I have written a neat list/dict/set 
> >> comprehension, I find it very necessary 
> >> to define local variable(s) to make it more clear and concise. Otherwise I 
> >> have to break it down 
> >> to several incrementally indented lines of for loops, if statements, and 
> >> variable assignments, 
> >> which I think look less nice. 
> > 
> >Well, if it's outgrown a list comp, write it on multiple lines. Like I 
> >said, not everything has to be a one-liner.
> True, but a comprehension can be more expressive than a less 
> "functional" expression (series of statements). 
> 
> James, can you provide (a) a real world example where you needed to 
> write a series of statements or loops and (b) a corresponding example of 
> how you would have preferred to have written that code, possibly 
> inventing some syntax or misusing ":=" as if it workeed they way you'd 
> like it to work? 
> 
> Cheers, 
> Cameron Simpson 

Yeah, I think list comprehension is particularly useful to construct a deeply 
nested list/dict. For example, I am now using Plotly to visualize a cellular 
network including several base stations and users. Here is the function I have 
written:

def plot_network(area, base_stations, users):
bs_poses = np.array([bs.pos for bs in base_stations])
ue_poses = np.array([ue.pos for ue in users])
fig = px.scatter(x=bs_poses[:, 0], y=bs_poses[:, 1])
fig.add_scatter(x=ue_poses[:, 0], y=ue_poses[:, 1])
fig.update_layout(
xaxis=dict(range=[0, area[0]], nticks=5),
yaxis=dict(range=[0, area[1]], nticks=5),
shapes=[dict(
type="circle",
fillcolor="PaleTurquoise",
x0=x-r, y0=y-r, x1=x+r, y1=y+r,
hovertext=f"({x:.2f}, {y:.2f})",
opacity=0.3
) for bs in base_stations for x, y in [bs.pos]
for r in [bs.cell_radius]],
)
return fig

Simply put, I want to scatter the BSs and users, and additionally I want to 
draw a big circle around each BS to represent its cell coverage. I can choose 
to write 'x0=bs.pos[0]-bs.cell_radius, y0=...' instead, but it becomes less 
concise, and if x, y, or r is the return value of a function instead of a 
property, it becomes more computationally expensive to repeat calling the 
function as well. I also can create the list of 'shapes' by appending to a 
list, like

shapes = []
for bs in base_stations:
   x, y = bs.pos
   r = bs.cell_radius
   shapes.append(dict(...))
fig.update_layout(
xaxis=dict(range=[0, area[0]], nticks=5),
yaxis=dict(range=[0, area[1]], nticks=5),
shapes=shapes
)

But in my opinion this is much less concise. I think it looks better to create 
the list within the nested structure. So I totally agree that list 
comprehension adds much expressiveness in Python. I only wonder whether it is a 
good idea to introduce a specific syntax for local variable assignment in list 
comprehensions, instead of using "for r in [bs.cell_radius]".
I am also surprised to know that the assignment operator ":=" in a list 
comprehension will assign a variable outside of the scope of the comprehension. 
I think it does not make sense since a list comprehension without a ":=" will 
never change name bindings outside itself.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
在 2022年9月1日星期四 UTC+2 18:16:03, 写道:
> On Fri, 2 Sept 2022 at 02:10, James Tsai  wrote: 
> > 
> > Hello, 
> > 
> > I find it very useful if I am allowed to define new local variables in a 
> > list comprehension. For example, I wish to have something like 
> > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or 
> > [(x, y) for x in range(10) with y := x ** 2 if x + y < 80]. 
> > 
> > For now this functionality can be achieved by writing 
> > [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80]. 
> > 
> > Is it worthwhile to add a new feature like this in Python? If so, how can I 
> > propose this to PEP?
> Not everything has to be a one-liner. 
> 
> ChrisA

No but very often when I have written a neat list/dict/set comprehension, I 
find it very necessary to define local variable(s) to make it more clear and 
concise. Otherwise I have to break it down to several incrementally indented 
lines of for loops, if statements, and variable assignments, which I think look 
less nice.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> On 9/1/22, James Tsai  wrote: 
> > 
> > I find it very useful if I am allowed to define new local variables in a 
> > list comprehension. For example, I wish to have something like 
> > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or 
> > [(x, y) for x in range(10) with y := x ** 2 if x + y < 80]. 
> > 
> > For now this functionality can be achieved by writing 
> > [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].
> You can assign a local variable in the `if` expression. For example: 
> 
> >>> [(x, y) for x in range(10) if x + (y := x**2) < 30] 
> [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16)]

Yeah this works great but like [(x, y) for x in range(10) for y in [x**2]] I 
written before, is kind of a hack. And if initially I do not need an "if" 
condition in the list comprehension, this becomes less convenient. I still can 
write 
>>> [(x, y) for x in range(10) if (y := x**2) or True]

But I wonder if Python could have a specific syntax to support this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
在 2022年9月1日星期四 UTC+2 16:15:17, 写道:
> James Tsai  writes: 
> 
> > I find it very useful if I am allowed to define new local variables in 
> > a list comprehension. For example, I wish to have something like 
> > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or 
> > [(x, y) for x in range(10) with y := x ** 2 if x + y < 80]. 
> > 
> > For now this functionality can be achieved by writing 
> > [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].
> x and y are, to a first approximation, new local variables defined in a 
> list comprehension. I think you need to restate what it is you want.
> > Is it worthwhile to add a new feature like this in Python? If so, how 
> > can I propose this to PEP?
> To make any sort of case you'd need to give an example that does not 
> have a clearer way to write it already. Your working version is, to me, 
> clearer that the ones you want to be able to write. 
> 
> -- 
> Ben.

By local variable definition I mean binding a variable to a single value, so it 
doesn't include giving an iterable that a variable can take values iteratively, 
e.g. 'for x in range(10)'. Does it not worth introducing a specific syntax to 
do this, instead of creating a new list ad hoc to define the variable like 'for 
y in [1]'?
-- 
https://mail.python.org/mailman/listinfo/python-list


Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
Hello,

I find it very useful if I am allowed to define new local variables in a list 
comprehension. For example, I wish to have something like
[(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
[(x, y) for x in range(10) with y := x ** 2 if x + y < 80].

For now this functionality can be achieved by writing
[(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].

Is it worthwhile to add a new feature like this in Python? If so, how can I 
propose this to PEP?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: empty stdout (subprocess.run)

2022-01-20 Thread James Smith
On Wednesday, January 19, 2022 at 11:14:28 PM UTC-5, cameron...@gmail.com wrote:

> But I recommend you use shell=False and make: 
> 
> cmd = ["/usr/bin/transmission-remote", "--torrent", str(torrentno), "--info"] 

I like that. :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: empty stdout (subprocess.run)

2022-01-20 Thread James Smith
On Wednesday, January 19, 2022 at 11:08:58 PM UTC-5, Dennis Lee Bieber wrote:

> Don't you need to provide for that %s? Perhaps 
> 
> cmd="/usr/bin/transmission-remote --torrent %s --info" % torrentno 

That works, thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


empty stdout (subprocess.run)

2022-01-19 Thread James Smith
I'm trying to run a shell command but the stdout is empty:

import subprocess

torrentno=8
cmd="/usr/bin/transmission-remote --torrent %s --info", str(torrentno)
res=subprocess.run(cmd, shell=True, check=True, universal_newlines=True, 
capture_output=True)
print(res)

CompletedProcess(args=('/usr/bin/transmission-remote --torrent %s --info', 
'1'), returncode=0, stdout='', stderr='')
-- 
https://mail.python.org/mailman/listinfo/python-list


Universal compiler that runs Java, Ruby, C++, and Python in a single VM

2021-03-16 Thread James Lu
It's called Oracle's Truffle. Truffle runs all those languages with an
autogenerated JIT.

This is my response to the neos drama.
-- 
https://mail.python.org/mailman/listinfo/python-list


Python subinterpreters with separate GILs

2021-02-10 Thread James Lu
Directly removing the Global Interpreter Lock (GIL) would break a lot
of libraries that implicitly assume it is there. What if Python had
"realms" that each had separate GILs?

The "realms" (not sure if "subinterpreter" is the correct term here)
could share objects.
-- 
https://mail.python.org/mailman/listinfo/python-list


Asyncio project code review

2021-01-08 Thread James

Good day for everyone.

I have new asyncio project which use aiohttp connector and asyncio 
protocols/transports for tunneling packets through Tor Network cleanly. 
Project called aiotor: https://github.com/torpyorg/aiotor


If someone with experience in asyncio field can make code review I will 
be appreciated for any comments.


I prepared pull request to make it convenient to review and comment on 
the code: https://github.com/torpyorg/aiotor/pull/1


Thanks in advance.
--
https://mail.python.org/mailman/listinfo/python-list


asyncio project code review

2021-01-08 Thread James

Good day everyone.

I have new asyncio project which use aiohttp connector and asyncio 
protocols/transports for tunneling packets through Tor Network cleanly. 
Project called aiotor: https://github.com/torpyorg/aiotor


If someone with experience in asyncio field can make code review I will 
be appreciated for any comments.


I prepared pull request to make it convenient to review and comment on 
the code: https://github.com/torpyorg/aiotor/pull/1



--
https://mail.python.org/mailman/listinfo/python-list


A library that converts a type-annotated function into a webpage with HTML forms?

2020-09-30 Thread James Lu
Is there a python library available that converts a type-annotated Python
function into a webpage with HTML forms?

Something like:


def foo(name: str, times: int):
return f"Hello {name}!" * times

serve_from(foo, host="0.0.0.0", port=3000)

Turning into a server that serves something like this:


name




And hitting the submit button executes the function.

I'm aware I could use sls, and build a form manually, but that's extra work.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [SOLVED] Module exists and cannot be found

2020-09-10 Thread James Moe via Python-list
On 9/8/20 10:35 PM, James Moe wrote:

> Module PyQt5 is most definitely installed. Apparently there is more to getting
> modules loaded than there used to be.
>
  Cause: Operator Error
  The python installation had become rather messy resulting in the errors I
showed. After installing python correctly, the errors disappeared and the app is
performing as expected.

  Thank you all for your replies.

-- 
James Moe
jmm-list at sohnen-moe dot com
Think.
-- 
https://mail.python.org/mailman/listinfo/python-list


Module exists and cannot be found

2020-09-08 Thread James Moe via Python-list
python 3.6.10
opensuse tumbleweed
linux 5.8.4

An old program based on Python (BackInTime) has recently been having
difficulties functioning. See below.

Module PyQt5 is most definitely installed. Apparently there is more to getting
modules loaded than there used to be.

(Also, I am not familiar with Python.)

[ error message (verbose option) ]
Traceback (most recent call last):
  File "/home/jmoe/diy/backintime-master/qt/app.py", line 35, in 
import qttools
  File "", line 971, in _find_and_load
  File "", line 955, in _find_and_load_unlocked
  File "", line 665, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 219, in _call_with_frames_removed
  File "/home/jmoe/diy/backintime-master/qt/qttools.py", line 21, in 
from PyQt5.QtGui import (QFont, QColor, QKeySequence)
  File "", line 971, in _find_and_load
  File "", line 941, in _find_and_load_unlocked
  File "", line 219, in _call_with_frames_removed
  File "", line 971, in _find_and_load
  File "", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'PyQt5'
[ end ]

[ the 1st code lines causing the above ]
qttools.py:
  import os
  import sys
  import gettext
  from PyQt5.QtGui import (QFont, QColor, QKeySequence) <<<-- line 21
  ...

app.py:
  import os
  import sys

  if not os.getenv('DISPLAY', ''):
os.putenv('DISPLAY', ':0.0')

  import datetime
  import gettext
  import re
  import subprocess
  import shutil
  import signal
  from contextlib import contextmanager
  from tempfile import TemporaryDirectory

  import qttools<<<--- line 35
  qttools.registerBackintimePath('common')
  ...
[ end ]

-- 
James Moe
jmm-list at sohnen-moe dot com
Think.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: An I connected here?

2020-07-17 Thread Rhodri James

On 17/07/2020 20:12, J. Pic wrote:

And Hollidays ;)


Nah, that's next week ;-)



Le ven. 17 juil. 2020 à 21:03, Rhodri James  a écrit :


On 17/07/2020 19:33, Steve wrote:

Sorry folks, I really messed that one up.  I tried to doctor up a reply

to

get the address correct but failed to delete enough to own the message...


Yeah, don't do that.  Just start a new message, otherwise you'll end up
with all the threading for the old message thread, irritating those of
us who sort by thread so that we aren't chopping and changing subject
all the time :-/


My message did not have anything to do with the "Fake News Detect"

subject.


I posted a request for assistance about a week ago, no response.  I also

see

very little traffic here, less than there used to be.  Has something gone
wrong with my set up?


No, nothing's wrong.  I can't answer for anyone else and I can't recall
your specific question, but I suspect you were asking about something I
know nothing about and wasn't sufficiently intrigued to go find out about.

I think there are fewer experts with time lurking around here (and I
don't count myself as one of those, TBH).  Recent controversies and the
attempts to moderate them have probably upset quite a lot of people one
way or another.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list






--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: An I connected here?

2020-07-17 Thread Rhodri James

On 17/07/2020 19:33, Steve wrote:

Sorry folks, I really messed that one up.  I tried to doctor up a reply to
get the address correct but failed to delete enough to own the message...


Yeah, don't do that.  Just start a new message, otherwise you'll end up 
with all the threading for the old message thread, irritating those of 
us who sort by thread so that we aren't chopping and changing subject 
all the time :-/



My message did not have anything to do with the "Fake News Detect" subject.

I posted a request for assistance about a week ago, no response.  I also see
very little traffic here, less than there used to be.  Has something gone
wrong with my set up?


No, nothing's wrong.  I can't answer for anyone else and I can't recall 
your specific question, but I suspect you were asking about something I 
know nothing about and wasn't sufficiently intrigued to go find out about.


I think there are fewer experts with time lurking around here (and I 
don't count myself as one of those, TBH).  Recent controversies and the 
attempts to moderate them have probably upset quite a lot of people one 
way or another.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Formal Question to Steering Council (re recent PEP8 changes)

2020-07-05 Thread Rhodri James

On 04/07/2020 16:38, Random832 wrote:

On Fri, Jul 3, 2020, at 08:48, Rhodri James wrote:

As I said in my preamble, it doesn't matter whether you believe that is
true or think it's utter bollocks.  I asked the question to get the
Steering Council's opinion, not anyone else's.  If you collectively
really must rehash the arguments again, please have the decency to do so
in a different thread.


The idea that the statement was in any way related to one of the authors being named 
"White" was an *obvious factual mistake* in your post.


Nope.  It was a factual mistake in someone else's post.  I hesitate to 
say "obvious" because I have in fact known people to genuinely think 
things like that.  It is *still* irrelevant to what was asked of the 
Steering Council.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: New to python - Just a question

2020-07-03 Thread Rhodri James

On 03/07/2020 11:09, Daley Okuwa via Python-list wrote:


Please can someone help

Write an algorithm (choose the language you prefer) that given a character 
string, for instance {‘c’,’a’,’i’,’o’,’p’,’a’}, will print out the list of 
characters appearing at least 2 times. In this specific example, it would 
return {‘a’}. Afterwards, comment out the cost in terms of space and time.


The first thing to do with any problem is to break it down into bits. 
In the case of Python, writing them out as "pseudo-code" instructions 
often helps.  In this case you have:


Set up something to count letters with
For each letter in the string:
If we haven't seen this letter before:
Set the counter for the letter to 1
Else:
Add 1 to the counter for the letter

For each counter:
If the count is 2 or more:
Print the letter

Now there are a lot of possible ways to write that, but they mostly come 
down to deciding what data structure to use to count letters with.  Have 
a browse through a tutorial (or the standard library if you are feeling 
adventurous) and see what you think might work, then try it.



Write a bash/python script that takes a directory as an argument and output the 
total lines of code in *.cpp files recursively.


In bash, what existing commands count things?  If you don't know, how 
might you find out?  Then you have to figure out how to do that for each 
*.cpp file in a directory, and add the totals together.


In Python, you can read a file one line at a time, so how to count the 
number of lines in a file should be pretty obvious.  Figuring out how to 
do that for every *.cpp file in a directory will involve looking through 
the standard library, or getting a bash script to do it for you :-)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Formal Question to Steering Council (re recent PEP8 changes)

2020-07-03 Thread Rhodri James

On 03/07/2020 15:28, Jon Ribbens via Python-list wrote:

On 2020-07-03, Rhodri James  wrote:

On 02/07/2020 23:46, Random832 wrote:

On Thu, Jul 2, 2020, at 18:29, Michael Torrie wrote:

Come again?  I can see no other link in the verbage with the
"relics of white supremacy" that she referred to.  If there are
other links, they should be included in the commit message.  I
agree with Rhodri that an explanation would be interesting.  Far be
it from me to demand one.  So whatever.


It's possible that this wasn't explained clearly enough in the commit
message itself (though I would argue it was definitely adequately
explained in the ensuing on-list discussion, and wonder how much of
that discussion you've actually read), but the point is that the
*whole idea* of "standard English" is tied to white supremacy, not
any particular standard whether via its authors or otherwise.


As I said in my preamble, it doesn't matter whether you believe that is
true or think it's utter bollocks.  I asked the question to get the
Steering Council's opinion, not anyone else's.


You don't get to decide whose opinions are offered.


But I do get to decide whose opinions are solicited.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Formal Question to Steering Council (re recent PEP8 changes)

2020-07-03 Thread Rhodri James

On 02/07/2020 23:46, Random832 wrote:

On Thu, Jul 2, 2020, at 18:29, Michael Torrie wrote:

Come again?  I can see no other link in the verbage with the
"relics of white supremacy" that she referred to.  If there are
other links, they should be included in the commit message.  I
agree with Rhodri that an explanation would be interesting.  Far be
it from me to demand one.  So whatever.


It's possible that this wasn't explained clearly enough in the commit
message itself (though I would argue it was definitely adequately
explained in the ensuing on-list discussion, and wonder how much of
that discussion you've actually read), but the point is that the
*whole idea* of "standard English" is tied to white supremacy, not
any particular standard whether via its authors or otherwise.


As I said in my preamble, it doesn't matter whether you believe that is 
true or think it's utter bollocks.  I asked the question to get the 
Steering Council's opinion, not anyone else's.  If you collectively 
really must rehash the arguments again, please have the decency to do so 
in a different thread.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Formal Question to Steering Council (re recent PEP8 changes)

2020-07-02 Thread Rhodri James

On 02/07/2020 18:11, Dieter Maurer wrote:

I am no member of the Council. Thus, your questions are not directed
to me. **BUT** you made your questions public and thus you are
likely prepared to receive public comments.


Fortunately you don't answer any of the questions, so I don't need to 
have an opinion on that :-)



The commit message tries to provide the motivation for
the change. In my view, it is good to document change motivations
and a commit message is not a bad place for that.


True.  However, the motivation as appeared in the discussions was 
(approximately) that many people, especially those whose first language 
is not English, find being given a list of writing guidelines like 
Strunk and White's "The Elements of Style" intimidating.  That's fair 
enough, though a bit more consideration suggests that many people have 
exactly the opposite problem.  The wording could be amended to reassure 
both, and I've been contemplating doing so.


The political diatribe about the linguistic contribution to white 
supremacy of standardized English appeared nowhere in the discussion. 
Had it done so, I suspect Keala would have realised quite quickly that 
using it would be (and has been) controversial and divisive, the exact 
opposite of her stated intentions.


All of which is quite beside the point for the questions I raised.  As I 
said, it doesn't matter whether you agree with that political opinion 
raised, disagree with it, or do not give a monkey's, should _any_ 
political opinion be in the repo?


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Formal Question to Steering Council (re recent PEP8 changes)

2020-07-02 Thread Rhodri James
We've had the requested 24 hour cooling off, and I don't imagine anyone 
is surprised that the situation remains unchanged.  The commit message 
that caused the controversy is still in the PEP repository, and is still 
controversial.  Whether you think it's the best thing since the last 
best thing or the biggest load of bollocks since the last biggest load 
of bollocks is irrelevant.  It's there, it espouses a political stance, 
and by implication the Steering Council support it.


Since explicit is better than implicit :-), I would like to formally ask 
the Steering Council to answer the following questions.


1. Does the Steering Council think political statements have any place 
in the Python repositories?


2. If so, for the avoidance of doubt does the Steering Council support 
the statements in commit 0c6427d? 
(https://github.com/python/peps/commit/0c6427dcec1e98ca0bd46a876a7219ee4a9347f4)


3. If not, what do they intend to do about the above commit?

If the answer to question 1 is a qualified yes or no, both follow-up 
questions apply.


If the answer to question 1 is a prevarication, non-answer or silence, 
people will still draw their own conclusions.  I mention this merely to 
reinforce the idea that these things are still answers as well as 
hostages to fortune.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Code of Conduct address "hold message"

2020-06-30 Thread Rhodri James

On 30/06/2020 15:25, Rhodri James wrote:
Having just had occasion to use the code of conduct link 
(conduct...@python.org), I got back the message:


   Your mail to 'conduct...@python.org' with the subject

     

   Is being held until the list moderator can review it for approval.


Ah, it looks like the message I was expecting is generated when the 
moderator actually picks up the complaint, so that's OK.  The generic 
moderation message is still rather off-putting, though.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Code of Conduct address "hold message"

2020-06-30 Thread Rhodri James
Having just had occasion to use the code of conduct link 
(conduct...@python.org), I got back the message:


  Your mail to 'conduct...@python.org' with the subject



  Is being held until the list moderator can review it for approval.

etc.  I know this is the standard moderation message, but it seems 
rather out of place for the CoC address.  It's not the least bit 
reassuring if you feel uncomfortable about making such reports, as some 
people (myself included) are.  If I were emailing a commercial company's 
complaints line I would expect something more in the nature of


  Thank you for your email about "".  We will deal with
  it as soon as we can."

Plus the usual platitudes about valuing my input and appreciating my 
custom which don't necessarily apply here ;-/


Any chance of getting the message altered to something a bit more friendly?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Pycharm offers only implementation of an abstract getter but not an abstract setter

2020-06-25 Thread Rhodri James

On 24/06/2020 22:46, zljubi...@gmail.com wrote:

Why Pycharm didn't offer a setter as well as getter?


This is a general Python mailing list.  If you have specific 
questions/complaints about PyCharm, they are probably better addressed 
directly to the makers of PyCharm.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 201, Issue 9

2020-06-09 Thread Rhodri James

On 09/06/2020 18:31, Joseph Jenne via Python-list wrote:

On 2020-06-09 09:00, zljubi...@gmail.com wrote:

Well the problem that I am facing with is, that I have to establish 
interface between python and outer system.


Original question was about creation of input object (data that I have 
received from outer system). If I accept recommendation to use "from_" 
instead of "from", it could work, for processing input, because 
processing is under my control.


However, my process will create output object that I should json 
serialize and return back to outer system as a response to the input. 
If I will have "from_" object property instead of "from", I believe 
that I should write a custom object to json serializer in order to 
support changing names from "from_" to "from".


It should be possible to name it from_ and then insert it into the 
__dict__ as 'from', although a custom serializer

would probably be preferable from a design standpoint.


Might it be simpler to use a dict from the start?  You could have a 
dictionary key of "from" without any problems.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Can't download Pygame and Pgzero

2020-06-05 Thread Rhodri James

On 05/06/2020 11:54, Lily Sararat via Python-list wrote:

I have trouble installing the Pygame and Pgzero on Window.  I based
on the instruction on the "Computer Coding Python Games for Kids" by
Carol Vorderman.  Nothing works.



I tried Python 3.6.2 as describe in the book and the latest version
3.8.3 still encounter on the same problem.  I really need to get this
sorted so my kid can spend his summer break mastering the coding.


Hi there Lily.  We aren't Pygame specialists, but we can give it a go. 
However to do that you're going to need to give us some details.  Which 
version of Windows are you using?  What exactly did you do to install 
Pygame and Pgzero, in order, and what exactly went wrong.  Please copy 
and paste any error messages, don't send screenshots because the mailing 
list will strip them off and we won't see them.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Finking: Imports, Namespaces, Poisoning, Readability

2020-06-05 Thread Rhodri James

AFAIKT the "three" are readability, naming conflicts and source location.

On 05/06/2020 01:15, DL Neil via Python-list wrote:

- how do you like to balance these three (and any other criteria)?


Readability is king.  Or queen, if you prefer.  Anything that damages 
readability drops dramatically in its desirability.  One consequence of 
that is that I rarely use "import ... as", since as you mentioned, 
renamed libraries are a rich source of WTF moments.  I would use "import 
numpy as np" (if I ever used numpy) because it seems to be standard, but 
I wouldn't type "import pygame as pg" despite having used PyGame 
extensively in the past.


I tend to use "from xxx import yy_yy, " when I'm not importing many 
things from a library and their names are sufficiently obvious.  The 
definitions of "not many" and "sufficiently obvious" are pretty 
flexible.  In particular, I'll list more items as the qualified names 
get longer, as you noted.  Source location is a non-issue; it's trivial 
to jump to the imports at the top of the file, look it up and jump back 
again.  Or have two buffers viewing the same file; that's a technique I 
use quite a lot anyway.  If I need to know the signature, that's what 
documentation is for.


I would never rename an object I've imported using "as".  It's just not 
worth the inevitable heartache.  If that means I have namespace 
collisions, that's either a vote to use the qualified name or to change 
the name of whatever I wrote that clashes with it.


- is your preference (or selection) influenced by the facilities offered 
by your favorite editor/IDE?


Not really.  I'm an EMACS user, so any of the "fancy" IDE handiwork is 
immediately out.  The only reason you need an IDE is if your support 
tools suck (sorry, Windows users).


- does your decision differ according to whether the 'target module' is 
one of yours, from the PSL, from some third party, corporate, ...?


I'm more likely to change my own module to fit :-)

- do you prefer PSL's importlib over Python's native import-s, for one 
of these (or any other) reason?


Um, why would I?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Binary Sort on Python List __xor__

2020-06-01 Thread Rhodri James

On 31/05/2020 18:01, Evan Schalton wrote:

I think you're arguing both sides of the argument -- numpy arrays do
have a lot of similar, related operations (because numpy uses them
internally -- since they're more efficient) which means they're not
fringe.

I'm advocating that the built-in list class add the efficient,
convenience methods -- especially since it wouldn't be overriding
other methods, it would be leveraging standard methods that are
currently unimplemented



Those methods make perfect sense in the bit-twiddling lists that you are 
using.  They make no sense whatsoever for lists like ["The", "quick", 
"brown", "fox"].  There's a decent purpose for a class implementing the 
features you want, but I honestly don't think the generic list class is it.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: .dll problem

2020-05-29 Thread Rhodri James

[Re-ordered because top-posting is evil ]:-)

On 29/05/2020 17:38, Souvik Dutta wrote:

On Fri, 29 May, 2020, 9:50 pm Preetha M,  wrote:


Hello. Warm regards from india. I am a kid who is currently learning
python. Hope you are doing well. I know that it is not a problem that you
can fix but whenever i try to open the software it shows that
api-ms-win-crt-runtime-l1-0-0.dll is missing. I tried reinstalling but it
is not working. Every application i install shows that something.dll is
missing. Please help.



Do you have DirectX installed. It must solve the problem.



DirectX is highly unlikely to be involved, as you have been told before 
Souvik.  What the OP actually needs is the missing Windows runtime, 
which can be obtained straightforwardly from Microsoft.  Here's the 
link: https://www.microsoft.com/en-in/download/details.aspx?id=48145


Incidentally, the first link Google turns up when you search for 
"windows runtime missing" explains what's going on and points to this link.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.path.join

2020-05-27 Thread Rhodri James

On 27/05/2020 17:39, BlindAnagram wrote:

I believe by attempting to make the directory I send absolute with
abspath() and then copying a file to this path.  They expected this to
copy the file into the directory with its original name but instead it
copies it to the file that abspath 'kindly' converts my directory into.

I did complain about their lack of knowledge but I also have a right to
complain about a function that converts an explicitly specified
directory into a file:-)


Well, they're getting exactly the behaviour I'd expect them to get (and 
not getting what they expect).  I'm faintly gobsmacked that anyone 
expects something like that to work.  If you want a directory, create 
it.  That's what os.mkdir (and the pathlib equivalent) is for.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.path.join

2020-05-27 Thread Rhodri James

On 27/05/2020 16:12, BlindAnagram wrote:

I'm sorry that you don't believe me but all I know is how I intend the
path to be used.  And the os.path functions aren't helpful here when
they actually_change_  the meanings of paths on Windows:


fp= "C:\\Documents\finance\\"
abspath(fp)

'C:\\Documents\\finance'

If you believe these 'before' and 'after' paths are the same I can only
assume that you don't work on Windows (where one refers to a directory
and the other a file without an extension).


More accurately, one is not a legal filename but both are legal 
directory names.


I entirely believe that you have a problem, but I'm inclined to think 
it's of your own making.  You seem to have decided how paths work 
without checking whether the language agrees with you.  It doesn't, and 
hasn't for over a decade without a significant number of complaints (as 
in I can't remember the last one, and I've been around here for a while 
-- it's too hot for me to want to go hunt in the archives :-).


How are these unexpected extensionless files getting created?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.path.join

2020-05-27 Thread Rhodri James

On 27/05/2020 14:41, BlindAnagram wrote:

That is true if you know for sure how your path will be used.

But if you don't, there is a world of difference between passing the
paths 'name' and 'name\\' on for others to use. And in this situation it
doesn't help when os.path functions strip the directory separator off.


Only if you impose meaning externally, which implies you do know how 
your path will be used after all.  If you want to know whether a given 
path corresponds to a file or a directory on a filing system, there's no 
real substitute for looking on the filing system.  Anything else is, as 
you have discovered, error-prone.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.path.join

2020-05-26 Thread Rhodri James

On 26/05/2020 18:07, BlindAnagram wrote:

On 26/05/2020 17:46, MRAB wrote:

On 2020-05-26 16:48, BlindAnagram wrote:

On 26/05/2020 16:22, Ben Bacarisse wrote:

BlindAnagram  writes:


I came across an issue that I am wondering whether I should report
as an
issue.  If I have a directory, say:

   base='C:\\Documents'

and I use os.path.join() as follows:

   join(base, '..\\..\\', 'build', '')


It rather defeats the purpose of os.sep if you include it in a part of
the path.  What you mean is better expressed as

   join(base, '..', '..', 'build', '')

(and base includes it too, but I can't suggest an alternative because I
don't know your intent is far as defaults go.)


Thanks for your input but while that part of my path may not be to your
liking, it works fine and does not seem to be relevant to my concern,
which is that join appears to treat os.sep as an absolute path, which it
is not.


If it starts with the path separator, then it's absolute (well, absolute
on that drive).


Agreed.  I did not think that I needed to add this exception to my
comment as I thought from the the context that it would be clear that I
was questioning how it worked at the end of a path, not when used at its
  start.


But you aren't talking about the end of the (finished) path, you are 
talking about the start of the final path component you pass to 
os.path.join(), "\\".  As the documentation says, "If a component is an 
absolute path, all previous components are thrown away and joining 
continues from the absolute path component."  Since "\\" is an absolute 
path component, all the previous components are thrown away and you are 
left with just "\\".


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Behaviour of os.path.join

2020-05-26 Thread Rhodri James

On 26/05/2020 18:01, BlindAnagram wrote:

On 26/05/2020 17:09, Stefan Ram wrote:

Mats Wichmann  writes:

an absolute path is one that starts with the pathname separator.


   The Python Library Reference does not use the term
   "pathname separator". It uses "directory separator"
   (os.sep) and "filename separator" ('/' on Unix).

   On Windows:

|>>> import pathlib
|>>> import os
|>>> pathlib.PureWindowsPath('\\').is_absolute()
|False
|>>> pathlib.PureWindowsPath(os.sep).is_absolute()
|False
|>>> pathlib.PureWindowsPath('/').is_absolute()
|False


Thanks, that seems to suggest that there is an issue and that I should
hence submit this as an issue.


It is indeed most curious as to why this obviously absolute path is not 
recognised as such :-)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: stderr writting before stdout

2020-05-25 Thread Rhodri James

On 24/05/2020 05:27, Souvik Dutta wrote:

Is there any precedence or priority order by which sys.stderr.write() and
sys.stdout.write() works.


No.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Strings: double versus single quotes

2020-05-23 Thread Rhodri James

On 22/05/2020 20:57, Manfred Lotz wrote:

I also believe that transferring habits from C, Rust or whatever to
Python doesn't make much sense as Python does not distinguish between a
character and string from a type perspective.


From a logical perspective, you are correct.  From the point of view of 
someone who writes more C code than Python, not having to remember a new 
set of habits for Python makes life a lot simpler.


Chacun à son goût and all that.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: why no camelCase in PEP 8?

2020-05-19 Thread Rhodri James

On 18/05/2020 22:07, Eli the Bearded wrote:

camelCase   ->noCamelCase
snake_case  ->no_snake_case

One of those is easier to "grep" for than the other.


Eh.  A changed case in the one, an extra character in the other; that's 
pretty much the same difficulty really.  I certainly don't find it 
"hard" to grep for _snake_case.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python Installation Problem

2020-05-05 Thread Rhodri James

On 05/05/2020 05:34, Adolf Yoshua Marbun wrote:

Dear Python,

I am currently learning about Python. First thing first, I need to install
the interpreter Python 3.8.2 before I get to the IDE. But, I have problem
during running command.

The installation was successful. When I try to run the command prompt,
typing "python --version", it always shows me an error message as attached
below this message. I tried to follow the message (reinstalling the
program), but didn't work. I don't know what it is and I have tried few
times to solve the problem from the internet.


Unfortunately this is a text-only mailing list, and your attachment was 
stripped off before any of us had the chance to see it.  Could you copy 
and paste the error message into a message, please?  Also if you could 
let us know what operating system you are using, some people may be able 
to offer more detailed advice.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


=+ for strings

2020-05-03 Thread James Smith
I tried:
dt=+"{:02d}".format(day)
but I got:
dt=+"{:02d}".format(day)
TypeError: bad operand type for unary +: 'str'

This works:
dt=dt+"{:02d}".format(day)

Why can't I do the shortcut on strings?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python Netcdf and ncdump

2020-04-30 Thread Rhodri James

On 30/04/2020 18:55, J Conrado wrote:

Please,

Please can someone explain to me why I have this difference: in Python 
int16 SST(y, x) and with ncdump -h short SST(y, x)


Presumably on your computer a (signed) short integer is a (signed) 
sixteen bit integer.  That's rather unhelpful of ncdump.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: [RELEASE] Python 3.9.0a6 is now available for testing

2020-04-29 Thread Rhodri James

On 29/04/2020 20:23, Schachner, Joseph wrote:

 norm=lambda m: m+(m and(m[-1]!= '\n'and'\n'or'  ')or'\n')

Parentheses   1  2  
  1 0
quotes 1  0 1   
0   1 01  0

OK I don't see any violation of quoting or parentheses matching.   Still trying 
to figure out what this lambda does.


Presumably it's something to do with recognising string prefixes?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-17 Thread Rhodri James

On 17/04/2020 22:27, dcwhat...@gmail.com wrote:

On Friday, April 17, 2020 at 2:11:17 PM UTC-4, Rhodri James wrote:

And people wonder why I stick to gdb when at all possible :-)

Never worked with it.  Is it a debugger for compiled code, i.e. it steps 
through the executable while displaying the source?  Or interpreted code?


The GNU project debugger has been around for quite a few decades now. 
It's a debugger for compiled code, covering about a dozen source 
languages (I can't be bothered to count at this time of night).  It is 
ridiculously flexible, command-line driven, and most importantly it does 
what you tell it to do.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-17 Thread Rhodri James

On 17/04/2020 17:18, dcwhat...@gmail.com wrote:

Maybe it isn't true for all IDE's or all languages. (I know SOMEONE
will interject here, to argue for the sake of arguing). But when I
worked with Groovy in Intellij about 5 years ago, there were times
when the IDE was confused, during a debugging sessions. I don't
remember the exact details, but that anomaly happened only with DEFed
variables ; it didn't happen when the data type was specified.


This is a general problem for IDEs, and type information isn't always 
helpful.  The number of times I have had to add useless bits of code to 
cast something to (uint8_t *) because I want to see the bytes and the 
IDE will not give up on trying to interpret them for me.


And people wonder why I stick to gdb when at all possible :-)

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-17 Thread Rhodri James

On 17/04/2020 12:40, Aakash Jana wrote:

I am running python 3.8 only but my issue is I need more zeroes after my
result.
I want 2/5 = 0.40
But I am only getting 0.4


When you just print or display a floating point number, Python only uses 
as many digits as needed if the answer happens to be a (small enough) 
exact decimal [*].


>>> foo = 2/5
>>> print(foo)
0.4

If you want the number displayed differently, you have to format it 
yourself.


>>> print("{:6f}".format(foo))
0.40


[*]: Since floats are stored internally in the standard IEEE *binary* 
format, what constitutes an *exact* decimal may be a little surprising!


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: RFC: For Loop Invariants

2020-04-11 Thread Rhodri James

On 10/04/2020 21:44, Elliott Dehnbostel wrote:

Hello Everyone,

I've also posted this to the python-ideas mailing list, but I thought to
post here as well for a more general audience.

If I've done this incorrectly, please let me know so that I can
improve/revise. I'm new to the Python community and quite enjoy the more
functional features of Python 3, but have I have a peeve about it. I'd like
to propose and discuss the following enhancement to Python 3:

*Consider the following trivial for-loop:*

chars = "abcaaabkjzhbjacvb"
seek = {'a','b','c'}
count = 0for a in chars:
  if a in seek:
   count += 1

Gross. Twice nested for a simple count.


a) I don't personally think that's gross (apart from the missing 
newline, which is just an email artefact I assume).


b) If it's simple like this and you care enough, refactor it as a 
comprehension:


  count = sum(1 for a in chars if a in seek)

It it's not so simple, neither the comprehension nor your proposal are 
going to be as readable as the twice nesting.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How To Change Package Representation on Shell?

2020-04-01 Thread Rhodri James

On 01/04/2020 21:22, Abdur-Rahmaan Janhangeer wrote:

Greetings list,

I have a custom package.


import package
package

'>

what do i have to modify from my package to have like


package

Hi!


Do you mean "How do I override the str() or repr() of a module"?  I 
don't think you can.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to instantiate a custom Python class inside a C extension?

2020-04-01 Thread Rhodri James

On 01/04/2020 18:24, Musbur wrote:

Am 01.04.2020 15:01 schrieb Rhodri James:

I believe you do it in C as you would in Python: you call the Series 
class!


pyseries = PyObject_CallObject((PyObject *)&series_type, NULL);


Well, that dumps core just as everything else I tried.

What does work, however, is calling PyType_Ready first:

     PyType_Ready(&series_type);
     pyseries = PyObject_New(Series, &series_type);
     PyObject_Init((PyObject *)pyseries, &series_type);o

I don't understand, though, why I have to do that and when. Didn't that 
already happen when the module was imported? Do I need to do it whenever 
I create a new instance in C?


It should have happened on your module being imported, the line was 
there in your code.  Stick a breakpoint on your module init function and 
see if it is being called.


(The "from thingy import *" always makes me nervous, but it shouldn't be 
responsible for this.)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to instantiate a custom Python class inside a C extension?

2020-04-01 Thread Rhodri James

On 01/04/2020 13:42, Musbur wrote:
So when created from C, neither the "new" nor the "init" functions are 
called on the object, only "finalize". No wonder I get segfaults in the 
real life application.


So how is this done right? Here's the C module:


I believe you do it in C as you would in Python: you call the Series class!

pyseries = PyObject_CallObject((PyObject *)&series_type, NULL);

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Like c enumeration in python3

2020-03-23 Thread Rhodri James

On 23/03/2020 02:18, Paulo da Silva wrote:

Hi!

Suppose a class C.
I want something like this:

class C:
KA=0
KB=1
KC=1
...
Kn=n

def __init__ ...
...


These constants come from an enum in a .h (header of C file).
They are many and may change from time to time.
Is there a way to somehow define them from inside __init__ giving for
example a list of names as strings?


It sounds like what you want is a separate script to process your .h 
file into a Python module containing an enum, then import that module 
into your program.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Rhodri James

On 19/03/2020 14:47, Peter J. Holzer wrote:

On 2020-03-19 14:24:35 +, Rhodri James wrote:

On 19/03/2020 13:00, Peter J. Holzer wrote:

It's more compact, especially, if "d" isn't a one-character variable,
but an expression:

  fname, lname = db[people].employee.object.get(pk=1234)[['first_name', 
'last_name']]

vs.

  fname = db[people].employee.object.get(pk=1234)['first_name']
  lname = db[people].employee.object.get(pk=1234)['last_name']


I have to say I don't think that's more compact at all.  It's too wide
to be compact.


But 83 characters is still more compact than 121 characters.


Only if your sole metric is a strict character count.  Width matters in 
perception; two shorter lines are easier to take in than one long line, 
even if the long line contains fewer characters.


Besides, terseness isn't one of Python's objectives.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Why is the program not printing three lines?

2020-03-19 Thread Rhodri James

On 19/03/2020 13:58, Souvik Dutta wrote:

I should have been more clear
class first():
 print("from first")
 def second():
 print("from second")
first()

When I run the above code the output is
"from first"
(2ND CODE)

class first():
 print("from first")
 def second():
 print("from second")
first.second()

When I run this code the output is
"from first"
"from second"

Thus going by the above logic

class first():
 print("from first")
 def second():
 print("from second")
first()
first.second()

This should have given the following output
from first
from first
from second


Nope.  You haven't made your logic clear, but I think you are still 
confused about when the code in the class suite is run, and still think 
of it as running when an instance is created.


Try running this code:

class first:
print("from first")

Just that.  No instantiation, no "first()", nothing else.  Just the 
class suite itself.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread Rhodri James

On 19/03/2020 13:00, Peter J. Holzer wrote:

On 2020-03-19 18:22:34 +1300, DL Neil via Python-list wrote:

On 19/03/20 3:28 PM, Santiago Basulto wrote:

myself missing A LOT features from NumPy, like fancy indexing or
boolean arrays.
So, has it ever been considered to bake into Python's builtin list and
dictionary types functionality inspired by NumPy? I think multi indexing
alone would be huge addition. A few examples:

[snip]>> I fear that I'm missing your point.


How is
l[[0, -1]] or fname, lname = d[['first_name', 'last_name']]
any better than
l[ 0 ], l[ -1 ] or
fname = d[ 'first_name' ]
lname = d[ 'last_name' ]


It's more compact, especially, if "d" isn't a one-character variable,
but an expression:

 fname, lname = db[people].employee.object.get(pk=1234)[['first_name', 
'last_name']]

vs.

 fname = db[people].employee.object.get(pk=1234)['first_name']
 lname = db[people].employee.object.get(pk=1234)['last_name']


I have to say I don't think that's more compact at all.  It's too wide 
to be compact.  I think the second version is more readable (and the 
third version, where you factored out the common lookup is better still).


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to build python binaries including external modules

2020-03-18 Thread James via Python-list
On Wednesday, March 18, 2020 at 4:44:46 PM UTC-7, Michael Torrie wrote:

> Cython requires a working Python interpreter to run the setup.py.  How
> would that work when building python itself?

Python binary is built with a host of default modules. My question was how to 
promote external module(s) to a list of default modules. Or is it possible?
The goal was to build python for cross-platforms with external modules.

James
-- 
https://mail.python.org/mailman/listinfo/python-list


How to build python binaries including external modules

2020-03-18 Thread James via Python-list
When you build python binaries from source, how to add external modules?
For example, to install cython, conventional method is building python first, 
then running setup.py for cython.
I'd like to combine the 2-step into one.

Thanks
James
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python question

2020-03-11 Thread Rhodri James

On 11/03/2020 04:06, Michael Torrie wrote:

On 3/10/20 6:49 PM, Souvik Dutta wrote:

What about moving on to a social media app completely made in pythoj for
python?

No thanks. I don't want to be on yet another web forum.  I don't need
"social media" or a "social media app."  Email works exceedingly well
for this sort of thing, despite Google's antics.


+10

The best response to "This system breaks when I abuse it" is almost 
always "Well stop abusing it then."


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable

2020-02-26 Thread Rhodri James

On 25/02/2020 15:06, BlindAnagram wrote:

My interest in this stems from wanting to keep the dictionary only
available to the function that uses it and also a worry about being
called from threaded code.


Hiding your dictionary away inside a class or instance isn't going to 
protect it from threading disasters by itself, though it will make it 
easier to protect it as you need.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable

2020-02-25 Thread Rhodri James

On 25/02/2020 15:20, BlindAnagram wrote:

class GetIt:
   seen = dict()

   def __call__(self, piece):
     return GetIt.seen[piece]

get_it = GetIt()

but then you have a global class instance hanging around, which is not
actually any better than a global dictionary.

This doesn't work for me since get_it(piece) returns the error:

builtins.TypeError: get_it() takes no arguments


It works for me (pace sticking something in GetIt.seen to avoid getting 
a KeyError).  You aren't muddling up the class name and instance name 
are you?


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: encapsulating a global variable

2020-02-25 Thread Rhodri James

On 25/02/2020 12:38, BlindAnagram wrote:

I would appreciate advice on whether it is possible to avoid the use of
a global variable used in a function by encapsulating it in a class
without maaking any changes to the call interface (which I cannot change).

I have:


seen = dict()

def get_it(piece):
...
return seen[piece]


and I am wondering if it is possible to use a class something like


class get_it(object):

   seen = dict()

   def __call__(piece):
 return seen[piece]


to avoid the global variable.


I wouldn't.  Calling the class name creates an instance of the class, so 
won't actually do what you want.  You could rewrite the class and create 
an instance to call instead:


class GetIt:
  seen = dict()

  def __call__(self, piece):
return GetIt.seen[piece]

get_it = GetIt()

but then you have a global class instance hanging around, which is not 
actually any better than a global dictionary.



--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: time.localtime add a parameter for timezone

2020-02-24 Thread Rhodri James

On 24/02/2020 17:21, Dieter Maurer wrote:

qbit wrote at 2020-2-24 05:18 -0800:

How about adding a time zone parameter to time.localtime?

A  offset just like the form: ± hh[:mm[:ss]].


Why should this be necessary? `localtime` returns the time
in the "local timezone" -- and the "local timezone" usually
does not change between different calls to `localtime`.


It can if your calls to localtime() happen either side of a daylight 
saving time switch.


That said, I agree that the timezone doesn't really belong in the output 
of localtime().  There are a very few occasions when you want it, but 
more often you should be working in UTC not local time.



--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Paper Print Help

2020-02-20 Thread Rhodri James

On 20/02/2020 15:08, Duram wrote:

On 19/02/2020 12:17, Rhodri James wrote:

On 19/02/2020 14:22, Duram via Python-list wrote:
I have a drawing in a .gif file with (a,b) pixels and want to 
paperprint it in a position (x,y), what would be the code?


What have you tried?


Nothing, I did not find the module that make to print to the paper


Please don't reply to me directly; if it's a question worth asking in 
public then it's worth answering in public too!


OK, let's backtrack a bit.  First off, what operating system are you using?

Second, do you have this GIF file in any sort of program at the moment, 
or do you want advice on how to write a program to handle the image?  I 
suspect your question is a bit too specific at the moment, and you have 
some mistaken assumptions about how images and (most especially) 
printing work.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Paper Print Help

2020-02-19 Thread Rhodri James

On 19/02/2020 14:22, Duram via Python-list wrote:
I have a drawing in a .gif file with (a,b) pixels and want to paperprint 
it in a position (x,y), what would be the code?


What have you tried?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Rhodri James

On 12/02/2020 17:46, Python wrote:

On Wed, Feb 12, 2020 at 01:16:03PM +, Rhodri James wrote:

On 12/02/2020 00:53, Python wrote:

In pretty much every job I've ever worked at, funding work (e.g. with
humans to do it) with exactly and precisely the resources required is
basically impossible, and management prefers to underfund the work
than to overfund it, for cost-savings reasons.  This basically means
that any non-trivial work you do inevitably will become technical debt



s/become/accrue/.  The work itself isn't the debt, but its sub-optimality
creates debt (or future headaches, if you prefer to think of it that way).



I think it's a purely semantic distinction without a practical
difference...which was the point I was trying to make.  The work is
the direct cause of the debt, and at the time it is performed the debt
is realized.  Without the work, that particular debt is not incurred.
You may have eliminated some old debt when the work is done, but your
new debt replaces your old debt.  Depending on the resources you can
devote, that debt may or MAY NOT be less than the other, and sometimes
the truth of this can not be discovered until you're already knee deep
in it.


Here's where the "purely semantic" distinction matters.  You are 
equating the work with the debt, but ignoring the benefit the work 
presumably brings (otherwise you wouldn't have done it at all).  Either 
you should be rolling it all together or separate both, surely.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Technical debt - was Re: datetime seems to be broken WRT timezones (even when you add them)

2020-02-12 Thread Rhodri James

On 12/02/2020 00:53, Python wrote:

In pretty much every job I've ever worked at, funding work (e.g. with
humans to do it) with exactly and precisely the resources required is
basically impossible, and management prefers to underfund the work
than to overfund it, for cost-savings reasons.  This basically means
that any non-trivial work you do inevitably will become technical debt


s/become/accrue/.  The work itself isn't the debt, but its 
sub-optimality creates debt (or future headaches, if you prefer to think 
of it that way).



IMMEDIATELY, because you will not be given the time to do the job
completely in the first place, there will inevitably be bugs which are
minor enough to ignore indefinitely, and most likely, in order to meet
arbitrary-but-nevertheless-real time constraints you will find
yourself obliged to take shortcuts.  So conceptually "costs" may be
different from "debt" but in practice, you never have one without the
other, and "debt" is really just "costs" you haven't paid yet.


It's that last bit, "you haven't paid yet", that's the important part. 
Project managers and accountants alike are very much in favour of 
putting off paying for things if they can.  Sometimes they can be 
persuaded that the interest on the debt (the extra cost that the code 
structure imposes on fixing bugs) is too much, and then you get the 
opportunity to refactor and reduce the overall debt (at a cost, 
obviously) and the interest you will pay in the future.


Sometimes, and this is the bit that bean counters really like, you can 
get away without paying the debt by ditching the project entirely before 
the debt is paid off.  If you don't want to piss your customers off you 
need to pay the cost of a replacement project, which will accrue its own 
technical debt...


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: ERROR in loading data

2020-02-04 Thread Rhodri James

On 04/02/2020 14:49, laiba.zubai...@gmail.com wrote:

#load the training and testing data, then scale it into the
# range [0, 1]
print("[INFO] loading  ADNI data...")
((trainX, trainY), (testX, testY)) = '/content/gdrive/My 
Drive/3_Classes/'.loads_data()
trainX = trainX.astype("float") / 255.0
testX = testX.astype("float") / 255.0
  
	# initialize the label names for the  ADNI dataset

labelNames = ["outAD", "outCN", "outMCI"]
When i try to run this code I got the following error.

[INFO] loading  ADNI data...
---
AttributeErrorTraceback (most recent call last)
 in ()
   1 print("[INFO] loading  ADNI data...")
> 2 ((trainX, trainY), (testX, testY)) = '/content/gdrive/My 
Drive/3_Classes/'.loads_data()
   3 trainX = trainX.astype("float") / 255.0
   4 testX = testX.astype("float") / 255.0
   5


So that error is saying that something on line 2 is trying to use an 
attribute incorrectly, probably one that doesn't exist (there really 
should be more explanatory information in the error, by the way).  The 
only thing on line 2 that tries to access an attribute is the string 
'/content/gdrive/My Drive/3_Classes/', which tries to run the method 
loads_data().  Fair enough.  A quick test on the interactive command 
line or a look in the documents will tell you that strings indeed do not 
have a loads_data() method.


I don't know what library you are intending to use, but you need to open 
your file with that first.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: when uses time.clock,there are always mistakes

2020-02-03 Thread Rhodri James

On 03/02/2020 08:04, 石盼 wrote:

Hello !
 The problem like this:
     RESTART: Shell 

  >>> import time
  >>> t = time.clock()
  Traceback (most recent call last):
    File "", line 1, in 
  t = time.clock()
  AttributeError: module 'time' has no attribute 'clock'


It is correct, there is no time.clock() function.  The documentation is 
here: https://docs.python.org/3/library/time.html


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Dynamic Data type assignment

2020-01-28 Thread Rhodri James

On 28/01/2020 12:03, sushma ms wrote:

Hi

Please find below example and the compiler error,

when i'm assigning value dynamically and when we comparing in "if" loop it
is throwing compiler error. It should not throw error


It absolutely should throw an error.


it should assign and
act as int why it is thinking as string.


Because it is a string.  The documentation of "input" is quite explicit 
about this:


 input([prompt])

If the prompt argument is present, it is written to standard output 
without a trailing newline. The function then reads a line from input, 
converts it to a string (stripping a trailing newline), and returns 
that. When EOF is read, EOFError is raised.



--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Friday Finking: Enum by gum

2020-01-24 Thread Rhodri James

On 24/01/2020 04:26, DL Neil via Python-list wrote:

Questions:

Have I made proper sense of this? (please don't laugh too much)


Um.

My basic take on enums is that they provide a convenient namespace to 
collect together related constants.  API flags and opcodes are an 
obvious example of related constants you would want to keep together, 
but Python enums can be more complex than that both as structured data 
and associated functions.


Is the above 'interfacing' an appropriate use of enum-s; or is it really 
'overkill' or posturing?


I think it's an entirely appropriate use of enums.  In fact it's pretty 
much my only use of them.  One caveat: when you care about the value of 
a constant, set it explicitly.  Don't rely on auto() to come up with the 
right number for you, because the documentation really gives you no 
guarantees.


Python v3.6+ brings Flag-enums into the game. These seem better for 
interface use, as described. Do you prefer them to the 'plain-vanilla' 
enum, and for what reason?


I prefer them when the interface calls for flags, because they behave 
like flags.  I use plain enums when I don't require that behaviour. 
It's horses for courses, as ever.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: [Python-ideas] Re: Enhancing Zipapp

2020-01-08 Thread Rhodri James

On 08/01/2020 18:08, many people wrote lots of stuff...

Folks, could we pick one list and have the discussion there, rather than 
on both python-list and python-ideas?  Getting *four* copies of Andrew's 
emails is a tad distracting :-)


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python, Be Bold!

2020-01-06 Thread Rhodri James

On 01/01/2020 07:22, Abdur-Rahmaan Janhangeer wrote:

-- Self-updating Python distributions


Microsoft have proved time and again that this is a really good thing if 
you want to piss off your customer base.  Let's not.



-- Distributions which notify about new releases


Surely this is the OS's package management system's job?


-- Easy compilation to python-specific executable (.pyz is a good candidate)


Don't we already have .pyc files?


-- More robust native Gui facilities


Why is this a core Python issue?  GUIs are inherently OS-specific 
(including those OSes -- or lack of OSes -- which have no graphical 
interface).


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python, Be Bold! - The Draft

2020-01-06 Thread Rhodri James

On 06/01/2020 10:21, Abdur-Rahmaan Janhangeer wrote:

Before we begin, we'd like to define the term executable used in the context
of this draft. It means an archive that is run by double-clicking.


I'm an embedded systems programmer.  Congratulations, you have just 
rendered your draft utterly irrelevant to me and those like me.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Dataset training using Kmeans

2020-01-06 Thread Rhodri James

On 05/01/2020 12:56, hanan lamaazi wrote:

Dear all,

I'm actually using the K-means algorithm for clustering, and scikit-learn
machine learning in python.

when I want to print my "score_accuarcy" using this command


print(metrics.accuracy_score(y_test, y_pred))


I get the following error :

"Classification metrics can't handle a mix of continuous-multioutput and
binary targets"


This is probably an exception from metrics.accuracy_score() (you've 
shorn off too much context for me to be certain).  Googling the text 
gives me no shortage of links; you are far more likely than me to 
recognise which of them are relevant to your circumstances.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Front end

2020-01-01 Thread James Lu
I would use software like Airtable. You set the columns, Airtable produces
a type-checked form. Every spreadsheet also comes with its own API, so you
can exfiltrate the data programmatically easily.

On Sat, Dec 28, 2019, 10:36 L A Smit  wrote:

> Hi
>
> Don't know if this is the correct subject but i want a program like an
> invoice, You make an invoice and save it and the next one is ready to
> use. I am completely new to programming and want this program for myself.
>
>
> I want to use python to do it. Have already build the program but don't
> know how to put it in usable format. I hope you understand what i mean.
>
> Ex: Input.
>
> Quote Nr:
>
> Client:
>
> Product:
>
> Then there will be costs and in the end a cost per product.
>
> In the end a save button to save quote with input from line 1 and 2.
>
> Then the template is ready for next input.
>
> I understand that there is probably hundreds of these programs but to
> teach myself i want to wright my own program and then i can update it
> when needed.
>
>
>
> Thx
>
>
> L Smit
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: hexdump module installation error

2019-12-19 Thread Rhodri James

On 19/12/2019 12:43, tommy yama wrote:

Thanks for your quick response i did not expect.
I hope you see the error below in my response as i just copy and paste it.

"no module named 'hexdump'."

In addition, i tried to execute python3 hexdump.py. However, no such file
directory.

from hexdump import hexdump

ModuleNotFoundError: No module named 'hexdump'

user@USERnoMacBook-Air LibraBrowser % python3 hexdump.py

/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python:
can't open file 'hexdump.py': [Errno 2] No such file or directory

user@USERnoMacBook-Air LibraBrowser %


Huh.  You've done a "pip3 install hexdump" so I don't know what might be 
happening here.  Sorry.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: hexdump module installation error

2019-12-19 Thread Rhodri James

On 19/12/2019 11:23, tommy yama wrote:

Thanks for your kind response.
The error was simply "module Hexdump was not found".


Several things:

a) Did it really say "module Hexdump was not found"?  "hexdump" and 
"Hexdump" are not the same things; module names are case-sensitive.


b) There will have been a whole load more stack trace that might be 
useful to us.  I should have been clearer when I asked you to copy and 
paste the error that I really meant the whole of the complaint that 
Python made to you, not just the final error message!  Apologies for that.


c) I would much prefer it if you didn't top-post, but interleaved your 
replies like I've done here.  I find it hard to follow top-posted 
messages because they reverse the normal flow of conversation.





On Wed, Dec 18, 2019 at 11:39 PM Rhodri James  wrote:


On 18/12/2019 02:23, tommy yama wrote:

Hi,

This sounds familiar to somebody?
After upgrading my mac OS to Catalina, this persists even after pip3
install hexdump.

[image: image.png]


I'm afraid this is a text-only mailing list.  Your screenshot has been
stripped out before any of us saw it.  Could you copy and paste (DON'T
retype!) the error instead, so we can all read it?

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list






--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: hexdump module installation error

2019-12-18 Thread Rhodri James

On 18/12/2019 02:23, tommy yama wrote:

Hi,

This sounds familiar to somebody?
After upgrading my mac OS to Catalina, this persists even after pip3
install hexdump.

[image: image.png]


I'm afraid this is a text-only mailing list.  Your screenshot has been 
stripped out before any of us saw it.  Could you copy and paste (DON'T 
retype!) the error instead, so we can all read it?


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-12 Thread Rhodri James

On 11/12/2019 21:32, mus...@posteo.org wrote:

On Tue, 10 Dec 2019 14:56:10 -0500
Dennis Lee Bieber  wrote:


It is called when the language IMPLEMENTATION decides to call
it. That time is not specified in the language description/reference
manual.

Yes it is:

"Note: del x doesn’t directly call x.__del__() — the former decrements
the reference count for x by one, and the latter is only called when
x’s reference count reaches zero."

Plain and simple: When the refcount reaches zero.
You are assuming that "when" implies "immediately on the occurence."  It 
doesn't.  This happens to be the behaviour in CPython, but other 
implementations vary as Chris has explained several times now.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-11 Thread Rhodri James

On 11/12/2019 14:17, Musbur wrote:

Am 10.12.2019 22:33 schrieb Paul Moore:


You do understand that the reference counting garbage collector is an
implementation detail of the CPython implementation *only*, don't you?


I don't think that's true. Here's a sentonce from near the top of the 
"gc" module documentation of Python 3:

https://docs.python.org/3/library/gc.html#module-gc

"Since the collector supplements the reference counting already used in 
Python, you can disable the collector if you are sure your program does 
not create reference cycles."


The way I read this is that Python automatically and immediately deletes 
objects once their refcount goes to zero, and the garbage collector only 
kicks in case of circular references or other obscure circumstances. The 
documentation makes no reference to the specific Python implementation, 
so I believe this is true for CPython as well as others.


That's a bug in the documentation, and needs fixing; thanks for pointing 
it out!  It is certainly true that some other Python implementations 
(Jython for example) do not use reference counting, and disabling the 
collector may have further-reaching implications for those 
implementations.  I can't speak to the details; the only other 
implementation I use is Micropython, and I don't use that often enough 
to have cared about the details of garbage collection beyond noting that 
it's different to CPython.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James

On 10/12/2019 19:25, R.Wieser wrote:

And to repeat, you have*no*  guarantee*at all*  in the language spec that
this will happen.

There is also absolutily no guarantee in those specs that my 'puter will not
suddenly transform into a bonzai tree.   Should I now expect it to happen ?


That's an implementation detail of your computer.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James

On 10/12/2019 19:00, R.Wieser wrote:

MRAB,


You merely disabled the mark-and-sweep collector.


Nope.   Go check the docs on "gc"


Yep.  Go and check the docs on "gc" *carefully*

*plonk*


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python3 - How do I import a class from another file

2019-12-10 Thread Rhodri James

On 10/12/2019 17:18, R.Wieser wrote:

Chris,


Okay. What should happen when you do this?

x = 5
del x

Should the integer 5 be deleted?


Yep.

What do you think happens instead ?   I've not seen you explain or support
anything in that regard, not even now.


As it happens, the object that is the integer 5 *isn't* deleted.  Once 
again, you are making assertions based on what you believe to be true, 
despite having been told otherwise.  That's fair enough, but you then 
give those assertions the weighting of fact.



There is a bit of a problem with the above though: It has got zero to do
with the __del__ I was talking about.


On the contrary, it's exactly the point.  You are asserting behaviour 
that you are not guaranteed.  It happens that current versions of 
CPython conform to your expectations.  I have a vague and unreliable 
recollection that earlier versions didn't.  Other Python interpreters 
may or may not.  The language description does not give you that 
guarantee, so relying on it is at best foolish.



 I've not seen you point out any
mistake with my example (pointing out race contition problems) either.


Greg Ewing did:

"In that case, it was only working by accident. You were unwittingly
relying on the garbage collector to immediately clean up the object
as soon as the last reference to it disappeared. That happens to be
true currently in CPython (which uses reference counting), but it's
not guaranteed by the language."

Unless you're referring to some other example.  It's a bit hard to tell 
without the context.



Not a smooth move bro.  Not a smooth move /at all/ :-(


Words fail me.


So the language designers couldn't possibly have been so stupid
as to do things this way, but you're going to ignore what they did?


Actually, they didn't.

Did you know you can disable the garbage collector ?  Well, you can.   Guess
what I saw when I disabled it, created a class instance and than deleted it
again.  Yup, the "print" command I placed in the "__del__" method did
actually show output - something that, according to you, could/should never
happen ...


What you disabled wasn't the garbage collector, it was the garbage 
collector's periodic background run to detect reference cycles and 
delete them when they have no external references.  The garbage 
collector itself ran just fine when your instance's reference count 
reached zero, exactly as everyone has been saying to you.


And to repeat, you have *no* guarantee *at all* in the language spec 
that this will happen.  The garbage collector could have waited until it 
was short of space before deleting the object, for example, which might 
not happen until your script terminates.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Randomizing Strings In A Microservices World

2019-12-10 Thread Rhodri James

On 10/12/2019 03:35, Tim Daneliuk wrote:

On 12/9/19 8:50 PM, Paul Rubin wrote:

Tim Daneliuk  writes:

- Imagine an environment in which there may be multiple instances of a given
   microservice written in Python.


Decide the maximum number of microservice instances, say 1000.  Chop up
the 10 digit range into 1000 pieces, so 0..99, 100-199, etc.
Give one range to each microservice instance.  Then have the
microservices give out the numbers sequentially, but treating them as 10
digit numbers and encrypting each one under a 10 digit pseudorandom
permutation shared by all the instances.  Look up "format preserving
encryption" for how to do this.

Obvious variants of the above are obvious, and maybe you need some way
to hand around chunks of range if some instance gives out more than a
million numbers.




The problem here is that the services are ephemeral and the number of said
services is not fixed.


Hm.  Normally I'd mash together the MAC address of the interface and the 
process ID of the service (or whatever individual identifier 
microservices have -- indeed, whatever microservices *are* :-), but ten 
digits is a bit few for that.  So you want some variant of Paul's approach.


* I assume there are a number of machines providing these services. 
Give them unique numbers -- I'm guessing three digits should be enough 
for that, but you know your own setup better.  How you assign those 
numbers is up to you; a config file in /etc, a Windows registry key, or 
some broadcast protocol that the machines use to dynamically configure 
themselves are all options that spring to mind.


* On each machine, something must spin up services when they are needed. 
 That something will be in a position to assign a unique number (within 
an individual machine) to each service.  So do that, using whatever 
digits you have left after the unique machine number.


* Mash these two numbers into a single ten digit identifier.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Regarding problem in python 3.8.0 installation

2019-12-09 Thread Rhodri James

On 08/12/2019 18:08, alok singh wrote:

Sir,

My system is windows 7 SP1 32-bit . after installing python in my
system,when i try to launch it using command prompt then a message is
shown. I am attaching a screenshot of the following.
kindly look seriously into my problem and tell me the solution..


I'm afraid this is a text-only mailing list, so your screenshot has been 
stripped off before any of us could see it.  Please could you copy and 
paste the text of the error message you receive.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named Adafruit_SSD1306 Update

2019-12-05 Thread Rhodri James

On 05/12/2019 19:30, Rhodri James wrote:

On 05/12/2019 18:49, RobH wrote:

Update:
I did python3 Internet.py
and now only get this error:

pi@raspberrypi:~/Downloads $ python3 Internet.py
   File "Internet.py", line 24
 font = ImageFont.truetype( 'Minecraftia.ttf', 35)
 ^
TabError: inconsistent use of tabs and spaces in indentation

I cannot see what is wrong, as the text is all lined up with that 
above and below:


The problem will be that you have a mix of tabs and spaces in your 
indentation.  This causes problems because some people don't think that 
the One True Tab Width is 8 characters ;-) so to them the indentation 
looks ragged.  Worse, when they mix tabs and spaces, code that looks to 
be at the same indentation level to them looks different to the 
interpreter.  The decision was taken a while ago that Python should put 
its foot down about this, and demand that we use either all tabs or all 
spaces for our indentation.  That's what you've fallen foul off; there 
must be a mix of tabs and spaces in that line!


Or more likely you've used tabs on that line and spaces elsewhere, or 
vice versa.  I should have remember to say that, sorry.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: ImportError: No module named Adafruit_SSD1306 Update

2019-12-05 Thread Rhodri James

On 05/12/2019 18:49, RobH wrote:

Update:
I did python3 Internet.py
and now only get this error:

pi@raspberrypi:~/Downloads $ python3 Internet.py
   File "Internet.py", line 24
     font = ImageFont.truetype( 'Minecraftia.ttf', 35)
     ^
TabError: inconsistent use of tabs and spaces in indentation

I cannot see what is wrong, as the text is all lined up with that above 
and below:


The problem will be that you have a mix of tabs and spaces in your 
indentation.  This causes problems because some people don't think that 
the One True Tab Width is 8 characters ;-) so to them the indentation 
looks ragged.  Worse, when they mix tabs and spaces, code that looks to 
be at the same indentation level to them looks different to the 
interpreter.  The decision was taken a while ago that Python should put 
its foot down about this, and demand that we use either all tabs or all 
spaces for our indentation.  That's what you've fallen foul off; there 
must be a mix of tabs and spaces in that line!


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-14 Thread Rhodri James

On 14/11/2019 17:11, R.Wieser wrote:

Rhodri,


MyVar is a global here, so nonlocal explicitly doesn't pick it up.

I do not agree with you there (the variable being global).  If it where than
I would have been able to alter the variable inside the procedure without
having to resort to a "global" override (an override which is only valid for
the context its used in by the way, not anywhere else)

Than again, that is how it works in a few other languages, so I might have
been poisonned by them.:-)


You have been.

  # This is at the top level of a module
  # I.e. it's a global variable
  my_global_variable = 5

  # You can read globals from within a function without declaring them
  def show_my_global():
print(my_global_variable)

  # If you try setting it, you get a local instead
  def fudge_my_global(n):
my_global_variable = n

  show_my_global()  # prints '5'
  fudge_my_global(2)
  show_my_global()  # prints '5'

  # If you read the variable before setting it, you get an exception
  def mess_up_my_global(n):
print(my_global_variable)
my_global_variable = n

  mess_up_my_global(2) # UnboundLocalError!

  # ...because it must be a local because of the assignment, but it
  # doesn't have a value at the time print() is called.

  # To do it right, declare you want the global from the get go
  def love_my_global(n):
global my_global_variable
print("It was ", my_global_variable)
my_global_variable = n

  love_my_global(3) # prints 'It was 5'
  show_my_global()  # prints '3'

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


A more

2019-11-14 Thread James Lu
Where do I go to find a more complete specification for Python? I want to
learn about common semi-internal language features used by popular
libraries, because I am reimplementing Python.

The reference guide says:

> While I am trying to be as precise as possible, I chose to use English
> rather than formal specifications for everything except syntax and lexical
> analysis. This should make the document more understandable to the average
> reader, but will leave room for ambiguities. *Consequently, if you were
> coming from Mars and tried to re-implement Python from this document alone,
> you might have to guess things and in fact you would probably end up
> implementing quite a different language. *
>

So I would like some additional help.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nonlocal fails ?

2019-11-14 Thread Rhodri James

On 14/11/2019 13:06, R.Wieser wrote:

Hello all,

I've just tried to use a "nonlocal MyVar" statement in a procedure
defenition, but it throws an error saying "Syntax error: no binding for
nonlocal 'MyVar' found.

According to platform.python_version() I'm running version 3.8.3

Why am I getting that error ? (already googeled ofcourse)

Testcode:
- - - - - - - - - - - -
Def Proc1()
 nonlocal MyVar
 MyVar = 5

MyVar = 7
Proc1()
print(MyVar)
- - - - - - - - - - - -
I've also tried moving "MyVar = 7" to the first line, but that doesn't
change anything.  Using "global MyVar" works..


The Language Reference says 
(https://docs.python.org/3/reference/simple_stmts.html#the-nonlocal-statement):


"The nonlocal statement causes the listed identifiers to refer to 
previously bound variables in the nearest enclosing scope *excluding 
globals.*"  (my emphasis.)


MyVar is a global here, so nonlocal explicitly doesn't pick it up.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Launching a Script on the Linux Platform

2019-11-12 Thread Rhodri James

On 12/11/2019 18:25, Rob Gaddi wrote:

On 11/12/19 10:06 AM, Wildman wrote:

What is the best approach for launching a Python GUI program
on a Linux platform.  The program will be distributed in .deb
format.  So the .deb will contain a menu file as well as a
.desktop file.  The post install script will update the system
menu.

My question is how should the program be executed?  Here are
two choices for the "command=" entry in the menu file...

command="/path/to/program.py"

In this case the hash-bang would have to be included in the
program script... #!/usr/bin/env python3

The other choice is this...

command="python3 /path/to/program.py"

(Of course, the Exec command in the .desktop file should match.)

Is one method better than the other or does it acutally matter?



I will note that without the shebang (and setting the execute bit), the 
program is only executable from the GUI menu, not the command prompt.  I 
personally start even GUI programs far more often from a prompt.


To follow Linux conventions you'd put the shebang, make the file 
executable, and put the executable somewhere on the PATH.  I'd stick to 
those conventions barring a particular reason not to.


Wildman is talking about launching his program from a menu, so putting 
it on the PATH is unnecessary.  It may even be a bad idea, depending on 
exactly what he's done :-)


As to the original question, there shouldn't really be much of a 
difference.  The original idea of the shebang line invoking env, as far 
I recall, was that you'd get the "proper" system python3 wherever it had 
been put rather than something random and possibly malicious.  I guess 
that means to go for your first option.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using Makefiles in Python projects

2019-11-12 Thread Rhodri James

On 11/11/2019 19:05, Bill Deegan wrote:

You could use SCons (native python... )


I could.  But I'd have to learn how to first, and particularly for 
complex cross-platform working that involves learning a lot of stuff I 
already know how to do in Make.  The time investment has never seemed 
that worthwhile.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using Makefiles in Python projects

2019-11-11 Thread Rhodri James

On 11/11/2019 17:55, Thomas Jollans wrote:
I'm sure it's possible to write Makefiles that work with both GNU make 
and NMake, but I imagine it's a rather limiting and thankless enterprise.


Is that something you actually do? (Maybe it's great, I really wouldn't 
know. Do tell!)


Trying to work cross-platform with NMake/GNU make is every bit as horrid 
as you're imagining when you start getting clever, and I haven't tried 
doing it for years.  Generally when I'm working on both Windows and 
Linux, Cygwin is involved anyway so I just use GNU make and be done with it.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Using Makefiles in Python projects

2019-11-11 Thread Rhodri James

On 09/11/2019 23:50, Thomas Jollans wrote:

On 09/11/2019 21:30, Chris Angelico wrote:

On Sun, Nov 10, 2019 at 2:10 AM Thomas Jollans  wrote:

On 07/11/2019 20:20, Vitaly Potyarkin wrote:

What do you think of using Makefiles for automating common chores in
Python projects? Like linting, type checking and testing?

I've come up with a reusable Makefile for automating virtual 
environment

management in Python projects. I think it can be useful for simplifying
the onboarding of new developers (both new to project and new to 
Python)

and for documenting project's development practices.

Here it is:
- Repo: https://github.com/sio/Makefile.venv
- Demo screencast: https://asciinema.org/a/279646

What do you think? Is this useful or I'm just unaware of some tool that
abstracts venv chores away better?


As others have said, make is a useful tool and many people use it for
different purposes in their Python projects. Nothing wrong with that.

HOWEVER, at risk of stating the obvious, using Makefiles written for/on
*nix systems on Windows is a bit of a hassle. If, for some reason, your
software is *nix-only anyway, that's fine. If not, using make means
sacrificing some portability.

If your software runs on Windows, of you think it might run on Windows
in the future, maybe consider writing simple Python scripts for
platform-independent tasks rather than makefiles and shell scripts.


Are you assuming that every Windows system has Python, but that you
can't get make or bash? Because neither half of that is true. I've
happily used makefiles on Windows, and these days, bash is as easy to
get hold of as Python is.

ChrisA


That's why I say "a bit of a hassle". You can get a MSYS set up (whether 
from Git for Windows or otherwise). You can get it to play nice with the 
right Python installation and the Python scripts you presumably want to 
call from the Makefile. But all of that is a bit of a hassle.


If you've got almost any development environment for Windows, you've got 
a version of make.  I quite like the NMake that comes with Visual 
Studio, for example, and use it in preference to the IDE when I can. 
Yes, it's a hassle, but it's a hassle you're going to go through anyway.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-11 Thread Rhodri James

On 07/11/2019 13:36, Stephen Waldron wrote:

This is how it is at the moment, however it may be more agreeable, especially 
if that is the only purpose of the function, for python users to be able to 
define new functions inside of function calls.


No, not seeing it.  Sorry, I don't think "I don't want to use up a 
precious, precious name in this namespace" is a good enough reason to do 
anything, never mind something with a lot of implicit naming going on. 
Suppose you had been good and made a module of your Book example.  What 
is someone reading your code supposed to make of this?


import books

my_books = [
books.Book("Triplanetary", 'E.E. "Doc" Smith'),
books.Book("Foundation", "Isaac Asimov")
]

books.doToBooks(my_books):
print(book.name, ":", book.author)
then:
if book.name == "Foundation":
print("READ THIS FIRST!")

The name "book" has just appeared out of thin air, and without stopping 
and reading the code of your module they will have to guess at what it 
is.  Now in this case their first guess is probably right, but this is a 
toy example and just as easily written with lambdas if you're that 
worried about using up names.


-10 from me.

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   7   8   9   10   >