A general idea.
Code:
local unit = "player"
local name = UnitName(unit)
local realm = GetRealmName()
print(unit, name, "from", realm)
for i=1, 4 do
unit = "party"..i
if UnitExists(unit) then
name, realm = UnitName(unit)
if not realm then
realm = GetRealmName()
end
print(unit, name, "from", realm)
end
end