Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

31 Mar 2015

PyCharm is awesome

So rigging guys, I started to use pycharm at Digic one year ago. Thanks Boris to mention me! This program easily awesome! I can not get enough of it! I can just really suggest for every rigging and developer guys. The best IDE for python programming that I've ever seen.

Official web

8 Nov 2012

Python 'super()' function bug

I have a diamond inheritance and used super() function to avoid issues.

# TypeError: super(type, obj): obj must be an instance or subtype of type #
I got this error message. I've seeked for solutions for this problem.
First you could try to reorder the importing. Sometimes it helps but not in every case. There is still the issue probably you have too many reload in baseclasses. Remove them.

I hope it is handy for you.

18 Oct 2012

Some definitions

Objects

Objects are Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects. (In a sense, and in conformance to Von Neumann’s model of a “stored program computer,” code is also represented by objects.) Every object has an identity, a type and a value.


Types

An object’s type determines the operations that the object supports (e.g., “does it have a length?”) and also defines the possible values for objects of that type.
to be continued..


Variable

In computer programming, a variable is a storage location and an associated symbolic name (an identifier) which contains some known or unknown quantity or information, a value. The variable name is the usual way to reference the stored value; this separation of name and content allows the name to be used independently of the exact information it represents. The identifier in computer source code can be bound to a value during run time, and the value of the variable may thus change during the course of program execution. Variables in programming may not directly correspond to the concept of variables in mathematics. The value of a computing variable is not necessarily part of an equation or formula as in mathematics. In computing, a variable may be employed in a repetitive process: assigned a value in one place, then used elsewhere, then reassigned a new value and used again in the same way (see iteration). Variables in computer programming are frequently given long names to make them relatively descriptive of their use, whereas variables in mathematics often have terse, one- or two-character names for brevity in transcription and manipulation.

23 Jun 2012

Python tipps and tricks

Class Attribute vs. Instance Attribute

I will show what is the difference between class and instance attribute. If you have some instances the class attribute will be affected by all of them, but the instance attribute just by the own instance.
1
2
3
4
5
6
7
8
9
10
11
12
class Name ():
   count = 0
   def __init__ (self, name):
      self .name = name
      Name.count += 1

man1 = Name('David')
man2 = Name('Jozsi')
print Name.count
# Result: 2 #
print man2.name
# Result: 'Jozsi' #


Lambda function bug

Sometimes the lambda function does not want to work. You do everything on right way but you've got error.

1
2
3
4
# If it's not working:
lamda x: call_function()
# Try this:
lamda : call_function()


For statement an other way

Today I learnt a new way to use 'for' statement. It is really useful if we want to give a simple function to every item:

1
2
3
4
5
# We have a list
lst = ['a_1', 'b_2', 'c_3']
numbers = [str.split('_') for str in lst]
# equivalent with this:
numbers = map ( lambda str: str.split('_')[1], lst)


Map function

There is the "map" function in pyton that is very handy. I show how it works.

1
2
3
4
5
6
7
8
9
10
# Example 1.
# We define a function first.
def myFunction (input): return input+1
result = map (myFunction, [1,2,3,4])
print result[1]
# Result: 3 #

# Example 2.
map ( lambda x : x+1, [1,2,3])
# Result: [-1, 1, 3] #
"map(f, sequence)" is directly equivalent with: "[f(x) for x in sequence]"


Class inheritance

I wrote a little template for class inheritance with super function.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class A (object):
   def __init__ ( self , name= 'alma' , *args, **kwds):
     super (A, self ).__init__( *args, **kwds )
     self .name = name
   def getName ( self ):
     print self .name

class B (A):
   def __init__ ( self , number=12 , *args, **kwds):
     super (B, self ).__init__( *args, **kwds )
     self .number = number
   def getNumber ( self ):
     print self .number

b_object = B()
b_object.getName()
# Result: 'alma' #


SetAttr command

I wrote a script some days ago and I had a problem with cmds.setAttr's keyable flag. If you want to lock and hide a double3-type-attribute you need to set separately each attribute.

# Wrong:
cmds.setAttr('pCube1.t', k=False)
# Correct:
for axis in ['x', 'y', 'z']:
  cmds.setAttr('pCube1.t'+axis, k=False)