私は適当な言語だと信じているimport car
を実行することによって使用したいPythonクラスを作成しました。現在、私のクラスで何かを使用できる唯一の方法は、Python3 IDEでファイル(/home/pi/Desktop/python/car.py
)を開き、実行してからクラスを使用することです。私は/usr/lib/python3.4
がそれを置くための適切な場所だろうと信じて私自身のpythonモジュールを作る
は、しかし、私はそれを試してみましたし、出力はここにある:
>>> import car
>>> my_car = car('n', 'vns', '15', '13')
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
my_car = car('n', 'vns', '15', '13')
TypeError: 'module' object is not callable
クラスコードは不要かもしれませんが、ここにある:
class car():
"""Your car."""
def __init__(self, make, model, year, fuel_capacity):
"""Atributtes of your car, fuel in gallons."""
self.make = make
self.model = model
self.year = year
self.fuel_capacity = fuel_capacity
self.fuel_level = 0
def fill_tank(self):
"""Fill up your gas."""
self.fuel_level = self.fuel_capacity
print("Fuel tank is full")
def drive(self):
"""Drive your car"""
print("The car is moving")
self.fuel_level = self.fuel_level
def specs(self):
print(self.year, self.make, self.model, self.fuel_capacity, "Gallons")
'mycar = car.car( 'n'、 'vns'、 '15'、 '13') ' – Mephy
または' from car輸入車 ' – Blorgbeard