getting an iterable value from intslidergrp - python

I have an intSlidergrp to make a given number of spheres, but the method I tried gives me this error: ''int' object is not iterable' so does anyone know how to make a for-loop out of the info given in the slidergrp.
def givenLights(*args):
wantedLights = cmds.intSliderGrp( sldr2, query=True,value=lights)
print wantedLights
for item in wantedLights:
cmds.polySphere(sx=5, sy=5)
win = cmds.window(title="electrical chords", widthHeight =(300,400),
topLeftCorner= (200,350))
cmds.columnLayout(adj = True, rs=(10))
lights = 0
sldr2 = cmds.intSliderGrp( field=True, value=lights,minValue=0,maxValue=100)
btn6 = cmds.button(label="Allign given lights",command=givenLights)
cmds.showWindow(win)

I found it myself
for i in range(inp):
cmds.polySphere(sx=5, sy=5)
I didn't add the range

Related

Python Json value overwritten by last value

lista =
[{Identity: joe,
summary:[
{distance: 1, time:2, status: idle},
{distance:2, time:5, status: moving}],
{unit: imperial}]
I can pull the data easily and put in pandas. The issue is, if an identity has multiple instances of, say idle, it takes the last value, instead of summing together.
my code...
zdrivershours = {}
zdistance = {}
zstophours = {}
For driver in resp:
driverid[driver['AssetID']] = driver['AssetName']
for value in [driver['SegmentSummary']]:
for value in value:
if value['SegmentType'] == 'Motion':
zdriverhours[driver['AssetID']] = round(value['Time']/3600,2)
if value['SegmentType'] == 'Stop':
zstophours[driver['AssetID']] = round(value['IdleTime']/3600,2)
zdistance[driver['AssetID']] = value['Distance']
To obtain the summatory of distance for every driver replace:
zdistance[driver['AssetID']] = value['Distance']
by
if driver['AssetID'] in zdistance:
zdistance[driver['AssetID']] = zdistance[driver['AssetID']] + value['Distance']
else:
zdistance[driver['AssetID']] = value['Distance']

Parsing Security Matrix Spreadsheet - NoneType is not Iterable

Trying to Nest no's and yes's with their respective applications and services.
That way when a request comes in for a specific zone to zone sequence, a check can be run against this logic to verify accepted requests.
I have tried calling Decision_List[Zone_Name][yes_no].update and i tried ,append when it was a list type and not a dict but there is no update method ?
Base_Sheet = range(5, sh.ncols)
Column_Rows = range(1, sh.nrows)
for colnum in Base_Sheet:
Zone_Name = sh.col_values(colnum)[0]
Zone_App_Header = {sh.col_values(4)[0]:{}}
Zone_Svc_Header = {sh.col_values(3)[0]:{}}
Zone_Proto_Header = {sh.col_values(2)[0]:{}}
Zone_DestPort_Header = {sh.col_values(1)[0]: {}}
Zone_SrcPort_Header = {sh.col_values(0)[0]: {}}
Decision_List = {Zone_Name:{}}
for rows in Column_Rows:
app_object = sh.col_values(4)[rows]
svc_object = sh.col_values(3)[rows]
proto_object = sh.col_values(3)[rows]
dst_object = sh.col_values(2)[rows]
src_object = sh.col_values(1)[rows]
yes_no = sh.col_values(colnum)[rows]
if yes_no not in Decision_List[Zone_Name]:
Decision_List[Zone_Name][yes_no] = [app_object]
else:
Decision_List[Zone_Name]=[yes_no].append(app_object)
I would like it present info as follows
Decision_List{Zone_Name:{yes:[ssh, ssl, soap], no:
[web-browsing,facebook]}}
I would still like to know why i couldnt call the append method on that specific yes_no key whos value was a list.
But in the mean time, i made a work around of sorts. I created a set as the key and gave the yes_no as the value. this will allow me to pair many no type values with the keys being a set of the application, port, service, etc.. and then i can search for yes values and create additional dicts out of them for logic.
Any better ideas out there i am all ears.
for rownum in range(0, sh.nrows):
#row_val is all the values in the row of cell.index[rownum] as determined by rownum
row_val = sh.row_values(rownum)
col_val = sh.col_values(rownum)
print rownum, col_val[0], col_val[1: CoR]
header.append({col_val[0]: col_val[1: CoR]})
print header[0]['Start Port']
dec_tree = {}
count = 1
Base_Sheet = range(5, sh.ncols)
Column_Rows = range(1, sh.nrows)
for colnum in Base_Sheet:
Zone_Name = sh.col_values(colnum)[0]
Zone_App_Header = {sh.col_values(4)[0]:{}}
Zone_Svc_Header = {sh.col_values(3)[0]:{}}
Zone_Proto_Header = {sh.col_values(2)[0]:{}}
Zone_DestPort_Header = {sh.col_values(1)[0]: {}}
Zone_SrcPort_Header = {sh.col_values(0)[0]: {}}
Decision_List = {Zone_Name:{}}
for rows in Column_Rows:
app_object = sh.col_values(4)[rows]
svc_object = sh.col_values(3)[rows]
proto_object = sh.col_values(3)[rows]
dst_object = sh.col_values(2)[rows]
src_object = sh.col_values(1)[rows]
yes_no = sh.col_values(colnum)[rows]
for rule_name in Decision_List.iterkeys():
Decision_List[Zone_Name][(app_object, svc_object, proto_object)]= yes_no
Thanks again.
I think still a better way is to use collections.defaultdict
In this manner it will ensure that i am able to append to the specific yes_no as i had originally intended.
for colnum in Base_Sheet:
Zone_Name = sh.col_values(colnum)[0]
Zone_App_Header = {sh.col_values(4)[0]:{}}
Zone_Svc_Header = {sh.col_values(3)[0]:{}}
Zone_Proto_Header = {sh.col_values(2)[0]:{}}
Zone_DestPort_Header = {sh.col_values(1)[0]: {}}
Zone_SrcPort_Header = {sh.col_values(0)[0]: {}}
Decision_List = {Zone_Name:defaultdict(list)}
for rows in Column_Rows:
app_object = sh.col_values(4)[rows]
svc_object = sh.col_values(3)[rows]
proto_object = sh.col_values(2)[rows]
dst_object = sh.col_values(1)[rows]
src_object = sh.col_values(0)[rows]
yes_no = sh.col_values(colnum)[rows]
if yes_no not in Decision_List[Zone_Name]:
Decision_List[Zone_Name][yes_no]= [app_object, svc_object, proto_object, dst_object, src_object]
else:
Decision_List[Zone_Name][yes_no].append([(app_object, svc_object, proto_object,dst_object, src_object)])
This allows me to then set the values as a set and append them as needed

Python: E1136:Value 'self.exchange.get_portfolio' is unsubscriptable

def get_portfolio(self):
contracts = settings.CONTRACTS
portfolio = {}
for symbol in contracts:
position = self.bitmex.position(symbol=symbol)
instrument = self.bitmex.instrument(symbol=symbol)
if instrument['isQuanto']:
future_type = "Quanto"
elif instrument['isInverse']:
future_type = "Inverse"
elif not instrument['isQuanto'] and not instrument['isInverse']:
future_type = "Linear"
else:
raise NotImplementedError("Unknown future type; not quanto or inverse: %s" % instrument['symbol'])
if instrument['underlyingToSettleMultiplier'] is None:
multiplier = float(instrument['multiplier']) / float(instrument['quoteToSettleMultiplier'])
else:
multiplier = float(instrument['multiplier']) / float(instrument['underlyingToSettleMultiplier'])
portfolio[symbol] = {
"currentQty": float(position['currentQty']),
"futureType": future_type,
"multiplier": multiplier,
"markPrice": float(instrument['markPrice']),
"spot": float(instrument['indicativeSettlePrice'])
}
return portfolio
qty = self.exchange.get_portfolio['currentQty']()
Does anybody know what I am doing wrong when I am calling the get_portfolio function because I keep getting this error message:
E1136:Value 'self.exchange.get_portfolio' is unsubscriptable
You have a little mistake in the call:
self.exchange.get_portfolio is a function, so you first have to call it and then you can reference the entries from the returned dict.
Oh I just saw, that you also have to insert your symbol before:
qty = self.exchange.get_portfolio()[<YOUR_SYMBOL>]['currentQty']
If you don't know the symbols, you can use the keys function which lists all the keys of your dict:
port = self.exchange.get_portfolio()
port_keys = port.keys()
qty = port[port_keys[<SOME KEY NUMBER>]]['currentQty']
You should do it as follows:
qty = self.exchange.get_portfolio()
qty = qty[qty.keys()[0]]['currentQty']
or in a single row:
qty = self.exchange.get_portfolio()[self.exchange.get_portfolio().keys()[0]]['currentQty']

Maya phone number query

I'm working on a script that needs a phone number queried from an tex field or int field for maya. I using python and I can't seem to find anything that works. Can you help?
Thanks
TED
Ok This is the mess that I came up with.
def makeTui():
if(cmds.window('window2',q=1,ex=1)):cmds.deleteUI('window2')
cmds.window('window2',menuBar=1)
cmds.formLayout('formLayout1')
cmds.text(label='Phone Number')
num = cmds.intField('textField4',width=100,height=20,changeCommand = num_callback)
cmds.text('text95',label='Service Provider')
cmds.optionMenu('optionMenu1')
cmds.menuItem(label='AT&T')
cmds.menuItem(label='Verizon')
cmds.menuItem(label='Sprint')
cmds.menuItem(label='Cricket')
cmds.menuItem(label='Tmobil')
cmds.iconTextButton('iconTextButton45',parent='formLayout1',image='render.png',command='num_callback()')
cmds.formLayout('formLayout1',e=1,attachForm=[['textField4', 'left', 100], ['text95', 'top', 30], ['optionMenu1', 'top', 30], ['optionMenu1', 'left', 100], ['iconTextButton45', 'left', 100], ['iconTextButton45', 'top', 60]])
cmds.showWindow('window2')
makeTui()
def num_callback():
print cmds.intField(num, q=True, value=True)
You want to define your callback function in the same scope as the UI items - that saves a lot of work in trying to remember the names of the widgets that you need to work on.
def create_ui():
window = cmds.window()
column = cmds.columnLayout(adj=True)
# three items arranged horizontally
row = cmds.rowLayout(nc = 3)
numfield = cmds.textFieldGrp(label = 'phone number')
cmds.text("provider")
provider = cmds.optionMenu()
for p in ('AT&T', 'Verizon', 'Sprint', 'T-Mobile'):
cmds.menuItem(label = p)
cmds.setParent("..")
# define this function here so it knows the widgets for
# the text field and the option menu
def render_button():
phoneno = cmds.textFieldGrp(numfield, q=True, text=True)
# remove any punctuation:
digits =[int(c) for c in phoneno if c.isdigit()]
providername = cmds.optionMenu(provider, q=True, v=True)
print digits, providername
cmds.iconTextButton(image='render.png', c = render_button)
cmds.showWindow(window)
Here the callback function knows the 'names' of the field for entering numbers and the optionmenu for picking providers. The actual work would go into the render_buttons() function. I used a text field, incidentally, since many people will expect to type things like 1(555)111-2222 and an intField wont' allow it.

AttributeError: Element instance has no attribute '__float__' in Python

I get this error when I run my script
AttributeError: Element instance has no attribute '__float__'
My code looks like this:
def populate():
parsedfiles = minidom.parse('C:\Users\User\Downloads\New folder\StreetTrees_ArbutusRidge.xml')
treelist = parsedfiles.getElementsByTagName('StreetTree')
for alltrees in treelist:
treeId = alltrees.getAttribute('TreeID')
neighbourhood = alltrees.getElementsByTagName('NeighbourhoodName')
commonName = alltrees.getElementsByTagName('CommonName')
diameter = alltrees.getElementsByTagName('Diameter')[0]
diameter = float(diameter)
streetNumber = alltrees.getElementsByTagName('CivicNumber')
street = alltrees.getElementsByTagName('StdStreet')
lat = 0
lon = 0
add_tree(treeId=treeId, neighbourhood=neighbourhood, commonName=commonName,
diameter=diameter, streetNumber=streetNumber, street=street, lat=0, lon=0)
I think I'm misinterpreting the diameter but I don't know how to fix it.
diameter is a DOM Element:
diameter = alltrees.getElementsByTagName('Diameter')[0]
It is not directly convertable to a float, because that's not textual data; you probably want the text contained in the element:
diameter = alltrees.getElementsByTagName('Diameter')[0]
diameter = float(diameter.firstChild.nodeValue)
Note that the W3C DOM is rather a pain to work with; you may want to look into the more Pythonic ElementTree API instead:
parsedfiles = etree.parse(r'C:\Users\User\Downloads\New folder\StreetTrees_ArbutusRidge.xml')
for alltrees in parsedfiles.findall('.//StreetTree'):
treeId = alltrees. attrib['TreeID']
neighbourhood = alltrees.findall('NeighbourhoodName')
commonName = alltrees.findall('CommonName')
diameter = float(alltrees.find('Diameter').text)
streetNumber = alltrees.findall('CivicNumber')
street = alltrees.findall('StdStreet')
add_tree(treeId=treeId, neighbourhood=neighbourhood, commonName=commonName,
diameter=diameter, streetNumber=streetNumber, street=street,
lat=0, lon=0)
where I am assuming that the various elements you are looking for are directly contained in the <StreetTree> element.

Categories

Resources