当前位置: 首页>>代码示例>>Python>>正文


Python Car.get_brand方法代码示例

本文整理汇总了Python中car.Car.get_brand方法的典型用法代码示例。如果您正苦于以下问题:Python Car.get_brand方法的具体用法?Python Car.get_brand怎么用?Python Car.get_brand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在car.Car的用法示例。


在下文中一共展示了Car.get_brand方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import get_brand [as 别名]
''' Open the json file and load it into a variable to be used later '''
with open('5-main.json') as json_data:
    data = json.load(json_data)

all_brands = []
total_doors = 0

''' Create a DOM document '''
document = Document()
all_cars = document.createElement("all_cars")
document.appendChild(all_cars)

''' Iterate through data to format each dict '''
for i in data:
    car = Car(i)

    brand = car.get_brand()
    nb_doors = car.get_nb_doors()
    xml = car.to_xml_node(document)
    if brand not in all_brands:
        all_brands.append(brand)
    total_doors += nb_doors

    all_cars.appendChild(xml)

print len(all_brands)
print total_doors
last_car = Car(data[3])
print last_car
print document.toxml(encoding='utf-8')
开发者ID:DamianAli,项目名称:holbertonschool-higher_level_programming,代码行数:32,代码来源:5-main.py

示例2: open

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import get_brand [as 别名]
from xml.dom.minidom import Document
import json
from car import Car

'''initializations'''
filename = "5-main.json"
file_obj = open(filename)
cars_json = json.load(file_obj)
file_obj.close()
cars=[]
brands=[]
doors=0
doc = Document()
element_cars = doc.createElement('cars')

doc.appendChild(element_cars)

for car in cars_json:
    c=Car(car)
    cars.append(c)
    if not c.get_brand() in brands:
        brands.append(c.get_brand())
    doors+=c.get_nb_doors()
    c_xml = c.to_xml_node(doc)
    element_cars.appendChild(c_xml)

print len(brands)
print doors
print cars[3]
print doc.toxml(encoding='utf-8')
开发者ID:bilalbarki,项目名称:holbertonschool-higher_level_programming,代码行数:32,代码来源:5-main.py

示例3: open

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import get_brand [as 别名]
json_open = open('5-main.json')
json_data = json_open.read()
data = json.loads(json_data)
json_open.close()

doc = minidom.Document()
cars = doc.createElement('cars')
doc.appendChild(cars)

brands = []
num_brands = 0
num_doors = 0

for f in data:
    car = Car(f)
    brands.append(car.get_brand())
    num_doors = (num_doors + car.get_nb_doors())
    car_xml = car.to_xml_node(doc)
    cars.appendChild(car_xml)

i = 0
len_brands = len(brands)
while i < len_brands:
    if brands[i] != brands[i -1]:
        num_brands += 1
    i += 1

print num_brands
print num_doors
print Car(data[3])
print doc.toxml(encoding='utf-8')
开发者ID:DoraKorpar,项目名称:holbertonschool-higher_level_programming,代码行数:33,代码来源:5-main.py

示例4: open

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import get_brand [as 别名]
'''Getting the information from a json file'''
with open("5-main.json") as json_file:
    json_data = json.load(json_file)

doorsNum = 0
counter = 0
brands = []
fourth_car = ""
doc = Document()
cars = doc.createElement("Cars")
while counter < len(json_data):
    c = Car(json_data[counter])
    ''' adding number of doors castied into ints '''
    doorsNum += int(c.get_nb_doors())
    '''Adding elements to the array brands '''
    brands.append(c.get_brand())
    if counter == 3:
        fourth_car = c
    counter +=1
    '''Appending to root element cars '''
    cars.appendChild(c.to_xml_node(doc))
doc.appendChild(cars)
''' set gets rid of the duplicates'''
print len(set(brands))
print doorsNum
print fourth_car
print doc.toxml(encoding='utf-8')



开发者ID:stvngrcia,项目名称:holbertonschool-higher_level_programming,代码行数:29,代码来源:5-main.py

示例5: byteify

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import get_brand [as 别名]
fd_contents = json.loads(fd_contents)
fd_contents = byteify(fd_contents)

cars = []
doc = Document()
cars_parent = doc.createElement('cars')
doc.appendChild(cars_parent)

for i in fd_contents:
    c = Car(i)
    cars.append(c)
    car_node = c.to_xml_node(doc)

    year = doc.createElement('year')
    year_content = doc.createTextNode('2015')
    year.appendChild(year_content)
    car_node.appendChild(year)

    car_node.setAttribute('weight', "1000")

    new_brand = doc.createElement('brand')
    brand_content = doc.createCDATASection(u"\u00a9" + str(c.get_brand()))
    new_brand.appendChild(brand_content)
    old_brand = car_node.getElementsByTagName('brand')
    car_node.replaceChild(new_brand, old_brand[0])

    cars_parent.appendChild(car_node)


print doc.toxml(encoding='utf-8')
开发者ID:mason-fish,项目名称:holbertonschool-higher_level_programming,代码行数:32,代码来源:7-main.py

示例6: Document

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import get_brand [as 别名]
from xml.dom.minidom import Document
from car import Car
from json import loads

"""Setting the dom obj"""
doc = Document()
x_cars = doc.createElement('cars')
doc.appendChild(x_cars)

"""Opening the json file"""
with open('./7-main.json') as f:
    data = loads(f.read())

"""Iterating through each obj and adding them to the dom"""
for car in data:
    item = Car(car)
    c_xml = item.to_xml_node(doc)
    year = doc.createElement('year')
    year_value = doc.createTextNode('2015')
    year.appendChild(year_value)
    c_xml.appendChild(year)
    c_xml.setAttribute('weight', str(1000))
    brand = doc.createElement('brand')
    brand_value = doc.createCDATASection(u"\u00a9" + item.get_brand())
    brand.appendChild(brand_value)
    c_xml.replaceChild(brand, c_xml.getElementsByTagName('brand')[0])
    x_cars.appendChild(c_xml)

"""Printing the dom to xml"""
print doc.toxml(encoding='utf-8')
开发者ID:havk64,项目名称:holbertonschool-higher_level_programming,代码行数:32,代码来源:7-main.py

示例7: Car

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import get_brand [as 别名]
from car import Car

c = Car(name="Rogue", brand="Nissan", nb_doors=5)
print c
print c.get_brand()
print c.to_hash()
开发者ID:tasneemfarag,项目名称:holbertonschool-higher_level_programming,代码行数:8,代码来源:2-main.py

示例8: Document

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import get_brand [as 别名]
file_open.close()

'''initialize lists and variables'''
cars = []
brands = []
totalDoors = 0
doc = Document()

'''special XML stuff to create an element'''
element_cars = doc.createElement('cars')

'''special XML stuff to create a child element'''
doc.appendChild(element_cars)

'''Iterating through the json file to place
   items in the list and update the number of
   total doors'''
for item in diffCars:
    obj = Car(item)
    cars.append(obj)
    if not obj.get_brand() in brands:
        brands.append(obj.get_brand())
    totalDoors = totalDoors + obj.get_nb_doors()
    objXml = obj.to_xml_node(doc)
    element_cars.appendChild(objXml)

print len(brands)
print totalDoors
print cars[3]
print doc.toxml(encoding = 'utf-8')
开发者ID:nappybrainiac,项目名称:holbertonschool-higher_level_programming,代码行数:32,代码来源:5-main.py

示例9: open

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import get_brand [as 别名]
'''copy originial JSON file content to new JSON file'''
json_file = open("5-main.json")
file_copy = json.load(json_file)
json_file.close()

'''arrays for cars and brands'''
cars = []
brands = []

'''initialize number of car doors'''
car_doors = 0

'''prepare DOM document and create root element'''
doc = minidom.Document()
all_cars = doc.createElement('cars')
doc.appendChild(all_cars)

for each in file_copy:
    objects = Car(each)
    cars.append(objects)
    if objects.get_brand() not in brands:
        brands.append(objects.get_brand())
    car_doors += objects.get_nb_doors()
    all_cars.appendChild(objects.to_xml_node(doc))

print len(brands)
print car_doors
print cars[3]
print doc.toxml(encoding = 'utf-8')
开发者ID:WaBlueKey,项目名称:holbertonschool-higher_level_programming,代码行数:31,代码来源:5-main.py


注:本文中的car.Car.get_brand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。