Re: Good editor for python

2018-11-11 Thread Brian J. Oney via Python-list
Hi Olivier

I am glad you did not trigger an editor war. I don't know how familiar you are
with emacs. The answer depends alot on your preference and future work. Emacs
and vi have been around for a long time for good reasons.

If you prefer an extensible and futureproof editor, I can wholeheartedly
recommend emacs or vi. I went from a happy emacs user to an even happier
spacemacs user. Spacemacs is a batteries-included emacs configuration which
lets you choose between emacs-like or vi keybindings, which are mnemonic,
efficient, consistent, and, above all, discoverable. Discoverability allows a
person who has been using something for a while to find out even more tricks
in the moment that those tricks would be useful. Spacemacs has tons of bells
and whistles and still manages to be fast (through lazy configuration
loading).

If you are looking at literate programming, Jupyter Notebooks are hard to
beat, especially if you want to share code with novices. In case you want a
medusa that eats everything else for lunch, look further. Such a beast can be
harnessed with org-mode, an emacs mode which can be just about anything you
want it to be. You can do literate devops, literate programming, mix
programming languages, export to your grandma's toaster, and feed the dog with
org-mode, if you want to play. Org-mode's syntax and power is unmatched, to my
knowledge.

That all depends on how far down the rabbit hole you want to dive. Emacs with
pdb is pretty good though. To get the functionality you miss is pretty simple
with spacemacs.  For more information and platform-specific instructions,
please see the following link.

https://github.com/syl20bnr/spacemacs

The basic template already activates python support.

That's my two cents.

Cheers
Brian

On Sun, 2018-11-11 at 08:45 -0600, Spencer Graves wrote:
>    People rave about Jupyter Notebooks, which reportedly allow you 
> to mix narrative with code describing what you are doing and why.
> 
> 
>    I primarily program in R, and RMarkdown Documents in RStudio 
> allow me to mix narrative with R and Python code.  I explain what I'm 
> doing and why, then write "```{python}" ... "```" to encapsulate a 
> Python code snippet and "```{r}" ... "```" for an R code snippet. Or I 
> just use the Idle editor that comes with Python.
> 
> 
>    Someone suggested that Apache Zeppelin  and / or BeakerX might be 
> able to do this also, but I've not tried or verified them.
> 
> 
>    Spencer Graves
> 
> 
> On 2018-11-11 08:11, Andrew Z wrote:
> > If you do scripts - emacs/vi is the way to go.
> > If you need something more (like creating libraries,  classes) go with
> > pycharm. It is a professionally made IDE.
> > 
> > Over past 2 years ive been trying to "downgrade" myself to something with
> > less belts and whistles,  but come back to it all the time.
> > 
> > On the other hand , if you already use emacs - u should not need anything
> > else.
> > 
> > On Sun, Nov 11, 2018, 04:15 Olive  > 
> > > I am not a professional programmer but I use Python regularly for custom
> > > scripts (and plot with matplotlib). I have just learned VBA for Excel: 
> > > what
> > > I found amazing was their editor: it is able to suggest on the spot all 
> > > the
> > > methods an object support and there is a well-integrated debugger. I 
> > > wonder
> > > if something similar exists for Python. For now I just use emacs with the
> > > command line pdb. What do people use here? Ideally I would like to have
> > > something that is cross platform Windows/Linux.
> > > 
> > > Olivier
> > > 
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
> > > 
> 
> 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

2018-11-07 Thread Brian J. Oney via Python-list
On Wed, 2018-11-07 at 10:22 +0100, srinivasan wrote:
> blkid -o export %s | grep \'TYPE\' | cut -d\"=\" -f3

You don't need to escape the single quotes.
Try either:

"blkid -o export %s | grep 'TYPE' | cut -d'=' -f3"
or:
'blkid -o export %s | grep "TYPE" | cut -d"=" -f3'
or:
"blkid -o export %s | grep \"TYPE\" | cut -d\"=\" -f3"

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


Re: email automation

2018-10-23 Thread Brian J. Oney via Python-list
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:
> > > 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';
> > 
> > From briefly skimming the relevant section, it looks like this gives
> > some examples with smtplib and imaplib. That sounds like a good place to
> > start!
> > 
> > If you happen to have a server (VPS, Raspberry Pi, PC, whatever) running
> > a full MTA that you can forward your emails to, you could feed the
> > relevant messages to your script directly with the help of procmail,
> > rather than polling an IMAP server.
> 
> +1
> 
> I experienced procmail and worked like a charm for me, in a case like
> yours. My script was parsing emails to grab some URIs of binary
> objects and queue them to be processed later.
> 
> You can easily trigger a python script and do whatever you need in
> that script. If it is a long term process, you should just parse email
> and use queues for the rest.
> 

Thank you for the insights. The developer of procmail says to avoid it, as the
last update was in 2001. Supposedly there are also some security concerns.
The mail server does some pretty good filtering already.

I made the mistake of being vague about the problem. Let me specify.

  - General Problem: too many emails to answer with due care
- Technical Problem 1: can't be run on mail server.
- Technical Problem 2: answers needed in 2 and possibly 4 languages.
- Future Problem 3: don't have resources to maintain the solution forever
- Future Problem 4: software may be running in many different countries
  with different languages and legal frameworks.
  - Goal: lighten the load 
- Potential: many emails pose questions to information already on the
  website.
  - Potential solution: automate personalized replies with relevant
information.

Nonetheless, barring a tip to an existing solution, I will be rolling my own.

Off the top of my head, I image the setup being eerily similar to a flask
website. I would rely on smtplib, imaplib, nltk, pyzmail, and jinja2.

Draft Algorithm:
  1. read mail
  2. tokenize body's contents
  3. apply logic to determine answer
  4. render appropriate answer template
  5. send email
  6. refile email

maildog/
  app.py
  answer_logic/
english.csv
german.csv
french.csv
  maildog/
__init__.py
send_mail.py
read_mail.py
refile_mail.py
decide_answer.py
  templates/
base.html
base.txt
info.html
info.txt
schedule.html
schedule.txt
  tests/
test_answer_common_email.py
test_explain_upcoming_schedule.py
test_read_email.py


Somehow I think someone smarter already solved this niche case. A part of me
wants to delve into OpenEMM. The rest wants to write code.

Now that it seems that I will be writing this. What is the recommended way to
set up a timer. I know 2 system options, systemd timers and cron jobs. I
prefer the former for the handy logging options. What about a python solution?
What would the advantage of a python queue be over a systemd timer? I guess
that's an apples an oranges comparison. In my case I most likely would have a
raspberry pi running a python script to read and possibly answer any emails.

Thanks again for the tips.

Regards,
Brian

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


Re: regex string matching python3

2018-10-01 Thread Brian J. Oney via Python-list
On Mon, 2018-10-01 at 10:49 -0700, nanman3...@gmail.com wrote:
> I have a string like this: 
> 
> b'\tC:94.3%[S:89.9%,D:4.4%],F:1.7%,M:4.0%,n:1440\n'
> 
> And I would like to  extract the numbers corresponding to S,D,F and M in this 
> string and convert them into an array like this: 
> 
> [ '89.9', '4.4', '1.7', '4.0']
> 
> Any help would be appreciated! 
Hi there,

import re

s = b'\tC:94.3%[S:89.9%,D:4.4%],F:1.7%,M:4.0%,n:1440\n'

pattern = re.compile('S:([0-9.]+)%,D:([0-9.]+)%\],F:([0-9.]+)%,M:([0-9.]+)')

stuff = [x for x in re.findall(pattern, s)[0]]

You may consider just getting everthing out of your string and then munging it 
to what ever you like.

I mean:

pattern = re.compile('([A-Za-z]):([0-9.]+)')
{x: float(y) for x, y in re.findall(pattern, s)


Then you could read what ever and put it in a handy format wherein it is clear 
what it was. I mean:

stuff = []
for s in iostream:
stuff.append({x: float(y) for x, y in re.findall(pattern, s)})


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


Re: RANT why the *%#&%^ does installing pip not install setuptools???

2018-07-05 Thread Brian J. Oney via Python-list
On Stretch:

~ $ aptitude show python-pip
Package: python-pip  
Version: 9.0.1-2
...
Maintainer: Debian Python Modules Team 
...
Depends: ca-certificates, python-pip-whl (= 9.0.1-2), python:any (<
2.8), python:any (>= 2.7.5-5~)
Recommends: build-essential, python-all-dev (>= 2.6), python-
setuptools,
python-wheel
...
Tags: admin::package-management, devel::lang:python, devel::packaging,
  implemented-in::python, role::program

And:
~ $ aptitude show python3-pip
Package: python3-pip 
Version: 9.0.1-2
...
Maintainer: Debian Python Modules Team 
...
Depends: ca-certificates, python-pip-whl (= 9.0.1-2), python3:any (>=
3.4~)
Recommends: build-essential, python3-dev (>= 3.2), python3-setuptools,
python3-wheel
...
 

It seems deliberate, but I am not the person to ask why.

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


Re: Python Templating Language

2017-12-17 Thread Brian J. Oney via Python-list
I am not exactly sure what you mean, so I will guess. 

Jinja may be what you're looking for. It's an important component of flask & 
ansible, for example.

pyweave may also serve your purposes.

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


advice for inventory software

2017-11-30 Thread Brian J. Oney via Python-list
Dear Python scripters,

I am writing modules for my insectary (for food), the processes of which I plan 
to mostly automate.

Currently, inventory and the traceability of material flows is my focus. My 
best idea (yet) for making things as simple as possible consists of a debian 
server hooked up to a barcode scanner. The input of information would consist 
of scanning barcode sequences (Start process, item1, ..., stop process). 

For this, I plan to implement a listener to the usb port, which takes the input 
and knows what to do with it. Later on, there will be multiple simultaneous 
input sources. For now, I imagine a simple flask app capturing the input and 
feeding it into an SQL database. 

Certainly, someone has had the opportunity to something similar if not 
identical. I would be particularly greatful for advice on design and work 
already done.

For those interested, I have my progress on github.com/oneyb. I almost done 
with the basic inventory barcode printing functionality I need.

You may think I am reinventing the wheel. If so, why would I ask for advice? 
Also, the highly closed nature of the insect breeding business, my slim budget, 
and the desire to easy extend functionality in the near future (plus a mild 
case of 'I wanna code' [aka NIH] syndrome), push me to learn and implement this 
myself.

Thanks in advance!

Cheers

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