Python 3 Basics

1. 科学计数法:

>>> format(pow(1.3,50)*10000,‘.2e‘)

‘4.98e+09‘

2. Python文件操作

主要功能,1)扫描目录,找到APK文件;2)解析debug/release;3)使用debug/release+time生成文件名;4)复制文件到远程目录给测试。

import sys,os,shutil,zipfile,time,string,re #导入依赖库

def getTime():
    return time.strftime("%m_%d_%H_%M",time.localtime(time.time()))

def FindapkName(MyPath):
    found =0
    for fileName in os.listdir(MyPath):
        FilePath = os.path.abspath(os.path.join(MyPath, fileName))
        #print(‘遍历文件 :‘ + FilePath )

#       输出找到的.txt格式的文件
        if ".apk" in fileName:
            print(‘找到apk文件 :‘ + FilePath )
            if found==1:
                print(‘找到多个APK文件,退出‘)
                sys.exit(1)
            found =1
            foundPath = FilePath

    if found==1:
        return foundPath
    else:
        print(‘没有找到apk‘)
        sys.exit(1)

def removeDot(line):
    return re.sub(r‘[{}]+‘.format(string.punctuation),‘‘,line )

def getIsDebug(fileName):
    if "debug.apk" in fileName:
        return ‘debug‘
    if "release.apk" in fileName:
        return ‘release‘;

    print(‘getIsDebug failed‘)
    sys.exit(1)

def getAppVersion(fileName):
    file = open(fileName, mode=‘r‘, encoding=‘UTF-8‘)

    for line in file:
        lineContent = line.split()
        #print(lineContent)
        if len(lineContent) ==2:
            #print(lineContent)
            if lineContent[0] == ‘versionName‘:
                version = lineContent[1]
                #strip ""
                return eval(version)

    print(‘getAppVersion failed‘)
    sys.exit(1)

#get version
gradleFileName = os.getcwd()+‘/app/‘+‘build.gradle‘
version = getAppVersion(gradleFileName)
print(‘version=‘+version)

appDIR = os.getcwd()+‘/app/‘
remoteDir = ‘//10.18.0.100/test/‘

#get AS generated APK
ASGeneratedName = FindapkName(appDIR)
#print(‘ASGeneratedName =‘ + ASGeneratedName)

#get debug
# settingFileName = os.getcwd()+‘/app/‘+‘src/main/java/‘+‘AppSetting.java‘
debugString = getIsDebug(ASGeneratedName)
print(‘isDebug =‘ + debugString)

releaseAPKName =  ‘SelfDriving_v‘ + version + ‘_‘+debugString + ‘_‘+getTime()+‘.apk‘

#write to 100
remoteVersiondDIR = remoteDir+‘v‘+version
if os.path.exists(remoteVersiondDIR) == False:
    print(‘创建远程目录‘+remoteVersiondDIR)
    os.mkdir(remoteVersiondDIR)
else:
    print(‘远程目录‘+remoteVersiondDIR+‘已经存在‘)

print(‘写入文件:‘+remoteVersiondDIR+‘/‘+releaseAPKName +‘请耐心等待‘)
shutil.copy(ASGeneratedName,remoteVersiondDIR+‘/‘+releaseAPKName)

remoteFile = ‘SelfDriving_‘+debugString+‘.apk‘
print(‘写入文件:‘+remoteDir+remoteFile)
shutil.copyfile(ASGeneratedName,remoteDir+remoteFile)

#delete local APK
os.remove(ASGeneratedName)

  

时间: 2024-12-09 01:19:53

Python 3 Basics的相关文章

萌新向Python数据分析及数据挖掘 第二章 pandas 第二节 Python Language Basics, IPython, and Jupyter Notebooks

Python Language Basics, IPython, and Jupyter Notebooks In [5]: import numpy as np #导入numpy np.random.seed(12345)#设定再现的的随机数 np.set_printoptions(precision=4, suppress=True) #设置打印设置 Signature: np.set_printoptions(precision=None, threshold=None, edgeitem

K-Means clusternig example with Python and Scikit-learn(推荐)

https://www.pythonprogramming.net/flat-clustering-machine-learning-python-scikit-learn/ Unsupervised Machine Learning: Flat Clustering K-Means clusternig example with Python and Scikit-learn This series is concerning "unsupervised machine learning.&q

计算机电子书 2018 BiliDrive 备份

下载方式 根据你的操作系统下载不同的 BiliDrive 二进制. 执行: bilidrive download <link> 链接 文档 链接 Webpack 中文指南.epub (409.01 KB) bdrive://ce58b7b58292296a61a97de1f89c62b66da24ab6 OpenIntro Statistics 3e.pdf (7.17 MB) bdrive://ef01910ee34f0a1c91d9435f750a49c6ac1bc5fa AngularJ

AcF 351b Career Skills

Department of Accounting andFinance Lancaster UniversityAcF 351b Career Skills in Accounting and FinancePython for Data AnalysisStream Assignment2019/201. OverviewPython for Data Analysis stream is designed to provide introductory programming knowled

Python basics

The tutorial is from Dan Klein and Pieter Abbeel A good tutorial: https://docs.python.org/2/tutorial/ Table of Contents Invoking the Interpreter Operators Strings Dir and Help Built-in Data Structures Lists Tuples Sets Dictionaries Writing Scripts In

第二周:神经网络的编程基础----------3、Python Basics with numpy (optional)

Python Basics with numpy (optional)Welcome to your first (Optional) programming exercise of the deep learning specialization. In this assignment you will: - Learn how to use numpy. - Implement some basic core deep learning functions such as the softm

第一周 Basics of Python 第一节 走进Python

本笔记大纲结构为:第X周--第X节 (x.x)-- 一,二,三... --1,2,3--①,②,③... 1.1 Walk into Python 一.Introduction to Python 1 案例:gogle yo tube  nasa 豆瓣 2 设计哲学: 简单:拥有简单脚本语言和解释型程序语言的易用性 明确:拥有传统编译型语言所有的强大通用的功能 优雅:解释型的.面向对象的.带有动态语义的高级程序设计语言 3 前世今生--创始人:Guido van Rossum 圣诞期间无聊写的

[Python Basics]下划线变量

夜暗归云绕柁牙,江涵星影鹭眠沙. 行人怅望苏台柳,曾与吴王扫落花. 我平时很常见到的带有下划线的python变量有两种: 前后双下划线,我之前的理解是python程序中的类似meta data的信息,例如__name__变量 前单下划线,python类中的私有变量或函数 单独下划线,用来表示上一个输出(在python Interactive console中).常见用法for _ in theList 今天遇到了一些新的挑战: `from feature import absolute_impo

[Python Basics]引用系统(The Import System)

欲上高楼去避愁,愁还随我上高楼.经行几处江山改,多少亲朋尽白头. 归休去,去归休.不成人总要封侯?浮云出处元无定,得似浮云也自由. 我从短暂的Python工作当中学到一件事,越是模块化,就越会发现python看似普通的import是大有玄机的. python引用python文件时的搜索路径往往都是当前terminal的pwd.(可以在sys还是os模块下append预期的路径) python在引用文件是看起来有点像是执行了一遍那个文件. python的相对路径真的限制好多,在我看来似乎是在套娃的