Python with text editor

2020-05-30 Thread Preetha M
Hello. Thank you for responding to my previous mail. Can someone tell me
how to connect python to sublime text 3. Whenever I select python and type
the code, it does not work when I press ctrl+B. Please tell.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python with text editor

2020-05-30 Thread DL Neil via Python-list

On 30/05/20 7:42 PM, Preetha M wrote:

Hello. Thank you for responding to my previous mail. Can someone tell me
how to connect python to sublime text 3. Whenever I select python and type
the code, it does not work when I press ctrl+B. Please tell.



ST is an editor/IDE which is not Python-specific. The build system on ST 
is (better) designed (and named) for compiled languages. Python does not 
require a compile-and-build process.


However, we can use the command even though all it does is directly 
execute the code - exactly what we want.


First, manually instruct ST how to build your (current) project: main 
menu > Tools > BuildSystem > Python3 (assumption!). Once done 
(configured), always remembered!


Thereafter, when you select Build (ctrl+b), ST will know that it is 
working on a Python 'build'...

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: why no camelCase in PEP 8?

2020-05-30 Thread Terry Reedy

On 5/29/2020 4:30 PM, Peter J. Holzer wrote:

On 2020-05-28 18:14:53 -0400, Terry Reedy wrote:

On 5/28/2020 4:18 PM, Peter J. Holzer wrote:

On 2020-05-19 05:59:30 +1000, Chris Angelico wrote:

Nobody ever requires you to comply with it for any other code.


That's obviously not true:

[...]

Revise Chris' claim to "Neither the PSF nor the Python core developers
require* that owners of non-stdlib code comply with PEP 8" and it would be
true.


Well, yes. But "Neither the PSF nor the Python core developers" is quite
different from "Nobody ever".


Right, I modified a statement that takenly literally is obvious false, 
undefensible, and not worth discussing to one that I believe to be true 
and that says something important.  I would qualify further to people in 
their PSF/core-dev roles.  There might be core-devs who enforce PEP-8 in 
other roles.



That's like saying "Nobody has ever been on the moon" is true if you
replace "Nobody" with "No catholic bishop".


Only as the level of an empty generic template.  has ever 
.  Semantically, the two statements are not at all paralley. 
The PSF/core-devs own python and PEP-8.  Catholic bishops do not own 
either the moon or means of walking there.  And there would be nothing 
wrong if a Catholic bishop were to walk on the moon, and I can imagine 
(and hope) that one might someday do so.



--
Terry Jan Reedy

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


Binary Sort on Python List __xor__

2020-05-30 Thread evan . schalton
I frequently use binary as bool placeholders and find myself filtering lists 
based on those bools, this seems to have a similar semantic meaning as the bit 
wise ^ or __xor__ operator and could add syntactic sugar to the base list class.

Use Case:

Controlling a stepper at half-step has the following cycle steps:

CYCLE = [
  [1,0,0,0],
  [1,1,0,0],
  [0,1,0,0],
  [0,1,1,0],
  [0,0,1,0],
  [0,0,1,1],
  [0,0,0,1],
  [1,0,0,1],
]

which can be represented as follows:

CYCLE = [
1<<3,
1<<3|1<<2,
1<<2,
1<<2|1<<1,
1<<1,
1<<1|1<<0,
1<<0,
1<<3|1<<0
]

or more cleanly:

CYCLE = [8, 12, 4, 6, 2, 3, 1, 9]

on a raspberrypi, using (for illustration's sake) GPIO pins 1,2,3,4 I'd like to 
use the __xor__ method (currently not implemented) to perform the bit-wise 
filter as follows:

class MyList(list):
def __init__(self, *args):
super().__init__(args)

def __xor__(self, num):
return [self[i] for i in [-index-1 for index, i in 
enumerate(bin(num)[:1:-1]) if i !='0']][::-1]

PINS = MyList(1,2,3,4)

PINS ^ 8
# [1]

PINS ^ 12
# [1, 2]

PINS ^ 4
# [2]

PINS ^ 6
# [2, 3]

PINS ^ 2
# [3]

PINS ^ 3
# [3, 4]

PINS ^ 1
# [4]

PINS ^ 9
# [1, 4]

The need here isn't strictly pi/stepper related; I've run into this several 
times in the past when evaluating combinations * permutations of items where a 
bitwise filter would be useful.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Binary Sort on Python List __xor__

2020-05-30 Thread MRAB

On 2020-05-30 23:52, [email protected] wrote:

I frequently use binary as bool placeholders and find myself filtering lists 
based on those bools, this seems to have a similar semantic meaning as the bit 
wise ^ or __xor__ operator and could add syntactic sugar to the base list class.

Use Case:

Controlling a stepper at half-step has the following cycle steps:

CYCLE = [
   [1,0,0,0],
   [1,1,0,0],
   [0,1,0,0],
   [0,1,1,0],
   [0,0,1,0],
   [0,0,1,1],
   [0,0,0,1],
   [1,0,0,1],
]

which can be represented as follows:

CYCLE = [
 1<<3,
 1<<3|1<<2,
 1<<2,
 1<<2|1<<1,
 1<<1,
 1<<1|1<<0,
 1<<0,
 1<<3|1<<0
]

or more cleanly:

CYCLE = [8, 12, 4, 6, 2, 3, 1, 9]


Or more clearly:

CYCLE = [
  0b1000,
  0b1100,
  0b0100,
  0b0110,
  0b0010,
  0b0011,
  0b0001,
  0b1001,
]


on a raspberrypi, using (for illustration's sake) GPIO pins 1,2,3,4 I'd like to 
use the __xor__ method (currently not implemented) to perform the bit-wise 
filter as follows:


Bit-masking is done with a bitwise AND, so I'd expect the __and__ method 
would be used. The __xor__ method would be for bit-toggling.




class MyList(list):
 def __init__(self, *args):
 super().__init__(args)
 
 def __xor__(self, num):

 return [self[i] for i in [-index-1 for index, i in 
enumerate(bin(num)[:1:-1]) if i !='0']][::-1]

PINS = MyList(1,2,3,4)

PINS ^ 8
# [1]

PINS ^ 12
# [1, 2]

PINS ^ 4
# [2]

PINS ^ 6
# [2, 3]

PINS ^ 2
# [3]

PINS ^ 3
# [3, 4]

PINS ^ 1
# [4]

PINS ^ 9
# [1, 4]

The need here isn't strictly pi/stepper related; I've run into this several 
times in the past when evaluating combinations * permutations of items where a 
bitwise filter would be useful.


Do you really need a class for this?

CYCLE = [
  0b1000,
  0b1100,
  0b0100,
  0b0110,
  0b0010,
  0b0011,
  0b0001,
  0b1001,
]

PINS = [1, 2, 3, 4]

def bit_filter(pins, bits):
return [pin for pin, bit in zip(PINS, format(bits, '04b')) if bit 
== '1']


bit_filter(PINS, 0b1000)
# [1]
bit_filter(PINS, 0b0100)
# [2]
bit_filter(PINS, 0b0110)
# [2, 3]
bit_filter(PINS, 0b0010)
# [3]
bit_filter(PINS, 0b0011)
# [3, 4]
bit_filter(PINS, 0b0001)
# [4]
bit_filter(PINS, 0b1001)
# [1, 4]
--
https://mail.python.org/mailman/listinfo/python-list


Re: Binary Sort on Python List __xor__

2020-05-30 Thread Evan Schalton
@MRAB,

Yes -- good point, it should be the __and__ operator.

do I need a new class? No, but based on this use case and other formatting 
techniques adding a filter method to the list class that takes in either bit 
mask or bool list would streamline a lot of code and not change any existing 
functionality
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Format Logfile Name with logging.ini

2020-05-30 Thread DL Neil via Python-list

On 30/05/20 4:52 AM, [email protected] wrote:

In an effort to clean up my python logging practices when creating libraries, I have 
begun reading into "Advanced Logging" and converting my logging practices into 
logging configuration `.ini` files:

[link](https://docs.python.org/3.4/howto/logging.html#configuring-logging)

My question is: When defining a FileHandler in a `.ini` file, all of the 
examples that I've seen hardcode the name and location of the log file. In the 
code snippet below, `python.log` is hardcoded into the `.ini` file:

```
[handler_hand02]
class=FileHandler
level=DEBUG
formatter=form02
args=('python.log', 'w')
```
[code reference 
link](https://docs.python.org/3.4/library/logging.config.html#logging-config-fileformat)

Desired Behavior:
On each run of the program, a new logfile is created in the `logs/` directory named 
"_program.log".

Current Behavior:
The format in the example above overwrites a single file called "python.log" on 
each run, which is not the desired behavior.

Question: Is there a standard procedure for using .ini files to create a new 
logfile prepended with the current Unix timestamp on each run of the program?



There is nothing in the PSL to do this (to my knowledge) - 
correction/education welcome...


However, it is a fairly standard pattern to take a base-name from a 
config file (.ini in MSFT wording) and then to post-process to suit the 
application's purposes.


In this case, adding a timestamp makes sense - although perhaps a more 
human-readable option unless file-name length is a concern.


The pattern is to:
Compute the (log) file-name.
Check to see if it name already exists (in this directory).
Re-compute if necessary - rinse-and-repeat.

Something like: Make unique file name 
https://code.activestate.com/recipes/577200-make-unique-file-name/

--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list