python3.8.3 mac使用bplist读写plist

 安装bplist

pip3 install bplist 

 代码部分

包含获取系统文件路径 指定文件名

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import os
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
from biplist import *

class pliatManager(object):
	"""docstring for ClassName"""
	# def __init__(self, arg):
		# super(ClassName, self).__init__()
		# self.arg = arg

	 # plist 路径
	def filePaht(self):
		# 获取系统桌面路径
		# 系统路径
		osPath = os.path.expanduser('~')
		# 桌面路径 
		subPath = "Desktop"
		pathstr = os.path.join(osPath,subPath)
		return  pathstr

	# plist 名字
	def plistName(self):
		checkfile ='Info.plist'
		return  checkfile

	# 切换目录  目录
	def changePath(self,pathstr):
		os.chdir(pathstr)
		ls = os.getcwd()
		print ("当前目录是 : ", pathstr)
		return

	# 读取plist
	def readPlistFromName(self,name):
		try:
			plist = readPlist(name)

			return  plist
			pass
		except Exception as e:
			raise e
			return 
	# 修改的原字典 键 值
	def changeValueForKey(self,plist,key,value):

		try:
			plist[key] = value;
			writePlist(plist,plm.plistName())
			print ("修改 ",key,"=",value )
			pass
		except Exception as e:
			print ("Something bad happened:",e)
			raise e
	def valueForKay(self,plist,key):

		return plist[key]


plm =  pliatManager()

filePaht =  plm.filePaht()
plistName =  plm.plistName()

plm.changePath(filePaht)

plist = plm.readPlistFromName(plistName);

CFBundleIdentifier = plm.valueForKay(plist,'CFBundleIdentifier')
CFBundleVersion = plm.valueForKay(plist,'CFBundleVersion')
CFBundleShortVersionString = plm.valueForKay(plist,'CFBundleShortVersionString')
CFBundleDisplayName = plm.valueForKay(plist,'CFBundleDisplayName')

print ("CFBundleDisplayName =", CFBundleDisplayName)
print ("CFBundleIdentifier =", CFBundleIdentifier)
print ("CFBundleShortVersionString =", CFBundleShortVersionString)
print ("CFBundleVersion =", CFBundleVersion)

plm.changeValueForKey(plist,"CFBundleDisplayName","55555")

plist文件内容 保存桌面 info.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>$(DEVELOPMENT_LANGUAGE)</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleVersion</key>
	<string>1</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>UIApplicationSceneManifest</key>
	<dict>
		<key>UIApplicationSupportsMultipleScenes</key>
		<false/>
		<key>UISceneConfigurations</key>
		<dict>
			<key>UIWindowSceneSessionRoleApplication</key>
			<array>
				<dict>
					<key>UISceneConfigurationName</key>
					<string>Default Configuration</string>
					<key>UISceneDelegateClassName</key>
					<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
				</dict>
			</array>
		</dict>
	</dict>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIRequiredDeviceCapabilities</key>
	<array>
		<string>armv7</string>
	</array>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
</dict>
</plist>

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值