import xml.etree.ElementTree as ET
tree = ET.parse(‘test.xml’)
notags = ET.tostring(tree.getroot(), encoding=’utf-8′,method=’text’)
f = open(‘test.txt’,’w’)
f.write(notags)
f.close()
December 16, 2017
How to convert xml into text file [python]
April 22, 2012
Membuat directory secara increment menggunakan python 3.2
March 30, 2012
Install Python 3.2 on Linux [Ubuntu]
links : http://pythonicway.blogspot.com/2011/02/install-python-32-on-linux-ubuntu.html
First of all, I don’t see a point to show you how to install Python on Windows. It’s dead easy download the installer from python.org and in few clicks you will have python up and running. Installing Python on Linux is bit different and requires some pre-work to be done.
So Let’s get started.
Note: Every Modern Linux had a python Installed. You can verify this by opening your Terminal and typing python. It will open the python shell for you. Do not remove the installed version.
Step 1: Pre-requisites for Ubuntu
To be able to compile Python Source, you will need few packages. Fire up the terminal and execute this command
sudo apt-get install build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev
It will take some time to finish depending upon your bandwidth. 🙂
Step 2: Downloading Python Sources and extracting them on your disk
Download a tarball from the python site here is a direct link. Once, the download is completed you can extract the files by doing a right-click on the file and then clicking the extract option
Fire up the terminal and execute this command which will download the file first and extract it on the disk.
wget http://www.python.org/ftp/python/3.2/Python-3.2rc2.tgz && tar -xvf Python-3.2rc2.tgz
Step 3: Installing Python 3.2
Fire up a new Terminal and execute the following commands individually.
1. ./configure
2. make
3. sudo make altinstall
February 14, 2012
Google python class with Nick Parlante (text version)
www.youtube.com/watch?v=tKTZoB2Vjuk
www.youtube.com/watch?v=EPYupizJYQI
www.youtube.com/watch?v=haycL41dAhg
Day 1 part 1
C:\Python32>python hello.py asdasd vsdf dfdf
Hello
[‘hello.py’, ‘asdasd’, ‘vsdf’, ‘dfdf’]
6
4
4
Hello hello.py!!!!
C:\Python32>python hello.py asdasd vsdf dfdf
File “hello.py”, line 5
def Hello(name) {
^
SyntaxError: invalid syntax
C:\Python32>python hello.py asdasd vsdf dfdf
File “hello.py”, line 8
}
^
SyntaxError: invalid syntax
(more…)
February 13, 2012
cx_oracle for python
cx_Oracle is a Python extension module that allows access to Oracle databases and conforms to the Python database API specification. This module is currently built against Oracle 9.2, 10.2, 11.1 and 11.2. For more information on the database API specification, see here. Use the provided setup.py to build and install the module which makes use of the DistUtils module made available in Python 2.0 and up.
If you are looking for support with Tuxedo servers, go here.
Download 5.1.1 released October 10, 2011
- Windows x86 Installer (Oracle 10g, Python 2.6)
- Windows x86 Installer (Oracle 10g, Python 2.7)
- Windows x86 Installer (Oracle 10g, Python 3.2)
- Windows x86 Installer (Oracle 11g, Python 2.6)
- Windows x86 Installer (Oracle 11g, Python 2.7)
- Windows x86 Installer(Oracle 11g, Python 3.2)
- Windows amd64 Installer (Oracle 10g, Python 2.6)
- Windows amd64 Installer (Oracle 10g, Python 2.7)
- Windows amd64 Installer (Oracle 10g, Python 3.2)
- Windows amd64 Installer (Oracle 11g, Python 2.6)
- Windows amd64 Installer (Oracle 11g, Python 2.7)
- Windows amd64 Installer(Oracle 11g, Python 3.2)
- CentOS 5 i386 RPM (Oracle 10g, Python 2.4)
- (more…)
August 14, 2011
I’ve no idea how can one go about writing a DSL in Python
links: http://news.ycombinator.com/item?id=403690
There’s multiple definitions, so what follows is not authoritative, but in my hummble opinion it will help you understand the field much better, as well as why so many people seem to be talking past each other as they silently adopt one definition while arguing with someone based on another.
A strong DSL is a specialized language designed for a specific task, with its own parser and syntax not directly based on another language. Ideally, it is not Turing complete, because that opens a huge can of worms, and much of the point of a strong DSL is to avoid this can of worms. The DSL should be carefully designed in conjunction with the eventual users, who most likely will not be programmers. I’ve heard of impressive results with this approach, but I’ve never witnessed them firsthand. This definition is favored by Martin Fowler, and much less importantly/impressively, me.
Ruby-style DSL’s in Python 2.5
## {{{ http://code.activestate.com/recipes/534150/ (r1) from __future__ import with_statement from contextlib import contextmanager class Table(object): def __init__(self, table_name): self.table_name = table_name self.fields = {} def __setattr__(self, attr, value): if attr in ("fields", "table_name"): object.__setattr__(self, attr, value) else: self.fields[attr] = value def execute(self): print "Creating table %s with fields: %s" % (self.table_name, self.fields) @contextmanager def create_table(table_name): table=Table(table_name) yield table table.execute() #try it! with create_table("Employee") as t: t.first_name = {"type" : "char", "length" : 30 } t.last_name = {"type" : "char", "length" : 30 } t.age = {"type" : "int"} #prints: #Creating table Employee with fields: {'first_name': {'length': #30, 'type': 'char'}, 'last_name': {'length': 30, 'type': 'char'}, 'age': #{'type': 'int'}} ## end of http://code.activestate.com/recipes/534150/ }}}