0

已编辑

好的,整个目标是找到给定对象的最小纬度:

>>>g.nodes
set([v99, v192, v60, v107, v54, v75, v16, v93, v190, v125, v193, v218, v114, v1, v180, v68, v11, v86, v82, v58, v166, v230, v98, v18, v20, v72, v221, v177, v36, v19, v97, v27, v206, v153, v233, v169, v88, v53, v229, v77, v50, v34, v90, v162, v106, v89, v67, v173, v158, v123, v214, v165, v223, v199, v155, v149, v59, v138, v69, v204, v154, v91, v119, v70, v152, v61, v121, v195, v38, v17, v66, v23, v213, v45, v13, v62, v150, v137, v136, v76, v29, v64, v207, v234, v46, v113, v41, v122, v120, v83, v203, v148, v30, v33, v191, v32, v127, v131, v2, v57, None, v81, v157, v104, v226, v139, v79, v200, v100, v186, v170, v175, v109, v172, v132, v9, v160, v96, v10, v198, v52, v87, v14, v163, v51, v144, v228, v21, v215, v201, v212, v187, v135, v209, v232, v164, v126, v161, v22, v115, v6, v133, v85, v171, v12, v183, v182, v31, v42, v111, v55, v80, v35, v211, v143, v24, v95, v56, v112, v178, v231, v4, v194, v92, v124, v117, v151, v219, v146, v94, v168, v101, v220, v39, v8, v105, v44, v40, v216, v7, v208, v197, v145, v202, v185, v205, v116, v48, v222, v217, v188, v134, v47, v5, v73, v227, v108, v156, v28, v224, v210, v176, v3, v37, v74, v167, v181, v15, v159, v118, v63, v25, v102, v110, v196, v43, v174, v103, v225, v142, v179, v128, v84, v129, v147, v78, v184, v141, v140, v189, v71, v65, v130, v49, v26])
>>> v99
v99
>>> v99.latitude
46.933333
>>> type(g.nodes)
<type 'set'>
>>> type(v99)
<type 'org.gephi.scripting.wrappers.GyNode'>
>>> type(v99.latitude)
<type 'float'>

插件的文档:http ://wiki.gephi.org/index.php/Scr​​ipting_Plugin

4

3 回答 3

2

您可以使用locals()

In [1]: x = 'hello'

In [2]: y = 'worlds'

In [3]: data = set(['x', 'y'])

In [4]: for i in data:
   ...:     print locals()[i]
   ...:     
worlds
hello

但是,你最好构造一个字典,比如:

data = {'x': 'hello', 'y': 'worlds'}
于 2013-08-19T11:07:22.993 回答
2

可以使用该locals()函数查找本地名称:

for i in data:
    print locals()[i]

但你真的想重新考虑你的数据结构,也许使用字典来存储xy.

locals()将当前本地命名空间作为字典返回。您应该将此字典视为只读的,尤其是在函数中。

于 2013-08-19T11:07:05.510 回答
0

我有一个对象列表

对象的文字list,在 Python 数据结构中称为列表,看起来像这样:

objectlist = ['x', 'y']

您在代码中描述的不是对象列表,它只是几个随机不关联的对象。

但是,很明显您不是在寻找对象列表。您希望能够查找“我标记为 'x' 的对象” - 正确的数据结构是 Python 所说的 dict - 其他语言称之为映射、关联数组或哈希表。然后,您可以使用 fromdata的值在 dict 中查找相应的值。

>>> objectdict = {'x': 'hello', 'y': 'world'}
>>> data = set(['x', 'y'])
>>> for i in data:
...     print objectdict[i]
...
world
hello
>>>
于 2013-08-19T11:12:16.940 回答