Python's exec Functions: Execute Dynamically Generated Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | # encoding: utf-8 # 版權所有 2024 ©塗聚文有限公司 # 許可資訊查看:言語成了邀功的功臣,還需要行爲每日來值班嗎? # 描述: 主、子表單 窗體傳值 Parent-child form operations # Author : geovindu,Geovin Du 塗聚文. # IDE : PyCharm 2023.1 python 3.11 # OS : windows 10 # Datetime : 2024/10/27 13:09 # User : geovindu # Product : PyCharm # Project : IctGame # File : ui/main.py # explain : 學習 # Python's exec Functions: Execute Dynamically Generated Code import sys import os import io import re from math import * import asyncio class AsyncMange( object ): """ """ def __init__( self ): self .__xNmae = None @property def xName( self ): """ :return: """ return self .__xNmae @xName .setter def xNmae( self ,xname): """ :param xname: :return: """ self .__xNmae = xname async def Add( self ): """ :return: """ print ( 'add' , self .xName) pass async def Edit( self ): """ :return: """ self .__xNmae = 44 print ( 'edit' , self .xName) pass async def __aenter__( self ): """ :return: """ return self async def __aexit__( self ,ty,val,tb): """ :param exc_type: :param exc_val: :param exc_tb: :return: """ pass async def main(): """ :return: """ async with AsyncMange() as m: m.xNmae = 23 await m.Add() await m.Edit() asyncio.run(main()) numbers = [ 2 , 3 , 7 , 4 , 8 ] exec ( "result = sum( number**2 for number in numbers if number % 2 == 0)" ) print (result) exec ( "print(dir())" , {}) exec ( 'print(fact(5))' , { 'fact' : factorial}) exec ( "name = input('Your name: ')\nprint(f'Hello, {name}!')" ) stringInput = """ def sumSquares(numbers): return sum(number**2 for number in numbers if number % 2 == 0) print(sumSquares(numbers)) """ compiled_code = compile (stringInput, "<string>" , "exec" ) exec (compiled_code) numbers = [ 12 , 23 , 37 , 44 , 58 ] exec (compiled_code) sumSquares(numbers) print (sumSquares(numbers)) with open ( "geovindu.py" , mode = "r" , encoding = "utf-8" ) as hello: code = hello.read() exec (code) |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2022-10-27 Python: Memento Pattern
2022-10-27 Python: Command Pattern
2016-10-27 Concurrency in csharp (Asynchronous, Parallel, and Multithreaded Programming)
2015-10-27 csharp: InvokeHelper
2015-10-27 Free Slideshow, Gallery And Lightboxes Scripts
2015-10-27 35 Gallery – Ajax Slide