本文整理汇总了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)
示例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)
示例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))