Re: Terminal Emulator

2024-05-14 Thread Mirko via Python-list

Am 14.05.24 um 19:44 schrieb Gordinator via Python-list:
I wish to write a terminal emulator in Python. I am a fairly 
competent Python user, and I wish to try a new project idea. What 
references can I use when writing my terminal emulator? I wish for 
it to be a true terminal emulator as well, not just a Tk text widget 
or something like that.


If you have any advice, please do let me know!



Not sure, what you mean with:


true terminal emulator as well, not just a Tk text widget or something like that
If you want to write a GUI terminal, than that *is* a terminal 
emulator and *has* a text widget as its visible core. If you want to 
write something like getty which runs on the virtual terminals 
(Ctrl+Alt+F*) than that is a terminal (not a terminal emulator).


In both cases, you write something that gets input from the 
keyboard, processes it and shows the result. How that processing is 
done, depends on the terminal standard, like DEC VT{100, 102, 220, 
320, etc}.


For a start, you might want to look at Terminator, which is a 
terminal emulator written in Python, Gtk and libvte (which does all 
the low level stuff).

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


Re: Extract lines from file, add to new files

2024-01-11 Thread Mirko via Python-list

Am 11.01.24 um 20:53 schrieb Rich Shepard via Python-list:

On Thu, 11 Jan 2024, Piergiorgio Sartor via Python-list wrote:


Why not to use bash script for all?


Piergiorgio,

That's certainly a possibility, and may well be better than python 
for this

task.

Thank you,

Rich


awk '/@/ {print >>"emails.txt";next};NF{print >>"salutation.txt"}' 
input.txt



SCNR ;-)
--
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter ttk Treeview binding responds to past events!

2023-09-12 Thread Mirko via Python-list

Am 12.09.23 um 07:43 schrieb John O'Hagan via Python-list:


My issue is solved, but I'm still curious about what is happening here.


MRAB already said it: When you enter the callback function, Tk's 
mainloop waits for it to return. So what's happening is:


1. Tk's mainloop pauses
2. temp_unbind() is called
3. TreeviewSelect is unbound
4. events are queued
5. TreeviewSelect is bound again
6. temp_unbind() returns
7. Tk's mainloop continues with the state:
- TreeviewSelect is bound
- events are queued

Am 11.09.23 um 23:58 schrieb Rob Cliffe:


Indeed.  And you don't need to specify a delay of 100 milliseconds. 0 will work 
(I'm guessing that's because queued actions are performed in the order that 
they were queued).


Ah, nice, didn't know that!

I have also found that after() is a cure for some ills, though I 
avoid using it more than I have to because it feels ... a bit 
fragile, perhaps.
Yeah. Though for me it was the delay which made it seem fragile. 
With a 0 delay, this looks much more reliable.



FWIW, here's a version without after(), solving this purely on the 
python side, not by temporarily unbinding the event, but by 
selectively doing nothing in the callback function.


from tkinter import *
from tkinter.ttk import *

class Test:
def __init__(self):
self.inhibit = False
root=Tk()
self.tree = Treeview(root)
self.tree.pack()
self.iid = self.tree.insert('', 0, text='test')
Button(root, command=self.temp_inhibit).pack()
mainloop()

def callback(self, *e):
if not self.inhibit:
print('called')

def temp_inhibit(self):
self.inhibit = True
self.tree.selection_set(self.iid)
self.tree.selection_remove(self.iid)
self.tree.selection_set(self.iid)
self.inhibit = False
self.callback()

c=Test()


HTH and regards
--
https://mail.python.org/mailman/listinfo/python-list


Re: Tkinter ttk Treeview binding responds to past events!

2023-09-11 Thread Mirko via Python-list

Am 11.09.23 um 14:30 schrieb John O'Hagan via Python-list:

I was surprised that the code below prints 'called' three times.


from tkinter import *
from tkinter.ttk import *

root=Tk()

def callback(*e):
     print('called')

tree = Treeview(root)
tree.pack()

iid = tree.insert('', 0, text='test')

tree.selection_set(iid)
tree.selection_remove(iid)
tree.selection_set(iid)

tree.bind('<>', callback)

mainloop()

In other words, selection events that occurred _before_ the callback
function was bound to the Treeview selections are triggering the
function upon binding. AFAIK, no other tk widget/binding combination
behaves this way (although I haven't tried all of them).

This was a problem because I wanted to reset the contents of the
Treeview without triggering a relatively expensive bound function, but
found that temporarily unbinding didn't prevent the calls.

I've worked around this by using a regular button-click binding for
selection instead, but I'm curious if anyone can cast any light on
this.

Cheers

John



AFAIK (it's been quite some time, since I used Tk/Tkinter):

These selection events are not triggered upon binding, but after the 
mainloop has startet. Tk's eventloop is queue-driven, so the 
tree.selection_{set,remove}() calls just place the events on the 
queue. After that, you setup a callback and when the mainloop 
starts, it processes the events from the queue, executing the 
registered callback.


I seem to remember, that I solved a similar issue by deferring the 
callback installation using root.after().



from tkinter import *
from tkinter.ttk import *

root=Tk()

def callback(*e):
print('called')

tree = Treeview(root)
tree.pack()

iid = tree.insert('', 0, text='test')

tree.selection_set(iid)
tree.selection_remove(iid)
tree.selection_set(iid)

root.after(100, lambda: tree.bind('<>', callback))

mainloop()



This does not print "called" at all after startup (but still selects 
the entry), because the callback has not been installed when the 
mainloop starts. But any subsequent interaction with the list 
(clicking) will print it (since the callback is then setup).


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


Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread Mirko via Python-list

Am 17.08.23 um 21:17 schrieb c.buhtz--- via Python-list:

Hello Mirko,

thanks for reply.

Am 17.08.2023 18:19 schrieb Mirko via Python-list:

You could solve it by defining _() locally like so:

def foobar(translate):
    _ = gettext.gettext


I see no way to do that. It is not the "class based API" of gettext 
installing _() into the builtins namespace.



Does this work:

def foobar(translate):
_ = __builtins__._



My users are able to configure the language of their UI explicit. It 
is a full application.



def orig_and_trans(msg):
    return (_(msg), msg)


This will be ignored by GNU gettext utils (xgettext in my case) will 
ignore this line because they do not know what "msg" is. The string 
"hello" won't appear in the pot-file.



xgettext has an option "-k" which allows you to specify an 
additional "keyword" (like a function name, I guess) for detecting 
translatable strings. With the orig_and_trans() function, the 
following command produces a messages.po with "hello" in it.


xgettext -korig_and_trans source.py
--
https://mail.python.org/mailman/listinfo/python-list


Re: GNU gettext: Print string translated and untranslated at the same time

2023-08-17 Thread Mirko via Python-list

Am 17.08.23 um 09:10 schrieb c.buhtz--- via Python-list:



     UnboundLocalError: local variable '_' referenced before assignment


This is a common gotcha:

https://docs.python.org/3/faq/programming.html#why-am-i-getting-an-unboundlocalerror-when-the-variable-has-a-value

You could solve it by defining _() locally like so:


def foobar(translate):
_ = gettext.gettext
if not translate:
# I try to mask the global _() builtins-function
def _(txt):
return txt
return _('minutes')



The question is if this can be solved somehow or if there is an alternative 
approach.


However, you might not need this, because the following seems to 
work for me:


def orig_and_trans(msg):
return (_(msg), msg)

print('The translated string "{}" is originally 
"{}".'.format(*orig_and_trans("hello")))


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


Re: why function throws an error?

2022-06-28 Thread Mirko via Python-list

Am 28.06.22 um 09:57 schrieb נתי שטרן:

 def add_route(self, route):
 #""" Add a route object, but do not change the :data:`Route.app`
 #attribute."""
 self.routes.append(route)
 self.router.add(route.rule, route.method, route, name=route.name
)
 #if DEBUG: route.prepare()
--



Are you still trying to combine different modules into one large 
module? That is not going to help you. First, you need to rewrite 
all those modules to seamlessly work together. This will likely be a 
huge task. Let's say you have a module that defines some function 
route():


def route():
print("route")

Another module defines a variable called "route":

route = True

A third module needs to call the function from the first module, but 
this fails now because the second module has overwritten (shadowed) 
the former function with a variable:


route = True
route()

Traceback (most recent call last):
  File "", line 1, in 
TypeError: 'bool' object is not callable


You would need to find all those cases where one module overwrites 
variables or functions from other modules. And sometimes those cases 
will be difficult to spot. Python is not designed for what you are 
trying to do. Even if you get this done, it will not help you. You 
can't just throw everything into a single file and then magically 
optimize it. When you have this huge final module, what do you think 
you can do with it to be faster?


If you have performance problems with some module, you have several 
options to optimize it:


- Find a better algorithm.
- Rewrite performance-critical parts in Cython or even C and import 
the compiled module.

- Use a JIT compiler such as PyPy
--
https://mail.python.org/mailman/listinfo/python-list


Re: No shortcut Icon on Desktop

2022-04-15 Thread Mirko via Python-list
Am 15.04.2022 um 18:53 schrieb Mats Wichmann:
> On 4/15/22 08:59, Grant Edwards wrote:
> 
>> Of course it's easy to add. But, we're talking about people who have
>> no idea how to do that. They have no clue how to "navigate to the
>> install directory". They don't even realize anything _was_ installed.
> 
> 
> I dunno, it's a pretty WIndows-y thing, 
> But anyway...

Yes, it is a pretty "Windows-y thing". How do Windows software
installers work? What do they do? They add shortcuts to the desktop.
 I do not use Windows for myself since many years, but it is hard
for me to remember any software that did not add those shortcuts.

> right-click + create shortcut.

Right-click on what and where? On something called "IDLE" (has what
to do with python?). Right click on "python.exe" which gives some
wired texty DOS-window (or how that thing is called) where one can
do what?

Don't get me wrong. I do not ask those questions. Myself, I'm
perfectly able to compile Python from source on pretty much any
system you throw me at. But we are talking about people who are new
to programming.

AFAIK, almost every Windows tool/application/utility does add those
desktop shortcuts/icons/links. Newcomers expect, want and need some
editor or IDE or "app". Just put a "Python" folder on the desktop
with an "IDLE Python Editor" on the desktop and done.

How hard is it do add that functionality to the Windows installer?
Because I just can't see any reason not to do it.

What is there to lose in trying/doing that? What dire consequences
does that might have?

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


Re: No shortcut Icon on Desktop

2022-04-14 Thread Mirko via Python-list
Am 13.04.2022 um 20:39 schrieb Dennis Lee Bieber:
> On Thu, 14 Apr 2022 03:38:11 +1000, Tim Deke  declaimed
> the following:
> 
>> Dear Sir,
>>
>> I have successfully downloaded Python into my laptop but the shortcut icon
>> is not appearing on the desktop. I am using Windows 10 with the PC
>> specifications as per snap shot attached below. Can you advise what to do?
>>
>> Thank you
>>
>> Tim Deke
>>

>   Python normally does not create "shortcut icon"s -- one downloads an

The Python Windows installer *absolutely* should. I do not know much
about (modern) Windows, but one thing I do know is, that most
Windows users are confused when after an installation there is no
easy way to call the program. I do not understand, why the Windows
installer *still* does not create a "Python 3.10" _*or similar*_
folder on the desktop with links to IDLE (with an icon text
describing it properly as a Python Editor/IDE), the CHM and some
introduction text in it.

> installer (which on my system would be saved in %userprofile%\downloads),
> and executes the installer (once). Python is not an all-in-one GUI
> development environment (ie; it is not something like Lazarus/FreePascal,
> Visual Studio, etc.). It is an interpreter for script files and depending
> upon how the installer sets up the environment, one may never need to
> directly invoke the Python interpreter -- one just invokes .py script files
> and the OS activates the correct interpreter.

With all due respect, but do you really think that it is useful for
a Python beginner to know how to run the bare interpreter? ;-)

Wouldn't it be much better to educate them about IDLE which can be
found in the "Startmenu"?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functionality like local static in C

2022-04-14 Thread Mirko via Python-list
Am 14.04.2022 um 17:02 schrieb Cecil Westerhof via Python-list:
> In C when you declare a variable static in a function, the variable
> retains its value between function calls.
> The first time the function is called it has the default value (0 for
> an int).
> But when the function changes the value in a call (for example to 43),
> the next time the function is called the variable does not have the
> default value, but the value it had when the function returned.
> Does python has something like that?
> 

There are several ways to emulate that:


### With a mutable default argument

In [1]: def func(var=[-1]):
   ...: var[0] += 1
   ...: return var[0]
   ...:

In [2]: func()
Out[2]: 0

In [3]: func()
Out[3]: 1

In [4]: func()
Out[4]: 2


### with a callable class

In [12]: class Func():
...: def __init__(self, var=-1):
...: self.var = var
...:
...: def __call__(self):
...: self.var += 1
...: return self.var
...:

In [13]: func = Func()

In [14]: func()
Out[14]: 0

In [15]: func()
Out[15]: 1

In [16]: func()
Out[16]: 2


### with a closure

In [29]: def outer(var=-1):
...: def inner():
...: nonlocal var
...: var += 1
...: return var
...: return inner
...:

In [30]: func = outer()

In [31]: func()
Out[31]: 0

In [32]: func()
Out[32]: 1

In [33]: func()
Out[33]: 2


### with a generator

In [2]: def func(init=0, end=3):
   ...: for var in range(init, end):
   ...: yield var
   ...:

In [3]: for i in func():
   ...: print(i)
   ...:
0
1
2


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


Re: venv and executing other python programs

2022-02-15 Thread Mirko via Python-list
Am 15.02.2022 um 08:53 schrieb Barry Scott:
> Or are you running the program from the command line after activating the
> venv?

This ...

Am 15.02.2022 um 11:18 schrieb Roel Schroeven:
> Suppose you're working on a program which, for example, prints json
> to stdout. And suppose you want to use a tool like jq (let's call it
> pjq as an example) to process that output, by piping the output of
> your program to it:

... and this.


Am 15.02.2022 um 08:21 schrieb Reto:
> Don't activate the venv for those programs then?
> The point of a venv is that you only enter it when you actually want
> that specific python stack.

Well, it's not that I activate the venv *for* those troubling
programs. I activate it to work on the particular project. ;-)

> Get yourself a terminal that can either multiplex, or add something like
> tmux or screen to the mix if you frequently need other python tools
> during development.

I already do that (terminator, since I don't get tmux to behave as I
want it).


Am 15.02.2022 um 13:36 schrieb Martin Di Paola:
> I did a few experiments in my machine. I created the following foo.py
[SNIP]
> Do you have a particular context where you are having troubles? May
> be there is something else going on...

It seems to me that on your system, venv includes the site-packages
by default. For that I've found a solution: Create the venv with
--system-site-packages or in the venv's pyvenv.cfg just set/add
"include-system-site-packages = true"

Without this, I get the following (Python 3.6.9, Linux Mint 19,
Pandas installed in /usr/lib/python3/dist-packages/pandas):


[2,  0] mirko@wizbox:~$ vim /home/mirko/bin/foo.py
[2,  0] mirko@wizbox:~$ chmod +x /home/mirko/bin/foo.py
[2,  0] mirko@wizbox:~$ cat /home/mirko/bin/foo.py
#!/usr/bin/env python3

import pandas
print("Works")

[2,  0] mirko@wizbox:~$ foo.py
Works

[2,  0] mirko@wizbox:~$ python3 -m venv xxx
[2,  0] mirko@wizbox:~$ source xxx/bin/activate

(xxx) [2,  0] mirko@wizbox:~$ foo.py
Traceback (most recent call last):
  File "/home/mirko/bin/foo.py", line 3, in 
import pandas
ModuleNotFoundError: No module named 'pandas'

(xxx) [2,  1] mirko@wizbox:~$ deactivate
[2,  0] mirko@wizbox:~$ foo.py
Works


So, the problem seems to be solved. Thanks all! :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


venv and executing other python programs

2022-02-14 Thread Mirko via Python-list
Hi,

I have recently started using venv for my hobby-programming. There
is an annoying problem. Since venv modifies $PATH, python programs
that use the "#!/usr/bin/env python" variant of the hashbang often
fail since their additional modules aren't install inside in venv.

How to people here deal with that?

Please note: I'm not interested in discussing whether the
env-variant is good or bad. ;-) It's not that *I* use it, but
several progs in /usr/bin/.

Thanks for your time.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script accessing own source code

2021-05-12 Thread Mirko via Python-list
Am 12.05.2021 um 20:41 schrieb Robin Becker:
> ...
>>
>> with open(__file__) as myself:
>>  print(myself.read(), end='')
> 
> very nice, but accessing code that's already seems quite easy. I
> think the real problem is to get a python script name that creates
> and writes itself. So I would ask if any one has the solution to the
> self writing script
> 
> python find-tomorrows-lotto-numbers.py
> 
> since GvR has been shown to have time traveling abilities such a
> script could paradoxically appear acausally.
> -- 
> yrs-not-too-seriously
> Robin Becker


Not sure, if that's what you mean, but writing a self-replicating
script is easy too:

import os
import sys

with open(os.path.abspath(__file__)) as myself:
with open(sys.argv[1], "w") as yourself:
yourself.write(myself.read())


Give it a filename as a command-line argument and it will write
itself to that file.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: The importance of mental health

2021-05-10 Thread Mirko via Python-list
Am 10.05.2021 um 15:16 schrieb Kyle Stanley:
> Hey all,
> 
> In these last few months, I have been in the process of healing from some
> pretty heavy past trauma. And now that I am on the road to recovery, I want
> to share my journey with the Python community in hopes that it may reach
> those that are struggling with their own mental health battles, as many of
> us are during these dark and difficult times.
> 
> Trigger warning that it includes a decent amount of highly personal
> content, so only check it out if you are okay with that:
> https://discuss.python.org/t/break-from-open-source/6372/7?u=aeros.
> 
> To anyone that would limit my employment opportunities as a result of
> having had these struggles, *that's perfectly okay*. I kept the post in the
> private section because I was originally in fear of discriminate. However,
> I have reached an important conclusion: *I would not want to work for your
> company if you discriminate against people who have overcome past struggles*
> .
> 


Thank you for your courage! This is what we need. True, genuine and
honest stories from people with mental health issues. To demystify
and destigmatize the entire topic. Everybody happily runs to the
doctors to get antibiotics/antivirals for their simple cold and
everybody literally "loves* to complain about how bad they feel when
having a cold. But even today in the year 2021, very few people dare
to go public with their "mental cold" or their "mental cancer". The
danger of mockery or discrimination is still far to high.


All the best, Kyle and good luck! :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: Autism in discussion groups

2021-05-10 Thread Mirko via Python-list
Am 09.05.2021 um 02:34 schrieb Michael Torrie:
> On 5/8/21 3:28 PM, Mirko via Python-list wrote:
>>
>> I apologize for this OT post, especially because it's in reply to an
>> at least partly troll post, but I just can't resist. Sorry.
>> 
>> P.S.: *NOT* among the core symptoms of (the high-functioning levels)
>> of ASS is the inability to learn. Mind that! (And that includes
>> social norms.)
> 
> Thank you for posting such an insightful comment. No need to apologize.
>  I really appreciate it. I think you are exactly correct.
> 

Thanks! :-)

In case anybody wonders: When I was talking about ASS, I was
referring to "Autismus-Spektrum-Störung". That's German for "Autism
Spectrum Disorder" or short ASD. Happens when it's lake evening, you
have some beers down and talk about a topic in a foreign language. :)
-- 
https://mail.python.org/mailman/listinfo/python-list


OT: Autism in discussion groups (was: Re: Proposal: Disconnect comp.lang.python from python-list)

2021-05-08 Thread Mirko via Python-list


I apologize for this OT post, especially because it's in reply to an
at least partly troll post, but I just can't resist. Sorry.


Am 08.05.2021 um 14:09 schrieb Talkie Toaster:
> On 06/05/2021 18:56, Mark Lawrence wrote:

>> Quite frankly I don't care how this discussion goes as the Python
>> community discriminates against Asperger's suffers such as myself.
>>
> 
> I believe I am also on the spectrum and feel the same way about the
> fluffy cloud echo chamber for fluffy clouds that is the Python
> "community".

I'm also on the autism spectrum but I do *NOT* appreciate how you
both instrumentalize our condition and use it as a self-righteous
self-defense and how you politicized it.

One of the core aspects of ASS is that we have difficulties
understanding and following common and accepted social norms. But
that is not a carte blanche for every kind of misbehavior. I don't
call myself Aspie for no reason. I believe that we have a right to
be what we are and to live according to our needs, situations,
conditions and specialties. But that doesn't mean that the rest of
the world has to unilaterally adapt to us. It's both sides! The
world needs to understand that our behavior is a little different we
need to understand that our behavior is sometimes off the limits. We
need to learn -- both sides -- how to live together and we need to
learn to *RESPECT* each other.

> This "code of conduct" bullsh1t is getting out of hand.

Unless the CoD includes ASS of course! Isn't it?! ;-)

You complain about a "fluffy cloud echo chamber", but you are
*calling* for the *same*. A fluffy cloud echo chamber where no ASS
person is ever called for any possibly disrespecting words or
behavior. A fluffy cloud echo chamber where everybody just accepts
and respects you for what you are. Does the concept sound familiar?


P.S.: *NOT* among the core symptoms of (the high-functioning levels)
of ASS is the inability to learn. Mind that! (And that includes
social norms.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: text displays on screen only when I click to exit the program

2021-04-30 Thread Mirko via Python-list
Am 30.04.2021 um 20:55 schrieb Quentin Bock:
> code with comments for context:
> 
> #Create a text based game where the user must find 3 items before
> completing a level
> #imports and variables for game
> import pygame
> from pygame import mixer
> running = True
> #initializes pygame
> pygame.init()
> 
> #creates the pygame window
> screen = pygame.display.set_mode((1200, 800))
> 
> #Title and Icon of window
> pygame.display.set_caption("3.02 Project")
> icon = pygame.image.load('3.02 icon.png')
> pygame.display.set_icon(icon)
> 
> #setting up font
> pygame.font.init()
> font = pygame.font.Font('C:\Windows\Fonts\OCRAEXT.ttf', 16)
> font_x = 10
> font_y = 40
> items_picked_up = 0
> items_left = 3
> 
> #functions to be called later in program
> def display_instruction(x, y):
> instructions = font.render("Each level contains 3 items you must pick
> up in each room."
>"When you have picked up 3 items, you will
> advance to the next room, there are 3 rooms.", True, (255, 255, 255))
> screen.blit(instructions, (10, 40))
> 
> def main():
> global running
> 
> #Game Loop
> while running:
> #sets screen color to black
> screen.fill((0, 0, 0))
> 
> #checks if the user quits or exits the window
> for event in pygame.event.get():
> if event.type == pygame.QUIT:
> running = False
> 
> display_instruction(font_x, font_y)
> pygame.display.update()
> 
> 
> main()
> 
> 
> 
> please excuse the def main() thing, this doesn't follow a tutorial this is
> all on my own, and I don't know why the text displays when I close the
> python window.
> I appreciate all help :)


Because you are calling display_instruction() and
pygame.display.update() outside of the game loop. Try to indent
those two lines one level more.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: UI design: combobox or radiobuttons?

2021-04-13 Thread Mirko via Python-list
Am 13.04.2021 um 23:53 schrieb Rich Shepard:
> My applications use environmental data, each of which has to specify
> the
> units (e.g., cm, m, km, ft, yd, mi). With the widget sets I've used
> (wxPython and TKinter) I've always used a combobox with the acceptable
> choices in it. I'm now planning a new application using PyQt5 and it
> occured
> to me that a set of radio buttons would also work.
> 
> While a set of radiobuttons occupies more room on the parent widget
> than
> does a combobox are there any technical or user issues that would
> suggest
> using one over the other?
> 
> TIA,
> 
> Rich

I use radiobuttons if the list of choices is small and static, like
about 2 - 5 fixed entries. Comboboxes are better for larger lists,
or if the user can add own entries, or if there's a chance that the
program needs more entries later.

IME, radiobuttons cause more visual distraction while comboboxes can
be less obvious for less tech-savvy people. OTOH, comboboxes require
two clicks.

For your situation with units, I would probably go for radios if the
user needs to change the units often and combos if radios would make
the view more complex and less obvious.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-08 Thread Mirko via Python-list
Am 07.03.2021 um 21:52 schrieb Avi Gross via Python-list:
> The precedence example used below made a strange assumption that the
> imaginary program would not be told up-front what computer language it was
> being asked to convert from. That is not the scenario being discussed as we
> have described. In any particular language, there usually is a well-known
> precedence order such as "*" coming before "+" unless you use something like
> parentheses to make your intent clear and over-ride it.

Well, no I did not assume some kind of magical universal translator
ala Star Trek. ;-)

The OP seems to claim, that he could compile any language by just
providing a JSON schema file which describes the language. I assumed
that those who tried this before did something similar. And that is
what sounds logically impossible (or at least unfeasible) to me. How
can one write a comparatively small descriptive schema that covers
all of a language's subtleties in syntax, grammar, semantics and
behavior?

I agree that my example wasn't good, since it would be just a matter
of specifying operator precedence. But there are numerous little and
large aspects to cover for any language. In the end, one would have
to write a more or less full blown parser. Or at least a schema that
is so long, that all advantages of this approach go away.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Mirko via Python-list
Am 06.03.2021 um 22:24 schrieb Ben Bacarisse:
> Mr Flibble  writes:
> 
>>> Someone who says that he is capable of writing a compiler that
>>> translates every language has megalomania. No one can do this.
>>
>> Just because you can't make one it doesn't follow that nobody else
>> can.
> 
> True, but lots of very knowledgeable people have tried and failed.

I even wonder why they have tried. Writing a universal
compiler/interpreter sounds logically impossible to me, Here's a
simple Python expression:

>>> 3+3*5
18

And here's the same expression in (GNU) Smalltalk:

st> 3+3*5
30


How would such a universal compiler know which evaluation strategy
to follow, if not by writing a parser end evaluator for every
supported language? And if it's hard for this simple problem, how
about more complex cases.

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


Re: Why assert is not a function?

2021-03-02 Thread Mirko via Python-list
Am 02.03.2021 um 23:09 schrieb Stestagg:
> Ignoring the question about this feature being particularly useful, it

It is useful because "assert" is primarily (if not purely and
exclusive) a debugging tool during development and testing.

In production code you don't want any asserts, but logging. Having
"assert" being a function would make it much harder to get rid of it
in production code.


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


Re: Installing Python (2.7) 'by hand' on Ubuntu - possible?

2020-12-22 Thread Mirko via Python-list
On 22.12.2020 at 20:24 Chris Green wrote:

> Yes, I do have the Python source.  The only thing I don't have the
> source for is a .so file and that's why I can't simply migrate the
> program(s) from Python 2 to Python 3.
> 

If it's just one .so and that library is compatible with basic libs
such as glibc and has no further big dependencies, then there may be
a simpler way than cx_freeze or even snap/docker/etc.

Python 2 will likely be available for quite some more years as an
optional package. But even with a self-compiled version, you should
be able to put the required libraries somewhere and set
LD_LIBRARY_PATH or maybe LD_PRELOAD accordingly. For a few depending
libs, this works well, but it gets really nasty if glibc or big
frameworks such as GTK are involved.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem

2020-10-04 Thread Mirko via Python-list
Am 03.10.2020 um 17:25 schrieb Dennis Lee Bieber:
> On Fri, 2 Oct 2020 21:47:38 +0200, Hexamorph  declaimed
> the following:
> 
> 
>>
>> - Add a folder named "Python.org " (or similar) to the
>> desktop with shortcuts to Python, IDLE and the CHM.
>>
>> - Add a checkbox (default enabled) like "Start the IDLE Python
>> Editor/Shell" at the end of the installation procedure.
>>
> 
>   Which may only result in reinforcing the idea that one runs the
> installer to run Python.


Perhaps not if the installer says, that Python is already installed
and accessible per Startmenu and desktop icons. At some point they
will probably notice this hint. There are multiple reasons, why
beginners don't find out how to start Python. Some expect a
GUI-Application like an Editor in the Startmenu, some expect desktop
icons, some don't realize, that the installer is just that. They all
need a different change.

However, I'm out of this discussion now. With the exception of Terry
changing IDLE's menu entry, this has been a very unproductive
discussion. People where only highlighting possible drawbacks and
remaining problems (including the usual nitpicking on edge-cases)
without coming up with own ideas.

If you want to lessen the amount of those initial newcomer
questions, reconsider what was proposed:

- Rename the MSI as suggested by Eryk Sun.
- Add a folder named "Python.org " (or similar) to the
desktop with shortcuts to Python, IDLE and the CHM.
- Add a checkbox (default enabled) like "Start the IDLE Python
Editor/Shell" at the end of the installation procedure.
- Perhaps, if possible, add a button like "Start the IDLE Python
Editor/Shell" to the Repair/Modify/Remove Dialog.

So long and happy hacking! :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem

2020-10-02 Thread Mirko via Python-list
Am 02.10.2020 um 11:58 schrieb Terry Reedy:
> On 10/1/2020 4:09 PM, Mirko via Python-list wrote:
> 
>> Renaming "IDLE" to "Python IDE" (or similar) might also.
> "IDLE" intentionally echoes 'Idle', as in Eric Idle of Monty
> Python.  It stands for "Integrated Development and Learning
> Environment".  It is *a* Python IDE aimed especially at beginners
> (the 'Learning' part).  (I should probably revised the doc a bit.)
> 
> Changing a name in use around the world, in books and web sites and
> discussion posts and a Stackoverflow tag ('python-idle') is a bad
> idea. And, as Chris said, implying that it is *the* Python IDE is
> not a good idea either.
> 
> I think changing the start menu entry
> "IDLE (Python 3.9 64 bit)"
> to something more descriptive, as suggested by Mirko, *is* a good idea.
> 
> The current longest entry under "Python 3.9" is
> "Python 3.9 Module Docs (64-bit)"
> So
> "IDLE Shell/Editor (3.9 64-bit)"
> would fit.  I opened a bpo issue with more discussion.
> https://bugs.python.org/issue41908
> Bpo users with an opinion should express it there.
> 
> Terry Jan Reedy
> 

(Sorry for the mail from the other wrong account again, need to
change that)

Thanks!

Sorry, I have been a bit unclear in my second post. I never meant to
rename IDLE itself. Only the entries in the Startmenu, the possible
desktop icons and such.

If I had a say in all this, I would do:

- Rename the MSI as suggested by Eryk Sun.

- Add a folder named "Python.org " (or similar) to the
desktop with shortcuts to Python, IDLE and the CHM.

- Add a checkbox (default enabled) like "Start the IDLE Python
Editor/Shell" at the end of the installation procedure.

- Add a button like "Start the IDLE Python Editor/Shell" to the
Repair/Modify/Remove Dialog.


For all I know, the points 2 and 3 are very common with installation
procedures on Windows (and therefore likely expected by the users).

And no, this will not solve all problems. There will always be some
people who just don't get it. But I would be very surprised, if that
doesn't cut down the number of these beginner troubles by one or two
orders of magnitude.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem

2020-10-01 Thread Mirko via Python-list
Am 01.10.2020 um 22:17 schrieb Chris Angelico:

> Maybe those usability improvements have already been done.

Haven't doubted that. Maybe they are just not enough yet.

> Renaming Idle to "Python IDE" would be a very bad idea, since there
> are many other Python IDEs.

You missed the "(or similar)" addition.

Call it "IDLE - Python IDE" or "Python Editor (IDLE)" or whatever.
Something that gives the newcomer a better clue than "IDLE".

> Starting something immediately after installation completes might
> help, but would probably just defer the issue to the *second* time
> someone wants something.

Probably not if they once have seen that there is some GUI editor
and can barely recall it was something like "IDE", "Python Editor"
or so. Again, will it help in *all* cases? No, but in some.

> There is no simple foolproof solution. That's why people still get confused.

That's what I mean. You dismiss suggestions on the grounds of "no
simple foolproof solution" ie. a perfect solution. I'm not talking
about solutions that will work in every case and solve all possible
problems. I'm talking about incremental improvements which reduce
some -- not remove all -- those troubles,

But again, I'm not the one who has to deal with all this.


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


Re: Problem

2020-10-01 Thread Mirko via Python-list
Am 30.09.2020 um 23:44 schrieb Chris Angelico:
> On Thu, Oct 1, 2020 at 7:33 AM Mirko via Python-list

>> We are seeing these troubles from newcomers on Windows all of the
>> time -- and that for years. Isn't it time to ask if the way Python
>> installs itself on Windows-Systems is appropriate?
>>
> 
> The problem is that there isn't "the way". Did the person:
> 
> 1) Download an MSI file from python.org?
> 2) Install ActiveState?
> 3) Install Enthought?
> 4) Install Anaconda?
> 5) Get Python from the Microsoft Store?
> 6) Something else?
> 
> They're all different, they all behave differently, they all have
> different defaults. And then there's the question of "did you install
> it for everyone or just you?", and so on.
> 
> The core Python devs have control of the first option, and some
> control over the fifth, but none of the others.

Yes, but usability improvements for the one from python.org could be
later adopted by the other distributors.

I think, that you are jumping from "How to improve the current
situation?" to "How to make it absolutely perfect?"

That's a sure path into the incapacity to act. I'm not talking about
solving all the problems that newcomers have, but reducing them.

Eryk Sun suggested to rename the installer to a more explicit
filename. Will that solve all the problems? No. But it reduces the
troubles by solving one particular case. Renaming "IDLE" to "Python
IDE" (or similar) might also. Adding desktop icons for it or have a
"Start the Python Editor (IDLE) now" button/checkbox at the end of
the installation also.

> So, go ahead, ask if it's appropriate good luck getting a useful response 
> :|

Well, I am not the one who needs to answer those beginner questions
time and time again. ;-)

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


Re: Problem

2020-09-30 Thread Mirko via Python-list
Am 30.09.2020 um 17:55 schrieb Dennis Lee Bieber:
> On Tue, 29 Sep 2020 22:31:18 + (UTC), Ron Villarreal via Python-list
>  declaimed the following:
> 
>> Tried to open Python 3.8. I have Windows 10. Icon won’t open.
> 
>   What "Icon"?
> 
>   Python is a language interpreter/compiler -- it runs from a command
> prompt/shell. Clicking on a Python SCRIPT might open a shell, which will
> almost immediately close when the script finishes executing (files with a
> .pyw extension are supposed to create their own GUI using one of a couple
> of libraries, and don't open a shell).


I'm just a lurker, hobby programmer and Linux geek, so take my words
with some caution.

We are seeing these troubles from newcomers on Windows all of the
time -- and that for years. Isn't it time to ask if the way Python
installs itself on Windows-Systems is appropriate?

I have only limited knowledge about current Windows systems. But it
seems to me that newcomers download some setup exe/msi and then
search the menu to run what ever is found (python.exe or even the
setup-program.)

That's Ok, if you understand what an interpreter/compiler for the
command-line is. But programming beginners usually don't know that
(especially not if there are Windows users).

There has been a lot of effort to make this group inclusive and
newcomer-friendly. But it seems to me that this is not the case for
the software itself. Given that Python ships with a rudimentary IDE
(IDLE), should that one be promoted more intensively?

Shouldn't IDLE be named something like "Python Editor" (or Python
IDE/App) in the menu, so beginners can more easily find it? Further
it might be a good idea to make this "Repair/Modify/Remove"-Dialog
more explicit by clearly saying "Python is already installed. If you
want to use it, do ...".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python error

2020-04-02 Thread Mirko via Python-list
Am 02.04.2020 um 20:09 schrieb J Conrado:
> Hi,
> 
> I have the version of python installed:
> Python 3.7.6 and Python 3.8.1
> If I type:
> python
> Python 3.7.6 (default, Jan  8 2020, 19:59:22)
> [GCC 7.3.0] :: Anaconda, Inc. on linux
> Type "help", "copyright", "credits" or "license" for more information.
 import numpy
> 
> it is Ok, no error, but if I did:
> 
> python3.8
> 
> Python 3.8.1 (default, Jan 31 2020, 15:49:05)
> [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 import numpy
> 
> Traceback (most recent call last):
>   File "", line 1, in 
> ModuleNotFoundError: No module named 'numpy'
> 
> Please,
> I would like to know why in the python3.8 version I have this error.


Because you installed numpy only for 3.7.6. All Python installations
have their own module paths, so you need to install numpy for 3.8.1
too. Do it with:

python3.8 -m pip install numpy
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Most elegant way to do something N times

2019-12-22 Thread Mirko via Python-list
Am 22.12.2019 um 21:34 schrieb Batuhan Taskaya:
> I encounter with cases like doing a function 6 time with no argument, or
> same arguments over and over or doing some structral thing N times and I
> dont know how elegant I can express that to the code. I dont know why but I
> dont like this for _ in range(n): do() thing. Any suggestions?
> 

Looks like perfectly legitimate code to me and 'for' is meant to do
exactly this, execute something N times.

However, you can always to something like this:

In [28]: def f(a, b, c):
...: print(a, b, c)
...:

In [29]: def repeat(func, times, *args):
...: for _ in range(times): func(*args)
...:

In [30]: repeat(f, 6, 1, 2, 3)
(1, 2, 3)
(1, 2, 3)
(1, 2, 3)
(1, 2, 3)
(1, 2, 3)
(1, 2, 3)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python shows error on line 15 that i cant fix

2019-09-21 Thread Mirko via Python-list
Am 21.09.2019 um 19:57 schrieb Dave Martin:

> Can you provide an example of how to use the suite feature. Thank you. 
> 

There is no suite feature, Terry just tried to explain indented
blocks to you in simple words. Really, indented blocks are one of
the most basic aspects of Python. You *need* to read the tutorial as
it has been suggested three times now.

Anyway, given the following code:

if name == "Dave":
print("Hello Dave")
print("How are you?)

Programming languages in general cannot exactly understand what that
code means.

It could mean:
"Say 'Hello Dave' and then 'How are you?" if the name is Dave.

But it could also mean:
"Say 'Hello Dave' if the name is Dave and then say "How are you?"
what ever the name is.

So, we need to tell Python which command should be executed if the
name is Dave and which not. Some languages solves this with block
markers:

if name == "Dave" then
   print("Hello Dave")
   print("How are you?)
endif

Or for the other meaning:

if name == "Dave" then
   print("Hello Dave")
endif
print("How are you?)


Python uses indented blocks to make clear which commands belong
together. Indentations are runs of whitespaces (of equal length) at
the beginning of the line:

if name == "Dave":
print("Hello Dave")
print("How are you?")

Or for the other meaning:

if name == "Dave":
print("Hello Dave")
print("How ar you"?)


For your code that means, that you need to indent the lines that
belong to the 'with' block

This is wrong:

with fits.open(fits_filename) as data:
df=pd.DataFrame(data[1].data)
...

What you need is this:

with fits.open(fits_filename) as data:
df=pd.DataFrame(data[1].data)
...

^-- See these spaces in front of the commands. That are indentations
and all consecutive indented lines are an indented block.


Please read the tutorial at
https://docs.python.org/3/tutorial/index.html  (fourth time now ;-) )
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definite or indefinite article for non-singletons?

2019-07-27 Thread Mirko via Python-list
Am 27.07.2019 um 23:10 schrieb Chris Angelico:
> When talking about indistinguishable objects, is it correct to talk
> about "the " or "an "?
> 
> Example:
> 
> def f(s):
> """Frob a thing.
> 
> If s is an empty string, frobs all the things.
> OR
> If s is the empty string, frobs all the things.
> """
> 
> It's entirely possible that a Python implementation will optimize
> small strings and thus have exactly one empty string, but it's also
> entirely possible to have multiple indistinguishable empty strings.
> Grammatically, is it better to think of empty strings as an entire
> category of object, and you were passed one from that category ("an
> empty string"), or to think of zero-length instances of 'str' as being
> implementation details referring to the one and only Platonic "empty
> string"?
> 
> Does it make a difference to usage if the object is mutable? For
> instance, would you say "the empty string" but "an empty set"?
> 
> ChrisA
> 


Quite frankly, even as a professional (german) writer and texter
(but hobby-programmer), I consider this question to be an
exaggeration about a very minor grammatical aspect. Yes, it makes a
difference if you are allowed to eat *an* apple or *this* apple
(*this* apple might be mine). But, I hobby-program since 20 years or
so, but I can not remember a situation, where a documentation that
confused "an" with "this" caused any troubles.

Anyway:


Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x=""
>>> y=""
>>> x is y
True


Jython 2.5.3 (, Sep 21 2017, 03:12:48)
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_131
Type "help", "copyright", "credits" or "license" for more information.
>>> x=""
>>> y=""
>>> x is y
False


So, obviously there are multiple empty strings possible, so I'd
write "an".

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


[OT] How to improve my programming skills?

2017-06-01 Thread Mirko via Python-list


Hello everybody!

TLDR: Sorry for OT. Long-time Linux geek and hobby programmer wants 
to improve his coding skills. What's most important: project 
planing, algorithms and data structures, contributing to FOSS, web 
development, learning other languages or something else?



Sorry for posting such a (long) off-topic question, which even is 
partly even more about psychology, than about technology. But I'm 
mostly using Python and Bash for programming and am reading this 
mailing list/newsgroup for many years now, and hope it's Ok (feel 
free to direct me somewhere more appropriate, as long it's an 
equally helpful and friendly place).


I'm looking for a way (*the* way, ie. the "BEST(tm)" way) to improve 
my coding skills. While I'm a quite hard-core computer geek since 25 
years and a really good (hobbyist) Linux-SOHO-Admin, my programming 
skills are less than sub-par. I wish to change that and become at 
least am average hobby-programmer. I'm an excellent autodidact and 
in fact, all what I know about computers is completely self-taught.


Now, the problem is, that I'm 41 years old now, have a day job 
(which hasn't much to do with advanced computing stuff), friends and 
all that. There is little time left for this undertaking (something 
like 5 - 10 hours per week), so I'm looking for the most efficient 
ways to do this.


I identify the following problems which could be worth improving:

- I never sit down and plan anything with pencil and paper, 
flowcharts, UML or anything else. I just fire up Vim and start 
typing. That works (albeit slowly) for simple programs, but as soon 
as the project becomes a little more complex the parts and 
components don't match well and I need to botch something together 
to somehow make it work. And in the resulting mess I lose the interest.


- I never learned algorithms and data structures. I know *what* 
(linked) lists, dicts, arrays, structs, and trees are; what binary 
search or bubble-sort is, but I never really studied them, let alone 
implemented them for educative purposes.


- When it comes to coding, I'm heavily shy and unsure. I really know 
my stuff when it's about Linux-SOHO-Administration, but when trying 
to contribute to FOSS projects I always hesitate for several reasons 
(somehow I never find those low-hanging fruits that everybody talks 
about; either it's super-easy or to difficult.)


- For my day job (which is absolutely not my dream job) it would be 
quite useful to know web design/development, especially WordPress 
stuff. But web programming always feel like being trapped in a 
mangrove jungle, with all those browser-specialties, different and 
incompatible JS-engines, PHP versions and all that. I'm almost never 
in the mood to learn web development.


- Beside Python and Bash -- which I both know rather well (for a 
hobbyist at least) -- I only know a little C, some LUA and a tiny 
bit of Scheme.


- I'm very hard to motivate, when the issue or topic doesn't 
interest me much. I know some tricks to increase my motivation in 
such cases, but don't use them enough.




What do you think, which of the problems would be most important to 
overcome? What would be the most efficient way for improving my 
general programming skills? Do you have any other suggestions or tips?



Much thanks for your time!

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