#apache #archlinux #asterisk #centos #debian #gentoo #haskell #kde #kubuntu #lisp #math #mysql #perl #python #ruby-lang #rubyonrails #suse #ubuntu #vim #wikipedia 0 1 2 3 4 5 6 7 8 9
Top Prev 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 Next
#python
<T`> so i have to change every line of code which is referencing thes vars for some testing
<T`> Leeds, see what i mean?
<Leeds> T`: sort of... better to fix your code though, I think
<T`> Leeds, no its for testing
<T`> i want to test some form validation code.. i dunno if i want to change to **data format
<T`> if i do, i will change ofcourse :)
<T`> Leeds, mind telling me how i can do that?
<Leeds> eval() or globals/locals
<Leeds> do not attempt to use that sort of thing in production code
<masterdriverz> can't you use self.dict.update(kwargs)?
<masterdriverz> self.__dict__.update(kwargs) even
<Leeds> in general, it's just stuff which shouldn't be done
<T`> as i said this is for a few secs of testing
<T`> just dont feel like editing all that code and then switching back
<T`> why is it called kwargs anyway.. hmm
<T`> keyword args?
<Leeds> yes
<Leeds> foo(fish=1, frog=None, dog="man")
<Leeds> kwargs gives you {'fish':1,'frog':None,'dog':'man'}
<T`> yup.. thanks
<T`> turns out i do want **data in my func..
<T`> because otherwise it complains about missing number of args
<T`> is there a way forargs to be coming up as undefined instead of complaining that numbrer of args isn't right by python for functions defined as func(self, arg1, arg2, arg3, arg4) ?
<masterdriverz> can someone point me to the doc where it describes the functions a class needs for various operands?
<masterdriverz> T`: you mean *args?
<Leeds> that's what keyword args are for
<T`> if someone caled it as func(arg1, arg2) for example, i want arg3, arg4 to just come up as None instead of throwing exceptouin by python
<VladDrac> python doesn't have anything like undefined
<Leeds> masterdriverz: somewhere around http://docs.python.org/ref/customization.html
<VladDrac> but you can make them optional
<VladDrac> func(arg1, arg2, arg3=None)
<T`> oh ok.. but its weird.. i have this other function which is of format function(arg1, arg2, arg3=None)
<T`> and they have it working..
<masterdriverz> Leeds: that looks like it, thanks
<T`> VladDrac, oh! that makes arg3 optional right?
<T`> only arg3 i mean.. not arg1, arg2
<VladDrac> well if unspecified, arg3 will be None
<VladDrac> and you can check arg3 for being none and handle accordingly
<VladDrac> though func(arg1, arg2, arg3="default string") will work equally well, giving arg3 a default string value
<Leeds> it makes it option for the caller... but it'll always be set in the functions
<T`> yea.. i thought somehow arg1, and arg2 also get None if you specify none is the last arg
<T`> because this example i see it "seems" to happen so, i must be mistaken somewhere though
<VladDrac> no, you can make them all optional, func(arg1=None, arg2=None, arg3=None)
<VladDrac> though you might want to look into something like func(*args) then
<Leeds> hmm... my English is suffering... too much chatting to non-native speakers :-|
<VladDrac> positional parameters will be passed as a list of arguments in 'args' and you can decide in the function itself how to handle
<T`> VladDrac, but i'm confused on why i need *args, and also **kwargs??
<kbrooks> hello - i have a question :P
<T`> whats the difference in usage?
<T`> Leeds, heh
Previous Page Next Page