OT language barrier, was: How execute at least two python files at once when imported?

2019-11-07 Thread Christian Gollwitzer

Am 06.11.19 um 17:34 schrieb Igor Korot:

On Wed, Nov 6, 2019 at 10:22 AM Spencer Du  wrote:



Sorry if I haven't stated my requirements clearly.

I just wanted a way to import at least two python files in parallel and I 
wanted to know how this can be done or a reason why its bad as stated in 
another post.


This is not a requirements.

Let me rephrase my question - what problem are you trying to solve?

Also, as I said before - I believe there is a language barrier.

Find some python forum in your native language and ask your question there.



Off topic, but how do you conclude that the OP is a non-native English 
speaker or has inferior command of the English language? He sounds very 
English to me, and the name and email address also do not indicate 
non-English origin to me?


My impression was that there IS a language barrier for technical terms, 
but not with English per se - he used the word "import" incorrectly, 
when he meant "run", because he abused "import lala" to run a Python 
program.


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


Re: psutil.boot_time() ... doesn't ?

2019-11-07 Thread R.Wieser
Dennis,

> Which is probably... last file system modification time

Nope.  Its from a file it saves at shutdown, and which gets updated once an 
hour (I also thought of that one, but the once-an-hour update threw a wrench 
into it).

> There is no way for a freshly booted system to differentiate between
[snip]

True.   But
1) thats not likely the moment I will be looking at the "has the time been 
updated"
2) The same goes for having NTP (or any other such "wait for it ..." method) 
update the clock.

> Except that "last boot time" is really "booted /n/ minutes ago
> from /now/".

Than thats the point where we disagree.   Boot time is not just a gadget for 
the user to look and gawk at, it has (or /should/ have) its usages.   Like 
allowing someone to determine which files have been altered since last boot.

Besides, all you now get is uptime, just presented differently.  :-(

> http://man7.org/linux/man-pages/man5/crontab.5.html#EXTENSIONS
>
> The main concern is just how soon after reboot that @reboot executes.

Yup.  And in which order the different programs and scripts are ran 

> https://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/
> has an example with a sleep...

Thanks for those links.  I'll have a look at them.

Regards,
Rudy Wieser


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


Re: SSL/TLS in Python using STARTTLS and ssl/ssltelnet and telnetlib

2019-11-07 Thread Colin McPhail via Python-list



> On 7 Nov 2019, at 03:24, Veek M  wrote:
> 
> Could someone suggest some introductory reading material that will allow 
> me to use 'telnetlib' with 'ssl' or 'ssltelnet'. 
> (currently using Pan since Knode is dropped on Debian)
> 
> I'm trying to write something that will download the NNTP headers over 
> TLS.
> 
> The idea is to 
> 1. telnet to port 119, send 'CAPABILITIES\r\n' using telnetlib
> 2. then switch to TLS using STARTTLS
> 3. I tried just connecting to port 119 using a new TLS connection NOT 
> OVER telnet and it didn't work. Apparently you need to pass the TLS 
> context to telnetlib or vice versa.
> ...

Any reason you're not using nntplib from the Python Standard Library? It 
supports the  STARTTLS command.

If you don't want to use nntplib you could look at its code to see how it works.

-- Colin

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


Re: SSL/TLS in Python using STARTTLS and ssl/ssltelnet and telnetlib

2019-11-07 Thread Jon Ribbens via Python-list
On 2019-11-07, Veek M  wrote:
> Could someone suggest some introductory reading material that will allow 
> me to use 'telnetlib' with 'ssl' or 'ssltelnet'. 
> (currently using Pan since Knode is dropped on Debian)
>
> I'm trying to write something that will download the NNTP headers over 
> TLS.

As someone else has pointed out, nntplib would be the obvious choice
for this. But even if you don't want to use that, you absolutely
should not be using telnetlib. NNTP is not Telnet and there is no
connection between the two protocols. (Don't get misled by the common
practice of using the command-line telnet client as a convenient way
for connecting to line-based TCP services for testing purposes.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How execute at least two python files at once when imported?

2019-11-07 Thread Gregory Ewing

Cameron Simpson wrote:
Spencer's modules run unconditional stuff in addition to defining 
classes. That may cause trouble.


It will -- because of the import lock, they won't run simultaneously
in the same process.

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


Re: OOP - how to abort an __init__ when the initialisation code fails ?

2019-11-07 Thread Gregory Ewing

Oscar Benjamin wrote:

In Python the original exception message plus traceback is often very
informative (to a programmer!) about the problem.


That's okay, exception chaining preserves the whole traceback if
you want to dig down that far.


Catching and
reraising can mean that you end up crafting an error message somewhere
higher up where the filename isn't known any more.


Well, the idea is to catch it some place where the filename *is*
known. And when reraising, only add to the error message rather
than replacing it altogether, so once the filename is in there
it stays there, even if another catch-and-reraise occurs higher
up.

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


Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread Stephen Waldron
Hi, I'm new to the group and to Python, so forgive me if I make any faux-pas 
here. As I can tell, the only way to pass a function as an argument is to 
reference its name as follows:

def foo1(message):
print(message)

def foo2(foo, message):
print("Your function says:")
foo(message)


>>foo2(foo1, "Hello World!")
Your function says:
Hello World!


This is how it is at the moment, however it may be more agreeable, especially 
if that is the only purpose of the function, for python users to be able to 
define new functions inside of function calls. The way I propose this may occur 
is using similar syntax as control structures, as exampled below:

def foo2(foo):
print("Message to print:", end = " ")
foo()


>>foo2():
print("Hello World!")

Message to print: Hello World!


In this proposal, it should be noted, that unlike control structures, the 
brackets are required for the function call. The "suite" or "annex" is defined 
as a function object by the compiler and passed inside the call. Here are some 
other examples of the proposal.



*Non-Function Arguments with Annexed Functions*
Non-Function Arguments should be placed in the brackets before annexed 
functions, and this should be reflected in the parameter order. If they are 
not, they won't be assigned to, which would cause an error unless a default 
value is given. These parameters could be available for passing in the annexed 
function if mentioned when the paramaeter is called.

def myFoo (num1, num2, foo):
return foo (num1, num2)


>>myFoo(20, 30):
return num1 + num2

50


*Annexing Multiple Functions or Out of Order Annex*
To specify the order in which functions are annexed, or annex multiple 
functions, one could use the parameter name before the specific suite.

class Book:
def __init__(self, name, author):
self.name = name
self.author = author


def doToBooks (bookList, first, then, book = None):

for book in bookList
first(book = book)
then(book = book)

myBooks = [
Book("The Way of the World", "Lucy Cole"),
Book("To Live or To Love", "Georgio Dunham"),
Book("Twelve Days of Success", "Anita Duvette")
]

doToBooks (myBooks):
print(book.name)
then:
print(" - " + book.author + "\n")



>
The Way of The World
 - Lucy Cole

To Live or To Die
 - Georgio Dunham

Twelve Days of Success
 - Anita Duvette



This proposal does not detract from the core appearance and appeal of Python 
while creating an option for users and module makers who want themselves or the 
users of their modules not to have to previously define functions in order to 
use the code. This would make such code more aesthetic and compact, and take 
away the need for defining a new function, name and all, specifically for such 
which ultimately would be used only once as an argument. 
   
-- 
https://mail.python.org/mailman/listinfo/python-list


Python 3.8 install

2019-11-07 Thread Daniel

How to install Python 3.8 on top of Python 3.6?

--
Este email foi escaneado pelo Avast antivírus.
https://www.avast.com/antivirus

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


Re: psutil.boot_time() ... doesn't ?

2019-11-07 Thread R.Wieser
Chris,

> Yes, but even if it's not recorded as a timestamp but as an
> uptime counter, that counter can be referenced against the
> current time in UTC.

Absolutily.   Though the keyword here is "can".  My "could easily imagine"
considers the other possibility.

I guess I should sit down sometime and just flip the date back and forward
(in-and-outof DST), and see how the result of psutil.boot_time() compares to
the thanwhile current time.

Regards,
Rudy Wieser


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


Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread Antoon Pardon
On 7/11/19 14:36, Stephen Waldron wrote:
> Hi, I'm new to the group and to Python, so forgive me if I make any faux-pas 
> here. As I can tell, the only way to pass a function as an argument is to 
> reference its name as follows:
>
> def foo1(message):
> print(message)
>
> def foo2(foo, message):
> print("Your function says:")
> foo(message)

No that is not true. "map" is a function that takes a function as its
first argument. But I can do the following if I want to produce the
inverses of a list of numbers.

from operator import truediv
from functools import partial

ls = range(1, 11)

for x in map(partial(truediv, 1), ls):
print(x)

In the code above "partial(truediv, 1)" will produce a function that
will inverse its argument and I don't need to give this function a name
to pass it as an argument in an other function.

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


Re: SSL/TLS in Python using STARTTLS and ssl/ssltelnet and telnetlib

2019-11-07 Thread Grant Edwards
On 2019-11-07, Jon Ribbens via Python-list  wrote:
> On 2019-11-07, Veek M  wrote:
>> Could someone suggest some introductory reading material that will allow 
>> me to use 'telnetlib' with 'ssl' or 'ssltelnet'. 
>> (currently using Pan since Knode is dropped on Debian)
>>
>> I'm trying to write something that will download the NNTP headers
>> over TLS.
>
> As someone else has pointed out, nntplib would be the obvious choice
> for this. But even if you don't want to use that, you absolutely
> should not be using telnetlib. NNTP is not Telnet and there is no
> connection between the two protocols. (Don't get misled by the common
> practice of using the command-line telnet client as a convenient way
> for connecting to line-based TCP services for testing purposes.)

IIRC, the reason that you could test stuff like NNTP servers using the
old Unix telnet client is because that client defaults to disabling
all of the actual TELNET protocol and handshaking support when
connected to a port other than 23.

-- 
Grant Edwards   grant.b.edwardsYow! PARDON me, am I
  at   speaking ENGLISH?
  gmail.com

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


Re: return a ctypes object to C

2019-11-07 Thread Arnaud Loonstra

On 31-10-2019 15:39, Arnaud Loonstra wrote:

On 31-10-2019 14:44, Thomas Jollans wrote:

On 31/10/2019 14.13, Arnaud Loonstra wrote:

On 30-10-2019 09:32, Arnaud Loonstra wrote:

Hi all,

I'm trying to wrap my head around the ctypes API. I have a C
structure I wish to create in Python and then return from python to C.

So a python method is called from C and needs to return an object
which we then process in C again.

I have a binding to access and create the C methods and structures so
in Python I can call the Zmsg() constructor. I now need to return this.

My python test method is simply:

def actor_test( *args, **kwargs):
  print("test")
  msg = Zmsg()
  frame = Zframe(b"Hello", 5)
  msg.prepend(frame)
  return msg

the method is called from C as follows:

PyObject *pReturn = PyObject_CallObject(pFunc, NULL);

This correctly calls the method. However the returned object is of
course a PyObject*. The debugger says it's

""    PyObject
  [class]    ""
  [super class]    ""
  [meta type]    ""
  ob_refcnt    1    Py_ssize_t

However how I can I get it back to the original C type (zmsg_t *)

Any help really appreciated.



What I've found so far is that I can return the address of the ctypes
object.

msg = Zmsg()
frame = Zframe(b"Hello", 5)
msg.prepend(frame)
return addressof(msg._as_parameter_.contents)

In C I can then cast it back to the original type.

PyObject *pReturn = PyObject_CallObject(pFunc, NULL);
assert(pReturn);
long bla = PyLong_AsLong(pReturn);
zmsg_t* test = (zmsg_t *)bla;
assert(test);
char *hello = zmsg_popstr(test);
assert(hello);
assert(streq(hello, "Hello"));

This works, I'm not sure if this is the right way. It also creates a
complicated setup with the garbage collector.

Anybody better ideas?


You've already got a complicated setup with your ctypes objects...

If you're using the Python C API anyway, why would you use ctypes at
all? You can create custom Python types in C to wrap your C pointers.

Alternatively: if you're using ctypes anyway, why use the Python C API
at all? You can create C function pointers from Python functions with
ctypes.

If you're mixing two different ways of interfacing Python and C, the
result will ALWAYS be messy. Better to stick to one. Personally, I
prefer cffi or cython depending on the situation, as I find them clearer
and easier to use than ctypes. Using the Python C API directly is
usually the hardest to understand and the easiest to get wrong.

-- Thomas


Hi Thomas,

I have an engine running which can call handlers. These handlers return 
a zmsg_t (a message) which the engine then can process.


In this engine we have Python embedded and I want to use a Python method 
as a handler. To embed Python we need to use the Python C API. To 
construct a zmsg_t type in Python we need to call the corresponding C 
method and we use ctypes to do that.


I'm using a ctypes binding because it already exists, it's here: 
https://github.com/zeromq/czmq/blob/d6283985ba52fd8c3f8fbdc7cd5c08372ff69ca1/bindings/python/czmq/_czmq_ctypes.py#L4392 



I know I can use cffi for example but that's IMHO just a ctypes 
alternative.


Are you saying it's better to create some approach to create a zmsg_t 
using the Python C API?


Please enlighten me if this should be done differently.

Rg,

Arnaud


Ok, you're reply triggered me to do some more reading into the C-API. 
I've found I can do it all using the C-API. Especially this guide was 
very helpful for my situation:


https://docs.python.org/3/extending/newtypes_tutorial.html

Thnx,

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


Re: Python 3.8 install

2019-11-07 Thread MRAB

On 2019-11-07 13:52, Daniel wrote:

How to install Python 3.8 on top of Python 3.6?


Don't do that.

If you're using Windows, you install into a separate folder, usually 
called Python36 for Python 3.6 and Python38 for Python 3.8.

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


Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread Stephen Waldron
Thanks Antoon. I do suppose that it is kind of wrong to say the only way is to 
"reference its [the function's] name" as an argument, however the point I was 
trying to make was that you cannot pass a function that is either not in some 
way previously defined or a reference to something previously defined.

In your example, you still make reference to the existing function `truediv` 
from the `operator` library, even though the `partial` function does create a 
new function.

What I'm aiming for is the ability to, within a function call, pass a suite 
that would be there automatically defined by the compiler/interpreter. Another 
comment did mention lambda functions, which does to some degree provide that 
capability, but is restricted to well, lambda functions (only expressions, not 
statements).

Your example does however suggest the possibilities of a function or expression 
that creates functions. For example, the `function` expression in JavaScript.

```
//Definition
function myFoo (str1, str2, foo){
console.log( foo(str1), foo(str2) );
}


//Call
myFoo ("hello", "world!", function(str){

str[0] = str[0].toUpper();
return str;

});


Output:
Hello World!
```

However it does not seem that there would be any such expression in Python as 
is. In python, this code would be written:


```
#Definition
def myFoo (str1, str2, foo):
print( foo(str1), foo(str2) )


#Call
def other_foo(str):
str = list(str)[0].upper() + str[1:]
return str

myFoo ("hello", "world!", other_foo)

```


Here is it rewritten using the proposal:
```
#Definition
def myFoo (str1, str2, foo, str = " "):
print( foo(str = str1), foo(str = str2) )


#Call
myFoo ("hello", "world!"):
str = list(str)[0].upper() + str[1:]
return str

```

Of course this example presents only a minor, though you can see the difference 
in the call, in which no new function needs be referenced.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread Stephen Waldron
Thanks Antoon. I do suppose that it is kind of wrong to say the only way is to 
"reference its [the function's] name" as an argument, however the point I was 
trying to make was that it isn't possible to pass a function that is either not 
in some way previously defined or a reference to something previously defined.

In your example, you still make reference to the existing function `truediv` 
from the `operator` library, even though the `partial` function does create a 
new function.

What I'm aiming for is the ability to, within a function call, pass a suite 
that would be there automatically defined by the compiler/interpreter. Another 
comment did mention lambda functions, which does to some degree provide that 
capability, but is restricted to well, lambda functions (only expressions, not 
statements).

Your example does however suggest the possibilities of a function or expression 
that creates functions. For example, the `function` expression in JavaScript.

```
//Definition
function myFoo (str1, str2, foo){
console.log( foo(str1), foo(str2) );
}


//Call
myFoo ("hello", "world!", function(str){

str[0] = str[0].toUpper();
return str;

});


Output:
Hello World!
```

However it does not seem that there would be any such expression in Python as 
is. In python, this code would be written:


```
#Definition
def myFoo (str1, str2, foo):
print( foo(str1), foo(str2) )


#Call
def other_foo(str):
str = list(str)[0].upper() + str[1:]
return str

myFoo ("hello", "world!", other_foo)

```


Here is it rewritten using the proposal:
```
#Definition
def myFoo (str1, str2, foo, str = " "):
print( foo(str = str1), foo(str = str2) )


#Call
myFoo ("hello", "world!"):
str = list(str)[0].upper() + str[1:]
return str

```

Of course this example presents only a minor, though you can see the difference 
in the call, in which no new function needs be referenced.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python 3.8 install

2019-11-07 Thread Terry Reedy

On 11/7/2019 11:59 AM, MRAB wrote:

On 2019-11-07 13:52, Daniel wrote:

How to install Python 3.8 on top of Python 3.6?


Don't do that.

If you're using Windows, you install into a separate folder, usually 
called Python36 for Python 3.6 and Python38 for Python 3.8.


Both the Windows and macOS installers put each version in separate 
directories by default.  On Windows, I change the patch to my Python 
directory but leave the final directory name, Pythonxy, alone.  On 
macOS, I don't touch the path.


--
Terry Jan Reedy

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


RE: Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread David Raymond
Here is it rewritten using the proposal:
```
#Definition
def myFoo (str1, str2, foo, str = " "):
print( foo(str = str1), foo(str = str2) )


#Call
myFoo ("hello", "world!"):
str = list(str)[0].upper() + str[1:]
return str
```

Are you looking for multi-line lambdas?
Isn't this basically just defining a function... but without an argument list? 
How would that know what "str" is?

Since you can already define functions inside of functions, what functionality 
does this give you that you can't already do with something like this:

def myFoo(str1, str2, foo):
print(foo(str1), foo(str2))

def main():
print("Stuff here")

def f1(str):
str = list(str)[0].upper() + str[1:]
return str
myFoo("hello", "world", f1)

def f1(str): #yup, same name
str = str[:-1] + list(str)[-1].upper()
return str
myFoo("hello", "world", f1)

del f1

print("More stuff")

main()


Which results in:
Stuff here
Hello World
hellO worlD
More stuff

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


Re: psutil.boot_time() ... doesn't ?

2019-11-07 Thread Chris Angelico
On Fri, Nov 8, 2019 at 1:24 AM R.Wieser  wrote:
>
> Chris,
>
> > Yes, but even if it's not recorded as a timestamp but as an
> > uptime counter, that counter can be referenced against the
> > current time in UTC.
>
> Absolutily.   Though the keyword here is "can".  My "could easily imagine"
> considers the other possibility.
>
> I guess I should sit down sometime and just flip the date back and forward
> (in-and-outof DST), and see how the result of psutil.boot_time() compares to
> the thanwhile current time.
>

Yep! Nothing like experimentation! :)

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


can't install http module

2019-11-07 Thread tony van der Hoff

Hi,
I'm attempting to install (among other things) the "http" module on my 
debian10 box, and am encountering the following problem:


##
tony@tony-lx:~/_pycharm/pygallery$ python3 -m pip install http

Collecting http
   Using cached 
https://files.pythonhosted.org/packages/e3/91/a9260805e532e33df273b8f7dffad5c51693f8f9ba5f86bedcf42a7f22eb/http-0.02.tar.gz

     Complete output from command python setup.py egg_info:
     Traceback (most recent call last):
   File "", line 1, in 
   File "/tmp/pip-install-fr02g_f6/http/setup.py", line 3, in 
     import http
   File "/tmp/pip-install-fr02g_f6/http/http/__init__.py", line 17, 
in 

     from request import Request
     ModuleNotFoundError: No module named 'request'

     
Command "python setup.py egg_info" failed with error code 1 in 
/tmp/pip-install-fr02g_f6/http/


##
So, I tried installing "request":

##

tony@tony-lx:~/_pycharm/pygallery$ python3 -m pip install request
Collecting request
   Downloading 
https://files.pythonhosted.org/packages/f1/27/7cbde262d854aedf217061a97020d66a63163c5c04e0ec02ff98c5d8f44e/request-2019.4.13.tar.gz

Collecting get (from request)
   Downloading 
https://files.pythonhosted.org/packages/3f/ef/bb46f77f7220ac1b7edba0c76d810c89fddb24ddd8c08f337b9b4a618db7/get-2019.4.13.tar.gz

Collecting post (from request)
   Downloading 
https://files.pythonhosted.org/packages/0f/05/bd79da5849ea6a92485ed7029ef97b1b75e55c26bc0ed3a7ec769af666f3/post-2019.4.13.tar.gz
Requirement already satisfied: setuptools in 
/usr/lib/python3/dist-packages (from request) (40.8.0)

Collecting query_string (from get->request)
   Downloading 
https://files.pythonhosted.org/packages/12/3c/412a45daf5bea9b1d06d7de41787ec4168001dfa418db7ec8723356b119f/query-string-2019.4.13.tar.gz

Collecting public (from query_string->get->request)
   Downloading 
https://files.pythonhosted.org/packages/54/4d/b40004cc6c07665e48af22cfe1e631f219bf4282e15fa76a5b6364f6885c/public-2019.4.13.tar.gz
Building wheels for collected packages: request, get, post, 
query-string, public

   Running setup.py bdist_wheel for request ... done
   Stored in directory: 
/home/tony/.cache/pip/wheels/30/84/5f/484cfba678967ef58c16fce6890925d5c7172622f20111fbfd

   Running setup.py bdist_wheel for get ... done
   Stored in directory: 
/home/tony/.cache/pip/wheels/c1/e3/c1/d02c8c58538853e4c9b78cadb74f6d5c5c370b48a69a7271aa

   Running setup.py bdist_wheel for post ... done
   Stored in directory: 
/home/tony/.cache/pip/wheels/c3/c3/24/b5c132b537ab380c02d69e6bd4dec1f5db56b5fe19030473d7

   Running setup.py bdist_wheel for query-string ... done
   Stored in directory: 
/home/tony/.cache/pip/wheels/d6/a4/78/01b20a9dc224dcc009fab669f7f27b943b8889c5150bd68d8a

   Running setup.py bdist_wheel for public ... done
   Stored in directory: 
/home/tony/.cache/pip/wheels/23/7c/6e/f5b4e09d6596c8b8802b347e48f149031e2363368048f1347a

Successfully built request get post query-string public
Installing collected packages: public, query-string, get, post, request
Successfully installed get-2019.4.13 post-2019.4.13 public-2019.4.13 
query-string-2019.4.13 request-2019.4.13

##
So far, so good; retry http:

##

tony@tony-lx:~/_pycharm/pygallery$ python3 -m pip install http
Collecting http
   Using cached 
https://files.pythonhosted.org/packages/e3/91/a9260805e532e33df273b8f7dffad5c51693f8f9ba5f86bedcf42a7f22eb/http-0.02.tar.gz

     Complete output from command python setup.py egg_info:
     Traceback (most recent call last):
   File "", line 1, in 
   File "/tmp/pip-install-zwguez5m/http/setup.py", line 3, in 
     import http
   File "/tmp/pip-install-zwguez5m/http/http/__init__.py", line 17, 
in 

     from request import Request
     ImportError: cannot import name 'Request' from 'request' 
(/home/tony/.local/lib/python3.7/site-packages/request/__init__.py)


     
Command "python setup.py egg_info" failed with error code 1 in 
/tmp/pip-install-zwguez5m/http/


##
So now I seem to have broken it. I'm not very savvy with the python 
packaging system, so perhaps someone here can help me as a numpty.

Thanks in advance.


-- Tony van der Hoff | mailto:t...@vanderhoff.org Buckinghamshire, England |
--
https://mail.python.org/mailman/listinfo/python-list


Re: can't install http module

2019-11-07 Thread Chris Angelico
On Fri, Nov 8, 2019 at 5:47 AM tony van der Hoff  wrote:
>
> Hi,
> I'm attempting to install (among other things) the "http" module on my
> debian10 box, and am encountering the following problem:
>

Can you link to the documentation for the package you're trying to
install? Python already ships with a module called "http". You don't
need to install it.

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


Using Makefiles in Python projects

2019-11-07 Thread Vitaly Potyarkin
What do you think of using Makefiles for automating common chores in
Python projects? Like linting, type checking and testing?

I've come up with a reusable Makefile for automating virtual environment
management in Python projects. I think it can be useful for simplifying
the onboarding of new developers (both new to project and new to Python)
and for documenting project's development practices.

Here it is:
- Repo: https://github.com/sio/Makefile.venv
- Demo screencast: https://asciinema.org/a/279646

What do you think? Is this useful or I'm just unaware of some tool that
abstracts venv chores away better?

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


Re: can't install http module

2019-11-07 Thread Tony van der Hoff




On 07/11/2019 19:00, Chris Angelico wrote:

On Fri, Nov 8, 2019 at 5:47 AM tony van der Hoff  wrote:


Hi,
I'm attempting to install (among other things) the "http" module on my
debian10 box, and am encountering the following problem:



Can you link to the documentation for the package you're trying to
install? Python already ships with a module called "http". You don't
need to install it.

Thanks Chris, but it doesn't seem to be installed here, but maybe I'm 
doing something stupid:


#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import cgi
import logging
from http import cookies


[Thu Nov 07 17:29:24.002303 2019] [cgi:error] [pid 30937] [client 
127.0.0.1:41912] AH01215: Traceback (most recent call last):: 
/home/tony/public_html/private/pygallery/pygallery.py
[Thu Nov 07 17:29:24.002455 2019] [cgi:error] [pid 30937] [client 
127.0.0.1:41912] AH01215:   File 
"/home/tony/public_html/private/pygallery/pygallery.py", line 6, in 
: /home/tony/public_html/private/pygallery/pygallery.py
[Thu Nov 07 17:29:24.002480 2019] [cgi:error] [pid 30937] [client 
127.0.0.1:41912] AH01215: from http import cookies: 
/home/tony/public_html/private/pygallery/pygallery.py
[Thu Nov 07 17:29:24.002502 2019] [cgi:error] [pid 30937] [client 
127.0.0.1:41912] AH01215: ImportError: No module named http: 
/home/tony/public_html/private/pygallery/pygallery.py


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


Re: can't install http module

2019-11-07 Thread Chris Angelico
On Fri, Nov 8, 2019 at 6:34 AM Tony van der Hoff  wrote:
>
>
>
> On 07/11/2019 19:00, Chris Angelico wrote:
> > On Fri, Nov 8, 2019 at 5:47 AM tony van der Hoff  
> > wrote:
> >>
> >> Hi,
> >> I'm attempting to install (among other things) the "http" module on my
> >> debian10 box, and am encountering the following problem:
> >>
> >
> > Can you link to the documentation for the package you're trying to
> > install? Python already ships with a module called "http". You don't
> > need to install it.
> >
> Thanks Chris, but it doesn't seem to be installed here, but maybe I'm
> doing something stupid:
>
> #!/usr/bin/env python
> # -*- coding: UTF-8 -*-
>

Ah. I wouldn't call this "something stupid", because this is a bit of
a gotcha, but there is a small problem here. In your original post,
you attempted to install using "python3 -m pip", but here your shebang
just says "python", so you're running it in Python 2.7. Replace the
shebang with "python3" (and then drop the coding cookie - Python 3
assumes UTF-8 by default) and you should be able to run your code. (At
least the import lines you posted. No idea about anything else.)

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


Can't run easy_install even though setuptools is installed

2019-11-07 Thread Chris Green
I'm a bit flummoxed.

I'm trying to install a Python package from pypi.org, it says it
should be installed by running "easy_install onkyo-eiscp" but I just
get "easy_install:  command not found" when I try that.  I do have
setuptools installed on my system and I can see "easy_install.py" in
the package installation area.

This is on an xubuntu 19.04 Linux system.

So what is wrong?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Can't run easy_install even though setuptools is installed

2019-11-07 Thread Cameron Simpson

On 07Nov2019 21:38, Chris Green  wrote:

I'm a bit flummoxed.

I'm trying to install a Python package from pypi.org, it says it
should be installed by running "easy_install onkyo-eiscp" but I just
get "easy_install:  command not found" when I try that.  I do have
setuptools installed on my system and I can see "easy_install.py" in
the package installation area.

This is on an xubuntu 19.04 Linux system.

So what is wrong?


Have you tried this?

   pip install onkyo-eiscp

Using the pip associated with your intended Python executable. "python 
-m pip" should also work, where "python" is the python you're intending 
to use it with.


Thus (using pip, the command line flavour of the module, should be 
preinstalled with Python 2 >=2.7.9 or Python 3 >=3.4):


   [~]fleet*> pip install onkyo-eiscp
   Collecting onkyo-eiscp
 Downloading 
   https://files.pythonhosted.org/packages/05/7b/a25440e34d015237d1f68b8e353f06eaa3a90c1fa77a6621e5e15e4388de/onkyo-eiscp-1.2.7.tar.gz 
   (48kB)

|| 51kB 864kB/s
   Collecting docopt>=0.4.1
 Downloading 
   https://files.pythonhosted.org/packages/a2/55/8f8cab2afd404cf578136ef2cc5dfb50baa1761b68c9da1fb1e4eed343c9/docopt-0.6.2.tar.gz

   Collecting netifaces
 Downloading 
   https://files.pythonhosted.org/packages/0d/18/fd6e9c71a35b67a73160ec80a49da63d1eed2d2055054cc2995714949132/netifaces-0.10.9.tar.gz

   Installing collected packages: docopt, netifaces, onkyo-eiscp
   Running setup.py install for docopt ... done
   Running setup.py install for netifaces ... done
   Running setup.py install for onkyo-eiscp ... done
   Successfully installed docopt-0.6.2 netifaces-0.10.9 onkyo-eiscp-1.2.7

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


Re: Using Makefiles in Python projects

2019-11-07 Thread Skip Montanaro
On Thu, Nov 7, 2019 at 1:24 PM Vitaly Potyarkin  wrote:
>
> What do you think of using Makefiles for automating common chores in
> Python projects? Like linting, type checking and testing?

Kinda unsure why this needs to be asked (says the guy who's used Make
longer than Python and nearly as long as Emacs). :-) That said, I will
answer in the affirmative. Make is a great tool. Every Makefile should
have "test", "lint" and "clean" targets (where they make sense) in
addition to something equating to "all" (the first target in the
file). In short, if you have to type a command more than once, you
need a Makefile. It will save you time and serve as documentation to
yourself and others about how the various pieces of your project fit
together.

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


Re: Using Makefiles in Python projects

2019-11-07 Thread Grant Edwards
On 2019-11-07, Skip Montanaro  wrote:

> In short, if you have to type a command more than once, you need a
> Makefile. It will save you time and serve as documentation to
> yourself and others about how the various pieces of your project fit
> together.

Definitely.

Some of the projects I work on don't actually use "make" to build the
software product.  But they still have a Makefiles with targets for
things like formatting documentation, installing the software on a
target, tagging and archiving a version, generating a tarball of GPL
sources, updating source trees from upstream, etc...

-- 
Grant Edwards   grant.b.edwardsYow! BARBARA STANWYCK makes
  at   me nervous!!
  gmail.com

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


Re: Using Makefiles in Python projects

2019-11-07 Thread Cameron Simpson

On 07Nov2019 22:20, Vitaly Potyarkin  wrote:

What do you think of using Makefiles for automating common chores in
Python projects? Like linting, type checking and testing?


I do use one for some things. (Not linting, which I'll describe lower 
down.)


I do like to use it for what make's strength is: running actions based 
on updated files, but there are a few "action" targets too.


Here's a slightly edited and trimmed excerpt from a Makefile (well, 
Mykefile, but the intent and syntax are very similar) from a current 
project:


   venv_dir = $./venv
   venv_reqs = requirements.txt
   venv_pip = $(venv_dir)/bin/pip

   py_static_bundle = $(py_app)/static/app.js

   fleet_dev = [ "$$HOST" = fleet -a "$$USER" = cameron ]

   _help:
   @echo '_build: make $(py_static_bundle)'
   @echo '_deploy_tip: formally deploy the current tip to the dev host 
dev tree:'
   @echo '_sync_dev: rsync the current working files into the dev tip 
tree'

   _build:
   make $(py_static_bundle)

   _venv:
   :make $(venv_dir)

   $(venv_dir):$(venv_reqs)
   python3 -m venv $(venv_dir)
   $(venv_pip) install -U pip
   $(venv_pip) install -U -r $(venv_reqs)

   $(py_static_bundle): $(app_js)
   env-dev browserify -t [ babelify --presets [ react ] ] $? >$@

   _sync_dev:
   $(fleet_dev) || { echo "not cameron@fleet, refusing to rsync" >&2; 
exit 1; }
   :make $(py_static_bundle)
   $(sync_src(target_dev_host:releases/tip))

Things to note:

"Virtual targets" are actions rather than result files, and start with 
an underscore.


The default target is _help, which recites a description of the other 
targets.


The _venv target makes the venv directory if missing, and that runs 
python3 -m venv and then pip to do the required packages.


There's a traditional make rule i.e. an action based on a dependent 
file, gosh! for the static bundle (javascript compiled into a single 
file).


You'll see that _sync_dev has a leading sanity check: it won't run 
unless I'm me on my personal machine; avoids accidents. This is 
important because it isn't running the formal deploy script, which 
builds a clean versioned tree at the far end, instead it just rsyncs my 
local code into a "live" dev tree at the far end. Obviously that is a 
very personal hack.


I've come up with a reusable Makefile for automating virtual 
environment

management in Python projects. I think it can be useful for simplifying
the onboarding of new developers (both new to project and new to Python)
and for documenting project's development practices.


These are laudable goals. I like the expose the dev practices in 
particular.



Here it is:
- Repo: https://github.com/sio/Makefile.venv
- Demo screencast: https://asciinema.org/a/279646

What do you think? Is this useful or I'm just unaware of some tool that
abstracts venv chores away better?


There may be other tools.

Linting can be personal. In my current team we have varying lint habits 
among the devs. OTOH a common "required lint before release" could be 
useful, covering off the project lint standards if they exist.


I lint by hand, with 2 main levels of automation:

1: I have a personal "lint" script with runs my preferred linters with 
my preferred options, so I can just say "lint filenames..." and have it 
do the right thing. It is also multilanguage: python linters, shell 
linters, etc.


2: I have a few VCS related shell functions. One is named "lint". With 
arguments is invokes the above lint script directly. _Without_ arguments 
it lints the "modified" (== changed and not committed) files. So I can 
just say "lint" and it lints my changes, not all the files.


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


Re: How execute at least two python files at once when imported?

2019-11-07 Thread Cameron Simpson

On 08Nov2019 00:52, Greg Ewing  wrote:

Cameron Simpson wrote:
Spencer's modules run unconditional stuff in addition to defining 
classes. That may cause trouble.


It will -- because of the import lock, they won't run simultaneously
in the same process.


I was unsure as to how serialised this was: just the import data 
structures or the whole source-of-the-module. But I guess serialising 
the latter is essential anyway, now I think about it.


Hence my separate post suggesting the OP move the "main task" into a 
function, runs the imports serailly (very cheap) and then kick off 
threads if that's what he wants.


Thanks for the clarification.

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


Re: Using Makefiles in Python projects

2019-11-07 Thread David
On Fri, 8 Nov 2019 at 09:43, Cameron Simpson  wrote:

[...]

> _help:
> @echo '_build: make $(py_static_bundle)'
> @echo '_deploy_tip: formally deploy the current tip to the dev 
> host dev tree:'
> @echo '_sync_dev: rsync the current working files into the dev 
> tip tree'

[...]

> Things to note:
>
> "Virtual targets" are actions rather than result files, and start with
> an underscore.
>
> The default target is _help, which recites a description of the other
> targets.

Hi, as you might be aware, the above recipe will not be run if a file
named '_help' exists.

The Gnu make documentation term for what you call "virtual targets"
is "phony targets", and it discusses them here:
https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets

I would add the line:
.PHONY: _help
And similar for all the other phony targets.

Doing this has other advantages as described in the linked docs.
In particular, it saves 'make' wasting time searching for built-in
implicit rules
that might build these never-built targets. 'make -d' will reveal this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Using Makefiles in Python projects

2019-11-07 Thread Cameron Simpson

On 08Nov2019 10:30, David  wrote:

On Fri, 8 Nov 2019 at 09:43, Cameron Simpson  wrote:
[...]


_help:
@echo '_build: make $(py_static_bundle)'
@echo '_deploy_tip: formally deploy the current tip to the dev host 
dev tree:'
@echo '_sync_dev: rsync the current working files into the dev tip 
tree'


[...]


Things to note:

"Virtual targets" are actions rather than result files, and start with
an underscore.

The default target is _help, which recites a description of the other
targets.


Hi, as you might be aware, the above recipe will not be run if a file
named '_help' exists.


Hence the funny name. I don't make files whole names begin with 
underscores.



The Gnu make documentation term for what you call "virtual targets"
is "phony targets", and it discusses them here:
https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html#Phony-Targets

I would add the line:
.PHONY: _help
And similar for all the other phony targets.


If you're using GNU make, go right ahead. But that approach treats 
.PHONY like a label to be applied to _its_ dependents. Probably that's 
exactly what it does. However, that is the inverse of the normal 
target:dependent relationship one puts in Makefiles.


My personal approach is this:

   _always:
   :

   _help:  _always

i.e. make the "phony" targets depend on "_always", which are thus always 
out of date and thus will always run. You've still to avoid making a 
"_always", but that is a smaller thing than the whole "_*" space, if 
that is a concern.


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


Questions on working with unittest.IsolatedAsyncioTestCase

2019-11-07 Thread Mond Wan
Hello all,

I would like to ask for helps on working with 
**unittest.IsolatedAsyncioTestCase**.

Q1: How to handle asyncio.CancelledError inside IsolatedAsyncioTestCase.

My test is hanging up if there are futures being cancelled some how. Is there a 
way for me to configure IsolatedAsyncioTestCase to throw any exceptions
to crash the main program such that I can read the line number?

I have also issue a post on stackoverflow, which include the codes I have 
written for explaining the question.

Stackoverflow: 
https://stackoverflow.com/questions/58744043/how-to-handle-cancellederror-with-python-3-8-unittest-isolatedasynciotestcase


Q2: addAsyncCleanup vs asyncTearDown?

In the py3.8 manual, there is a method **addAsyncCleanup** for cleaning up 
stuff in async way. Why we need this instead of merging them altogether
into **asyncTearDown** at all?


Q3: Is it possible to configure a timeout mechanism for IsolatedAsyncioTestCase?

During my development, my tests always pending in somewhere. I cannot located 
them until I add print statements line by line. Is it possible to
configure the IsolatedAsyncioTestCase to crash the test, with line number, 
after specific period if such future is not resolved?


Thanks for your time

--

Mond WAN

Senior Engineer, Engineering Department

Anywhere Networks
Mobile/WhatsApp: +852 3899 1928

mondwan@anywherenetworks.com

www.AnywhereNetworks.com

P2 Wireless Technologies is now Anywhere Networks!

[Anywhere Networks]

Disclaimer: This email and its attachment(s) are solely for the use of the 
intended addressee and may contain confidential information. If you are not the 
intended recipient, you must not use, distribute or copy this email. If you 
have received this email in error, please notify the sender immediately and 
delete this email. No employee or agent is authorized to bind the company or 
conclude a binding agreement on behalf of the company without express written 
approval by an authorized senior officer of the company. In no event will this 
email or its content be construed as written approval.


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