Re: Question about the @staticmethod decorator

2019-03-18 Thread Terry Reedy

On 3/17/2019 2:15 PM, Arup Rakshit wrote:

I am reading a book where the author says that:

In principle, it would also be possible to implement any @staticmethod 
completely outside of the class at module scope without any loss of 
functionality — so you may want to consider carefully whether a particular 
function should be a module scope function or a static method. The 
@staticmethod decorator merely facilitates a particular organisation of the 
code allowing us to place what could otherwise be free functions within classes.

I didn’t get quiet well this block of text. My first question is how would I 
make a module level function as static method of a class. Can anyone give me an 
example of this? What are the contexts that would let you to think if they are 
good fit inside the class or module level scope functions?


The addition of @staticmethod was unnecessary in that it did not enable 
any new functionality.  I think beginners should just ignore it.


--
Terry Jan Reedy


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


running "python -i" in subprocess shows no prompt

2019-03-18 Thread finnkochinski
Hello,
I try to start a separate python subprocess using the attached code. This 
example should catch all stdout and stderr output from the launched subprocess 
and send commands to its stdin.
The problem is that the prompt ">>>" asking for then next input is neither sent 
to stdout nor to stderr. The commands sent to stdin aren't echoed to stdout 
either.
 The output from the attached code looks as follows:
'''
Python 2.7.13 (default, Nov 23 2017, 15:37:09)
[GCC 6.3.0 20170406] on linux2
Type "help", "copyright", "credits" or "license" for more information.
1
4
9
16
'''

I am expecting to get the same output as if I sent the same input to a 
standalone interactive python interpreter, which would be this:
'''
Python 2.7.13 (default, Nov 23 2017, 15:37:09)
[GCC 6.3.0 20170406] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1*1
1
>>> 2*2
4
>>> 3*3
9
>>> 4*4
16
>>>
'''

I cannot simple print the ">>>" after each readline(), because I don't know how 
much output will follow before the next input prompt is required.
What needs to be changed in my code to make the subprocess forward the missing 
parts to the output pipes?

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


I wrote a free book about TDD and clean architecture in Python

2019-03-18 Thread giordani . leonardo
Hi all,

I published on Leanpub a free book, "Clean Architectures in Python". It's a 
humble attempt to organise and expand some posts I published on my blog in the 
last years.

You can find it here: https://leanpub.com/clean-architectures-in-python

The main content is divided in two parts, this is a brief overview of the table 
of contents

* Part 1 - Tools
- Chapter 1 - Introduction to TDD
- Chapter 2 - On unit testing
- Chapter 3 - Mocks

* Part 2 - The clean architecture
- Chapter 1 - Components of a clean architecture
- Chapter 2 - A basic example
- Chapter 3 - Error management
- Chapter 4 - Database repositories

Some highlights:

- The book is written with beginners in mind

- It contains 3 full projects, two small ones to introduce TDD and mocks, a 
bigger one to describe the clean architecture approach

- Each project is explained step-by-step, and each step is linked to a tag in a 
companion repository on GitHub

The book is free, but if you want to contribute I will definitely appreciate 
the help. My target is to encourage the discussion about software 
architectures, both in the Python community and outside it.

As of today the book has been downloaded by 7,500 readers. I hope you will 
enjoy the book! if you do, please spread the news on your favourite social 
network
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: running "python -i" in subprocess shows no prompt

2019-03-18 Thread Chris Angelico
On Tue, Mar 19, 2019 at 2:50 AM  wrote:
>
> Hello,
> I try to start a separate python subprocess using the attached code. This 
> example should catch all stdout and stderr output from the launched 
> subprocess and send commands to its stdin.
> The problem is that the prompt ">>>" asking for then next input is neither 
> sent to stdout nor to stderr. The commands sent to stdin aren't echoed to 
> stdout either.
>

Many programs behave differently when they're connected to an actual
TTY compared to being connected to a pipe. What you often need to do
is use a pseudo-terminal, which you can then feed stuff to and capture
stuff from. Python makes this available with the pty module:

https://docs.python.org/3/library/pty.html
https://docs.python.org/2/library/pty.html

(I would strongly recommend using Python 3 rather than Python 2, but
it should be possible to do either way.)

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


Re: I wrote a free book about TDD and clean architecture in Python

2019-03-18 Thread Arup Rakshit
Hello,

Thanks for writing this great book. I joined python community just couple of 
weeks. 


Thanks,

Arup Rakshit
[email protected]



> On 16-Mar-2019, at 4:59 PM, [email protected] wrote:
> 
> Hi all,
> 
> I published on Leanpub a free book, "Clean Architectures in Python". It's a 
> humble attempt to organise and expand some posts I published on my blog in 
> the last years.
> 
> You can find it here: https://leanpub.com/clean-architectures-in-python
> 
> The main content is divided in two parts, this is a brief overview of the 
> table of contents
> 
> * Part 1 - Tools
> - Chapter 1 - Introduction to TDD
> - Chapter 2 - On unit testing
> - Chapter 3 - Mocks
> 
> * Part 2 - The clean architecture
> - Chapter 1 - Components of a clean architecture
> - Chapter 2 - A basic example
> - Chapter 3 - Error management
> - Chapter 4 - Database repositories
> 
> Some highlights:
> 
> - The book is written with beginners in mind
> 
> - It contains 3 full projects, two small ones to introduce TDD and mocks, a 
> bigger one to describe the clean architecture approach
> 
> - Each project is explained step-by-step, and each step is linked to a tag in 
> a companion repository on GitHub
> 
> The book is free, but if you want to contribute I will definitely appreciate 
> the help. My target is to encourage the discussion about software 
> architectures, both in the Python community and outside it.
> 
> As of today the book has been downloaded by 7,500 readers. I hope you will 
> enjoy the book! if you do, please spread the news on your favourite social 
> network
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


tkinter

2019-03-18 Thread Informatico de Neurodesarrollo

Hello friends:

I am a beginner on programming in python.

I want make a simple program that test continuously (every 5 seg) the 
connection  to internet and change the background color when are not 
available. I try this , but not work properly:


 #!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
from tkinter import *
import socket, time

def DetectarConexion():
    testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    try:
        testConn.connect(('8.8.8.8', 80))
        testConn.close()
        return True
    except:
        testConn.close()
        return False

root = Tk()
root.title("Conexión")
root.geometry("80x50")

while True:
    if DetectarConexion():
        # Background:Green
        root.config(background="#38EB5C")
    else:
        # Background:Red
        root.config(background="#F50743")
    time.sleep(5)

root.mainloop()


Any ideas, will be welcome.


T.I.A


--

Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.


--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

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


Re: tkinter

2019-03-18 Thread Chris Angelico
On Tue, Mar 19, 2019 at 3:33 AM Informatico de Neurodesarrollo
 wrote:
>
> Hello friends:
>
> I am a beginner on programming in python.

Cool! Then I would recommend making your program as simple as you possibly can.

> I want make a simple program that test continuously (every 5 seg) the
> connection  to internet and change the background color when are not
> available. I try this , but not work properly:
>
>   #!/usr/bin/env python3
> # -*- coding: utf-8 -*-
> #
> from tkinter import *
> import socket, time
>
> def DetectarConexion():
>  testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
>  try:
>  testConn.connect(('8.8.8.8', 80))
>  testConn.close()
>  return True
>  except:
>  testConn.close()
>  return False

This part of the code is completely independent of the Tkinter code.
Split it up into the two parts and develop each one separately.

> root = Tk()
> root.title("Conexión")
> root.geometry("80x50")
>
> while True:
>  if DetectarConexion():
>  # Background:Green
>  root.config(background="#38EB5C")
>  else:
>  # Background:Red
>  root.config(background="#F50743")
>  time.sleep(5)
>
> root.mainloop()
>

You have two separate parts to this code, and it's possible that
neither of them is working. I would recommend concentrating first on
the connection status function. Remove everything about Tkinter, and
replace it with a simple print() call:

while True:
if DetectarConexion():
print("Connection is happy")
else:
print("Connection is down!")
time.sleep(5)

Now you can work on making sure your connection tester is working.
What exactly are you testing? What goes wrong when you don't have a
connection?

Specific advice:
1) Avoid using the bare "except:" clause. It may be hiding bugs in your code.
2) Make sure you're trying something that actually does work.
Connecting to 8.8.8.8 port 80 isn't going to succeed even if your
connection is live.

Start with that, and you should be able to get a lot further with your testing.

Have fun with it! If you run into trouble, post your updated code,
what you're trying, and what's happening.

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


Re: tkinter

2019-03-18 Thread Paul Sutton
On 18/03/2019 16:00, Informatico de Neurodesarrollo wrote:
> Hello friends:
> 
> I am a beginner on programming in python.
> 
> I want make a simple program that test continuously (every 5 seg) the
> connection  to internet and change the background color when are not
> available. I try this , but not work properly:
> 
>  #!/usr/bin/env python3
> # -*- coding: utf-8 -*-
> #
> from tkinter import *
> import socket, time
> 
> def DetectarConexion():
>     testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
>     try:
>         testConn.connect(('8.8.8.8', 80))
>         testConn.close()
>         return True
>     except:
>         testConn.close()
>         return False
> 
> root = Tk()
> root.title("Conexión")
> root.geometry("80x50")
> 
> while True:
>     if DetectarConexion():
>         # Background:Green
>         root.config(background="#38EB5C")
>     else:
>         # Background:Red
>         root.config(background="#F50743")
>     time.sleep(5)
> 
> root.mainloop()
> 
> 
> Any ideas, will be welcome.
> 
> 
> T.I.A
> 
> 

I asked about a tkinter app for a project I am working on a while back ,
 what was suggested (which was a very useful suggestion) is get the
routine and feedback working without the GUI first,  so in this case a
simply python program would ping something ever 5 mins and say if this
was successful or not.

Not sure if you would ping as such, but if you can get a normal python
script to do what you want,  then you can add a gui later.

hope this helps

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


Re: running "python -i" in subprocess shows no prompt

2019-03-18 Thread Grant Edwards
On 2019-03-18,   wrote:

> I try to start a separate python subprocess using the attached
> code. This example should catch all stdout and stderr output from
> the launched subprocess and send commands to its stdin.  The problem
> is that the prompt ">>>" asking for then next input is neither sent
> to stdout nor to stderr.  The commands sent to stdin aren't echoed
> to stdout either.

Perhaps the prompt/echo is sent to stdin?

If not connected to a tty, it may not issue prompts and echo commands.
Many command line utilities modify their behavior depending on whether
they're connected to a tty or not.

-- 
Grant Edwards   grant.b.edwardsYow! I'm young ... I'm
  at   HEALTHY ... I can HIKE
  gmail.comTHRU CAPT GROGAN'S LUMBAR
   REGIONS!

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


Re: tkinter

2019-03-18 Thread Informatico de Neurodesarrollo
This code work fine, every 5 second test the connection to this machine 
(10.44.0.15) on my network.


#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  DetectConn_1_0.py
#
#First: Testing connection
#

import socket, time

def isInternet():
    testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    output = testConn.connect_ex(('10.44.0.15', 80))
    if output == 0:
    return True
    else:
    return False
    testConn.close()

while True:
    if isInternet():
        print("Hay conexión")
    else:
        print("No hay conexión")

    time.sleep(5)


What's next?, I am all eyes

El 18/03/19 a las 12:44, Chris Angelico escribió:

On Tue, Mar 19, 2019 at 3:33 AM Informatico de Neurodesarrollo
 wrote:

Hello friends:

I am a beginner on programming in python.

Cool! Then I would recommend making your program as simple as you possibly can.


I want make a simple program that test continuously (every 5 seg) the
connection  to internet and change the background color when are not
available. I try this , but not work properly:

   #!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
from tkinter import *
import socket, time

def DetectarConexion():
  testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  try:
  testConn.connect(('8.8.8.8', 80))
  testConn.close()
  return True
  except:
  testConn.close()
  return False

This part of the code is completely independent of the Tkinter code.
Split it up into the two parts and develop each one separately.


root = Tk()
root.title("Conexión")
root.geometry("80x50")

while True:
  if DetectarConexion():
  # Background:Green
  root.config(background="#38EB5C")
  else:
  # Background:Red
  root.config(background="#F50743")
  time.sleep(5)

root.mainloop()


You have two separate parts to this code, and it's possible that
neither of them is working. I would recommend concentrating first on
the connection status function. Remove everything about Tkinter, and
replace it with a simple print() call:

while True:
 if DetectarConexion():
 print("Connection is happy")
 else:
 print("Connection is down!")
 time.sleep(5)

Now you can work on making sure your connection tester is working.
What exactly are you testing? What goes wrong when you don't have a
connection?

Specific advice:
1) Avoid using the bare "except:" clause. It may be hiding bugs in your code.
2) Make sure you're trying something that actually does work.
Connecting to 8.8.8.8 port 80 isn't going to succeed even if your
connection is live.

Start with that, and you should be able to get a lot further with your testing.

Have fun with it! If you run into trouble, post your updated code,
what you're trying, and what's happening.

Chris Angelico


--

Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.


--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

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


Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Arup Rakshit
Hi,

In this piece of code:

class RefrigeratedShippingContainer(ShippingContainer):
MAX_CELSIUS = 4.0

def __init__(self, owner_code, contents, celsius):
super().__init__(owner_code, contents)

if celsius > RefrigeratedShippingContainer.MAX_CELSIUS:
raise ValueError("Temperature too hot!")
self._celsius = celsius

@staticmethod
def _c_to_f(celsius):
return celsius * 9/5 + 32

@staticmethod
def _f_to_c(fahrenheit):
return (fahrenheit - 32) * 5/9

@staticmethod
def _make_bic_code(owner_code, serial):
return iso6346.create(owner_code=owner_code,
  serial=str(serial).zfill(6),
  category='R')
@property
def celsius(self):
return self._celsius

@celsius.setter
def celsius(self, value):
if value > RefrigeratedShippingContainer.MAX_CELSIUS:
raise ValueError("Temperature too hot!")
self._celsius = value

@property
def fahrenheit(self):
return RefrigeratedShippingContainer._c_to_f(self.celsius)

@fahrenheit.setter
def fahrenheit(self, value):
self.celsius = RefrigeratedShippingContainer._f_to_c(value)

If I call `_c_to_f`, `_f_to_c` methods on `self` instead of 
`RefrigeratedShippingContainer` class object, still it works. So what is the 
reason behind of this calling on the class object, instead class instance 
object? 


Thanks,

Arup Rakshit
[email protected]



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


Re: tkinter

2019-03-18 Thread Chris Angelico
On Tue, Mar 19, 2019 at 4:55 AM Informatico de Neurodesarrollo
 wrote:
>
> This code work fine, every 5 second test the connection to this machine
> (10.44.0.15) on my network.
>
> def isInternet():
>  testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
>  output = testConn.connect_ex(('10.44.0.15', 80))
>  if output == 0:
>  return True
>  else:
>  return False
>  testConn.close()
>
> while True:
>  if isInternet():
>  print("Hay conexión")
>  else:
>  print("No hay conexión")
>
>  time.sleep(5)
>
>
> What's next?, I am all eyes
>

Great! Now that that's working, you can go grab your Tkinter code
back. But you'll have to rework things. Set your networking code
aside, and just make something that, every five seconds, changes its
background colour. You may want to do some research on how to do that
reliably. Hint: you most likely won't have a "while" loop in your
final code.

Once you have both parts working separately, then you can put them
together, by having the background colour change be controlled by the
connection check. But first make sure that they work on their own.

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


Re: tkinter

2019-03-18 Thread MRAB

On 2019-03-18 16:00, Informatico de Neurodesarrollo wrote:

Hello friends:

I am a beginner on programming in python.

I want make a simple program that test continuously (every 5 seg) the
connection  to internet and change the background color when are not
available. I try this , but not work properly:

   #!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
from tkinter import *
import socket, time

def DetectarConexion():
      testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
      try:
          testConn.connect(('8.8.8.8', 80))
          testConn.close()
          return True
      except:
          testConn.close()
          return False

root = Tk()
root.title("Conexión")
root.geometry("80x50")

You have a problem here: the loop will repeat forever, so you'll never 
reach the root.mainloop() line and show the GUI.



while True:
      if DetectarConexion():
          # Background:Green
          root.config(background="#38EB5C")
      else:
          # Background:Red
          root.config(background="#F50743")
      time.sleep(5)

root.mainloop()


Any ideas, will be welcome.


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


Block Ctrl+S while running Python script at Windows console?

2019-03-18 Thread Malcolm Greene
I'm running some Python 3.6 scripts at the Windows 10/Windows Server 2016 
console. In my every day workflow, I seem to be accidentally sending Ctrl+S 
keystrokes to some of console sessions, pausing my running scripts until I send 
another corresponding Ctrl+S to un-pause the affected scripts. My challenge is 
I don't know when I'm sending these keystrokes other than seeing scripts that 
seem to have stopped, clicking on their console window, and typing Ctrl+S to 
unblock them.

Wondering if there's a way to have my Python scripts ignore these Ctrl+S 
signals or if this behavior is outside of my Python script's control. If 
there's a way to disable this behavior under Windows 10/Windows Server 2016, 
I'm open to that as well.

Thank you,
Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tkinter

2019-03-18 Thread Informatico de Neurodesarrollo

Thanks, I was noted it. I have figure out, how can I do that.

I keep in touch


El 18/03/19 a las 14:09, MRAB escribió:

On 2019-03-18 16:00, Informatico de Neurodesarrollo wrote:

Hello friends:

I am a beginner on programming in python.

I want make a simple program that test continuously (every 5 seg) the
connection  to internet and change the background color when are not
available. I try this , but not work properly:

   #!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
from tkinter import *
import socket, time

def DetectarConexion():
      testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
      try:
          testConn.connect(('8.8.8.8', 80))
          testConn.close()
          return True
      except:
          testConn.close()
          return False

root = Tk()
root.title("Conexión")
root.geometry("80x50")

You have a problem here: the loop will repeat forever, so you'll never 
reach the root.mainloop() line and show the GUI.



while True:
      if DetectarConexion():
          # Background:Green
          root.config(background="#38EB5C")
      else:
          # Background:Red
          root.config(background="#F50743")
      time.sleep(5)

root.mainloop()


Any ideas, will be welcome.



--

Ing. Jesús Reyes Piedra
Admin Red Neurodesarrollo,Cárdenas
La caja decía:"Requiere windows 95 o superior"...
Entonces instalé LINUX.


--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/

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


Python 3.5.7 is now available

2019-03-18 Thread Larry Hastings


On behalf of the Python development community, I'm chuffed to announce 
the availability of Python 3.5.7.


Python 3.5 is in "security fixes only" mode.  It only accepts security 
fixes, not conventional bug fixes, and the release is source-only.


And you can find Python 3.5.7rc1 here:

   https://www.python.org/downloads/release/python-357/


Best wishes,



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


Python 3.4.10 is now available

2019-03-18 Thread Larry Hastings


On behalf of the Python development community, I'm proud--if slightly 
sad--to announce the availability of Python 3.4.10.


Python 3.4.10 was released in "security fixes only" mode.  It only 
contains security fixes, not conventional bug fixes, and it is a 
source-only release.


Python 3.4.10 is the final release in the Python 3.4 series. As of this 
release, the 3.4 branch has been retired, no further changes to 3.4 will 
be accepted, and no new releases will be made.  This is standard Python 
policy; Python releases get five years of support and are then retired.


If you're still using Python 3.4, you should consider upgrading to the 
current version--3.7.2 as of this writing.  Newer versions of Python
have many new features, performance improvements, and bug fixes, which 
should all serve to enhance your Python programming experience.


We in the Python core development community thank you for your interest 
in 3.4, and we wish you all the best!



You can find Python 3.4.10 here:

   https://www.python.org/downloads/release/python-3410/


One I completely finish the Python 3.4.10 release process, I will retire 
as Python 3.4 Release Manager.  I'll still be Python 3.5 Release Manager 
for another eighteen months or so.



Python 3.4 is OVER!
https://www.youtube.com/watch?v=YlGqN3AKOsA



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


Re: Block Ctrl+S while running Python script at Windows console?

2019-03-18 Thread eryk sun
On 3/18/19, Malcolm Greene  wrote:
>
> I'm running some Python 3.6 scripts at the Windows 10/Windows Server 2016
> console. In my every day workflow, I seem to be accidentally sending Ctrl+S
> keystrokes to some of console sessions, pausing my running scripts until I
> send another corresponding Ctrl+S to un-pause the affected scripts. My
> challenge is I don't know when I'm sending these keystrokes other than
> seeing scripts that seem to have stopped, clicking on their console window,
> and typing Ctrl+S to unblock them.
>
> Wondering if there's a way to have my Python scripts ignore these Ctrl+S
> signals or if this behavior is outside of my Python script's control. If
> there's a way to disable this behavior under Windows 10/Windows Server 2016,
> I'm open to that as well.

Ctrl+S functions as pause in line-edit mode if extended text selection
is enabled in the console defaults or properties dialog, It's
implemented by blocking console I/O operations in the host process,
conhost.exe.  Pretty much any key will resume. It doesn't have to be
Ctrl+Q or Ctrl+S. Another common culprit is quick-edit mode, in which
case a stray mouse click can select text, even just a single
character. The console pauses while text is selected.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Block Ctrl+S while running Python script at Windows console?

2019-03-18 Thread eryk sun
On 3/18/19, eryk sun  wrote:
>
> Ctrl+S functions as pause in line-edit mode if extended text selection
> is enabled in the console defaults or properties dialog

Correction, it pauses if extended text selection is *disabled*.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess svn checkout password issue

2019-03-18 Thread Barry



> On 15 Mar 2019, at 22:17, Martin De Kauwe  wrote:
> 
> Hi,
> 
> I'm trying to write a script that will make a checkout from a svn repo and 
> build the result for the user. However, when I attempt to interface with the 
> shell it asks the user for their filename and I don't know how to capture 
> this with my implementation. 
> 
> user = "XXX578"
> root="https://trac.nci.org.au/svn/cable";
> repo_name = "CMIP6-MOSRS"
> 
> cmd = "svn checkout %s/branches/Users/%s/%s" % (root, user, repo_name)
> p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
>  stdout=subprocess.PIPE, 
> stderr=subprocess.PIPE)
> error = subprocess.call(cmd, shell=True)
> if error is 1:
>raise("Error downloading repo"
> 
> I tried adding .wait(timeout=60) to the subprocess.Popen command but that 
> didn't work.
> 
> Any advice on whether there is an augmentation to the above, or a better 
> approach, would be much appreciated. I need to solve this with standard 
> python libs as I'm trying to make this as simple as possible for the user.
> 
> The full script is here if that helps:
> 
> https://github.com/mdekauwe/CABLE_benchmarking/blob/master/scripts/get_cable.py

You could also use the pysvn library that provides a pythonic api to drive svn
>From https://pysvn.sourceforge.io/ notes its not on PyPi but ther are kits for 
>windows, mac. Debian and Fedora provide pysvn as well.

It allows you to provide the username and password  via the api.

See https://pysvn.sourceforge.io/Docs/pysvn_prog_ref.html#pysvn_client_checkout
And 
https://pysvn.sourceforge.io/Docs/pysvn_prog_ref.html#pysvn_client_callback_get_login
 to provide the username and password.

Barry
Pysvn author


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


Re: Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Ben Finney
Arup Rakshit  writes:

> class RefrigeratedShippingContainer(ShippingContainer):
> # ...
>
> @staticmethod
> def _c_to_f(celsius):
> return celsius * 9/5 + 32
>
> @staticmethod
> def _f_to_c(fahrenheit):
> return (fahrenheit - 32) * 5/9

Both those functions are decorated with ‘staticmethod’. That means
https://docs.python.org/3/library/functions.html#staticmethod>
that the function will, unlike typical methods, not automatically
receive any implicit first argument. That's why the function signature
has no ‘self’ or ‘klass’ or the like.

> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of
> `RefrigeratedShippingContainer` class object, still it works.

That's right, and is indeed the point of making a static method on a
class. From the above documentation link:

[A staticmethod-decorated function] can be called either on the
class (such as `C.f()`) or on an instance (such as `C().f()`). The
instance is ignored except for its class.

> So what is the reason behind of this calling on the class object,
> instead class instance object?

Whichever makes the most sense in the code where that function is
called.

The purpose of a static method is to imply that, though the function
*could* be entirely separate from any class, it is conceptually part of
a spacific class's behaviour.

In the specific example you show, I expect the code maintenance was
deemed to be easier when the RefrigeratedShippingContainer encapsulates
the conversions of temperature units.

-- 
 \ “When we pray to God we must be seeking nothing — nothing.” |
  `\—Francis of Assisi |
_o__)  |
Ben Finney

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


Re: Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Michael Torrie
On 03/18/2019 05:55 PM, Ben Finney wrote:
>> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of
>> `RefrigeratedShippingContainer` class object, still it works.
> 
> That's right, and is indeed the point of making a static method on a
> class. 

I'm confused. The methods that refer to
RefigeratedShippingContainer.MAX_CELSIUS are not static methods.  For
example, __init__() and celsius().  In fact he never said anything about
static methods unless I'm really missing something.

> In the specific example you show, I expect the code maintenance was
> deemed to be easier when the RefrigeratedShippingContainer encapsulates
> the conversions of temperature units.

I'm not sure this answers his question.  He's asking why refer to a
class variable with the class's name when self also apparently works.


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


Re: Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Ben Finney
Arup Rakshit  writes:

Michael Torrie  writes:

> On 03/18/2019 05:55 PM, Ben Finney wrote:
> >> If I call `_c_to_f`, `_f_to_c` methods on `self` instead of
> >> `RefrigeratedShippingContainer` class object, still it works.
> > 
> > That's right, and is indeed the point of making a static method on a
> > class. 
>
> I'm confused. […] he never said anything about static methods unless
> I'm really missing something.

You included it, quoted above (but stripped out the attribution; please
don't do that). The only methods discussed in Arup Rakshit's message are
‘_c_to_f’ and ‘_f_to_c’, both static methods on the class.

-- 
 \ “A child of five could understand this. Fetch me a child of |
  `\  five.” —Groucho Marx |
_o__)  |
Ben Finney

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


Re: Reasoning of calling a method on class object instead of class instance object

2019-03-18 Thread Michael Torrie
On 03/18/2019 07:09 PM, Ben Finney wrote:
> Arup Rakshit  writes:
> 
> Michael Torrie  writes:
> 
>> On 03/18/2019 05:55 PM, Ben Finney wrote:
 If I call `_c_to_f`, `_f_to_c` methods on `self` instead of
 `RefrigeratedShippingContainer` class object, still it works.
>>>
>>> That's right, and is indeed the point of making a static method on a
>>> class. 
>>
>> I'm confused. […] he never said anything about static methods unless
>> I'm really missing something.
> 
> You included it, quoted above (but stripped out the attribution; please
> don't do that). The only methods discussed in Arup Rakshit's message are
> ‘_c_to_f’ and ‘_f_to_c’, both static methods on the class.

Gotcha. Thanks.

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


Re: Block Ctrl+S while running Python script at Windows console? (solved)

2019-03-18 Thread Malcolm Greene
Eryk,

> Another common culprit is quick-edit mode, in which case a stray mouse click 
> can select text, even just a single character. The console pauses while text 
> is selected.

MYSTERY SOLVED !! THANK YOU !!

Apparently, while mouse clicking between windows, I was inadvertently selecting 
a char on my console, thereby pausing the process that was running. Disabling 
Quick-Edit mode via the Properties dialog fixes this behavior.

I tried other console property setting combinations to block Ctrl+S keyboard 
behavior, but without success. Not a problem since I'm pretty sure I'm not 
typing random Ctrl+S keystrokes while working. 

Thanks again Eryk!
Malcolm
-- 
https://mail.python.org/mailman/listinfo/python-list


error while importing a module

2019-03-18 Thread Sharan Basappa
I have a design file that I am importing in a test file to run some tests.
The design file compiles fine when I run it standalone but when I import it in 
the test file, I see error on the very first line where I am importing the 
design file.

This is the line from test file:

"""
test my design
"""
import assertion_design as asd

Here is the error:
WindowsErrorTraceback (most recent call last)
D:\Users\sharanb\OneDrive - HCL Technologies 
Ltd\Projects\MyBackup\Projects\Initiatives\machine 
learning\programs\assertion\assertion_design_test.py in ()
  4 provided by the user
  5 """
> 6 import assertion_design as asd

Am I missing something?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: error while importing a module

2019-03-18 Thread Sharan Basappa
On Tuesday, 19 March 2019 08:34:25 UTC+5:30, Sharan Basappa  wrote:
> I have a design file that I am importing in a test file to run some tests.
> The design file compiles fine when I run it standalone but when I import it 
> in the test file, I see error on the very first line where I am importing the 
> design file.
> 
> This is the line from test file:
> 
> """
> test my design
> """
> import assertion_design as asd
> 
> Here is the error:
> WindowsErrorTraceback (most recent call last)
> D:\Users\sharanb\OneDrive - HCL Technologies 
> Ltd\Projects\MyBackup\Projects\Initiatives\machine 
> learning\programs\assertion\assertion_design_test.py in ()
>   4 provided by the user
>   5 """
> > 6 import assertion_design as asd
> 
> Am I missing something?

folks,

i think i figured it out.
The following 2 lines were missing before the import

import sys
sys.path.append('D:\Users\sharanb\OneDrive - HCL Technologies 
Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion')

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


Re: error while importing a module

2019-03-18 Thread Cameron Simpson

On 18Mar2019 20:11, Sharan Basappa  wrote:

On Tuesday, 19 March 2019 08:34:25 UTC+5:30, Sharan Basappa  wrote:

I have a design file that I am importing in a test file to run some tests.

[...]

The design file compiles fine when I run it standalone but when I import it in 
the test file, I see error on the very first line where I am importing the 
design file.

The following 2 lines were missing before the import

import sys
sys.path.append('D:\Users\sharanb\OneDrive - HCL Technologies 
Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion')


I suggest you make that string a "raw" string:

 sys.path.append(r'D:\Users\sharanb\OneDrive - HCL Technologies 
Ltd\Projects\MyBackup\Projects\Initiatives\machine learning\programs\assertion')

Unlike a normal Python string 'foo', a raw string r'foo' does not 
interpret slosh escapes (\n, \r etc).  In any string which is supposed 
to include sloshes (backslashes) you should write these as raw string to 
avoid unfortunate slosh escapes being interpreted as special characters.  

In your string above the sequence \a indicates an ASCII BEL character, 
which rings the terminal bell (in modern terminal emulators this often 
means to emit a beep or to flash the window to attract attention). So it 
isn't the path string you thought it was.


There are several slosh escapes recognised by Python strings; see the 
documentation for details. But when you _don't_ want the sequences 
interpreted, use a raw string.


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


Re: tkinter

2019-03-18 Thread Terry Reedy

On 3/18/2019 12:00 PM, Informatico de Neurodesarrollo wrote:

Hello friends:

I am a beginner on programming in python.

I want make a simple program that test continuously (every 5 seg) the 
connection  to internet and change the background color when are not 
available. I try this , but not work properly:


  #!/usr/bin/env python3
# -*- coding: utf-8 -*-


Not needed for py 3 where utf-8 is default


from tkinter import *
import socket, time

def DetectarConexion():
     testConn = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
     try:
         testConn.connect(('8.8.8.8', 80))
         testConn.close()
         return True
     except:
         testConn.close()
         return False

root = Tk()
root.title("Conexión")
root.geometry("80x50")

while True:
     if DetectarConexion():
         # Background:Green
         root.config(background="#38EB5C")
     else:
         # Background:Red
         root.config(background="#F50743")
     time.sleep(5)


This is your problem.  Loop with event loop in order to not block gui. 
See working code below.



root.mainloop()


#!/usr/bin/env python3

from tkinter import *

connected = False
def DetectarConexion():
global connected
connected = not connected
return connected

root = Tk()
root.title("Conexión")
root.geometry("80x50")

def colorupdate():
if DetectarConexion():
# Background:Green
root.config(background="#38EB5C")
else:
# Background:Red
root.config(background="#F50743")
root.after(1000, colorupdate)  # 1000 milliseconds = 1 second

colorupdate()
root.mainloop()



--
Terry Jan Reedy


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


Re: running "python -i" in subprocess shows no prompt

2019-03-18 Thread Terry Reedy

On 3/18/2019 9:10 AM, [email protected] wrote:

I try to start a separate python subprocess using the attached code. This 
example should catch all stdout and stderr output from the launched subprocess 
and send commands to its stdin.


Subprocess is not intended for interaction.  My attempts to use the 
subprocess pipes failed like yours did.


IDLE makes a socket connection to the execution subprocess, but using 
multiprocessing may be better for you.  This was the answer I got when I 
asked the same question you did.  (IDLE was written before multiprocess, 
and I may experiment with switching.)


--
Terry Jan Reedy

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