[Tutor] sub-modules and python3

2017-05-31 Thread john

Hi folks,

In the past I used a simple "import filename" for sub-modules in python 
2.  With python 3 I have run into errors reported (file not found) using 
python 2 import statements.  But I'm not asking how to correct the 
import as I am able to change the way I write the import as a work 
around - but I'm importing all the files at once.  What I want to know 
is what is the best practice for my situation.


Is there a simple way using python 3  to emulate python 2 imports?

Is there a standard python 3 import tool for sub-modules (files)?

Is it acceptable to add/change the os path to allow my app to find the 
modules/files?


Any help or thoughts on the matter is welcome.


Johnf


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sub-modules and python3

2017-05-31 Thread Mats Wichmann
On 05/31/2017 11:22 AM, john wrote:
> Hi folks,
> 
> In the past I used a simple "import filename" for sub-modules in python
> 2.  With python 3 I have run into errors reported (file not found) using
> python 2 import statements.  But I'm not asking how to correct the
> import as I am able to change the way I write the import as a work
> around - but I'm importing all the files at once.  What I want to know
> is what is the best practice for my situation.
> 
> Is there a simple way using python 3  to emulate python 2 imports?
> 
> Is there a standard python 3 import tool for sub-modules (files)?
> 
> Is it acceptable to add/change the os path to allow my app to find the
> modules/files?
> 
> Any help or thoughts on the matter is welcome.

try running the 2to3 tool and see what it suggests - I know it's
supposed to know what changes should be made to imports.  You don't have
to accept its' suggestions, of course.


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sub-modules and python3

2017-05-31 Thread Peter Otten
john wrote:

> Hi folks,
> 
> In the past I used a simple "import filename" for sub-modules in python
> 2.  With python 3 I have run into errors reported (file not found) using
> python 2 import statements.  But I'm not asking how to correct the
> import as I am able to change the way I write the import as a work
> around - but I'm importing all the files at once.  What I want to know
> is what is the best practice for my situation.
> 
> Is there a simple way using python 3  to emulate python 2 imports?
> 
> Is there a standard python 3 import tool for sub-modules (files)?

> Any help or thoughts on the matter is welcome.

Are you talking about intra-package imports? Rather than having Python 3 
emulate Python 2 you could switch on absolute imports in py2:

from __future__ import absolute_import  # must be at the beginning 
# of the module, then

import alpha # import toplevel alpha.py
from . import alpha  # import sibling in current package

> Is it acceptable to add/change the os path to allow my app to find the
> modules/files?

That is likely to create a big mess; you may end up with two versions of the 
same module, with puzzling results.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Issue with wsgi_ref.simple_server - sometimes very slow!

2017-05-31 Thread Attila Szabó
Hi All,

I'm facing a really strange behavior with python's wsgi_ref.simple_server
module.

I have the following setup:
- Raspberry Pi 2
- Ubuntu Mate 16.04
- Python3.5
-

I have the following simple source:

#!/usr/bin/env python3import wsgiref.simple_server
def my_func(env, start_response):
  start_response('200 OK', [])
  return [''.encode()]

server = wsgiref.simple_server.make_server(
  '0.0.0.0',
  19891,
  my_func,)

server.serve_forever()

After several requests (around every ~5 requests) the response time is
getting really-really slow (1-60sec) compared to the average 0.1s response,
the server serves the request and then quick again for couple of new
requests and then againgetting to be slow...

I'm trying to reach the node via my router, and also from outside internet
and the latency is there.

I have tried the same code also on Windows10 with same python version, from
behind the same router and the issue was not present.
Also I have removed the router and connected internet directly to Raspberry
PI and I faced the same issue.
So I think I can say that that is not because of the router for sure.

Also, always when I interrupt the running server I'm getting the following
exception:

Exception happened during processing of request from ('192.168.1.100',
3540)Traceback (most recent call last):
  File "/usr/lib/python3.5/socketserver.py", line 313, in
_handle_request_noblock
self.process_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 341, in process_request
self.finish_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 354, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.5/socketserver.py", line 681, in __init__
self.handle()
  File "/usr/lib/python3.5/wsgiref/simple_server.py", line 119, in handle
self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python3.5/socket.py", line 575, in readinto
return self._sock.recv_into(b)KeyboardInterrupt

That's why I think there is some issue with that recv_into function, but I
cannot figure it out how to resolve this... :/


Does anybody faced this same issue? Or anybody has an idea what should I
try or what should I modify in python source to solve this issue?

Thanks,
Attila
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sub-modules and python3

2017-05-31 Thread johnf

I'm not trying to support python 2 and python 3.

I just want to use python 3.  The issue of using absolute imports seems 
like a hack.  What happens if a user or I need to change the path.  
Should I have to change the all the imports?



I believe I am going to use absolute paths in the end (all I need is a 
good editor to make the changes) but I was hoping to find something that 
would work in a more universal way.



Johnf


On 05/31/2017 12:03 PM, Peter Otten wrote:

john wrote:


Hi folks,

In the past I used a simple "import filename" for sub-modules in python
2.  With python 3 I have run into errors reported (file not found) using
python 2 import statements.  But I'm not asking how to correct the
import as I am able to change the way I write the import as a work
around - but I'm importing all the files at once.  What I want to know
is what is the best practice for my situation.

Is there a simple way using python 3  to emulate python 2 imports?

Is there a standard python 3 import tool for sub-modules (files)?
Any help or thoughts on the matter is welcome.

Are you talking about intra-package imports? Rather than having Python 3
emulate Python 2 you could switch on absolute imports in py2:

from __future__ import absolute_import  # must be at the beginning
 # of the module, then

import alpha # import toplevel alpha.py
from . import alpha  # import sibling in current package


Is it acceptable to add/change the os path to allow my app to find the
modules/files?

That is likely to create a big mess; you may end up with two versions of the
same module, with puzzling results.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] sub-modules and python3

2017-05-31 Thread Ben Finney
johnf  writes:

> I just want to use python 3. The issue of using absolute imports seems
> like a hack.

Absolute import is what Python 3 does when you ask to import a module
without leading dots.

Relative import is what Python 3 does when you ask to import a module
with leading dots.

If you want to use Python 3 – and I am glad you do! – that's the import
behaviour you'll get.

> What happens if a user or I need to change the path. Should I have to
> change the all the imports?

You are asking for relative imports, and yes relative import is what you
should use to avoid having to care where the code is installed.

In Python 3, to import from a relative path, use leading dots (because a
path without leading dots is absolute). This explicitly tells Python
that the path is relative to the module where the import statement is.

You would have learned this when you worked through the Python 3
tutorial https://docs.python.org/3/tutorial/modules.html>. Maybe
it's time to work through again?

-- 
 \   “About four years ago, I was — no, it was yesterday.” —Steven |
  `\Wright |
_o__)  |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor