I can't seem to utilize the addAttr method correctly. I'm using the same arguments as when I call from pymel.core but it's not giving me the same results.
I'm trying to add a custom message attribute so I can easily search for certain types of objects later. When I do it from pymel.core and include the same object reference as an argument, it works fine.
#get object reference
test_object = pm.ls(sl=1)[0]
#this one spits out an error
test_object.addAttr(longName = 'custom', attributeType = 'message')
#this one works fine
pm.addAttr(test_object, longName = 'custom', attributeType = 'message')
I keep getting this error
Error: TypeError: file line 1: addAttr() takes exactly 2 arguments (1 given)
What additional argument is it looking for when I use it this way? I am clearly missing something obvious about how methods work but I can't figure it out.
The addAttr method exposed for DG nodes in Maya PyMel has following signature.
addAttr(attr, **kwargs)
Here attr is an positional argument representing the attribute name. The kwargs can be supplied with all other relevant flags used in pm.addAttr() method. So you have to pass the attribute name as first argument.
node.addAttr('custom', attributeType='message')
Hope this will help.
from cgsociety thread
pCube.addAttr('timeBasedAttr', keyable=True, attributeType='float', min=0.0, max=1.0)
you should write :
test_object.addAttr('custom', attributeType = 'message')
Ive tried and it doesn't output error.
Related
from selenium import webdriver
import time
browser=webdriver.Edge("C:/Users/senem/Desktop/selenium/msedgedriver.exe")
browser.get("https://www.instagram.com/")
time.sleep(13)
username=webdriver.Edge.find_element_by_name("username")
password=webdriver.Edge.find_element_by_name("password")
username.send_keys("user")
password.send_keys("password")
time.sleep(10)
browser.close()
Hello to everyone. This is error message:
Traceback (most recent call last): File
"C:/Users/senem/PycharmProjects/denemefibo/instagram.py", line 8, in
username=webdriver.Edge.find_element_by_name("username") TypeError: find_element_by_name() missing 1 required positional
argument: 'name'
Can you help me about it?
Simple Explanation
When you create your browser variable and set it to webdriver.Edge, you are creating an INSTANCE of the class. Just remember that since you've created that browser, you need to use that specific browser everywhere. So you don't want to keep using webdriver.Edge
More technical explanation
This explanation is in regards to Object Oriented Programming with Python.
Behind the scenes, find_element_by_name is actually asking for two arguments (self, name). self is automatically passed when you create a new instance, in this case the instance created is browser. So when you pass in username, you are passing in the SECOND argument because self is automatically filled.
Now that we understand this, let's look at your code. You created an instance browser but you are not using it. When you attempt to use the method find_element_by_name you are using the class directly, not using the instance you made. Since you aren't using the instance, that self parameter is no longer fulfilled. So when you pass in username, it treats that as the self, and you get an error because it still needs name.
Solution
You need to replace webdriver.Edge with browser.
username=browser.find_element_by_name("username")
password=browser.find_element_by_name("password")
So I have am connecting to a contract, and that seems to work fine, I am trying to use this class: web3.personal.Personal from https://web3py.readthedocs.io/en/stable/web3.personal.html and I dont seem to understand what i am dong wrong... when i print(web3.personal.Personal) gives me back a class object but I cant seem to use any functions associated with this class, says I am missing "self" argument
contract_abi = my_abi
w3 = Web3(HTTPProvider(myurl))
myContract = w3.eth.contract(address ,abi)
ref = ref = web3.personal.Personal('web3')
print(ref) #this works
print(ref.newAccount(password='the-passphrase')) #This crashes
TypeError: newAccount() missing 1 required positional argument: 'self'
TypeError: 'property' object is not callable
It seems that web3.personal.Personal is a class, so in order to create a object you need to say ref = web3.personal.Personal()
Please note, classes are often (but not always) written with a capital letter.
I am still learning Python in Maya. I cannot get my code to work. I am trying to create a locator and parent it under my selection and then zero out the locators transforms.
import maya.cmds as cmds
sel = cmds.ls(selection = True)
loc = cmds.spaceLocator()
cmds.parent(loc, sel)
cmds.setAttr(loc, "translateX", 0)
I always get this error message:
#Error: TypeError: file <maya console> line 7: Invalid argument 1, '[u'locator6']'. Expected arguments of type ( list, )
Sometimes with a bit other code I get something like:
#There does not exist something with name 'translateX'
I know that it does work when I replace loc with the name of the locator, but I try to keep the code as universal as I can and not bound to the name of a locator.
How does the setAttr function work in Maya with variables? Maya docs and other questions at various forums could not help... :/
setAttr takes one complete attribute as its argument:
cmds.setAtt( loc + ".translateX", 0)
where loc has to be a single string. spaceLocator like most creation commands returns a list, not a single string. So the whole thing is:
sel = cmds.ls(selection = True)
loc = cmds.spaceLocator()
cmds.parent(loc, sel)
cmds.setAttr(loc[0] + ".translateX", 0)
I know you seem to be asking asking for maya cmds but I'd like to chime this in as an alternative.
In PyMel the spaceLocator function returns the created object itself. The attributes are then methods inside the object, allowing you to do the following. One reason why I love PyMel!
import pymel.core as pm
sel = pm.selected()[0]
loc = pm.spaceLocator()
pm.parent(loc, sel)
loc.translateX.set(0)
Hello I have this method called save_schedule that takes some arguments (transport_id, departure_id, etc) to be saved to the database. but when I ran the code I got this following error
newSchedule = TravelScheduleDetailRepository(self.transport_id=transport_id, self.transport_type=transport_type, self.transport_company_name=transport_company_name, self.departure_city_id=departure_city_id, self.departure_country_id=departure_country_id, self.destination_city_id=destination_city_id, self.destination_country_id=destination_country_id, self.departure_date=departure_date, self.available_seat=available_seat)
SyntaxError: keyword can't be an expression
I still can't find on how to correctly assign the arguments.
here's my code :
def save_travel_schedule(self, transport_id, transport_type, transport_company_name, departure_city_id, departure_country_id, destination_city_id, destination_country_id, departure_date, available_seat):
newSchedule = TravelScheduleDetailRepository(self.transport_id=transport_id, self.transport_type=transport_type, self.transport_company_name=transport_company_name, self.departure_city_id=departure_city_id, self.departure_country_id=departure_country_id, self.destination_city_id=destination_city_id, self.destination_country_id=destination_country_id, self.departure_date=departure_date, self.available_seat=available_seat)
session.add(newSchedule)
session.commit()
any help would be appreciated. thank you!
You got the order wrong.
self.transport_type=transport_type should be transport_type=self.tranport_type, not the other way around.
Same for all the other parameters.
The keyword arguments in the TravelScheduleDetailRepository class do not require the reference to the instance: self.
Removing self. from all the keyword arguments should fix your problem.
self is only used when you are referring to a property or method in an instance.
I am trying to use Twython to work with the Twitter API in python, and I am observing some behavior that seems odd to me.
If I run the following code...
from twython import Twython
from random import randint
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) # In the actual code, I obviously assign these, but I can't disclose them here, so the code won't work...
user_id = randint(1,250000000)
twitter_user = twitter.lookup_user(user_id)
I get this error.
Traceback (most recent call last):
File "Twitter_API_Extraction.py", line 76, in <module>
twitter_user = twitter.lookup_user(user_id) # returns a list of dictionaries with all the users requested
TypeError: lookup_user() takes exactly 1 argument (2 given)
The Twython docs indicate I only need to pass the user id or the screen name (https://twython.readthedocs.org/en/latest/api.html). Some googling suggested that this error usually mean I need to pass self as the first parameter, but I didn't quite get why.
However, if I use the following assignment instead...
twitter_user = twitter.lookup_user(user_id = randint(1,250000000))
Everything comes up roses. I can't figure out why this is, and it is a problem later in the code when I am trying to access followers using the same lookup_user function.
Any clarification on what is triggering this error and how I am bypassing it via assignment in the function call would be most appreciated!
Per the API documentation:
lookup_user(**params)
Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values passed to the user_id and/or screen_name parameters.
The ** syntax (documentation) means you need to provide named arguments (i.e. f(a=b)), in this case user_id and/or screen_name
In your first attempt you're trying to pass a positional argument (i.e. f(a)), which the function is not set up for.
The API states that lookup_user takes keyword arguments only. Keyword arguments take the form keyword=value, which is what you are doing with lookup_user(user_id=randint(1,...)). It means you cannot pass positional arguments, which is what you are doing with lookup_user(userid).