0

Edited

Alright the whole aim is to find the min latitude in the given objects:

>>>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'>

The plugin's documentation: http://wiki.gephi.org/index.php/Scripting_Plugin

3 Answers 3

2

You can use the locals() function to look up local names:

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

but you really want to rethink your data structure instead and perhaps use a dictionary to store x and y.

locals() returns the current local namespace as a dictionary. You should treat this dictionary as read-only, especially within functions.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your suggestion, however I am working on a ready plug in that has some deficiencies in its API.
@DDL449: External APIs do not set local names.
@DDL449 You didn't mention that you were working on "a ready plug in that has some deficiencies in its API.". If you reword your question to tell us more detail about the problem you're trying to solve we might be able to give an answer that better fits your problem.
@DDL449: You may want to update your question with additional information; perhaps we can suggest better solutions for what you are trying to achieve here.
2

You can use 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

But, you'd better construct a dictionary, smth like:

data = {'x': 'hello', 'y': 'worlds'}

Comments

0

I have a list of objects

A literal list of objects, in the since of the Python data structure called a list, would look like this:

objectlist = ['x', 'y']

What you've described in your code is not a list of objects, it's just several random unassociated objects.

However, it's pretty clear that you aren't after a list of objects. You want to be able to look up "the object I have labelled 'x'" - the right data structure for that is what Python calls a dict - what other languages call a mapping, or an associative array, or a hash table. You can then use the values from data to look up the corresponding values in the dict.

>>> objectdict = {'x': 'hello', 'y': 'world'}
>>> data = set(['x', 'y'])
>>> for i in data:
...     print objectdict[i]
...
world
hello
>>>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.