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


Python Car.to_comma方法代码示例

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


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

示例1: open

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

filename = "6-main.json"
file_obj = open(filename)
cars_json = json.load(file_obj)
file_obj.close()
cars=[]
my_list = []

for car in cars_json:
    c = Car(car)
    cars.append(c)
    '''append to_comma() string to my_list variable'''
    my_list.append(c.to_comma())

print "".join(my_list)
开发者ID:bilalbarki,项目名称:holbertonschool-higher_level_programming,代码行数:20,代码来源:6-main.py

示例2: open

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

cars = []
comma_cars = []

'''Loads json data from file'''
json_file = open("6-main.json")
data = json.loads(json_file.read())

'''Creates a list of comma-separated car values'''
for car in data:
    car = Car(car)
    cars.append(car)
    comma_cars.append(car.to_comma())

'''Prints the list of cars'''
print "".join(comma_cars)
开发者ID:carabina,项目名称:holbertonschool-higher_level_programming,代码行数:20,代码来源:6-main.py

示例3: safe_load

# 需要导入模块: from car import Car [as 别名]
# 或者: from car.Car import to_comma [as 别名]
Since the project specifies our functions check for str
(utf-8) I convert the json here. Otherwise could allow
in checking. Can also use yaml safe_load() since we know
all characters will be ASCII.
'''
def byteify(input):
    if isinstance(input, dict):
        return {byteify(key): byteify(value)
                for key, value in input.iteritems()}
    elif isinstance(input, list):
        return [byteify(element) for element in input]
    elif isinstance(input, unicode):
        return input.encode('utf-8')
    else:
        return input

fd = open('6-main.json')
fd_contents = fd.read()
fd.close

fd_contents = json.loads(fd_contents)
fd_contents = byteify(fd_contents)

cars = []

for i in fd_contents:
    c = Car(i)
    cars.append(c.to_comma())

print "{0}".format("".join(cars))
开发者ID:mason-fish,项目名称:holbertonschool-higher_level_programming,代码行数:32,代码来源:6-main.py


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