38.startfile不需要双引号_打开一个链接 webbrowser.open

 

# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.

import time
import os
import webbrowser

gl_log_file_name = ''

def add_to_log_func(info):
    global gl_log_file_name
    log_directory=os.getcwd()+'\\log\\'
    if not os.path.exists(log_directory):
        os.makedirs(log_directory)


    gl_log_file_name = log_directory+time.strftime('%Y%m%d', time.localtime())+'.txt'
    f = open(gl_log_file_name, 'a')  # 'a'追加模式
    # current_time = time.time()
    # print(current_time)
    # print(time.localtime())
    time2 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    #print(time2)
    f.write(time2+' '+info+' \n')
    f.close()
def read_file_func():
    global gl_log_file_name
    print('当前文件名:',  gl_log_file_name)
    f = open(gl_log_file_name, 'r')
    read_content = f.read()
    #print('读取内容:', read_content)
    f.close()
    return read_content

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.
class my_class_func:
    count = 0
    name = 'defaultName'
    def __init__(self,name): #类似构造函数
        self.name = name
    def setCount(self,count):
        self.count = count
    def getCount(self):
        return self.count
class my_class2(object):#@property访问类的属性
    def __init__(self):
        self._param = None
    @property
    def param(self):
        print("get param:%s" % self._param)
        return self._param
    @param.setter
    def param(self,value):
        print("set param:%s" % self._param)
        self._param=value
    @param.deleter #删除
    def param(self):
        print("del param:%s" % self._param)
        del self._param




# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    #print_hi('PyCharm')
    #list的使用
    zlist=['hello','quant','vvp','vvp3a']
    z2 = zlist[1:] #从索引1开始提取信息
      # 从索引1开始提取信息
    z2 = zlist[0:]#从索引0开始提取信息
    print(z2)
    print(zlist)
    print(zlist[2:4]) #[]前开后闭,包前不包后

    #元组,不能二次赋值
    tuple2 = ('aa','bb','cc')
    print('元组:', tuple2[2:3])
    print('不换行:'+str(tuple2[2:3])+' ',end='')
    print('\n换行')
    print(tuple2)

    #字典dictionary
    dic = {}
    dic['a1'] = 'ap60'
    dic['a2'] = 'ap70'
    dic.update({'a3' : 'p80'})#新增
    dic.update(a6='p90')#新增2
    dic.setdefault('a5','p91')#新增3
    print('dic:',dic)
    print('dic_value', dic.values())
    fun1 =lambda x,y:x+y  #兰布达表达式
    print('fun1(2,3)=',fun1(2,3))
    fun2 = lambda x:x*x
    print('fun1(3)=', fun2(3))

    cls = my_class_func('high_tree')
    cls.setCount(20)
    print('count = %d' % cls.getCount())
    print('name:%s' % cls.name)
    print('--------------------------------')
    #property进行类的操作
    cls2 = my_class2()
    cls2.param = 30
    print('current_param:%s' % cls2.param)
    del cls2.param

    #add_to_log_func('abcdefg')
    #print("read_content:\n", read_file_func())
    # msg = input('key key for exit......')
    # n_msg = int(msg)
    # if n_msg == 7 or n_msg > 6: #python或的表示方法
    #     print('true:', msg)
    # else:
    #     print('false:', msg)
    #print('PYTHONPATH:',os.environ['PYTHONPATH'])#获取环境变量的配置路径
    #print('脚本py路径:',os.getcwd())
    #C:\Windows\System32\mspaint.exe
    exe_path = r'C:\Windows\System32\mspaint.exe'
    exe_path2 = r'"C:\Program Files\Internet Explorer\iexplore.exe"'
    exe_path2a = r'"C:\Program Files\WinRAR\WinRAR.exe"'
    exe_path3a = r'C:\"Program Files"\WinRAR\WinRAR.exe'  #链接中有空格要把用双引号扩起来
    #os.system(exe_path3a)

    exe_path5a = r'C:\Program Files\WinRAR\WinRAR.exe'  # startfile不需要双引号
    os.startfile(exe_path5a) #python启动exe文件,os.startfile接受一个普通路径,即便该路径包含空白也没关系(无需像os.system
    #示例中那样用引号将Program Files括起
    #打开一个链接
    webbrowser.open("https://txwtech.blog.csdn.net/article/details/128274820")
    #print(exe_path2a)
   # os.system(exe_path2)
   #  import sys
   #  from PyQt5 import QtWidgets,QtCore
   #  app = QtWidgets.QApplication(sys.argv)
   #  widget= QtWidgets.QWidget()
   #  widget.resize(360,360)
   #  widget.setWindowTitle('hello,pyqt5')
   #  widget.show()
   #  sys.exit(app.exec())










# See PyCharm help at https://www.jetbrains.com/help/pycharm/

 

posted @ 2024-01-03 08:40  txwtech  阅读(4)  评论(0编辑  收藏  举报