Yocto

https://www.yoctoproject.org

Yocto offical web

System envn.

  • Git 1.8.3.1 or greater

  • tar 1.27 or greater

  • Python 3.4.0 or greater.

sudo apt-get install gawk wget git-core diffstat unzip texinfo gcc-multilib      build-essential chrpath socat cpio python python3 python3-pip python3-pexpect      xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev      xterm

The first demo.

download poky-sumo-19.0.3.tar.bz2 from web and extract it.
The default machine is x86.

The first thing is to init the env. by run below script

source oe-init-build-env

command to build: bitbake core-image-minimal
command to run qemu: runqemu qemux86

  

image name
description
core-image-minimal A small image just capable of allowing a device to boot.
core-image-base A console-only image that fully supports the target device hardware.
core-image-sato Image with sato,a mobile environment and visual style for mobile devices.  The image supports X11 with a Sato theme,Pimlico applications and contains terminal,editor and file manager.
fsl-image-test Builds contents core-image-base plus Freescale test applications and multimedia components.
fsl-image-gui Builds contents of core-image-sato with Freescale test applications and multimedia with hardware accelerated X11

 

The built images are located in

cd tmp/deploy/images 

#Using a existing layer

1. Clone a layer from git 

git clone -b sumo git://git.yoctoproject.org/meta-freescale 

2. add the layer to yocto (it must be in build folder)

bitbake-layers add-layer ../meta-freescale

#List local layers
bitbake-layers show-layer

#to build the firmware for imx6ullevk
edit build/conf/local.conf,change the machine as MACHINE ??= "imx6ullevk"
bitbake core-image-minimal

bitbake -c clean core-image-minimal

#to build the application developement environment
bitbake -c do_populate_sdk_ext core-image-minimal


#create a new layer  

on the build folder

bitbake-layers create-layer meta-stfir-ul

bitbake-layers add-layer ../meta-stfir-ul
bitbake-layers show-layers


#to find the layer which cotains linux kernel
bitbake-layers show-recipes | grep linux -A 10 | grep meta-freescale -B 5

#check the layer
yocto-check-layer meta-ul


#know which linux version and name is used
bitbake -e virtual/kernel | grep "^PV"
bitbake -e virtual/kernel | grep "^PN"

PN is the package name
PV is the package version

bitbake -e u-boot | grep "^PN"

-e means environment

Where is from virtual/kernel?

PREFERRED_PROVIDER

Determines which recipe should be given preference when multiple recipes provide the same item. You should always suffix the variable with the name of the provided item,and you should set it to the PN of the recipe to which you want to give precedence. Some examples:

     PREFERRED_PROVIDER_virtual/kernel ?= "linux-yocto"
     PREFERRED_PROVIDER_virtual/xserver = "xserver-xf86"
     PREFERRED_PROVIDER_virtual/libgl ?= "mesa"                    

#the bblayers.conf must in meta-ul for searching the dependence metas.

 

#Customize kernel setting
bitbake -c menuconfig virtual/kernel
or
bitbake linux-imx -c menuconfig

bitbake -c savedefconfig virtual/kernel
the defconfig file will be saved in build/tmp/work/fpa1000-poky-linux-gnueabi/linux-imx/4.9.88-r0/build/
you can copy the file to the layer for finally customizing linux when compilation.

#to list all commands in virutal/kernel
bitbake -c listtasks virtual/kernel
bitbake -c listtasks virtual/bootloader

#to clear the state to initial in case the menuconfig is wrong
bitbake -c cleansstate virtual/kernel

#to show all the bbappends
bitbake-layers show-appends

#update the kernel configuration fragment

recommend to update the kernel configuration fragment.
in your layer,example recipes-kernel\linux\
file: PN_PV.bbappend (linux-imx_4.9.88.bbappend)
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:"

COMPATIBLE_MACHINE = "(fpa1000)"

SRC_URI += "file://can_config"

a folder name : linux-imx-4.9.88 has file can_config,which is to disable the CAN device
CONFIG_CAN is not set
CONFIG_CAN_FLEXCAN is not set
CONFIG_CAN_M_CAN is not set


how to generate a configuration fragment
bitbake linux-imx -c menuconfig
change what you want,save it when exit,run below command will generate the config.frame which is the changes
bitbake linux-imx -c diffconfig
compile the kernel
bitbake linux-imx -c compile -f
deploy
bitbake linux-imx -c deploy
install and package
bitbake linux-imx

---The summay

To apply kernel config,there are two methods,
1. copy whole file defconfig
bitbake linux-imx -c menuconfig
#bitbake linux-imx -c savedefconfig
copy the generated defconfig to your bbapend folder
cp ./tmp/work/fpa1000-poky-linux-gnueabi/linux-imx/4.9.88-r0/build/.config ../meta-ul/recipes-kernel/linux/linux-imx-4.9.88/defconfig
in the bbapend file
SRC_URI += " \
file://defconfig \
file://git/arch/arm/boot/dts/fpa1000.dts \
"
2. using config frame,
it is better to use patch file,but now I use the whole file
The config framement must be *.cfg.
copy the *.cfg to the destination folder (linux-imx-4.9.88/poky),and change *.bbappend

SRC_URI += "file://disable_can.cfg"
SRC_URI += "file://git/arch/arm/boot/dts/fpa1000.dts"
SRC_URI += "file://disable_media.cfg"
SRC_URI += "file://disable_ATA.cfg"
SRC_URI += "file://disable_network.cfg"


Note: The search file path is very import. According to the debug information below,it will search the paths ins sequencly.
It will patch the file in case find the file. Special for the same file name. for example,defconfig,it is same name in meta-freescale and meta-ul,it always failure when I put the
file in linux-imx-4.9.88/. it is success when I put the file in linux-imx-4.9.88/poky/
checking the log.do_fetch at temp.
DEBUG: Searching for defconfig in paths:
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/poky
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/poky
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/poky
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/poky
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/fpa1000
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/fpa1000
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/fpa1000
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/fpa1000
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/mx6ull
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/mx6ull
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/mx6ull
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/mx6ull
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/imxepdc
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/imxepdc
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/imxepdc
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/imxepdc
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/imxpxp
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/imxpxp
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/imxpxp
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/imxpxp
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/mx6
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/mx6
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/mx6
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/mx6
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/imx
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/imx
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/imx
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/imx
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/armv7ve
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/armv7ve
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/armv7ve
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/armv7ve
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/arm
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/arm
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/arm
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/arm
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/
DEBUG: Searching for git/arch/arm/boot/dts/fpa1000.dts in paths:
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/poky
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/poky
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/poky
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/poky
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/fpa1000
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/fpa1000
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/fpa1000
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/fpa1000
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/mx6ull
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/mx6ull
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/mx6ull
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/mx6ull
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/imxepdc
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/imxepdc
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/imxepdc
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/imxepdc
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/imxpxp
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/imxpxp
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/imxpxp
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/imxpxp
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/mx6
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/mx6
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/mx6
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/mx6
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/imx
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/imx
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/imx
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/imx
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/armv7ve
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/armv7ve
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/armv7ve
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/armv7ve
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/arm
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/arm
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/arm
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/arm
/home/zjb/yocto/poky-sumo-19.0.3/meta-ul/recipes-kernel/linux/linux-imx-4.9.88/
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx-4.9.88/
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/linux-imx/
/home/zjb/yocto/poky-sumo-19.0.3/meta-freescale/recipes-kernel/linux/files/

 


#customize u-boot
#the command will show the all commands for u-boot
bitbake u-boot-imx -c listtasks
#below command will create a terminate and switch to u-boot git folder,in git folder you can use menuconfig oldconfig related to customize u-boot.
bitbake u-boot-imx -c devshell

you can use build only recipe
e.g. bitbake linux-imx or bitbake u-boot-imx


The build log file can be found at build/tmp/...
using commmand below to find the exactly folder
bitbake -e linux-imx | grep ^T=

to find the source folder
bitbake -e linux-imx | grep ^S=
bitbake -e u-boot-imx | grep ^S=

#device tree

The device tree is loacted in : home/zjb/yocto/poky-sumo-19.0.3/build/tmp/work/fpa1000-poky-linux-gnueabi/linux-imx/4.9.88-r0/git/arch/arm/boot/dts
only compile the dts
bitbake linux-imx -c devshell
make dtbs


#add image to build
CORE_IMAGE_EXTRA_INSTALL += " <packagename>"
or
IMAGE_INSTALL_append = " lighttpd wget"


#how to use local mirror to build
in your layer.conf file

build with network,normally the all tar files are achieved in downloads folder:
bitbake core-image-minimal

copy:
copy build/downloads/* to /home/zjb/SourceMirror/

change to "No network" in layer.conf

SOURCE_MIRROR_URL ?= "file:///home/zjb/SourceMirror/"
INHERIT += "own-mirrors"
BB_NO_NETWORK = "1"


#override the files because the internet is not avaliable

example lighthttpd,the original bb file URI as below
SRC_URI = "http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-${PV}.tar.xz \
file://index.html.lighttpd \
file://lighttpd.conf \
file://lighttpd \
file://lighttpd.service \
file://0001-Use-pkg-config-for-pcre-dependency-instead-of-config.patch \
"

as we don‘t have interrnet access,recreate bbappend in your meta layer
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:"

COMPATIBLE_MACHINE = "(fpa1000)"

SRC_URI = "file://lighttpd-1.4.48.tar.gz \
file://index.html.lighttpd \
file://lighttpd.conf \
file://lighttpd \
file://lighttpd.service \
file://0001-Use-pkg-config-for-pcre-dependency-instead-of-config.patch \
"
you can see,we only replace the main URL as local file address.
add copy the download lighttpd-1.4.48.tar.gz in your /lighttpd-1.4.48/ folder


#how to know which packages are installed
the manifest are located in tmp/delploy/images/<imagename>/<imagename.manifest

#customize busybox
bitbake -c menuconfig busybox,quit and save what your changes
bitbake -c diffconfig,system will generate the config fragment.

 

#only build a specific bb file.

bitbake -b xx.bb to only build a specific bb file.

#using self customized device tree.
copy a device tree from original to the folder,e.g. fpa1000.dts
meta-ul/recipes-kernel/linux/linux-imx-4.9.88/git/arch/arm/boot/dts/

and then in the machine conf,e.g. fpa1000.conf,change the device config.
#KERNEL_DEVICETREE = "imx6ull-14x14-evk.dtb imx6ull-14x14-evk-btwifi.dtb"
KERNEL_DEVICETREE = "fpa1000.dtb"

 

#The image in sd-card of one board does not work,use below method to burn the image from nxp offical web
1. connect the micro sd card to linux
2. fdisk -l to find out which device name,it is /dev/sdc in my system or lsblk
3. bunzip2 -dk -f fsl-image-validation-imx-x11-imx6ull14x14evk.sdcard.bz2
4. sudo dd if=fsl-image-validation-imx-x11-imx6ull14x14evk.sdcard of=/dev/sdc bs=1M conv=fsync

#using below command to find out which output format
bitbake core-image-minimal -e | grep ^IMAGE_FSTYPES

#using wic.gz image
gunzip core-image-minimal-fpa1000-20190621060255.rootfs.wiz.gz
sudo dd if=core-image-minimal-fpa1000-20190621060255.rootfs.wiz of=/dev/sdb bs=1M iflag=fullblock oflag=direct conv=fsync

using self-build image,need to change the fdt_file in uboot to fpa1000.dtb


#how to change the u-boot using self-device
1. fpa1000.conf
UBOOT_CONFIG ??= "sd"
#UBOOT_CONFIG[sd] = "mx6ull_14x14_evk_config,sdcard"
#UBOOT_CONFIG[mfgtool] = "mx6ull_14x14_evk_config"
UBOOT_CONFIG[sd] = "fpa1000_config,sdcard"
UBOOT_CONFIG[mfgtool] = "fpa1000_config"

2. in ul/recipes-bsp/u-boot
1). u-boot-imx_2017.03.bbappend
SRC_URI += "file://git/configs/fpa1000_defconfig"
SRC_URI += "file://git/arch/arm/dts/fpa1000.dts"
SRC_URI += "file://git/arch/arm/dts/Makefile"

2). fpa1000_defconfig is copy from u-boot/git/configs/mx6ul_14x14_evk_defconfig with change
3). fpa1000.dts is copy from u-boot/git/arch/arm/imx6ul-14x14-evk.dts without change
4). Makefile is copy from u-boot/git/arch/arm/makefile with change

 

#u-boot source code
the u-boot source code is not in work/tmp folder,using bitbake u-boot-imx -c unpack

#u-boot enviroment string is defined in mx6ullevk.h
/home/zjb/yocto/poky-sumo-19.0.3/build/tmp/work/fpa1000-poky-linux-gnueabi/u-boot-imx/2017.03-r0/git/include/configs

#find command
find . -name ‘defconfig‘

#grep a text in files
grep -rnw . -e ‘findfdt‘

#how to use patch
The folder structure of generating patch is very important,because the patch command want to know where to apply.
for example,we want to apply the patch for file ./include/configs/mx6ullevk.h
1. generate the patch
setup two folders with same structure as file
./include/configs/mx6ullevk.h (or used the origin source code)
./modify/configs/mx6ullevk.h
diff -Nupr --no-dereference ./include/ ./modify/ >mx6ullevk.h.patch

2. in bbapend file.
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:"
SRC_URI += "file://mx6ullevk.h.patch"

and put the generate mx6ullevk.h.patch to the folder ${PN}-${PV}


#how to change default fdt_file in u-boot enviornment
The variable is stored in the u-boot source code /include/configs/mx6ullevk.h
using patch to change it.


#enable cgi for lighttpd
1. in lighttpd.conf
server.modules = (
# "mod_rewrite",
# "mod_redirect",
"mod_alias",
"mod_access",
# "mod_cml",
# "mod_trigger_b4_dl",
# "mod_auth",
# "mod_status",
# "mod_setenv",
# "mod_fastcgi",
# "mod_proxy",
# "mod_simple_vhost",
# "mod_evhost",
# "mod_userdir",
"mod_cgi",
"mod_compress",
# "mod_ssi",
# "mod_usertrack",
# "mod_expire",
# "mod_secdownload",
# "mod_rrdtool",
# "mod_webdav",
"mod_accesslog" )


cgi.assign = (
".cgi" => ""
)

alias.url += ("/cgi-bin" => "/www/pages/cgi-bin")

##
# which extensions should not be handle via static-file transfer
#
# .php,.pl,.fcgi are most often handled by mod_fastcgi or mod_cgi
static-file.exclude-extensions = ( ".php",".pl",".fcgi",".cgi" )


2. in lighttpd_%.bbapend
RDEPENDS_${PN} += "lighttpd-module-cgi \
lighttpd-module-alias \
lighttpd-module-compress"


#to view which module is compile
build/deploy/

in board
cat /proc/config.gz |gunzip

#where to find the log informationtmp/work/yourlinuxfolder/version/temp

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Python中的函数(二) 在上一篇文章中提到了Python中函数的定义和使用,在这篇文章里我们来讨论下关于函数的一些更深的话题。在学习C语言函数的时候,遇到的问题主要有形参实参的区别、参数的传递和改变、变量的作用域。同样在Python中,关于对函数的理解和使用也存在这些问题。下面来逐一讲解。一.函
Python中的字符串 可能大多数人在学习C语言的时候,最先接触的数据类型就是字符串,因为大多教程都是以&quot;Hello world&quot;这个程序作为入门程序,这个程序中要打印的&quot;Hello world&quot;就是字符串。如果你做过自然语言处理方面的研究,并且用Python
Python 面向对象编程(一) 虽然Python是解释性语言,但是它是面向对象的,能够进行对象编程。下面就来了解一下如何在Python中进行对象编程。一.如何定义一个类 在进行python面向对象编程之前,先来了解几个术语:类,类对象,实例对象,属性,函数和方法。 类是对现实世界中一些事物的封装,
Python面向对象编程(二) 在前面一篇文章中谈到了类的基本定义和使用方法,这只体现了面向对象编程的三大特点之一:封装。下面就来了解一下另外两大特征:继承和多态。 在Python中,如果需要的话,可以让一个类去继承一个类,被继承的类称为父类或者超类、也可以称作基类,继承的类称为子类。并且Pytho
Python中的函数(一) 接触过C语言的朋友对函数这个词肯定非常熟悉,无论在哪门编程语言当中,函数(当然在某些语言里称作方法,意义是相同的)都扮演着至关重要的角色。今天就来了解一下Python中的函数用法。一.函数的定义 在某些编程语言当中,函数声明和函数定义是区分开的(在这些编程语言当中函数声明
在windows下如何快速搭建web.py开发框架 用Python进行web开发的话有很多框架供选择,比如最出名的Django,tornado等,除了这些框架之外,有一个轻量级的框架使用起来也是非常方便和顺手,就是web.py。它由一名黑客所创建,但是不幸的是这位创建者于2013年自杀了。据说现在由
将Sublime Text 2搭建成一个好用的IDE 说起编辑器,可能大部分人要推荐的是Vim和Emacs,本人用过Vim,功能确实强大,但是不是很习惯,之前一直有朋友推荐SUblime Text 2这款编辑器,然后这段时间就试了一下,就深深地喜欢上这款编辑器了...
Python中的模块 有过C语言编程经验的朋友都知道在C语言中如果要引用sqrt这个函数,必须用语句&quot;#include&lt;math.h&gt;&quot;引入math.h这个头文件,否则是无法正常进行调用的。那么在Python中,如果要引用一些内置的函数,该怎么处理呢?在Python中
Python的基础语法 在对Python有了基础的认识之后,下面来了解一下Python的基础语法,看看它和C语言、java之间的基础语法差异。一.变量、表达式和语句 Python中的语句也称作命令,比如print &quot;hello python&quot;这就是一条语句。 表达式,顾名思义,是
Eclipse+PyDevʽjango+Mysql搭建Python web开发环境 Python的web框架有很多,目前主流的有Django、Tornado、Web.py等,最流行的要属Django了,也是被大家最看好的框架之一。下面就来讲讲如何搭建Django的开发环境。一.准备工作 需要下载的
在windows下安装配置Ulipad 今天推荐一款轻便的文本编辑器Ulipad,用来写一些小的Python脚本非常方便。 Ulipad下载地址: https://github.com/limodou/ulipad http://files.cnblogs.com/dolphin0520/u...
Python中的函数(三) 在前面两篇文章中已经探讨了函数的一些相关用法,下面一起来了解一下函数参数类型的问题。在C语言中,调用函数时必须依照函数定义时的参数个数以及类型来传递参数,否则将会发生错误,这个是严格进行规定的。然而在Python中函数参数定义和传递的方式相比而言就灵活多了。一.函数参数的
在Notepad++中搭配Python开发环境 Python在最近几年一度成为最流行的语言之一,不仅仅是因为它简洁明了,更在于它的功能之强大。它不仅能够完成一般脚本语言所能做的事情,还能很方便快捷地进行大规模的项目开发。在学习Python之前我们来看一下Python的历史由来,&quot;Pytho
Python中的条件选择和循环语句 同C语言、Java一样,Python中也存在条件选择和循环语句,其风格和C语言、java的很类似,但是在写法和用法上还是有一些区别。今天就让我们一起来了解一下。一.条件选择语句 Python中条件选择语句的关键字为:if 、elif 、else这三个。其基本形式如
关于raw_input( )和sys.stdin.readline( )的区别 之前一直认为用raw_input( )和sys.stdin.readline( )来获取输入的效果完全相同,但是最近在写程序时有类似这样一段代码:import sysline = sys.stdin.readline()
初识Python 跟学习所有的编程语言一样,首先得了解这门语言的编程风格和最基础的语法。下面就让我们一起来了解一下Python的编程风格。1.逻辑行与物理行 在Python中有逻辑行和物理行这个概念,物理行是指在编辑器中实际看到的一行,逻辑行是指一条Python语句。在Python中提倡一个物理行只
当我们的代码是有访问网络相关的操作时,比如http请求或者访问远程数据库,经常可能会发生一些错误,有些错误可能重新去发送请求就会成功,本文分析常见可能需要重试的场景,并最后给出python代码实现。
1.经典迭代器 2.将Sentence中的__iter__改成生成器函数 改成生成器后用法不变,但更加简洁。 3.惰性实现 当列表比较大,占内存较大时,我们可以采用惰性实现,每次只读取一个元素到内存。 或者使用更简洁的生成器表达式 4.yield from itertools模块含有大量生成器函数可
本文介绍简单介绍socket的常用函数,并以python-kafka中的源码socketpair为例,来讲解python socket的运用
python实践中经常出现编码相关的异常,大多网上找资料而没有理解原理,导致一次次重复错误。本文对常用Unicode、UTF-8、GB2312编码的原理进行介绍,接着介绍了python字符类型unicode和str以及常见编解码错误UnicodeEncodeError和UnicodeDEcodeEr