Python Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Python Examples

Quick Start
Unicode
Byte Array
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
Signatures
Socket / SSL
SFTP
SMTP
Spider
SSH Key
SSH
SSH Tunnel
Tar
HTTP Upload
XML
XMP
Zip

More Examples...
String
Email Object
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

 

Defining Source Code Encoding

Download Chilkat Python Library

When working with strings, it is extremely important to declare the character encoding used by your source file. If literal strings are used within your Python program, it is essential to save your source in the same encoding as declared with the Python "magic comment".

# file: Unicode1.py
# -*- coding: utf-8 -*-

# (From http://www.python.org/dev/peps/pep-0263/ )
# Python has a syntax to declare the encoding of
# a Python source file. The encoding information is then used by the
# Python parser to interpret the file using the given encoding. Most
# notably this enhances the interpretation of Unicode literals in
# the source code and makes it possible to write Unicode literals
# using e.g. UTF-8 directly in an Unicode aware editor

# Python will default to ASCII as standard encoding if no other
# encoding hints are given.

# To define a source code encoding, a magic comment must
# be placed into the source files either as first or second
# line in the file.  This example sets the source code encoding to
# "utf-8".

import chilkat 

# The source code encoding only applies to how Python parses
# your script source.  
# Python string variables are nothing more than null-terminated bytes.  
# The Python language does not try to interpret the bytes according to 
# a character encoding.
# 
# Chilkat objects are capable of accepting either ANSI or utf-8 encoded strings,
# and can return ANSI or utf-8 strings.
# Each Chilkat object has a "Utf8" property that controls whether arguments and
# return values are utf-8 or ANSI.

# For example:
# create a new email object.
email = chilkat.CkEmail()
# indicate that input/output strings should be utf-8
email.put_Utf8(True)

# set the email subject to a utf-8 string literal.
email.put_Subject('èéêë')

# REMEMBER: When editing Python source code, make sure you save your source file
# using the character encoding specified by the "magic comment".

print "Done!"





 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.