python自学之with

#!/usr/bin/env python
# encoding: utf-8
'''
@author: heshengjin-何胜金
@contact: 2356899074@qq.com
@software: pycharm
@file: meizi.py
@time: 2018/12/19 17:25
@desc:testWith
'''
import types
import os
import random

def testWith():
    # 不存在就创建目录
    save_path = r"测试python-with"
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    # 文件
    filename = str(random.randrange(1000))
    path = save_path + "/" + filename + ".txt"
    with open(path, "w+") as fp:
        slist = [r'窦靖童景甜唐艺昕机场“势不三立”有戏看了',r'http://lady.163.com/18/1219/00/E3BL885R00267VQQ.html']
        for s in slist:
            # fp.write("%s\n" % (s.encode("utf8")))
            fp.write("%s\n" % s)

def mytuple():
    t = (0, 1, 2, 3, 4)
    print( type(t))
    return t

NAME = "xueweihan"

def get_NAME():
    return NAME

def set_NAME(name_value):
    global NAME
    NAME = name_value


if __name__ == '__main__':
    testWith()
    print(  get_NAME())
    set_NAME("hsj")
    print(  get_NAME())

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值