Re: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited)

2017-12-10 Thread Rustom Mody
On Sunday, December 10, 2017 at 11:15:15 AM UTC+5:30, Frank Millman wrote:
> "Rustom Mody"  wrote in message 
> 
> 
> 
> I was sending some files to some students.
> Since it was more than one, the natural choice was a tarball.
> [I believe that since it was a very tiny total space I did not compress the
> tarball… but I dont remember this part exactly]
> The point is that instead of sending a stuff.tgz or stuff.tar file I sent a 
> file
> called just stuff; ie I must have done:
> $ tar xvf stuff directory
> rather than the more normal
> $ tar xvf stuff.tar directory
> 
> I got a return mail soon enough: “Your file is corrupt; it wont open”
> (in file-roller or whatever tar-GUI the kids nowadays use)
> 
> I could have given them the answer: There are no associations in
> Linux. Just
> $ mv stuff stuff.tar
> and it will work
> As it happens I am lazy; easier to believe that my file was "wrongly" named;
> did the mv myself, and resent the now "correct" tarball; problem solved.
> 
> 
> 
> I had a similar experience a few years ago, but the recipient was not a 
> student, but a bank's IT department!
> 
> I had to send them an encrypted document, and their spec specified PGP. I 
> used GPG instead, which produces exactly the same result, but with a .gpg 
> file extension.
> 
> I was told that my file did not work. After much time trying to figure out 
> what was wrong, I spoke to one of their staff over the phone, and asked him 
> to right-click on the file, select 'rename', and change '.gpg' to '.pgp'. He 
> did so, tried again, and said 'Ah, now it works'.

Inspired by this thread, I added

alias o="xdg-open"

to my ~/.bash_aliases

And as best as I can see, now
$ o foo.png
$ o bar.mp3
$ o baz.pdf
and 
$ o http://python.org

all do the “Right Thing”

My main attraction for this is that I often end up doing evince foo.png instead 
of eog foo.png

The one thing that does not work (yet) is
$ o foo.py
starts up gedit (instead of emacs)

PS. As it happens I had figured out something for my students some years ago:
https://bitbucket.org/rustom/vit-projects/wiki/emacsasdefault

I’ll have to reread and recheckout what I wrote back then 😉
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited)

2017-12-10 Thread Chris Green
Chris Angelico  wrote:
> On Sun, Dec 10, 2017 at 12:56 PM, Steve D'Aprano
>  wrote:
> > Remember the context here: we're replying to a thread discussing somebody 
> > who
> > is running Ubuntu with a GUI desktop environment. Of course there are *some*
> > Linux systems which don't run a GUI at all, but you can't double-click on
> > files on such systems, and they aren't Ubuntu, so they aren't relevant.
> 
> Been a long time since I had an Ubuntu, but is it really the case that
> you can't install Ubuntu without a GUI? Anyhow, your first part is
> correct: without a GUI, you can't exactly double-click on a file.
> 
You'd have to install 'ubuntu server' to get an Ubuntu without a GUI,

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


Re: Save and load initialized class

2017-12-10 Thread Steve D'Aprano
On Sun, 10 Dec 2017 04:52 am, MRAB wrote:

> Try updating __dict__:
> 
>  Opts.__dict__.update(json.load(open("mybuffer")))

__dict__ is implementation, vars() is the public interface:

vars(Opts).update(json.load(open("mybuffer")))


Looks nicer too :-)




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited)

2017-12-10 Thread Thomas Jollans
On 10/12/17 07:01, Chris Angelico wrote:
> On Sun, Dec 10, 2017 at 4:52 PM, Steve D'Aprano
>  wrote:
>> On Sun, 10 Dec 2017 02:01 pm, Chris Angelico wrote:
>>
>>> On Sun, Dec 10, 2017 at 12:56 PM, Steve D'Aprano
>>>  wrote:
 Remember the context here: we're replying to a thread discussing somebody
 who is running Ubuntu with a GUI desktop environment. Of course there are
 *some* Linux systems which don't run a GUI at all, but you can't
 double-click on files on such systems, and they aren't Ubuntu, so they
 aren't relevant.
>>>
>>> Been a long time since I had an Ubuntu, but is it really the case that
>>> you can't install Ubuntu without a GUI?
>>
>> I mispoke -- I meant something like "they aren't whatever Ububtu GUI the OP
>> has installed".
>>
>> There is, apparently, headless Ubuntu, but it isn't clear to me whether they
>> install X (or Mir, Wayland or some other alternative) or not. E.g. this:
>>
>> https://www.howtoforge.com/tutorial/ubuntu-gnome-vnc-headless-server/
>>
>> seems to suggest to me that X.org is already installed, I can see X utils
>> being installed as a recommended package but I couldn't spot X being added as
>> a dependency. So my *guess* is that even headless Ubuntu server includes an X
>> server. (Or possibly Mir.)
> 
> Or that installing a VNC server automatically installs X11 or
> equivalent. That's what I'd expect, though it's entirely possible that
> a headless server still gets certain libraries installed.


Indeed, VNC pulls in X11: https://packages.ubuntu.com/xenial/vnc4server

If you're interested in what the bare-bones Ubuntu server install
contains, you can look it up here:
https://packages.ubuntu.com/xenial/ubuntu-server

In other news: in case you hadn't heard, Mir is dead. Mark Shuttleworth
killed it this summer.
-- 
https://mail.python.org/mailman/listinfo/python-list


Can't install wrapt on Windows

2017-12-10 Thread Cutter

Hi,

I have trouble installing pylint on Windows 10, Python 3.6. There's a 
problem during the installation of wrapt, which is a dependency of pylint.


Here are the contents of the commandline:


C:\WINDOWS\system32>python -m pip install pylint
Collecting pylint
  Using cached pylint-1.7.4-py2.py3-none-any.whl
Collecting colorama; sys_platform == "win32" (from pylint)
  Using cached colorama-0.3.9-py2.py3-none-any.whl
Requirement already satisfied: mccabe in 
c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from 
pylint)
Requirement already satisfied: isort>=4.2.5 in 
c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from 
pylint)
Collecting astroid>=1.5.1 (from pylint)
  Using cached astroid-1.5.3-py2.py3-none-any.whl
Requirement already satisfied: six in 
c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from 
pylint)
Requirement already satisfied: lazy-object-proxy in 
c:\users\(...)\appdata\local\programs\python\python36\lib\site-packages (from 
astroid>=1.5.1->pylint)
Collecting wrapt (from astroid>=1.5.1->pylint)
  Using cached wrapt-1.10.11.tar.gz
Installing collected packages: colorama, wrapt, astroid, pylint
  Running setup.py install for wrapt ... error
Exception:
Traceback (most recent call last):
  File 
"C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\compat\__init__.py",
 line 73, in console_to_str
return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 51: 
invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File 
"C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\basecommand.py",
 line 215, in main
status = self.run(options, args)
  File 
"C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\commands\install.py",
 line 342, in run
prefix=options.prefix_path,
  File 
"C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\req\req_set.py",
 line 784, in install
**kwargs
  File 
"C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\req\req_install.py",
 line 878, in install
spinner=spinner,
  File 
"C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\utils\__init__.py",
 line 676, in call_subprocess
line = console_to_str(proc.stdout.readline())
  File 
"C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\compat\__init__.py",
 line 75, in console_to_str
return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 51: 
invalid start byte

The same problem happens from a venv.
I have reinstalled Python 3.6.3 and 3.6.4rc1 several times, that didn't 
change anything.


Note that the installation of pylint was reported to be successful a few 
times but despite that, pylint was unusable: when I tried to use pylint 
an error message said that module wrapt.wrappers couldn't be found. 
Since the wrapt module seemed to be incorrectly installed I uninstalled 
it. I don't know how I managed to get passed the above error message a 
couple of times when installing pylint.


I would appreciate any help.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited)

2017-12-10 Thread Rick Johnson
Rustom Mody wrote:

[...]

> Whether there was nothing wrong in what I did, the "wrong-
> right" was de facto, or de jure… I will leave to more wise
> persons than myself

A file with no extension (regardless of the OS or desktop
enviroment that it was created on), is like a sealed box with
no label to indicate the contents. 

And it's not like we can just pick file up and shake
it, in a crude attempt to intuit the contents.


>>> box.shake(ms=1000, aggression=0.1, log=sys.stdout)
Hiss

"What was that?" o_O

>>> box.shake(ms=3000, aggression=0.9, log=sys.stdout)
Reeoooww!
Hi!
Hiss!

"Holy crap! O_O

"Grandma must have gift-wrapped the cat again!"


Granted, the label could be an outright lie or mistake.
However, we can safely assume that outright lies, mistakes,
and even gift-wrapped cats, will be the minority. The vast
majority of file extensions we encounter will be truthful
reflections of the contents.

Unless we're paranoid, of course. 

But that's another issue entirely...

Our DEs can deal with lies and mismarked labels on a case by
case basis.

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


Processing Game Help

2017-12-10 Thread Lauren Porter
Hello all! I've been trying to create a game in Python Processing where a 
spaceship moves horizontally in order to miss a collision with an asteroid. I'm 
having difficulty making it so that the game quits when an asteroid hits the 
spaceship, could anybody help? Here is my code. As you can see, I tried using 
globals in order use variables from previous classes, but nothing has worked. 
For this specific approach, no error message popped up, but nothing happened 
either. Thanks so much!

COLORS = {"black":"#00", "white":"#FF",
  "red":"#FF", "green":"#00FF00",
  "blue":"#D1F5FF", "yellow":"#00",
  "orange":"#FFA500", "hendrixorange":"#F58025",
  "purple":"#9B30FF", "gray":"#808080", "lightgray": "#CACACA",
  "darkgray":"#A9A9A9"}
import random
asteroid = []
spaceship = []
stars = []
justPressed = False
aX = 0
aY = 0
x = 0
y = 0

def setup():
global aX, aY, X, Y
size(640, 480)
for s in range(1):
X = 320
Y = 440
spaceship.append(Space(X, Y, COLORS["orange"]))
for a in range(4):
aX = random.randint(0, 640)
aY = 0
asteroid.append(Asteroid(aX, aY, COLORS["orange"]))
for d in range(100):
randX = random.randint(0, 640)
randY = random.randint(0, 480)
stars.append(Star(randX, randY, COLORS["orange"]))



class Space:
def __init__(self, x, y, color):
self.x = x
self.y = y
self.color = color   

def spaceship(self):
fill(COLORS["blue"])
stroke(COLORS["white"])
ellipse(self.x, self.y, 75, 75) #body
fill(COLORS["green"])
fill(COLORS["gray"])
stroke(COLORS["green"])
ellipse(self.x, self.y + 20, 120, 35)
stroke(COLORS["orange"])
fill(COLORS["purple"])
ellipse(self.x, self.y + 20, 10, 10)
ellipse(self.x + 30, self.y + 20, 10, 10)
ellipse(self.x - 30, self.y + 20, 10, 10)

def move(self, dx, dy):
self.x += dx
self.y += dy

class Asteroid:
def __init__(self, x, y, color):
self.x = x
self.y = y
self.color = color

def update(self):
self.velx = 0
self.vely = random.randint(1, 5)
self.x += self.velx
self.y += self.vely
if self.y > 480:
self.y = 0
self.x = random.randint(1,640)

def asteroid(self):
fill(COLORS["lightgray"])
stroke(COLORS["white"])
ellipse(self.x, self.y, 50, 50)
fill(COLORS["gray"])
ellipse(self.x +15, self.y + 6, 15, 15)
ellipse(self.x -12, self.y + 7, 10, 10)
ellipse(self.x + 5, self.y - 13, 11, 11)
ellipse(self.x - 12, self.y - 9, 7, 7)
ellipse(self.x + 2, self.y + 18, 7, 7)

class Star:
def __init__(self, x, y, color):
self.x = x
self.y = y
self.color = color   

def star(self):
fill(COLORS["white"])
ellipse(self.x, self.y, 3, 3)


def draw():
global justPressed
background(COLORS["black"])
for f in stars:
f.star()
for f in spaceship:
f.spaceship()
if f.x < 60:
f.move(3, 0)
elif f.x > 580:
f.move(-3, 0)
elif justPressed :
if key == 'd':
f.move(3, 0)
elif key == 'a':
f.move(-3, 0)
for f in asteroid:
f.asteroid() 
f.update()
#collision detection 'for' loop
distance = sqrt(((aX - X)**2) + ((aY - Y)**2))
for f in asteroid:
if distance < 62.5:
background(COLORS["red"])


def keyTyped():
global justPressed
justPressed = True
print("typed", key)

def keyPressed():
global justPressed
justPressed = True
print("pressed", key)

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


Re: Save and load initialized class

2017-12-10 Thread Bob van der Poel
Yes, all cool. But,

   json.dump(Opts.__dict__, open("mybuffer", "w"))

still doesn't work with python3. Returns "is not JSON serializable"

On Sun, Dec 10, 2017 at 4:00 AM, Steve D'Aprano 
wrote:

> On Sun, 10 Dec 2017 04:52 am, MRAB wrote:
>
> > Try updating __dict__:
> >
> >  Opts.__dict__.update(json.load(open("mybuffer")))
>
> __dict__ is implementation, vars() is the public interface:
>
> vars(Opts).update(json.load(open("mybuffer")))
>
>
> Looks nicer too :-)
>
>
>
>
> --
> Steve
> “Cheer up,” they said, “things could be worse.” So I cheered up, and sure
> enough, things got worse.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 

 Listen to my FREE CD at http://www.mellowood.ca/music/cedars 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: [email protected]
WWW:   http://www.mellowood.ca
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited)

2017-12-10 Thread Chris Angelico
On Mon, Dec 11, 2017 at 10:10 AM, Rick Johnson
 wrote:
> Rustom Mody wrote:
>
> [...]
>
>> Whether there was nothing wrong in what I did, the "wrong-
>> right" was de facto, or de jure… I will leave to more wise
>> persons than myself
>
> A file with no extension (regardless of the OS or desktop
> enviroment that it was created on), is like a sealed box with
> no label to indicate the contents.
>
> And it's not like we can just pick file up and shake
> it, in a crude attempt to intuit the contents.

No, but fortunately we have magic. And magic can tell us a lot about
what a file contains.

man 5 magic

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


Re: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited)

2017-12-10 Thread Steve D'Aprano
On Mon, 11 Dec 2017 11:29 am, Chris Angelico wrote:

> On Mon, Dec 11, 2017 at 10:10 AM, Rick Johnson
>  wrote:

>> And it's not like we can just pick file up and shake
>> it, in a crude attempt to intuit the contents.
> 
> No, but fortunately we have magic. And magic can tell us a lot about
> what a file contains.
> 
> man 5 magic

https://pypi.python.org/pypi/python-magic



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: Please tell me how to execute python file in Ubuntu by double clicking on file. (Posting On Python-List Prohibited)

2017-12-10 Thread Chris Angelico
On Mon, Dec 11, 2017 at 2:35 PM, Steve D'Aprano
 wrote:
> On Mon, 11 Dec 2017 11:29 am, Chris Angelico wrote:
>
>> On Mon, Dec 11, 2017 at 10:10 AM, Rick Johnson
>>  wrote:
>
>>> And it's not like we can just pick file up and shake
>>> it, in a crude attempt to intuit the contents.
>>
>> No, but fortunately we have magic. And magic can tell us a lot about
>> what a file contains.
>>
>> man 5 magic
>
> https://pypi.python.org/pypi/python-magic
>

Yep, that's an interface to the same magic I'm talking about. Wands,
scrolls, incantations, they're all just front ends to libmagic.

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


Re: Processing Game Help

2017-12-10 Thread Bill

Lauren Porter wrote:

Hello all! I've been trying to create a game in Python Processing where a 
spaceship moves horizontally in order to miss a collision with an asteroid. I'm 
having difficulty making it so that the game quits when an asteroid hits the 
spaceship, could anybody help? Here is my code.


The code looks rather "naked" with any sort of documentation.
Do you want to ask us to figure out how it is supposed to work in order 
to help you?
My debugging suggestion is "print, print, print!" so you can follow what 
your code is doing.
I find that the sooner I start doing that, the sooner my debugging 
session is over.  Good luck!


Bill


As you can see, I tried using globals in order use variables from previous 
classes, but nothing has worked. For this specific approach, no error message 
popped up, but nothing happened either. Thanks so much!

COLORS = {"black":"#00", "white":"#FF",
   "red":"#FF", "green":"#00FF00",
   "blue":"#D1F5FF", "yellow":"#00",
   "orange":"#FFA500", "hendrixorange":"#F58025",
   "purple":"#9B30FF", "gray":"#808080", "lightgray": "#CACACA",
   "darkgray":"#A9A9A9"}
import random
asteroid = []
spaceship = []
stars = []
justPressed = False
aX = 0
aY = 0
x = 0
y = 0

def setup():
 global aX, aY, X, Y
 size(640, 480)
 for s in range(1):
 X = 320
 Y = 440
 spaceship.append(Space(X, Y, COLORS["orange"]))
 for a in range(4):
 aX = random.randint(0, 640)
 aY = 0
 asteroid.append(Asteroid(aX, aY, COLORS["orange"]))
 for d in range(100):
 randX = random.randint(0, 640)
 randY = random.randint(0, 480)
 stars.append(Star(randX, randY, COLORS["orange"]))



class Space:
 def __init__(self, x, y, color):
 self.x = x
 self.y = y
 self.color = color

 def spaceship(self):
 fill(COLORS["blue"])
 stroke(COLORS["white"])
 ellipse(self.x, self.y, 75, 75) #body
 fill(COLORS["green"])
 fill(COLORS["gray"])
 stroke(COLORS["green"])
 ellipse(self.x, self.y + 20, 120, 35)
 stroke(COLORS["orange"])
 fill(COLORS["purple"])
 ellipse(self.x, self.y + 20, 10, 10)
 ellipse(self.x + 30, self.y + 20, 10, 10)
 ellipse(self.x - 30, self.y + 20, 10, 10)
 
 def move(self, dx, dy):

 self.x += dx
 self.y += dy

class Asteroid:
 def __init__(self, x, y, color):
 self.x = x
 self.y = y
 self.color = color
 
 def update(self):

 self.velx = 0
 self.vely = random.randint(1, 5)
 self.x += self.velx
 self.y += self.vely
 if self.y > 480:
 self.y = 0
 self.x = random.randint(1,640)
 
 def asteroid(self):

 fill(COLORS["lightgray"])
 stroke(COLORS["white"])
 ellipse(self.x, self.y, 50, 50)
 fill(COLORS["gray"])
 ellipse(self.x +15, self.y + 6, 15, 15)
 ellipse(self.x -12, self.y + 7, 10, 10)
 ellipse(self.x + 5, self.y - 13, 11, 11)
 ellipse(self.x - 12, self.y - 9, 7, 7)
 ellipse(self.x + 2, self.y + 18, 7, 7)
 
class Star:

 def __init__(self, x, y, color):
 self.x = x
 self.y = y
 self.color = color

 def star(self):
 fill(COLORS["white"])
 ellipse(self.x, self.y, 3, 3)


def draw():
 global justPressed
 background(COLORS["black"])
 for f in stars:
 f.star()
 for f in spaceship:
 f.spaceship()
 if f.x < 60:
 f.move(3, 0)
 elif f.x > 580:
 f.move(-3, 0)
 elif justPressed :
 if key == 'd':
 f.move(3, 0)
 elif key == 'a':
 f.move(-3, 0)
 for f in asteroid:
 f.asteroid()
 f.update()
 #collision detection 'for' loop
 distance = sqrt(((aX - X)**2) + ((aY - Y)**2))
 for f in asteroid:
 if distance < 62.5:
 background(COLORS["red"])
 
 
def keyTyped():

 global justPressed
 justPressed = True
 print("typed", key)
 
def keyPressed():

 global justPressed
 justPressed = True
 print("pressed", key)



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


Re: Can't install wrapt on Windows

2017-12-10 Thread dieter
Cutter  writes:
> ...
> I have trouble installing pylint on Windows 10, Python 3.6. There's a
> problem during the installation of wrapt, which is a dependency of
> pylint.
>
> Here are the contents of the commandline:
>
>> C:\WINDOWS\system32>python -m pip install pylint
>> ...
>> Collecting wrapt (from astroid>=1.5.1->pylint)
>>   Using cached wrapt-1.10.11.tar.gz
>> Installing collected packages: colorama, wrapt, astroid, pylint
>>   Running setup.py install for wrapt ... error
>> Exception:
>> Traceback (most recent call last):
>>   File 
>> "C:\Users\(...)\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\compat\__init__.py",
>>  line 73, in console_to_str
>> return s.decode(sys.__stdout__.encoding)
>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 51: 
>> invalid start byte

Obviously, something causes some "s" to be decoded using the
"stdout" encoding (which usually is the system encoding).
In your case, this encoding is "utf-8", but "s" does not seem to
be utf-8 encoded.

I would use debugging to find out what "s" is, where is comes from
and why it does not use the "stdout" encoding.

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