如何将python制作为简单的软件?
打开电脑,点运行,输入cmd,打开一个dos窗口 先敲python -V 我的输出是 Python 2.7.1 ,如果提示找不到的话,请添加环境变量。
怎么添加windows环境变量,自己上网去搜。
然后用python运行你的脚本:假定为abc.py python abc.py 如果还是提示找不到,就用dos命令跳到abc.py所在的文件夹
python idle 的打开方式
1.open使用open打开文件后一定要记得调用文件对象的close()方法。
比如可以用try/finally语句来确保最后能关闭文件。
file_object = open('thefile.txt')try: all_the_text = file_object.read( )finally: file_object.close( )注:不能把open语句放在try块里,因为当打开文件出现异常时,文件对象file_object无法执行close()方法。
2.读文件读文本文件input = open('data', 'r')#第二个参数默认为rinput = open('data')读二进制文件input = open('data', 'rb')读取所有内容file_object = open('thefile.txt')try: all_the_text = file_object.read( )finally: file_object.close( )读固定字节file_object = open('abinfile', 'rb')try: while True: chunk = file_object.read(100) if not chunk: break do_something_with(chunk)finally: file_object.close( )读每行list_of_all_the_lines = file_object.readlines( )如果文件是文本文件,还可以直接遍历文件对象获取每行:for line in file_object: process line...
mac下用什么软件打开python的源代码
可以的,没有什么不可以txt里面存的都是字节流,无非是注意1) 是否有读的权限2) mac上txt上默认的line separtator是"\r", windows是"\r\n",如果splitlines行为有异常要注意是否line separtator有问题import ospath = os.path.expanduser(r"~/Desktop/hello_world.txt")print pathwith open(path) as f: content = f.read() for i in content.splitlines(): print i
软件无法打开(coreldrw)软件无法打开,打开后显示
#!/usr/bin/env python3# -*- coding: utf-8 -*-r'''learning.pyA Python 3 tutorial from http://www.liaoxuefeng.comUsage:python3 learning.py'''import sysdef check_version(): v = sys.version_info if v.major == 3 and v.minor >= 4: return True print('Your current python is %d.%d. Please use Python 3.4.' % (v.major, v.minor)) return Falseif not check_version(): exit(1)import os, io, json, subprocess, tempfilefrom urllib import parsefrom wsgiref.simple_server import make_serverEXEC = sys.executablePORT = 39093HOST = 'local.liaoxuefeng.com:%d' % PORTTEMP = tempfile.mkdtemp(suffix='_py', prefix='learn_python_')INDEX = 0def main(): httpd = make_server('127.0.0.1', PORT, application) print('Ready for Python code on port %d...' % PORT) httpd.serve_forever()def get_name(): global INDEX INDEX = INDEX + 1 return 'test_%d' % INDEXdef write_py(name, code): fpath = os.path.join(TEMP, '%s.py' % name) with open(fpath, 'w', encoding='utf-8') as f: f.write(code) print('Code wrote to: %s' % fpath) return fpathdef decode(s): try: return s.decode('utf-8') except UnicodeDecodeError: return s.decode('gbk')def application(environ, start_response): host = environ.get('HTTP_HOST') method = environ.get('REQUEST_METHOD') path = environ.get('PATH_INFO') if method == 'GET' and path == '/': start_response('200 OK', [('Content-Type', 'text/html')]) return [b'Learning PythonRun'] if method == 'GET' and path == '/env': start_response('200 OK', [('Content-Type', 'text/html')]) L = [b'ENV'] for k, v in environ.items(): p = '%s = %s' % (k, str(v)) L.append(p.encode('utf-8')) L.append(b'') return L if host != HOST or method != 'POST' or path != '/run' or not environ.get('CONTENT_TYPE', '').lower().startswith('application/x-www-form-urlencoded'): start_response('400 Bad Request', [('Content-Type', 'application/json')]) return [b'{"error":"bad_request"}'] s = environ['wsgi.input'].read(int(environ['CONTENT_LENGTH'])) qs = parse.parse_qs(s.decode('utf-8')) if not 'code' in qs: start_response('400 Bad Request', [('Content-Type', 'application/json')]) return [b'{"error":"invalid_params"}'] name = qs['name'][0] if 'name' in qs else get_name() code = qs['code'][0] headers = [('Content-Type', 'application/json')] origin = environ.get('HTTP_ORIGIN', '') if origin.find('.liaoxuefeng.com') == -1: start_response('400 Bad Request', [('Content-Type', 'application/json')]) return [b'{"error":"invalid_origin"}'] headers.append(('Access-Control-Allow-Origin', origin)) start_response('200 OK', headers) r = dict() try: fpath = write_py(name, code) print('Execute: %s %s' % (EXEC, fpath)) r['output'] = decode(subprocess.check_output([EXEC, fpath], stderr=subprocess.STDOUT, timeout=5)) except subprocess.CalledProcessError as e: r = dict(error='Exception', output=decode(e.output)) except subprocess.TimeoutExpired as e: r = dict(error='Timeout', output='执行超时') except subprocess.CalledProcessError as e: r = dict(error='Error', output='执行错误') print('Execute done.') return [json.dumps(r).encode('utf-8')]if __name__ == '__main__': main()Python代码运行助手 展开
python 关闭打开文件问题 新手
Sybase,DB2,Mysql、SQLite等数据库通信:程序员可通过遵循Python DB-API(数据库应用程序编程接口)规范的模块与Microsoft SQL Server,Oracle。
数据库编程,能方便进行系统维护和管理,Linux下标志性语言之一,是很多系统管理员理想的编程工具。
图形处理,还提供SGML,许多程序员利用python进行XML程序的开发,XML分析模块:python提供的re模块能支持正则表达式。
python自带有一个Gadfly模块:有PIL、Tkinter等图形库支持,能方便进行图形处理。
数学处理系统编程。
网络编程:提供丰富的模块支持sockets编程。
很多大规模软件开发计划例如Zope:NumPy扩展提供大量与许多标准数学库的接口。
文本处理:提供API。
多媒体应用,Mnet 及BitTorrent. Google都在广泛地使用它。
Web编程:应用的开发语言,支持最新的XML技术,能方便快速地开发分布式应用程序,提供了一个完整的SQL环境:Python的PyOpenGL模块封装了“OpenGL应用程序编程接口”,能进行二维和三维图像处理。
PyGame模块可用于编写游戏软件...
在一个python窗体中打开另一个程序
兄弟的意思是,打开**.py的源代码么?这个简单,有几种方法:1,最简单,打开记事本,然后把**.py拖拽到记事本上。
(如果不知道记事本是啥,开始-运行,输入notepad)2,右键**.py,选择,打开为,然后选择记事本/写字板3,将.py文件的编辑器默认为记事本,方法为:右键**.py ->属性 ->修改,选择记事本,然后勾选选择框下边的复选框(大概的意思是:总是用选择的程序打开此类文件),单击OK4,安装一个python的编辑器,例如Notepad++,Gvim,Eclips,Kate,等等。
。
转载请注明出处51数据库 » python 打开软件