我有一个特定的格式,我想将元组转储到YAML文件中。我尝试运行以下代码将元组转储到YAML文件中。在下面的代码中,我尝试使用append()将一对元组(x,y)添加到列表中。在此之后,我会将列表转储回YAML文件。我的问题是,当我转储回YAML文件时,是否可以保持文件的特定格式不变? import ruamel.yaml
def addObstacles():
yaml = ruamel.yaml.YAML()
with open('input.yaml') as f:
doc = yaml.load(f)
x = 5
y
编辑:下面是当前的问题:
Traceback (most recent call last): File "figure.py", line 32, in <module> import Python2
File "C:\scripts\python2.py", line 12, in <module> shp = shape.Python1(self.size, self.length, self.breadth,self.height)
NameError: name 'self' is not defined
我有一个tcl驱动程序脚本,它反过来调用其他几个程序。我想从我的tcl脚本中调用一个python脚本。假设这是我的python脚本"1.py“
#!/usr/bin/python2.4
import os
import sys
try:
fi = open('sample_+_file', 'w')
except IOError:
print 'Can\'t open file for writing.'
sys.exit(0)
tcl脚本是"1.tcl“
#! /usr/bin/tclsh
pro
我必须对python1和python2进行归档。
Python2.py的代码类似于:
import sys
variable1=value1
variable2=value2
#and some python code from here on
python1脚本应该接受variable1和variable2的输入值,并在不篡改其他代码的情况下更改python2.py中的相应值。
示例2:如果任何用户给出android的variable1值。python2中variable1的值需要修改为android
谢谢
注意: python2不是一个配置文件,它有许多其它模块
我一直在iPython中收到这个(众所周知的)错误。然而,同样的导入在普通的Python中工作得很好。(Python 3.3.5,详情见下文)
iPython:
Python 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 10:37:12) [MSC v.1600 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.
IPython 2.0.0 -- An enhanced Interactive Pyth