我尝试使用virtualenvwrapper创建一个兼具python2和python3的virtualenv
每个virtualenv与python2和python3通过Homebrew我希望这将工作:
(virtualenv的名字是'double')
mkvirtualenv double -p `which python`
mkvirtualenv double -p `which python3`
Run Code Online (Sandbox Code Playgroud)
它提到了这一点
Not overwriting existing python script both/bin/python (you must use both/bin/python3.4)
Run Code Online (Sandbox Code Playgroud)
但这似乎并非如此.打字python python2.7 python3并python3.4全部启动python3.4翻译.
我写了自己的矢量类:
#! /usr/bin/env python3
class V:
"""Defines a 2D vector"""
def __init__(self,x,y):
self.x = x
self.y = y
def __add__(self,other):
newx = self.x + other.x
newy = self.y + other.y
return V(newx,newy)
def __sub__(self,other):
newx = self.x - other.x
newy = self.y - other.y
return V(newx,newy)
def __str__(self):
return "V({x},{y})".format(x=self.x,y=self.y)
Run Code Online (Sandbox Code Playgroud)
我想定义V(0,0)是一个空向量,这样就可以了:(第一种情况应该返回"Vector为空")
v = V(0,0)
u = V(1,2)
if u:
print (u)
else:
print("Vector is empty")
if v:
print(v)
else:
print("Vector is empty")
Run Code Online (Sandbox Code Playgroud)