Download

mangledcobwebΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 7 μήνες)

79 εμφανίσεις

BS0756


SHIVAM YADAV

BSO763


UTTAM KUMAR

BSO854


SAHIL MONGA



Designed by
Guido van
Rossum



First appeared in 1991


Developer: Python Software Foundation


Stable Release: 2.6.3 on

2.10.2009


Influenced by ABC ,

ALGOL

Haskell ,

Lisp ,
Modula
-
3,

Perl,

Java


Supports multiple

programming
paradigms

(primarily

object
oriented,

imperative, and

functional)


Automatic

memory management


Often used as a

scripting language


The language has an open, community
-
based
development model


Dynamic

name resolution

(late binding)


automatically allocates and reclaims
("garbage collects") objects when no longer
used


Memory grows and shrink on demand


It keeps track of low
-
level memory details


programs are automatically compiled to
portable
byte code (.
pyc
)




runs on any platform with a
compatible
version of Python installed


Integer Variable


>>>
integer_variable

= 12345



Sting Variable


>>>
String_variable

= ‘Hi’



Float Variable


>>>
float_varialbe

= 123.456



>>> list = [‘a’,’b’,123,12.04]


Python knows a number of
compound

data
types, used to group together other values.
The most versatile is the
list
, which can be
written as a list of comma
-
separated values
(items) between square brackets. List items
need not all have the same type.



For Integer.


>>> x =
int
(input(“enter the number”))


For String.


>>> x =
str
(input(“enter the String”))


For Float.


>>> x = float(input(“enter the float”))


>>> x =
int
(input("Please enter an integer: "))

>>> if x < 0:

print('Negative changed to zero')

elif

x == 0:

print('Zero')

else:

print('More')




>>> # Measure some strings:



>>> a = ['cat', 'window', 'defenestrate']



>>> for x in a:




print(x,
len
(x))



NOTE:


#
is used for comment and


Len
is used for length of the string.



We can create a function that writes the Add
two numbers:


>>> def Add(
a,b
): #defining function



c=
a+b




print(c)




>>> Add(25,30) #for calling a function.




55



OPENING FILE


The open() command returns a file object.

<
filehandle
> = open(<filename>, <access type>)


Python can read, write or append to a file:


'r' = read


'w' = write


'a' = append


Create a file called “hello.txt” containing one line:
“Hello, world!”


>>>
myFile

= open("hello.txt", "r")



You can read the contents of the file into a single
string.

>>>
myFile

= open("hello.txt", "r")

>>>
myString

=
myFile.read
()

>>> print
myString



OUTPUT

Hello, world!



reading the file into a list of strings.


>>>
myFile

= open("
hello.txt","r
")

>>>
myStringList

=
myFile.readlines
()


>>> print
myStringList

['Hello, world!
\
n', "How
ya

doin
'?
\
n"]


>>> print
myStringList
[1]

How
ya

doin
'?



Open the file for writing or appending.

>>>
myFile

= open("new.txt",
"w")



Use the
<file>.write()

method.

>>>
myFile.write
("This is a new
file
\
n")

>>>
myFile.close
()




XML Parsing


DOM


SAX


Writing XML file using Python


Reading XML file using Python




includes many powerful data structures as
part of the core language and libraries


excellent support for Unicode and range of
encodings


implementations of the industry
-
standard
DOM and SAX interfaces


The Python standard library


implementation of Simple API for XML (SAX) and
Document Object Model (DOM)


PyXML


extends the standard library with additional XML
parsers


has adapters to allow more parsers to support the
SAX interface


4Suite, provided by
Fourthought


offers additional DOM implementations tailored for
different applications


DOM parser has to build an object model of
the whole document.


based on an object structure (structure it
Models)


SAX: Simple API for XML


Efficient memory utilization


Event
-
driven nature , faster processing


Streamed reading from disk is
mpossible



Import
minidom


Create a new Document


Create User Element


Set Attributes to user element


Append user element in xml document


Write into an xml file


Close the file



Importing SAX and
Filehandler


Using
StartElement

&
EndElement


Parse the data


Display the contents









THANKS !!!