Re: import locale and print range on same line

2016-01-24 Thread eryk sun
On Sat, Jan 23, 2016 at 8:45 PM, Terry Reedy  wrote:
> On 1/23/2016 8:58 AM, Chris Angelico wrote:
>> On Sun, Jan 24, 2016 at 12:45 AM, Steven D'Aprano 
>> wrote:
>>> [steve@ando ~]$ python -c "for i in range(5):

  print 'hello world'
 "
>>>
>>> hello world
>>> hello world
>>> hello world
>>> hello world
>>> hello world
>>> [steve@ando ~]$
>>
>> Well, not everyone's shells are as awesome as bash...
>
> Like Windows command prompt is not.  I tried:
>
> C:\Users\Terry>python -c "for i in range(5):\n\tprint('hello world')"
>   File "", line 1
> for i in range(5):\n  print('hello world')
>  ^
> SyntaxError: unexpected character after line continuation character

cmd's parsing can be inscrutably finicky and limited, but luckily
enough this example works:

C:\>py -2 -c ^
More? "def f(n):^
More?
More? for i in range(n):^
More?
More? print 'hello world'^
More?
More? f(5)
hello world
hello world
hello world
hello world
hello world

cmd prints the "More?" prompt when a line is continued. Note that it's
necessary to hit enter again after escaping the first enter. Also, as
is usual with cmd, the closing double quote is optional, so I omitted
it after f(5).
-- 
https://mail.python.org/mailman/listinfo/python-list


Attribute path not in PurePosixPath ?

2016-01-24 Thread Vincent Vande Vyvre

Hi,

Refering to the doc 
https://docs.python.org/3/library/pathlib.html?highlight=pathlib#pathlib.PurePath.path



Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import PurePath
>>> p = PurePath('/home/vincent/Images')
>>> p.name
'Images'
>>> p.suffix
''
>>> p.parent
PurePosixPath('/home/vincent')
>>> [parent for parent in p.parents]
[PurePosixPath('/home/vincent'), PurePosixPath('/home'), PurePosixPath('/')]
>>> p.path
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'PurePosixPath' object has no attribute 'path'


Am I misunderstood the doc ?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Attribute path not in PurePosixPath ?

2016-01-24 Thread Vincent Vande Vyvre

Le 24/01/2016 08:58, Vincent Vande Vyvre a écrit :

Hi,

Refering to the doc 
https://docs.python.org/3/library/pathlib.html?highlight=pathlib#pathlib.PurePath.path


 


Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pathlib import PurePath
>>> p = PurePath('/home/vincent/Images')
>>> p.name
'Images'
>>> p.suffix
''
>>> p.parent
PurePosixPath('/home/vincent')
>>> [parent for parent in p.parents]
[PurePosixPath('/home/vincent'), PurePosixPath('/home'), 
PurePosixPath('/')]

>>> p.path
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'PurePosixPath' object has no attribute 'path'
 



Am I misunderstood the doc ?



OOps, is new in 3.4.5

Sorry for the noise.

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


Re: pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with "Permission denied" error (Python 2.7.11 on Win XP SP3);

2016-01-24 Thread Chris Angelico
On Sun, Jan 24, 2016 at 8:12 PM, Steve Petrie, P.Eng.
 wrote:
> I know what "upstream" means, in terms of: water flow in a river, or vehicle
> flow on a highway, or data flow over a comms link. "upstream" is where a
> moving particle was, earlier in time
>
> But my puzzlement is -- where is "upstream" in relation to an email forum,
> in the context of a thread?
>
> The fix for the mitmdump bang line bug was applied to file
> mitmdump-script.py, and according to its "Date Modified" field on my Win XP,
> this file arrived in the e:\a p p s\Python27\Scripts\ directory, when I
> installed mitmproxy. So it looks to me like file mitmdump-script.py is a
> product of the mitmproxy project.
>
> Am I correct in assuming, that "upstream" in the context of this present
> thread, means I should report the bang line bug to an mitmproxy forum?

"Upstream" normally refers to a flow of software, rather than of
discussions, but your conclusion is correct: upstream would be the
source of the software you're working with, so in this case, somewhere
specific to mitmproxy.

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


Re: Calculating longitudinal acceleration, lateral acceleration and normal acceleration

2016-01-24 Thread Grant Edwards
On 2016-01-24, Robert James Liguori  wrote:

> Is there a python library to calculate longitudinal acceleration,
> lateral acceleration and normal acceleration?

Yes.

> Thanks.

You're Welcome.


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


Re: pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with "Permission denied" error (Python 2.7.11 on Win XP SP3);

2016-01-24 Thread Steve Petrie, P.Eng.

Chris,

Thanks for your response -- much appreciated.

Please see my remarks embedded below.

- Original Message - 
From: "Chris Angelico" 

To: "Steve Petrie, P.Eng." 
Cc: 
Sent: Saturday, January 23, 2016 10:14 AM
Subject: Re: pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with 
"Permission denied" error (Python 2.7.11 on Win XP SP3);




On Fri, Jan 22, 2016 at 3:40 AM, Steve Petrie, P.Eng.
 wrote:
In both failure cases, it looks to me like there is a bug in the pip 
logic,
that is using a *nix forward slash "/" instead of a double backslash 
"\\"

before the file name "make.bat".


I'm not sure what your exact problem is, but I can say that it isn't
this; the Unix-style forward slash is perfectly legal under Windows
(and it's even legal to mix and match).

ChrisA


I never knew that the forward slash is legal under Windows -- thanks for 
the tip :)


After further research, I got mitmproxy installed under Windows XP. Now 
mitmdump starts ok (with one "warning").


* * *
* * *

In case other Windows XP "orphans" want to use mitmdump, here's what I 
learned (via Google):


1. There was a bug in pip-8.0.0 (bug fixed recently in pip-8.0.2) that 
caused the "Permission denied" error:


I did another upgrade of pip, and this time the upgrade installed 
pip-8.0.2 (instead of pip-8.0.0).


And pip-8.0.2 successfully installed mitmproxy.

2. But then mitmdump wouldn't start (can't use mitmproxy under 
Windows -- there's no GUI port):


  C:\Documents and Settings\SteveP>mitmdump --help
  failed to create process.

This "failed to create process" problem, was caused by whitespace, in 
the pathname to the python directory, in the bang line in file 
mitmdump-script.py:


I changed the bang line (wrapping the pathname in double quotes) in file 
mitmdump-script.py:


  from: #!e:\a p p s\python27\python.exe
 to: #!"e:\a p p s\python27\python.exe"

and now mitmdump starts ok with one warning:

  C:\Documents and Settings\SteveP>mitmdump --help
  e:\a p p 
s\python27\lib\site-packages\watchdog\observers\__init__.py:89: 
UserWarning: Failed to import read_directory_changes. Fall back to 
polling.
warnings.warn("Failed to import read_directory_changes. Fall back 
to polling.")

  usage: mitmdump-script.py [options] [filter]
  ...

I tried to fix the warning, but so far no success (due to my Python 
ignorance).


However, mitmdump does start (with the same warning) and it creates an 
empty output file:


  C:\Documents and Settings\SteveP>mitmdump -w mitmdump_20160123.txt
  e:\a p p 
s\python27\lib\site-packages\watchdog\observers\__init__.py:89: 
UserWarning: Failed to import read_directory_changes. Fall back to 
polling.
warnings.warn("Failed to import read_directory_changes. Fall back 
to polling.")


I haven't yet got mitmdump to actually write anything to the output 
file, but I expect that's just a matter of studying the mitmdump docs.


* * *
* * *

Thanks again for the response.

Best Regards,

Steve

P.S. Be assured -- I will soon be moving away from Windows XP to a new 
computer running Debian Linux.



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


Re: pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with "Permission denied" error (Python 2.7.11 on Win XP SP3);

2016-01-24 Thread Steve Petrie, P.Eng.
- Original Message - 
From: "Chris Angelico" 

To: "Steve Petrie, P.Eng." 
Cc: 
Sent: Saturday, January 23, 2016 2:56 PM
Subject: Re: pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with 
"Permission denied" error (Python 2.7.11 on Win XP SP3);



In case other Windows XP "orphans" want to use mitmdump, here's what 
I

learned (via Google):

I changed the bang line (wrapping the pathname in double quotes) in 
file

mitmdump-script.py:

  from: #!e:\a p p s\python27\python.exe
 to: #!"e:\a p p s\python27\python.exe"


Spaces in names are often a pain. I'd raise this upstream as a bug
report - it should be fixed properly rather than depending on manual
editing.



I'd like to raise the bug report you suggest, but I'm not clear on the 
meaning of the word "upstream" in relation to Python-list. (I've seen 
"upstream" used by participants in another forum 
 and always wondered what "upstream" meant 
there.)


I know what "upstream" means, in terms of: water flow in a river, or 
vehicle flow on a highway, or data flow over a comms link. "upstream" is 
where a moving particle was, earlier in time


But my puzzlement is -- where is "upstream" in relation to an email 
forum, in the context of a thread?


The fix for the mitmdump bang line bug was applied to file 
mitmdump-script.py, and according to its "Date Modified" field on my Win 
XP, this file arrived in the e:\a p p s\Python27\Scripts\ directory, 
when I installed mitmproxy. So it looks to me like file 
mitmdump-script.py is a product of the mitmproxy project.


Am I correct in assuming, that "upstream" in the context of this present 
thread, means I should report the bang line bug to an mitmproxy forum?


Steve

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


Re: Calculating longitudinal acceleration, lateral acceleration and normal acceleration

2016-01-24 Thread Pete Dowdell

On 24/01/16 07:27, Robert James Liguori wrote:

Is there a python library to calculate longitudinal acceleration, lateral 
acceleration and normal acceleration?


Might be rocket science...

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


Please Unsubscribe

2016-01-24 Thread Dave Tan

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


.format won't display my value with 2 decimal places: Why?

2016-01-24 Thread Michael Sullivan
Hi.  I'm very very new to python.  I have been working my way through a 
free python pdf file I found (python3handson.pdf) and I'm having trouble 
with one of my programs:



'''discount.py

Exercise 1.14.3.1. * Write a program, discount.py, that prompts the user 
for an original price and
for a discount percentage and prints out the new price to the nearest 
cent. For example if the user enters
2.89 for the price and 20 for the discount percentage, the value would 
be (1- 20/100)*2.89, rounded to two
decimal places, 2.31. For price .65 with a 25 percent discount, the 
value would be (1- 25/100)*.65, rounded
to two decimal places, .49. 10 Write the general calculation code 
following the pattern of the calculations

illustrated in the two concrete examples.

'''

oPrice = 0
newPrice = 0
discount = 0

oPrice = input('What is the original price?  ')
discount = input('How much is this item discounted?  ')

oPrice = float(oPrice)
discount = float(discount)
newPrice = oPrice - (oPrice * discount)

print('The new price is {}' .format(newPrice, '.2f'))


When I run this thing, and I enter 5.00 for original price and .2 for 
the discount, it always results in 4.0.  When I entered my format 
function call directly into the shell, it comes out like I would expect:




>>> format(4.0, '.2f')
'4.00'


What exactly am I doing wrong here?
--
https://mail.python.org/mailman/listinfo/python-list


Re: .format won't display my value with 2 decimal places: Why?

2016-01-24 Thread MRAB

On 2016-01-22 04:57:03, "Michael Sullivan"  wrote:

Hi.  I'm very very new to python.  I have been working my way through a 
free python pdf file I found (python3handson.pdf) and I'm having 
trouble with one of my programs:



'''discount.py

Exercise 1.14.3.1. * Write a program, discount.py, that prompts the 
user for an original price and
for a discount percentage and prints out the new price to the nearest 
cent. For example if the user enters
2.89 for the price and 20 for the discount percentage, the value would 
be (1- 20/100)*2.89, rounded to two
decimal places, 2.31. For price .65 with a 25 percent discount, the 
value would be (1- 25/100)*.65, rounded
to two decimal places, .49. 10 Write the general calculation code 
following the pattern of the calculations

illustrated in the two concrete examples.

'''

oPrice = 0
newPrice = 0
discount = 0

oPrice = input('What is the original price?  ')
discount = input('How much is this item discounted?  ')

oPrice = float(oPrice)
discount = float(discount)
newPrice = oPrice - (oPrice * discount)

print('The new price is {}' .format(newPrice, '.2f'))


When I run this thing, and I enter 5.00 for original price and .2 for 
the discount, it always results in 4.0.  When I entered my format 
function call directly into the shell, it comes out like I would 
expect:




>>> format(4.0, '.2f')
'4.00'


What exactly am I doing wrong here?

You're confusing the builtin 'format' function with the 'format' method 
of the 'str' class.


The format function accepts a value and a format:

>>> format(4.0, '.2f')
'4.00'
The format method, on the other hand, belongs to the format string it's 
attached to. In this example:


'The new price is {}' .format(newPrice, '.2f')

the format string is 'The new price is {}' and you're calling its 
'format' method with 2 values for that string, the first being 4.0 
(used) and the second on being '.2f' (unused).


What you want is:

print('The new price is {:.2f}'.format(newPrice))

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


Re: pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with "Permission denied" error (Python 2.7.11 on Win XP SP3);

2016-01-24 Thread Larry Hudson via Python-list

On 01/23/2016 11:43 AM, Steve Petrie, P.Eng. wrote:
[snip]

I'm not sure what your exact problem is, but I can say that it isn't
this; the Unix-style forward slash is perfectly legal under Windows
(and it's even legal to mix and match).

ChrisA


I never knew that the forward slash is legal under Windows -- thanks for the 
tip :)


A minor clarification...

If the path string is typed directly into Windows where it is parsed by (whatever is the current 
equivalent of) command.com, forward slashes are NOT accepted.  Because there it is used to 
indicate command-line options.


But if this string comes from a program where it is parsed by an API, it IS accepted.  And this 
has been the case even since MSDOS prior to Windows.


 -=- Larry -=-

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


Re: pip install mitmproxy - fails on watchdog-0.8.3.tar.gz with "Permission denied" error (Python 2.7.11 on Win XP SP3);

2016-01-24 Thread Terry Reedy

On 1/24/2016 5:35 PM, Larry Hudson via Python-list wrote:


If the path string is typed directly into Windows where it is parsed by
(whatever is the current equivalent of) command.com, forward slashes are
NOT accepted.


More specifically, / is not accepted in paths to be executed. It seems 
to be generally accepted in path arguments, as in cd path, or


C:\Users\Terry>C:\programs\python35\python.exe C:/programs/python34/tem.py

--
Terry Jan Reedy

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


tkinter newbie question

2016-01-24 Thread KP
See my code below (which works). I'd like to have the 2nd window as a class in 
a separate unit. How do I code that unit and how do I call it from my first 
unit?

As always, thanks for all help!




#!/usr/bin/env python
"""
""" 
from tkinter import *
from settings import *

class window1():

def open_window2(self):
t = Toplevel(self.root)
t.title('New window')
t.geometry('262x65+200+250')
t.transient(self.root)

def setup_menu(self):
self.menubar = Menu(self.root)
self.menu1 = Menu(self.menubar, tearoff=0 ) 
self.menu1.add_command(label="Settings",   accelerator='Ctrl+S', 
command=self.open_window2)
self.menubar.add_cascade(label="Menu 1", menu=self.menu1)  
self.root.config(menu=self.menubar)

def __init__(self):
self.root = Tk()
self.root.title('Window #1')
self.setup_menu()
self.root.geometry('800x600+200+200')
#
self.root.mainloop()

if __name__ == '__main__':

w1 = window1()
-- 
https://mail.python.org/mailman/listinfo/python-list