Re: New Python curses book

2021-03-30 Thread Brian Oney via Python-list
Congratulations!

Indeed, I was wondering for a moment if this was a guide to al dente spaghetti 
code. With each curse being a funny way to mess with the colleagues performing 
the code review ;)

Or a list of funny Monty Python curses?

Or a set of programming problems that are cursed?



On March 30, 2021 6:35:20 PM GMT+02:00, Chris Angelico  wrote:
>On Wed, Mar 31, 2021 at 3:21 AM Avi Gross via Python-list
> wrote:
>>
>> Congratulations, Alan, on the book.
>>
>> I continue to wonder if people will buy the book for the wrong reason or ban
>> it thinking you created an AI snake that creates and spews new CURSES never
>> heard before.
>
>A reasonable misunderstanding. After all, profanity is the one
>language that every computer programmer understands, regardless of
>culture, tools, era, or anything else.
>
>ChrisA
>-- 
>https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Pandas split Date in day month year and hour

2020-08-19 Thread Brian Oney via Python-list


On August 19, 2020 7:32:45 PM GMT+02:00, J Conrado  
wrote:
>
>
>Hi,
>
>
>I'm satarting using Pandas to read excel. I have a meteorological 
>synoptic data and I have for date:
>
>
>0   2017-11-01 00:00:00
>1   2017-11-01 03:00:00
>2   2017-11-01 06:00:00
>3   2017-11-01 09:00:00
>4   2017-11-01 12:00:00
>..  ...
>229 2017-11-30 09:00:00
>230 2017-11-30 12:00:00
>231 2017-11-30 15:00:00
>232 2017-11-30 18:00:00
>233 2017-11-30 21:00:00
>
>
>I would like know how can I get for this array the values for day, month 
>and hour:
>
>2017-11-01 03:00:00   year = 2017  month = 11    day = 1    and 
>    hour = 3
>
From the hip, I would use the strptime function (in the time module?)

time.strptime(string_value, '%F %T')

If I recall correctly, the doc for the specific strings is in the strptime 
function's doc.

This is just a starting point. Good luck! 

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


Re: 3rd party mail package

2019-12-13 Thread Brian Oney via Python-list
How about a 1st party package in the stdlib?
>From the hip: Take an example or two from the 'python 2 or 3 standard library 
>by example' book by a guy named Doug.

Hth (really) 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: a regex question

2019-10-25 Thread Brian Oney via Python-list



On October 25, 2019 12:22:44 PM GMT+02:00, Maggie Q Roth  
wrote:
>Hello
>
>There are two primary types of lines in the log:
>
>60.191.38.xx/
>42.120.161.xx   /archives/1005
>
>I know how to write regex to match each line, but don't get the good
>result
>with one regex to match both lines.

What is a good result?

The is an re.MULTILINE flag. Did you try that? What does that do?

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


Re: python is bugging

2019-09-21 Thread Brian Oney via Python-list
On Sat, 2019-09-21 at 08:57 -0700, Dave Martin wrote:
> On Saturday, September 21, 2019 at 11:55:29 AM UTC-4, Dave Martin
> wrote:
> > what does expected an indented block
> 
> *what does an indented block mean?

It means that the line of code belongs to a certain body as defined
above its position.  

Please follow the tutorial.

https://docs.python.org/3/tutorial/index.html

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


Re: Web framework for static pages

2019-08-13 Thread Brian Oney via Python-list



On August 13, 2019 4:00:30 PM GMT+02:00, "Morten W. Petersen" 
 wrote:
>Ok. Isn't it a bit splitting of hairs to talk about static site
>generators
>and their templates?
>
>Wouldn't a static site generator that can create a good, usable website
>with little input be desirable?
>
>I could pick and choose CSS templates, HTML templates and write some of
>my
>own, but that takes quite a bit of time.
>
>Yes, my fixation on XML HTML might be a bit purist or perfectionist,
>but
>isn't it strange that there isn't a DTD for XML HTML 5? Is it the
>ability
>to write websites using a text editor only what makes web companies
>continue the malformed input cycle, or is it legacy websites?
>
>-Morten

It's all text. Or do you have a better suggestion?

What is wrong with templates?


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


Re: Web framework for static pages

2019-08-12 Thread Brian Oney via Python-list



On August 12, 2019 9:14:55 AM GMT+02:00, morphex  wrote:
>Hi.
>

>What frameworks are there for generating static web pages in Python?

I have used:
https://github.com/Frozen-Flask/Frozen-Flask

It's pretty simple. Develop with flask and then "freeze" it.

I am looking forward to further answers.

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


Re: Please help me

2019-08-06 Thread Brian Oney via Python-list
On Mon, 2019-08-05 at 21:10 +0430, arash kohansal wrote:
> Hello ive just installed python on my pc and ive already check the
> path
> choice part but microsoft visual code can not find it and it does not
> have
> the reload item

Check out: https://code.visualstudio.com/docs/languages/python

or

https://realpython.com/python-development-visual-studio-code/

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


Re: Proper shebang for python3

2019-07-21 Thread Brian Oney via Python-list



On July 21, 2019 10:04:47 AM GMT+02:00, Manfred Lotz  wrote:
>On Sun, 21 Jul 2019 10:21:55 +1000
>Cameron Simpson  wrote:
>
>> On 21Jul2019 09:31, Chris Angelico  wrote:
>> >On Sun, Jul 21, 2019 at 9:15 AM Cameron Simpson 
>> >wrote: So you mean that a tool that depends on running on a
>> >consistent environment, it should use a shebang of
>> >"/usr/bin/python3.6" instead of "/usr/bin/env python3"?  
>> 
>> Jeez. No. That is the _opposite_ of what I'm saying.
>> 
>> >Because, wow, that would be exactly what is
>> >already happening on my system. Why use /usr/bin/env and then wrap
>> >something around it to force the environment, when you could just
>set
>> >a correct shebang so it properly defines its execution environment? 
>
>> 
>> Because the shebang is hardwired and inflexible.
>> 
>> Because it means hand patching (even scripted) a bazillion scripts to
>
>> that they know their physical install.
>> 
>> Because it presumes detailed hardwired knowledge of the target system
>> in a script which should work anywhere.
>> 
>> Instead a tiny _common_ shell script resembling this:
>> 
>>   #!/bin/sh
>>   # Run command in the official environment.
>>   exec env - PATH=/path/to/3.6venv/bin:/usr/sbin:/bin exec ${1+"$@"}
>> 
>> arranges things. The "env -" is aimed at "clean" daemon or install 
>> environments.  You can do subtler or less intrusive things in other 
>> settings.
>> 
>
>I took a look and found that Fedora 30 and Debian Jessie both use
>hard-wired paths for python in the rpm resp. deb packages.
>
>I'm being new to Python and I am not acquainted in any way with
>virtualenv resp. venv so cannot currently judge its pro and cons.
>
>So I will stick to:
>   #!/usr/bin/env python3 
>
>as shebang for my scripts.

I think that's a good decision. Most of the conversation applies to sysadmins 
concerned with answering your question in absolute terms. When you start 
writing scripts which are restricted to a specific environment and are intended 
to be distributed, you may revisit this thread.

Be blissful until then :). Chris et al have "fixed" things for you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Proper shebang for python3

2019-07-20 Thread Brian Oney via Python-list
On Sat, 2019-07-20 at 15:26 -0500, Tim Daneliuk wrote:
> On 7/20/19 2:56 PM, Peter J. Holzer wrote:
> > On 2019-07-20 14:11:44 -0500, Tim Daneliuk wrote:
> > > So, no, do NOT encode the hard location - ever.  Always use env to
> > > discover the one that the user has specified.  The only exception is
> > > /bin/sh which - for a variety of reasons - can reliably counted upon.
> > > 
> > > We don't need to bikeshed this.  All we need is people who disagree
> > > with this view to spend a year in software packaging, operations,
> > > deployment and DevOps ... then get back to us...
> > 
> > After 25 years in software packaging, operations, deployment and DevOps
> > I disagree: A program should not behave differently because of a
> > different path, #!/usr/bin/env is a total no-no.
> > 
> > There is a nice way to achieve this: Just use the interpreter of the
> > virtual environment in the shebang.
> > (That requires rewriting the shebang during installation, but that's a
> > minor inconvenience)
> > 
> > hp
> > 
> 
> 
> And what happens with programs that have no virtenv equivalent?
> perl, go, ruby, awk, sed, grep, etc. have no simple way to
> get installed virtual short of insisting the everything live in a
> docker container or VM?
> 
> The fact is that most large compute environments are slow to upgrade
> the OS.  That means core tools also lag considerably behind as well.
> Being able to install newer versions along side the OS' own and then
> use them by default is manifestly necessary.  That's why users have
> the ability to modify $PATH to suit their own needs.  All /usr/bin/env
> does is to tell the interpreter, "honor the intent of the spawning shell".
> This shouldn't even be a question ... and it's why so much garbage continues
> to live forever.  Having to constantly code around old systems versions of
> tools with not other recourse is just crazy.
> 
> In actual fact, the very best way to write portable, reliable, and operable
> systems of code is to divorce them entirely (or as a nearly as possible) for
> the OS tools as you can.  That's why docker works so well.  That's why go
> avoids dynamic linking.
> 
> In my case, that's why I compile my own version of
> languages and daily use utilities to live outside the OS.  I get absolutely
> predicable behavior irrespective of my distro and whatever backleveled cruft
> it has laying around.   I _know_ every version of every important tool my code
> will be using ... all by setting up $PATH properly and using /usr/bin/env in
> my interpreters.
> 
> If you want really big fun, try going into an older CentOS or RedHat 
> instances and, say,
> upgrading system python to python3.  It's super fun.  Yes, in that case, you 
> COULD
> use a venv.  But there are tons of other tools for which this is not an 
> option -
> gcc, autoconf, perl, go awk, sed, bash, ad infinitum, ad nauseum are 
> invariably
> backleveled on production OS instances.  My way fixes that problem.  Your way
> forces me to code around it ... which is a way worse solution.
> 
> You may have 25 years at this but I have 40 - does that make me nearly twice
> as right?  Arguments from authority are silly.
> 
> P.S. https://www.tundraware.com/TechnicalNotes/Divorce-Your-Linux-Admin/
Nice.

Emacs (well spacemacs) is my authority.

The key sequence 'SPC i !' inserts

#!/usr/bin/env python

as specified in the insert-shebang package 
https://github.com/psachin/insert-shebang

My limited experience tells me to expect the user (me) to know what
they're doing, hence env.

Why not make a compromise? What would be a potential pitfall of the
following spitbang?

#!python








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


Re: CAD Application

2019-05-06 Thread Brian Oney via Python-list
FreeCAD is written in Python. It has a python interpreter.

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


Re: PYTHON equivalents of BITAND and BITSHIFT of MATLAB

2019-05-01 Thread Brian Oney via Python-list
On Wed, 2019-05-01 at 10:35 -0700, blmadha...@gmail.com wrote:
> Hi,
> 
> I have the following line from a MATLAB program with FCF (format: UInt_16) as 
> input:
> 
> ftype = bitand(FCF, 7)
> typeBits = bitshift(FCF, -9)
> subtype = bitand(typeBits, 7)
> 
> I wrote the following in Python for the above commands:
> 
> ftype = FCF & 7
> typeBits = FCF << -9 --> Is this correct or FCF >> -9?
> subtype = typeBits & 7
>  
> Can someone help me write the equivalent command in PYTHON?
> 
> Look forward to your suggestions.

From the Matlab doc:
'
intout = bitshift(A,k)
intout = bitshift(A,k,assumedtype)
Description

example

intout = bitshift(A,k) returns A shifted to the left by k bits,
equivalent to multiplying by 2k. Negative values of k correspond to
shifting bits right or dividing by 2|k| and rounding to the nearest
integer towards negative infinity. Any overflow bits are truncated. '

So the equivalent would be:

>>> typeBits = FCF >> 9

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


Re: How to find files with a string

2019-01-09 Thread Brian Oney via Python-list
On Wed, 2019-01-09 at 08:29 -0800, anton.gridus...@gmail.com wrote:
> Hello everyone!
> 
> I need to find a file, that contains a string TeNum
> 
> I try to 
> 
> import os
> import sys
> def find_value(fname):
> value = 0
> with open(fname, encoding='cp866') as fn:
> try:
> for i in fn:
> if 'TeNam' in i:
> print(fname)
> except IndexError:
> pass
> return {fname}
> def main():
> dirname = ('H:\\1\\3')
> os.chdir(dirname)
> res = {}
> for i in os.listdir(dirname):
> res.update(find_value(i))
> print('Filename is: ')
> if __name__ == "__main__":
> main()
> 
> But there are mistakes like
> C:\Users\Anton\AppData\Local\Programs\Python\Python36-32\python.exe 
> "C:/Users/Anton/PycharmProjects/Работа с файловой системой/Перебор файлов из 
> папки.py"
> Traceback (most recent call last):
>   File "C:/Users/Anton/PycharmProjects/Работа с файловой системой/Перебор 
> файлов из папки.py", line 21, in 
> main()
>   File "C:/Users/Anton/PycharmProjects/Работа с файловой системой/Перебор 
> файлов из папки.py", line 18, in main
> res.update(find_value(i))
> ValueError: dictionary update sequence element #0 has length 35; 2 is required
> 
> Process finished with exit code 1
> 
> Could you help me to solve this thread?

the error message is somewhat clear. You need to add a key-value pair to
a dictionary. You may consider changing 'res' to a 'list'. You then need
to 'append'. 

Either way, 'find_value' will return the filename regardless of whether
the value is present or not. That should get you started.


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


Re: mouse click automation

2019-01-01 Thread Brian Oney via Python-list
I am unfamiliar with pynput. I have had good experience with pyautogui. As your 
script isn't yet advanced, you may consider it.

https://pyautogui.readthedocs.io/en/latest/introduction.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What Python books to you recommend to beginners?

2018-11-28 Thread Brian Oney via Python-list
On Wed, 2018-11-28 at 08:44 -0600, Skip Montanaro wrote:
> What do people recommend? The target is Python 3.6 and 3.7. The
> audience at work is a mostly financial/statistical crowd, so exposure
> to things like Pandas would be nice, though I'm sure there are
> dedicated books for just that.

Given your audience "Python for Data Analysis, 2nd Edition" by Wes
McKinney would suit well. The Python tutorial should suit for basic
syntax.

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


Re: Error Python version 3.6 does not support this syntax.

2018-11-27 Thread Brian Oney via Python-list
On Tue, 2018-11-27 at 13:50 +0100, srinivasan wrote:
> 
> *except BluetoothctlError, e:*
> 
I don't have python3.6 available, but I believe the proper syntax is:

except BluetoothctlError as e:
print(e)

See:
https://docs.python.org/3/tutorial/errors.html?highlight=exception


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


Re: how to match list members in py3.x

2018-11-25 Thread Brian Oney via Python-list
On Sun, 2018-11-25 at 07:43 -0800, Muhammad Rizwan wrote:
> for each word in each line how can we check to see if a word is already 
> present in a list and if it is not how to append that word to a new list

For your problem consider a set.
https://en.wikipedia.org/wiki/Set_theory

For the python syntax consider the py3 tutorial.
https://docs.python.org/3/tutorial/index.html

HTH

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


Re: All of a sudden code started throwing errors

2018-11-14 Thread Brian Oney via Python-list
On Wed, 2018-11-14 at 09:47 +0100, srinivasan wrote:
> -68 >= -60

It's a problem with your test of wifi strength. Good job of making informative 
output and running
tests!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: IDLE Default Working Directory

2018-11-14 Thread Brian Oney via Python-list
On Tue, 2018-11-13 at 10:33 -0600, Bev in TX wrote:
> > On Nov 12, 2018, at 10:07 AM, Brian Oney  
> > wrote:
> > On Mon, 2018-11-12 at 09:35 -0600, Bev in TX wrote:
> > > I am not the OP and I’m on macOS — no shortcuts.  How would one do the 
> > > same thing on other platforms?
> > > Bev in TX
> > Hello there,
> > I am not an IDLE user. You may try a startup script from python, as per the 
> > following. 
> > oney@oney:~$ cat pyhelp/change_to_current_dir.py #!/usr/bin/env python3
> > import osimport sys
> > os.chdir(os.path.dirname(os.path.abspath(__file__)))
> 
> Thanks so much for taking the time and effort to provide that script.  I 
> experimented with it, but it does not work as desired in Idle.  I tried:* 
> Changed to project directory and then opened Idle
>      Idle -> File-> Open still opens ~/Documents — not the project folder.
> * Placed the change folder script in ~/Documents, opened it in Idle and ran 
> it 
>      Idle did not change to the project folder — it stayed in whichever 
> folder the change folder script resided.
> 
> Unless someone can come up with a better option for macOS, the best that I 
> can think of is to add the project folder to the side bar so that it is 
> easier to access it in Idle -> File -> Open.
>      
Hi Bev

The idea is to put that script in the project folder.

You could begin your lecture with an introduction to the import system and 
command line. The script needs to reside in the desired directory. Once that is 
the case you would import it:

import path.to.script.sans.py.ending

It may be to much to ask of students. It's easiest to put that script in the 
project folder. You know have everthing in the same place, where students can 
copy that directory, take it whereever there is python installed, run that 
script, and pick up where they left off.

If you want to control where the directory changes to do this:

#!/usr/bin/env python3

import os
os.chdir('path/to/project/directory')


That is brittle though. What if the student don't all have access to that 
directory? What if they fail to put the project directory in the right place? 
What if the network drives are down and you end up working locally? 

You could send them a zip-file of everything including my first suggestion and 
it would just work.

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


Re: IDLE Default Working Directory

2018-11-12 Thread Brian Oney via Python-list
On Mon, 2018-11-12 at 09:35 -0600, Bev in TX wrote:
> On Nov 12, 2018, at 9:16 AM, eryk sun  wrote:
> > On 11/12/18, Christman, Roger Graydon mailto:d...@psu.edu>> 
> > wrote:
> > > I looked in IDLE's own configuration menu, and didn't see anything there 
> > > --
> > > and I fear that I might have to fight some Windows settings somewhere else
> > > instead.   I think this is Windows 10.
> > 
> > Modify the "Start in" field of the IDLE shortcut. You can use
> > environment variables, e.g. "%UserProfile%\Documents".
> 
> I am not the OP and I’m on macOS — no shortcuts.  How would one do the same 
> thing on other platforms?
> Bev in TX
> 
> 
> 
> 
Hello there,
I am not an IDLE user. You may try a startup script from python, as per the 
following. 
oney@oney:~$ cat pyhelp/change_to_current_dir.py #!/usr/bin/env python3
import osimport sys
print("Current directory is:")print(os.path.abspath(os.path.curdir))print("Path 
to this file is:")print(os.path.abspath(__file__))# Changing current directory 
to this file's 
directoryos.chdir(os.path.dirname(os.path.abspath(__file__)))print("Current 
directory now is:")print(os.path.abspath(os.path.curdir))# 
sys.path.append(os.path.abspath(__file__))# os.curdir()oney@oney:~$ 
python3Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on 
linuxType "help", "copyright", "credits" or "license" for more information.>>> 
import pyhelp.change_to_current_dirCurrent directory is:/home/oneyDirectory of 
this file is:/home/oney/pyhelp/change_to_current_dir.pyCurrent directory now 
is:/home/oney/pyhelp>>> 
HTH
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issue in parsing the strings in python code

2018-11-12 Thread Brian Oney via Python-list
On Mon, 2018-11-12 at 14:17 +, Rhodri James wrote:
> On 12/11/2018 09:37, srinivasan wrote:
> > Because the problem is every time when ever I see the output  using the
> > "nmcli c show", the below output is the weird output, so instead of
> > connecting to SSID "NIFunkloch" it randomly connects to "NIFunkloch 1552"
> > or sometimes to NIFunkloch 1000" or so on
> > 
> > root:~/qa/robot_tests# nmcli c show
> > NAMEUUID  TYPE  DEVICE
> > 
> > NIFunkloch 1552 c8e1e8c0-0f25-4299-a9ae-2910cfef2ebd  wifi  wlp1s0
> > 
> > Wired connection 1  2a14fbe6-58a0-3b7f-b986-5d1b36a94ec0  ethernet
> > enp0s21f0u4
> > NIFunkloch  1da7d068-4548-4446-bf88-a440e49db1b1  wifi  --
> 
> [snipped for brevity]
> 
> That looks conveniently aligned.  Can't you just slice each line to get 
> the entries you are after?
> 

I believe the idea is to allow the help seeker to piece the following puzzle 
together.

$ nmcli -t NAME,SOMETHINGELSE c show
>>> help(subprocess.Popen)
>>> text.split(':')
>>> aarrr.shiver_me(timbers) if "I am" in "the Bermuda triangle" else 
>>> help("where")
-- 
https://mail.python.org/mailman/listinfo/python-list


[ANN] maildog, Re: email automation

2018-10-30 Thread Brian Oney via Python-list
On Tue, 2018-10-23 at 13:58 +0200, Brian J. Oney wrote:
> On Tue, 2018-10-23 at 10:31 +0100, Ali Rıza KELEŞ wrote:
> > On Tue, 23 Oct 2018 at 09:07, Thomas Jollans  wrote:
> Now that it seems that I will be writing this. 

So I have gotten so far as to have a little package called 'maildog' working
for me. It reads emails and sends customized replies on my behalf. Currently,
I have it working for two languages.

If you also have to reply to the same email ofter for whatever reason this
little puppy may help you write fewer repetive email replies. That's what it
does for me.

If I have piqued your interest, have a look at https://github.com/oneyb/maildog/

Thank you for the tips.

Kind regards
Brian

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


Re: regular expression problem

2018-10-28 Thread Brian Oney via Python-list
On Sun, 2018-10-28 at 22:04 +0100, Karsten Hilbert wrote:
> [^<:]

Would a simple regex work?

I mean:

~$ python
Python 2.7.13 (default, Sep 26 2018, 18:42:22) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> t = '$$'
>>> re.findall('[^<>:$]+', t)
['name', 'options', 'range']

You can then interpret what you have extracted afterwards.
Maybe if you want to have the single ones grouped you could consider:

>>> t = t*2
>>> t
''
>>> re.findall('\$<+([^:]+)::([^:]+)::([^:]+)>+\$', t)
[('name', 'options', 'range'), ('name', 'options', 'range')]

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


Re: Accessing clipboard through software built on Python

2018-10-28 Thread Brian Oney via Python-list
You don't have to start from scratch. You don't to do anything other than learn 
to use anamnesis. I use anamnesis as my clipboard manager. I you can easily 
tell to get which ever one you want (i.e.  the thousandth item).

# Inform yourself
https://sourceforge.net/projects/anamnesis/
# Install it
cd ~/bin/src/
wget -O anamnesis.tar.gz  
https://sourceforge.net/projects/anamnesis/files/latest/download
tar xzf anamnesis.tar.gz
ln -sf ~/bin/src/anamnesis-1.0.4/source/anamnesis.py ~/bin/anamnesis

# Be happy


It hasn't changed in years and that's just fine. I just works. I can access it 
through the command line when I am in a remote ssh session. Or I have it as a 
autostarted daemon. It uses sqlite to store all your copied (and selected, if 
configured) text, which can be slow on a spinning disk. If this turns you off, 
replace your OS hard drive with an ssd - life's too short.

HTH

On October 28, 2018 5:14:54 PM GMT+01:00, Tim Daneliuk  
wrote:
>On 10/27/2018 08:17 AM, Musatov wrote:
>> I am wondering if Python could be used to write a program that
>allows:
>> 
>> 1. Highlight some text
>> 2. Ctl+HOTKEY1 stores the string of text somewhere as COPIEDTEXT1
>> 3. Highlight another string of text
>> 4. Ctl+HOTKEY1 stores another string of text somewhere as COPIEDTEXT2
>> 
>> THEN
>> 
>> 5. Ctl+HOTKEY2 pastes COPIEDTEXT1
>> 6. Ctl+HOTKEY2 pastes COPIEDTEXT2
>> 
>> I found "pyperclip" and "Tkinter" but I don't know where to start.
>> 
>> Thanks,
>> 
>> Musatov
>> 
>
>
>I am able to do this with clipboard (pip install clipboard).
>
>
>However, the highlighted text must be copied explicitly:
>
>Highlight
>Ctl-C
>
>In Python:
>
>TEXT1 = clipboard.paste()
>
>Highlight again
>
>TEXT2 = clipboard.paste()
>
>X actually has several clipboard buffers and it can be tricky to get
>this going.  I don't recall,
>but either clipboard or pyperclip have a way to get to them all IIRC
>...
>
>HTH,
>-Tim
>
>-- 
>https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


email automation

2018-10-22 Thread Brian Oney via Python-list
Dear List,

I would like to send out custom automated replies to email. In the future, I
would like to be able to integrate nltk and fuzzy matching if necessary.

After some basic research I have a few options:

 1. Grapple with OpenEMM (interesting software, has python library, still 
alive and kicking, a bit overkill for my use-case);
 2. build on the examples in 'Automate the boring stuff';
 3. forget about it.
 
Please tell me about any possible alternatives I missed.

Kind regards,
Brian
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: ESR "Waning of Python" post

2018-10-17 Thread Brian Oney via Python-list



On October 17, 2018 7:56:51 AM GMT+02:00, Marko Rauhamaa  
wrote:
>I can't be positive about swapping. I don't remember hearing thrashing.
>However, I do admit running emacs for months on end and occasionally
>with huge buffers so the resident size can be a couple of gigabytes.
>
That's a pretty good stress test for any program, especially one with so much 
human interaction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: JPEGImage() hangs

2018-09-27 Thread Brian Oney via Python-list
Could you please try another tool like `convert'? E.g.

$ convert 102_PANA/P1020466.JPG test.png


What does that say?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] master/slave debate in Python

2018-09-26 Thread Brian Oney via Python-list
> PS: I'm not a great fan of it, but I think we all know that off-topic is 
> in a way what this list excels at.
+1

An open source community thrives on being open. It also welcomes those who like 
to pick a fight for various, usually personal reasons.

Has any heard of that Python language? I hear they named it after a person's 
pretty snake. No? Okay.

"I have a vewwy great fwiend in Wome called 'Biggus Dickus'"
...
"Can I go now, sir?"

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


Re: 2 Bugs: in Python 3 tutorial, and in bugs.python.org tracker registration system

2018-09-22 Thread Brian Oney via Python-list
That's one thing that confused me. Generators are supposed to be one-off 
iterators. Iterators, *I understood* as reusable iterables.

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


Re: What is not working with my "map" usage?

2018-09-21 Thread Brian Oney via Python-list
Hi Viet,

map applies the function to each of the elements of the list you provide.

It would be roughly equivalent to:

[add_all_elements(x) for x in alist]

It may help you to consider the term and function "map" from the view of linear 
algebra.

Apparently it's a common term:
https://en.wikipedia.org/wiki/Map_%28higher-order_function%29?wprov=sfla1

HTH


On September 21, 2018 11:29:41 PM GMT+02:00, Viet Nguyen via Python-list 
 wrote:
>Hi,
>
>I want to add up all of the list elements.  But when I use the "map"
>function, it didn't seem to work as I expect.  Could someone point out
>how "map" can be applied here then?
>
>def add_all_elements (*args):  
>total = 0
>for i in args:
>   print(type(i))
>   print("i = %s" % i)
>   print("BEFORE total = %s" % total)
>   total += int(i)
>   print("AFTER total = %s\n" % total)
>print("FINAL total = %s\n" % total)
>return total
>
>
>alist = ['2', '09', '49']
>
>
>## this one works Okay
>
>add_all_elements(*alist)
>
>i = 2
>BEFORE total = 0
>AFTER total = 2
>
>
>i = 09
>BEFORE total = 2
>AFTER total = 11
>
>
>i = 49
>BEFORE total = 11
>AFTER total = 60
>
>FINAL total = 60
>
>
>## Why is this NOT Okay when I use map ??  What must I change ?
>
 list(map(add_all_elements,alist))
>
>i = 2
>BEFORE total = 0
>AFTER total = 2
>
>FINAL total = 2
>
>
>i = 09
>BEFORE total = 0
>AFTER total = 9
>
>FINAL total = 9
>
>
>i = 49
>BEFORE total = 0
>AFTER total = 49
>
>FINAL total = 49
>
>[2, 9, 49]
>
>
>Thanks,
>Viet
>-- 
>https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fumbling with emacs + elpy + flake8

2018-09-13 Thread Brian Oney via Python-list
Hi Martin,

I have messed around alot with the myriad emacs configurations out there. I 
found spacemacs and threw out my crappy but beloved .emacs config. I have 
looked back, but will stay put. http://spacemacs.org/

Fumbling is a nice word.

Spacemacs caters to lots of programmers. I can honestly recommend giving it a 
serious look. It's a well conceived emacs configuration.

** Features
- Auto-completion using 
[[https://github.com/proofit404/anaconda-mode][anaconda-mode]]
- Code Navigation using  
[[https://github.com/proofit404/anaconda-mode][anaconda-mode]]
- Documentation Lookup using  
[[https://github.com/proofit404/anaconda-mode][anaconda-mode]]  and 
[[https://github.com/tsgates/pylookup][pylookup]]
- Test Runners using [[https://github.com/syl20bnr/nose.el][nose.el]] or 
[[https://github.com/ionrock/pytest-el][pytest]]
- Virtual Environment using  
[[https://github.com/jorgenschaefer/pyvenv][pyvenv]] and 
[[https://github.com/yyuu/pyenv][pyenv]]
- semantic mode is enabled
- PEP8 compliant formatting via [[https://github.com/google/yapf][YAPF]]
- PEP8 checks with [[https://pypi.python.org/pypi/flake8][flake8]] or 
[[https://pypi.python.org/pypi/pylint/1.6.4][pylint]]
- Suppression of unused import with 
[[https://github.com/myint/autoflake][autoflake]]
- Use the ~%~ key to jump between blocks with 
[[https://github.com/redguardtoo/evil-matchit][evil-matchit]]
- Sort imports with [[https://pypi.python.org/pypi/isort][isort]]
For more see:
~/.emacs.d/layers/+lang/python/README.org


Here's what I ask you to consider:

pip install flake8
pip install --upgrade "jedi>=0.9.0" "json-rpc>=1.8.1" "service_factory>=0.1.5"
if [ -d ~/.emacs.d ]; then \rm -rf ~/.emacs.d/; fi
git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d
emacs


It may be a rabbit hole, but that adventure belongs to emacs, somehow.

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


Re: I need help to put the output from terminal in a csv file

2018-09-07 Thread Brian Oney via Python-list
Please study the following to get you started. It looks like JSON output that 
you are dealing,
which is good. I added a ", to the "body"-line, because I assume that you 
botched that when giving
an example.

```python
#!/usr/bin/env python


import json


output = '''
{
   "error" : {
  "body" : "The requested device is currently not online.",
  "detail" : "Make sure to connect the device",
  "event" : 123456,
  "header" : "Device Unavailable (123456)"
   }
}
'''


# help(json.loads)
parsed = json.loads(output)

if type(parsed) == dict:
if type(parsed['error']) == dict:
print("yay!")
```

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


Re: >< swap operator

2018-08-14 Thread Brian Oney via Python-list
On Tue, 2018-08-14 at 10:55 -0400, Dennis Lee Bieber wrote:
> On Tue, 14 Aug 2018 06:18:41 -0700 (PDT), skybuck2...@hotmail.com declaimed
> the following:
> 
> > On Monday, August 13, 2018 at 10:01:37 PM UTC+2, Léo El Amri wrote:
> > > On 13/08/2018 21:54, skybuck2...@hotmail.com wrote:
> > > > I just had a funny idea how to implement a swap operator for types:
> > > > 
> > > > A >< B
> > > > 
> > > > would mean swap A and B.
> > > 
> > > I think that:
> > > 
> > > a, b = b, a
> > > 
> > > is pretty enough
> > 
> > LOL.
> > 
> > A >< B is shorter !
> > 
> 
>   But is specific to swapping just two entities...
> 
>   c, a, b = a, b, c
> 
> moves three entities at once -- and can be expanded for more.
> 
> > > > a = 1
> > > > b = 2
> > > > c = "confusion"
> > > > 
> > > > c, a, b = a, b, c
> > > > print a
> 
> 2
> > > > print b
> 
> confusion
> > > > print c
> 
> 1
Indeed, that is elegant.  It doesn't take a special knowledge of syntax, for 
good guessers. It also doesn't look like two male variables peeing on each 
others feet.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Want to be a rockstar programmer?

2018-07-23 Thread Brian Oney via Python-list
meh, I'm more into 90s and 00s metal rock and punk rock. Oh well, I knew it 
wasn't meant to be. ;)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: For next loops

2018-07-23 Thread Brian Oney via Python-list
What if ply != com in the first (0th) iteration? 

It's better to have an 'else:'-statement in your case, I suppose.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] Bit twiddling homework

2018-07-20 Thread Brian Oney via Python-list
On Fri, 2018-07-20 at 10:38 -0400, Dennis Lee Bieber wrote:
> On Fri, 20 Jul 2018 11:00:09 +0200, Brian Oney via Python-list
>  declaimed the following:
> 
> > Are 16|1 and 16+1 internally the same operation (for integers)? 
> 
>   For those integers the EFFECT/RESULT will be the same. But...
> 
> > > > 17 + 1
> 
> 18
> > > > 17 | 1
> 
> 17
Of course. There was a reason I chose those integers and timed them. I am 
ignorant of how Python stores an integer internally. Either way (2^x bit) the 
result would be the same regardless.
In retrospect, I seem to suggest that Python would have different sets of 
operations for an integer based on it's value; that's poor wording. Anyways.
 
> {From the original post}
> > For example, bitwise operators are neat (here a shift):
> > C:
> >  int res = 1 << 4 
> >  printf("%d\n", res)
> > 16
> > 
> > Translates to pseudocrap:
> >  0001 -> leftwards bitshift of 4 places -> 0001 
> > 
> 
>   Python also supports shift...
> 
> > > > 17 << 2
> 
> 68
> > > > 17 >> 2
> 
> 4
Nice! Once again Python shines as a prototyping language!
> [Side comment, even in C bitwise operators aren't really considered playing
> "directly with memory". That would be more something like:
> 
>   int * i;// i is a pointer (address) to an 
> integer
>   i = 0x01FF; // set i to access address 511
>   printf("%d\n", *i); // print (as integer) whatever is stored at 511
> 
> THAT you can not do in Python (at least, not without using something like
> the ctypes library).]
> 
Thank you for the explanation. That is a nice example.
>   Hex is basically just a means of shortening a binary string by
> representing runs of 4 bits using a single symbol. Same with Octal (runs of
> 3 bits). In both cases, each symbol translates to an integral number of
> bits, and position in a multi-symbol value can be translated directly.
> 
>   This is not possible when representing binary values in Decimal, as
> each place in the decimal representation does not map to an integral number
> of bits.
> 
Yup! Wikipedia has the same info scattered about the hexadecimal page. You 
describe it nicely from the perspective of a computer scientist.
> > Therefore, what book or learning course do you recommend? I imagine 
> > something that tours or skims
> > the fundamentals of Boolean algebra and digital logic, and then goes to C 
> > and some fun homework
> > problems. It may seem to you that the emphasis there is wrongly placed. 
> 
>   While Boolean algebra and digital logic are core concepts for
> computers, neither really appear in books that teach programming. Boolean
> logic is more in the realms of pure math and then feeds to digital logic
> (at the gate level -- NAND, NOR, AND, OR gates and combinations to create
> things like adders). Consider de Morgan's theorem:
> 
> A & B =>  not(not A | not B)
> A | B =>  not(not A & not B)
> 
> > > > b = 24
> > > > a = 19
> > > > a & b
> 
> 16
> > > > a | b
> 
> 27
> > > > a ^ b
> 
> 11
> > > > ~(~a & ~b)
> 
> 27
> > > > ~(~a | ~b)
> 
> 16
Thank you for the advice. Those are also some nice examples. Cool, I can do 
this stuff in Python. I guess this is also why Python is so popular; an 
instructor can take one language and cover a ton of material without having to 
saddle students with learning another language.
>   Can't really help with suggesting books -- The ones from my college
> days are likely out-of-print; I haven't really had a need to buy newer
> books for such basic concepts. Even simple discrete 74xx chips are so rare
> these days that the idea of creating a four-bit ADDER from gates is hard to
> find.
> 
>   Parallax used to have a slew of educational stuff based on BASIC Stamps
> and a logic simulator (and project board), but neither appear to still be
> in their catalog (the books used to be available as PDF for most of their
> educational stuff). I did find a copy on a third-party site for the Digital
> Logic intro
> http://rambal.com/index.php?controller=attachment_attachment=686=AOvVaw3YI9p_blIFAgardqgB2SBq
> 
> Can't find a download for their logical simulator, but there is something
> that might be usable at 
> https://sourceforge.net/projects/cedarlogic/
> 
> 
>   Just to put this back on topic for the group...
> 
>   Pretty much all of what you ask can be learned in Python (and using the
> interactive interpreter is a lot faster than wr

Re: [OT] Bit twiddling homework

2018-07-20 Thread Brian Oney via Python-list
On Fri, 2018-07-20 at 18:07 +0900, xffox wrote:
> On Fri, Jul 20, 2018 at 08:25:04AM +0200, Brian Oney via Python-list wrote:
> > Therefore, what book or learning course do you recommend? I imagine 
> > something that tours or skims
> > the fundamentals of Boolean algebra and digital logic, and then goes to C 
> > and some fun homework
> > problems. It may seem to you that the emphasis there is wrongly placed. 
> 
> "Hacker's Delight" (please don't judge by the name):
> https://en.wikipedia.org/wiki/Hacker's_Delight . It's a collection of
> bit-level hacks. Figuring out each trick before reading the solution can
> provide a list of fun homework problems. Hope it helps.
That's what I am looking for. Thank you so much. Have a nice weekend!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [OT] Bit twiddling homework

2018-07-20 Thread Brian Oney via Python-list
On Fri, 2018-07-20 at 06:37 +, Steven D'Aprano wrote:
> On Fri, 20 Jul 2018 08:25:04 +0200, Brian Oney via Python-list wrote:
> 
> > PS: Can I twiddle bits in Python?
> 
> Yes.
> 
> These operators work on ints:
> 
>   bitwise AND:  &
>   bitwise OR:   |
>   bitwise XOR:  ^
> 
That's right I had forgotten about that. Thank you for the quick answer.Some 
fun:$ ipythonPython 2.7.13 (default, Nov 24 2017, 17:33:09) ...In [1]: j = 16; 
i = 1
In [2]: print(i+j); print(i|j)1717
In [3]: %timeit i+j1000 loops, best of 3: 65.8 ns per loop
In [4]: %timeit i|j1000 loops, best of 3: 73 ns per loop
In [5]: %timeit 16|11000 loops, best of 3: 28.8 ns per loop
In [6]: %timeit 16+11000 loops, best of 3: 28.8 ns per loop
I wonder why the difference between [3] and [4]. My mental ranking of speed of 
operations tells me it should be the other way around.
Are 16|1 and 16+1 internally the same operation (for integers)? 
-- 
https://mail.python.org/mailman/listinfo/python-list


[OT] Bit twiddling homework

2018-07-20 Thread Brian Oney via Python-list
Dear Python-List,

an old dog wants to learn some new tricks.

Due to my contact with microcontrollers, I am learning C/C++. I am aware that 
this is the
endearing, helpful, yet chatty python-list. Many of you are competent 
C-programmers. 

The allure of C is that I can play directly with memory. 
For example, bitwise operators are neat (here a shift):
C:
  int res = 1 << 4 
  printf("%d\n", res)
16

Translates to pseudocrap:
 0001 -> leftwards bitshift of 4 places -> 0001 


I think that is pretty neat. After having imbibed the some of the computational 
basis for binary
digits (X₂) a few weeks ago, I learned yesterday about hexadecimals (X₁₆). 
While in the rabbit
hole, I learned about Claude Shannon's and Alan Turing's work on digital logic. 
I am excited to
learn about what kind of computations I can do in these number systems. 

Therefore, what book or learning course do you recommend? I imagine something 
that tours or skims
the fundamentals of Boolean algebra and digital logic, and then goes to C and 
some fun homework
problems. It may seem to you that the emphasis there is wrongly placed. 

Thank you for the tips.

Cheers,
Brian
PS: Can I twiddle bits in Python?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: command line utility for cups

2018-06-20 Thread Brian Oney via Python-list
On Wed, 2018-06-20 at 12:36 +0200, George Fischhof wrote:
> Hi,
> You can also try click library from pypi, that is a very good command line
> stuff.
> 
> George

Thank you for the tip. I am away of click and it's awesomeness, but am hesitant 
because it's not apart of stdlib. I have gotten bitten too often. 

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


Re: command line utility for cups

2018-06-20 Thread Brian Oney via Python-list
Thanks Peter!

That's pretty slick.

I will get it working for sure now.

Regards,
Brian
-- 
https://mail.python.org/mailman/listinfo/python-list


command line utility for cups

2018-06-20 Thread Brian Oney via Python-list
Dear all,

I am having trouble with argparse. I am trying to translate the following line 
to a sleek python
script:

lpr -o media=legal -o sides=two-sided-long-edge filename

Now where I am.

import argparse
parser = argparse.ArgumentParser(description='Print stuff with cups')
parser.add_argument('--printer', '-p',
help='Use this printer, try running: lpstat -a')
parser.add_argument('--options', '-o', 
help='Options for this printer, try running: \
lpoptions -p PRINTER -l')

parser.parse_known_args(['-o', 'sides=one-sided', '-o', 'test=crap'])
Namespace(options='test=crap', printer=None))

How should I deal with multiple options being fed into my script?

Thanks!

Cheers,
Brian
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: text mining

2018-06-16 Thread Brian Oney via Python-list


На 15 юни 2018 г. 14:57:46 GMT+02:00, Steven D'Aprano 
 написа:
>Seriously, you are asking strangers to help you out of the goodness of 
>their heart. If your intention was to send the message that you're
>lazy, 
>drunk, or just don't give a damn about the question, you were
>successful.

Answers like these make me also want ask "questions" like those. Thank you. I 
hope he's drunk.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: stock quotes off the web, py style

2018-05-16 Thread Brian Oney via Python-list
thank you for that tip. I missed that somehow...

На 16 май 2018 г. 16:31:37 GMT+02:00, Peter Otten <__pete...@web.de> написа:
>Friedrich Rentsch wrote:
>
>>  >>> ibm = urllib2.urlopen
>> ("https://api.iextrading.com/1.0/stock/IBM/quote;).read()
>>  >>> ibm = eval (ibm)
>
>Dont do this. You are allowing the guys at iextrading.com to execute 
>arbitrary code on your machine. Use
>
>ibm = json.loads(ibm)
>
>instead or 
>
>import urllib.request, json
>ibm = urllib.request.urlopen(
>"https://api.iextrading.com/1.0/stock/IBM/quote;
>).read()
>ibm = json.loads(ibm.decode("utf-8"))
>
>if you are using Python 3.
>
>
>-- 
>https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python gotcha of the day

2018-03-14 Thread Brian Oney via Python-list
explicit is better than implicit.

That gives me an idea for a module with the following debugging command line 
functionality.

import sass

>>> "" ":p"
Traceback: 
Are you telling me that ' ' is supposed to an operator? (Rock thrown)




On March 14, 2018 10:40:38 AM GMT+01:00, Thomas Jollans  wrote:
>On 2018-03-14 05:08, Steven D'Aprano wrote:
>> Explain the difference between these two triple-quoted strings:
>> 
>> Here is a triple-quoted string containing spaces and a triple-quote:
>> 
>> py> """ \""" """
>> ' """ '
>> 
>> 
>> But remove the spaces, and two of the quotation marks disappear:
>> 
>> py> """\""
>> '"'
>> 
>> 
>> If nobody gets the answer, I shall reveal all later.
>> 
>> (Hint: it is not a bug.)
>> 
>
>Ah, subtle!
>
>Initially I thought the first one was being interpreted as
>
>''' """ '''
>
>and the second one as
>
>"" '"' "" ""
>
>which left me rather puzzled as to why the first wasn't being
>interpreted as
>
>"" ' "' " " ""
>
>but of course that's not what's going on at all. The second one is
>
>'''"''' ""
>
>As to WHY - in both your examples, the literal can be interpreted as a
>triple-quoted string, so it is (rather than some combination of
>single-quoted strings). And, in both cases, the SHORTEST possible
>reading as a triple-quoted string is used.
>
>There, now I can go back to work.
>
>- Thomas
>
>-- 
>https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Templating Language

2017-12-18 Thread Brian Oney via Python-list
you may consider checking out a more general approach. Noweb was the first
to my knowledge and lead the way for Sweave (R or S), and pyweave, as
mentioned.

https://en.wikipedia.org/wiki/Noweb

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