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

Python Notes

  • difference between raw_input and input: raw_input takes everything as string, while input treat everything as non-string or expression.
  • str() or `` or repr(): convert other types into string
  • import math, math.sqrt(81)
  • family=['mom','dad','brother'] family[-1]='brother'
  • 'abcd'[-1] = 'd'

tulpe vs list

A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The only difference is that tuples can't be changed ie. tuples are immutable and tuples use parentheses and lists use square brackets.

One usage of Python

Image you have something like
data1=value1,data2=value2,....

And you want to format them into 'data1':value1, 'data2':value2,...

You could do this quickly using python

def foramtConversion(**items):
     print items

then put your values into this foramtConversion() function as parameters, boom, you get what you want, simple like that.

Python Scribbles

Installation:
1. download, select the right version, seem there are some for AMD.
2. there are 2 major versions here. 2X and 3X, 3X is for the future, but you might have some compatible issue, after all, not everyone is up to the speed yet.
3. set C:\python at PATH, be notes, it's just C:\python, not C:\python\bin. After that you are in business.
4. type python, you are in.
5. run a python script, say, named as "test.py"
print "help world!"
file = open("data.txt", "w")
file.write("this is a test for python script, just showing that we could write python script\n")
file.close()
you could run it using: python test.py  

Be noted, you don't need import any lib for this scripts. (that's because print, open are build-in functions)

Other things:
1. there is ActivePython: saying python for windows.
2. WLST (weblogic scripting tool): Jython
3. there are some version of python which are database modules (must be easy to work with database).
4. google command line (python)
5. Jython: Jython programs can seamlessly import and use any Java class. Except for some standard modules, Jython programs use Java classes instead of Python modules.
6. .pyw: the .pyw extension simply means: run this Python script without creating a console window. This is
generally what you want if you have a program which is GUI-based. You can run *exactly* the same program with a console window simply by renaming it to .py.
7. PyDev is a Python IDE for Eclipse, which may be used in Python, Jython and IronPython development.
7.1. Aptana Studio 3 (has PyDev pre-installed.)
8. Python module is a file containing Python definitions and statements.