Re: int.to_bytes() for a single byte

2018-11-06 Thread jladasky
On Tuesday, November 6, 2018 at 7:19:09 PM UTC-8, Terry Reedy wrote:
> On 11/6/2018 9:30 PM, j...y@it.u wrote:
> 
> > b = i.to_bytes(1, "big")
> > 
> >Is there another function which provides a more logical interface to this 
> >straightforward task?
> 
> Yes
>  >>> 33 .to_bytes(1, 'big')
> b'!'
>  >>> bytes((33,))
> b'!'

Thanks Terry, that's what I was looking for.

I had tried using the bytes() constructor directly, and was getting a byte 
array of zeros, of the length specified by the integer.  That's in the 
documentation, and it might be useful, but I haven't seen an obvious use case, 
and it isn't what I wanted.  Wrapping the integer in a tuple solves the problem 
of it being interpreted as a length.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: int.to_bytes() for a single byte

2018-11-06 Thread Terry Reedy

On 11/6/2018 9:30 PM, jlada...@itu.edu wrote:


b = i.to_bytes(1, "big")

Is there another function which provides a more logical interface to this 
straightforward task?


Yes
>>> 33 .to_bytes(1, 'big')
b'!'
>>> bytes((33,))
b'!'

See >>> bytes(   # in IDLE or >>> help(bytes)


--
Terry Jan Reedy

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


Re: int.to_bytes() for a single byte

2018-11-06 Thread bob gailer

On 11/6/2018 9:30 PM, jlada...@itu.edu wrote:

I'm using Python 3.6.  I have a need to convert several small integers into 
single bytes.  As far as I can tell from reading through the Python docs, the 
correct way to accomplish this task is:

b = i.to_bytes(1, "big")

This seems to work, but I find it cumbersome.  I have to supply the byteorder argument to prevent a 
TypeError.  However, byte order doesn't matter if I'm only generating a single byte.  Whether I 
choose "big" or "little" I should get the same result.  Is there another 
function which provides a more logical interface to this straightforward task?

Take a look at the struct module.

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


int.to_bytes() for a single byte

2018-11-06 Thread jladasky
I'm using Python 3.6.  I have a need to convert several small integers into 
single bytes.  As far as I can tell from reading through the Python docs, the 
correct way to accomplish this task is:

b = i.to_bytes(1, "big")

This seems to work, but I find it cumbersome.  I have to supply the byteorder 
argument to prevent a TypeError.  However, byte order doesn't matter if I'm 
only generating a single byte.  Whether I choose "big" or "little" I should get 
the same result.  Is there another function which provides a more logical 
interface to this straightforward task?

Thanks for any suggestions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Asyncio tasks getting cancelled

2018-11-06 Thread Ian Kelly
On Tue, Nov 6, 2018 at 3:39 PM Ian Kelly  wrote:
>
> n Mon, Nov 5, 2018 at 8:43 PM  wrote:
> > What I meant was, the error message is specific to futures in the
> > 'PENDING' state. Which should be set to 'RUNNING' before any actions
> > occur. So it appears the tasks weren't started at all.
>
> Ah. I don't think asyncio uses a RUNNING state. There's nothing about
> it in the docs; tasks are either done or they're not:
> https://docs.python.org/3/library/asyncio-task.html#task-object
>
> And inspecting the current task also shows PENDING:
>
> py> from asyncio import *
> py> async def main():
> ...   print(current_task()._state)
> ...
> py> run(main())
> PENDING

Looks like the only states are PENDING, CANCELLED, and FINISHED:
https://github.com/python/cpython/blob/3.7/Lib/asyncio/base_futures.py#L17
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Asyncio tasks getting cancelled

2018-11-06 Thread Ian Kelly
n Mon, Nov 5, 2018 at 8:43 PM  wrote:
>
> On Mon, Nov 05, 2018 at 07:15:04PM -0700, Ian Kelly wrote:
> > > For context:
> > > https://github.com/ldo/dbussy/issues/13
> > > https://gist.github.com/tu500/3232fe03bd1d85b1529c558f920b8e43
> > >
> > > It really feels like asyncio is loosing strong references to scheduled
> > > tasks, as excplicitly keeping them around helps. Also, the error
> > > messages I'm getting are the ones from here:
> > > https://github.com/python/cpython/blob/16c8a53490a22bd4fcde2efaf4694dd06ded882b/Lib/asyncio/tasks.py#L145
> > > Which indicates that the tasks actually weren't even started at all?
> >
> > No, it indicates that it was cleaned up (likely because the program
> > exited) before the task completed. Which likely implies that the loop
> > exited without waiting for it. From the stack trace, you're using
> > loop.run_until_complete(main()). Like asyncio.run, that only runs
> > until the specific thing you pass it completes, which might wait on
> > other things or might not. Anything else that's still pending is going
> > to be left up in the air unless you subsequently restart the same
> > event loop.
>
> What I meant was, the error message is specific to futures in the
> 'PENDING' state. Which should be set to 'RUNNING' before any actions
> occur. So it appears the tasks weren't started at all.

Ah. I don't think asyncio uses a RUNNING state. There's nothing about
it in the docs; tasks are either done or they're not:
https://docs.python.org/3/library/asyncio-task.html#task-object

And inspecting the current task also shows PENDING:

py> from asyncio import *
py> async def main():
...   print(current_task()._state)
...
py> run(main())
PENDING

> Also the cleanup happens instantly, ie before the loop exits (as the
> main loop has an asyncio.sleep timeout. Printing a message also clearly
> shows this happens way before main returns.

Okay, that wasn't clear from the log you posted. It's not obvious to
me why that would be happening. although it does sound like the tasks
are getting created and then immediately garbage-collected for some
reason. It could be a bug in asyncio, or it could be a bug in the way
the tasks are created, e.g. on a separate event loop that gets dropped
on the floor.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Overwhelmed by the Simplicity of Python. Any Recommendation?

2018-11-06 Thread Lie Ryan
> I like to step through my code line by line,
> it's impossible to do it with
> object-oriented programming language.

I suggest pudb, it's a curses based debugger, which is nicer than pdb, but 
doesn't require tedious IDE setup.

> Also, there's no good REPL IDE. 

Not quite sure what you meant by REPL IDE, but did you try IPython
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: 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-06 Thread Rhodri James

On 06/11/2018 18:10, srinivasan wrote:

root:~/qa/test_library# python3 sd.py
   File "sd.py", line 99
*cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
* ^*
*SyntaxError: can't assign to literal*


Look at the 'cut' element of the pipeline.  You have used double quotes 
in a double quoted string without escaping them.  As a result, the 
interpreter thinks you are trying to assign the string literal " -f3" to 
the string literal "blkid -o export %s | grep 'Type' | cut -d"


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


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-06 Thread srinivasan
Dear Python Experts Team,

As am newbie to python development, I am trying to use the below function
to get verify the filesystem type of the SD card parition using bash
command in python using subprocess module, I ma seeing the below Error
"SyntaxError: can't assign to literal"

*CODE:*
**

import helper
from os import path
import subprocess
import os
import otg_ni


class emmc(object):
"""
emmc getters and setters
info:
https://www.kernel.org/doc/Documentation/cpu-freq/user-guide.txt
"""

def __init__(self):
self._helper = helper.helper()
self._otg_ni = otg_ni.otg_ni()


*def get_fstype_of_mounted_partition(self, fs):*
"""
Get the filesystem type of the mounted partition.

:partition_name : Partition path as string (e.g. /dev/mmcblk0p1)
:return: filesystem type as string or None if not found
"""

*cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
*return self._helper.execute_cmd_output_string(cmd)*



*def execute_cmd_output_string(self, cmd, enable_shell=False):*
"""
Execute a command and return its output as a string.

:param cmd: abs path of the command with arguments
:param enable_shell : force the cmd to be run as shell script
:return: a string.
"""

try:
result = subprocess.check_output(split(cmd),
 stderr=subprocess.STDOUT,
 shell=enable_shell)

except subprocess.CalledProcessError as e:
s = """While executing '{}' something went wrong.
Return code == '{}'
Return output:\n'{}'
""".format(cmd, e.returncode, e.output, shell=enable_shell)
raise AssertionError(s)

return result.strip().decode("utf-8")
*if __name__ == "__main__":*
m = emmc()
*m.get_fstype_of_mounted_partition("/dev/mmcblk0p1")*
*Error:*
*==*

root:~/qa/test_library# python3 sd.py
  File "sd.py", line 99
*cmd = "blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)*
* ^*
*SyntaxError: can't assign to literal*
root:~/qa/test_library#

Kindly do the needful as early as possible, as am stuck with this issue
from past 2 days no clues yet, please redirect me to the correct forum if
this is not the right place for pasting python related queries

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


Re: Unable to remove python from my computer.

2018-11-06 Thread Rhodri James

On 06/11/2018 09:25, Thomas Jollans wrote:

On 2018-11-06 10:05, Varshit Jain wrote:

Hi Python Support Team,


I just want to remove python 3.6.6 from my computer. I am unable to do
it. Please find attached video that describe my problem.


Use your words, friend!

(this list is text-only)


More exactly, I'm afraid the mailing list has stripped off the video you 
attached, so we can't watch it.  I'm afraid I wouldn't in any case; I 
learned long ago not to open attachments from people I don't already know.


Could you please describe to us your problem?  Are you using Windows, 
Linux, Mac or something else?  Copy any error messages the uninstaller 
might have given you, preferably cutting and pasting rather than just 
retyping them (it's easy to mistype something critical!).  Please don't 
send us screen shots, those will just get stripped off by the mailing 
list as well.


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


Re: Unable to remove python from my computer.

2018-11-06 Thread Thomas Jollans
On 2018-11-06 10:05, Varshit Jain wrote:
> Hi Python Support Team,
> 
> 
> I just want to remove python 3.6.6 from my computer. I am unable to do
> it. Please find attached video that describe my problem. 

Use your words, friend!

(this list is text-only)
-- 
https://mail.python.org/mailman/listinfo/python-list


Unable to remove python from my computer.

2018-11-06 Thread Varshit Jain

Hi Python Support Team,


I just want to remove python 3.6.6 from my computer. I am unable to do 
it. Please find attached video that describe my problem. Suggest me 
solution / Steps to remove python from my PC.



Regards,
Varshit Jain

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